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

Merged
merged 3 commits into from Mar 2, 2018

Conversation

Projects
None yet
3 participants
@cmyers
Contributor

cmyers commented Nov 18, 2017

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.

@marwahaha marwahaha changed the title from Fix #3883 lazy load parentLocale in defineLocale, fallback to global if missing to [bug] Fix #3883 lazy load parentLocale in defineLocale, fallback to global if missing Nov 20, 2017

@cmyers cmyers changed the title from [bug] Fix #3883 lazy load parentLocale in defineLocale, fallback to global if missing to [bugfix] Fix #3883 lazy load parentLocale in defineLocale, fallback to global if missing Nov 30, 2017

@marwahaha marwahaha requested a review from ichernev Dec 22, 2017

@marwahaha

This comment has been minimized.

Member

marwahaha commented Dec 22, 2017

@ichernev - you should look at this one

@marwahaha

This comment has been minimized.

Member

marwahaha commented Jan 2, 2018

@cmyers - could you write some quick documentation for this over here? Or, if you think this doesn't deserve docs, just let me know.

@cmyers

This comment has been minimized.

Contributor

cmyers commented Jan 2, 2018

@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.

cmyers added a commit to cmyers/momentjs.com that referenced this pull request Jan 6, 2018

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.
@cmyers

This comment has been minimized.

Contributor

cmyers commented Jan 6, 2018

Submitted momentjs.com PRs for documentation:

moment/momentjs.com#484
moment/momentjs.com#485

@marwahaha marwahaha added Docs written and removed Needs docs labels Jan 7, 2018

marwahaha added a commit to moment/momentjs.com that referenced this pull request Mar 2, 2018

Update Customise parent locale (#485)
* 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

@marwahaha marwahaha merged commit f6c7069 into moment:develop Mar 2, 2018

5 checks passed

Base branch Looks good!
Generated files No edits to generated files! :)
Title Your title looks great!
continuous-integration/travis-ci/pr The Travis CI build passed
Details
licence/cla Contributor License Agreement is signed.
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment