fix(react-intl): support opting out of global intl context (#4118)#4125
Merged
longlho merged 3 commits intoformatjs:mainfrom Jun 6, 2023
voodoocreation:support-opting-out-of-global-context
Merged
fix(react-intl): support opting out of global intl context (#4118)#4125longlho merged 3 commits intoformatjs:mainfrom voodoocreation:support-opting-out-of-global-context
longlho merged 3 commits intoformatjs:mainfrom
voodoocreation:support-opting-out-of-global-context
Conversation
Member
|
Thanks a lot for your contributions! |
Contributor
Author
|
Thanks! Is there anything further I need to do within the release process or have you got it from here? I didn't bump the package version because it looked like that wasn't done within previous PRs and may have been done by an admin performing a release after merging. Just let me know if there's anything else I need to do 🙏 |
Member
|
yeah I published it yesterday |
unional
pushed a commit
to unional/formatjs
that referenced
this pull request
Jun 7, 2023
…4118) (formatjs#4125) Co-authored-by: Raice Hannay <raice.hannay@xero.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
This PR is just to address what was raised in issue #4118.
Because the
react-intlcontext is created in the upper scope and is hit instantly, the cleanest way was simply to reference an optional new global value (window.__REACT_INTL_BYPASS_GLOBAL_CONTEXT__) to allow consumers to opt out of using a globally-exposed context onwindowwhen it would cause major issues within their application/system infrastructure.If
window.__REACT_INTL_BYPASS_GLOBAL_CONTEXT__isn't defined, it will simply work using the default behaviour. This is just to provide the option to allow consumers to bypass that when the bundled code needs to operate in a more isolated context when it's not possible to ensure all running apps are on the exact same version ofreact-intl, which is currently not supported without resorting to hacking thereact-intlpackage viapatch-package, which unfortunately isn't a sustainable solution if that patching is required in hundreds of repositories within a company.I would have preferred to avoid adding the extra global property, but any other solutions would have resulted in much more significant changes and/or duplication due to the
react-intlcontext being set in the upper scope rather than within a function call, so in order to keep the scope of the changes small and allow everything to continue to operate largely the same, this was the simplest way forward.