-
Notifications
You must be signed in to change notification settings - Fork 7k
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
[bugfix] Fix #3883 lazy load parentLocale in defineLocale, fallback to global if missing #4310
Conversation
@ichernev - you should look at this one |
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
@marwahaha No problem I'll take a look at that section and update as necessary. I planned on updating the warnings section for parent-locale also being as that warning was removed some time ago. |
This adds the description of defining a locale with a parent that hasn't itself been defined or loaded yet which has been available since 2.16.0. This adds the additional behavior when creating a moment of lazy loading the parent locale if it isn't already loaded, or defaulting to the global locale if the parent doesn't exist. See PR (moment/moment#4310) As the next version number isn't determined yet, this should be merged only with the next release that includes the above PR.
Submitted momentjs.com PRs for documentation: |
* Update Customise parent locale This adds the description of defining a locale with a parent that hasn't itself been defined or loaded yet which has been available since 2.16.0. This adds the additional behavior when creating a moment of lazy loading the parent locale if it isn't already loaded, or defaulting to the global locale if the parent doesn't exist. See PR (moment/moment#4310) As the next version number isn't determined yet, this should be merged only with the next release that includes the above PR. * Update 00-intro.md
Fixes #3883. It's currently possible to define a locale with a parent that is not yet defined. However, in the case of this bug when attempting to create a moment using a child locale with a parent that hasn't been loaded yet or hasn't been defined causes an exception to be thrown during prepareConfig.
This fix first attempts to load the parent locale during
defineLocale
if it can't be found initially. If in the case that a moment is created or a locale is set with a child who's parent can't be loaded or hasn't been defined,chooseLocale
returns the global locale instead of null. This mitigates the error described in this bug report in the instance the parentLocale can't be located, and follows the same logic when defining a child can't load a parent. I've added a test for this case.As this is an edge case it may not be necessary, but makes for a nicer experience rather than having an unhandled exception thrown. I considered adding a warning in
chooseLocale
but this affected a number of tests.Also, a warning was previously shown to indicate the parentLocale is missing but was removed (assuming due to the ability to define a parent after a child). However, the documentation specifies that it should still show the warning? I'm assuming in this instance the documentation needs updating.
Apologies if these scenarios have already been discussed and addressed.