-
Notifications
You must be signed in to change notification settings - Fork 261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Removing the i18n middleware from the application #10923
Conversation
@@ -90,7 +90,7 @@ const errorHandler = Vue.config.errorHandler || console.error; // eslint-disable | |||
createApp(nuxt.publicRuntimeConfig).then(mountApp).catch(errorHandler); // eslint-disable-line no-undef | |||
|
|||
function callMiddleware(Components, context) { | |||
let midd = ['i18n']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was the only place I found it. If you can find it elsewhere let me know.
shell/initialize/App.js
Outdated
// Ensure we initialize i18n for all pages | ||
this.$store.dispatch('i18n/init'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you have a better idea of where we should init this let me know.
I moved this from the store/index because the store/index didn't actually call it for every page. Notably, if you refreshed the login page after changing the language it would switch back to english.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps from within the install function of the i18n plugin itself? I think we have the store available to us at that point.
Honestly, I think that it fits here just as well. This is essentially the root of our app and dispatching some sort of init method makes sense at this point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea. It doesn't look like we currently expose the store to the install function and useStore is only evailable in the setup function within that plugin. Is there a reason we shouldn't expose it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We must install the plugin always after the store, since that's how it works, plus that's something which belongs to the plugin only and it's easier to find.
Since in the plugin install we have the options (as _options
), should we not be able to dispatch it there?
@@ -778,7 +778,6 @@ export const actions = { | |||
} | |||
|
|||
res = await allHash(promises); | |||
dispatch('i18n/init'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No point in having it here if we need it for every page and we're already making that call elsewhere.
c0a5986
to
a47f883
Compare
shell/plugins/i18n.js
Outdated
console.warn('The implicit addition of i18n options has been deprecated in Rancher Shell and will be removed in a future version. Make sure to invoke `Vue.use(i18n)` to maintain compatibility.'); | ||
// This is being done for backwards compatibility with our extensions that have written tests and didn't properly make use of Vue.use() when importing and mocking translations | ||
// Example failing test https://github.com/rancher/dashboard/actions/runs/8927503474/job/24521022320?pr=10923 | ||
const isThisFileBeingExecutedInATest = process.env.JEST_WORKER_ID !== undefined || process.env.NODE_ENV === 'test'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't sure which would be true in our extensions so I used both.
Do we even want to use this pattern? It's a little odd but it provides the backwards compatibility while keeping our production environment in the ideal state.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK process.env.NODE_ENV === 'test'
is the standard.
This is what we use in other configs:
https://github.com/rancher/dashboard/blob/master/shell/babel.config.js#L23-L28
Also, I've never seen the other one, but I dunno everything 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did open an issue for Kubewarden to fix this1. Maybe this is a scenario where we need to identify and update all extensions that are relying on this behavior.
Ideally, we would be able to remove this pattern after that's done.
Footnotes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switched to process.env.NODE_ENV === 'test'
and running the new tests.
And yeah, it's definitely temporary so I think it's fine to do for now.
a47f883
to
5312b64
Compare
Whenever you're ready, feel free to let me know if you'd like any additional changes or if you approve. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -14,7 +14,7 @@ global.TextEncoder = TextEncoder; | |||
global.TextDecoder = TextDecoder; | |||
|
|||
Vue.config.productionTip = false; | |||
Vue.use(i18n); | |||
Vue.use(i18n, { store: { dispatch() {} } }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should dispatch be mocked with jest.fn()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it could actually just be entirely omitted now that I access it using the optional operator. If not, yeah we should mock it.
I'll address it in my next PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we mock the dispatch, then we should mock everything else too.
In both cases we are not that strict though, as we do not test the i18n, we just want to not break it.
Summary
Removing the i18n middleware from the application
Technical notes summary
The i18n middleware only initialized the i18n store. I moved the initialization elsewhere.
Areas or cases that should be tested
Translations on any page could be tested.
Screenshot/Video
i18n.mp4
Checklist