Skip to content

fix(react-intl): support opting out of global intl context (#4118)#4125

Merged
longlho merged 3 commits intoformatjs:mainfrom
voodoocreation:support-opting-out-of-global-context
Jun 6, 2023
Merged

fix(react-intl): support opting out of global intl context (#4118)#4125
longlho merged 3 commits intoformatjs:mainfrom
voodoocreation:support-opting-out-of-global-context

Conversation

@voodoocreation
Copy link
Contributor

Changes

This PR is just to address what was raised in issue #4118.

Because the react-intl context 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 on window when 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 of react-intl, which is currently not supported without resorting to hacking the react-intl package via patch-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-intl context 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.

@longlho longlho merged commit 357c861 into formatjs:main Jun 6, 2023
@longlho
Copy link
Member

longlho commented Jun 6, 2023

Thanks a lot for your contributions!

@voodoocreation voodoocreation deleted the support-opting-out-of-global-context branch June 6, 2023 03:36
@voodoocreation
Copy link
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 🙏

@longlho
Copy link
Member

longlho commented Jun 6, 2023

yeah I published it yesterday

unional pushed a commit to unional/formatjs that referenced this pull request Jun 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants