-
Notifications
You must be signed in to change notification settings - Fork 56
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
Dynamically import locales #2047
Conversation
@RobbieTheWagner |
test-app/ember-cli-build.js
Outdated
@@ -19,4 +19,16 @@ module.exports = function (defaults) { | |||
const { maybeEmbroider } = require('@embroider/test-setup'); | |||
|
|||
return maybeEmbroider(app); | |||
|
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.
Do we need this commented out code?
I would love to find a way to make things work without needing to force flatpickr onto the window so early. I admit, I still don't understand why we need it on the window for locales to work. I would expect importing the locale and then passing what you imported in to work. |
Me too, it was working before because the lib was put in vendor.js that was loaded at the start of the app. https://github.com/RobbieTheWagner/ember-flatpickr/blob/93d73ca7d0f501c68702730b708f2f0eca321ed1/index.js. For the explanation, i'll try to make an example repo for a clearer explanation of the problem. My english is sometimes not the best. And flatpickr has a weird initialization logic. I'll do some research on my side. |
I've made an example repo with console.logs to see the problem. To be able to register a locale globaly, flatpickr must be registed before the locale file imported. Otherwise, the locale is never registered to the global window.flatpickr.l10ns. The problem is that ember calls the import 'flatpickr' after you import the locale. That moment is when the I know it's a weird behavior but that's how flatpickr deals with locales. Not sure if the explanation is better. |
I added an option to disable this behavior. So it can be manually disabled and then tree-shaked if needed.
Will need a glass of whiskey after this |
The merge from main broke the tests. I will take a look tomorrow |
What if the |
That's a possibility, but i don't know if the tree shaking will work if you dynamically import the locale based on runtime variables. Will try this later. |
It looks like if i do something like this:
It works. Webpack generates a bundle for each lang. These are lazy-loaded later. Great ! These bundlers are very smart. All the small red squares are a locale. When i choose a lang that is not already loaded it calls the chunk. |
Great, glad that dynamic importing seems to work! Let's do that then, and not add an initializer. |
Just a side note, but i tried to upgrade eslint-plugin-ember and there are some deprecations concerning using @ember/runloop and 'afterRender' queue. |
); | ||
|
||
// Pass all values and setup flatpickr | ||
scheduleOnce('afterRender', this, this._setFlatpickrOptions, element); | ||
} | ||
|
||
_setFlatpickrOptions(element: HTMLInputElement): void { | ||
const fastboot = getOwner(this)?.lookup('service:fastboot') as unknown as (FastbootService | undefined); | ||
@waitFor |
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.
@AmauryD can you please explain this waitFor
here? I thought test waiters would be in test files or test helpers?
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.
Due to the change of _setFlatpickrOptions to async, it caused issues with one test. I needed to add a waitFor statement in the suite. However, for user convenience, I preferred to add @waitFor
from @ember/test-waiters to the addon code and do not change the test suite, as there's a chance that consumers' test suites might also break.
What do you think ?
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.
@AmauryD I don't think application code should be handling cases for testing. If anything, we should add some of the waiting to the test helpers we ship, but I don't think we want to add waitFor
to the addon code. I could be wrong, but that addon sounds like it is for test helpers.
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'm fine with it.
Adding the waiting logic to the current test-support would be great. But i currently don't know how i would check that the operation of the flatpickr component is done without service level code or some trickery.
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 is great, thanks so much for taking this on!
No problem, thank's for your support ! |
No description provided.