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
[react-intl] Context exposed on window is causing issues within a microfrontend infrastructure #4118
Comments
I'd recommend not using different versions of |
That's not possible in our case, we have teams all over the world who own their own codebases and deploy independently from each other, with different maintenance schedules, so it's impossible to ever guarantee that all codebases have the same version of We don't have the mismatched provider issue because the provider is specific to each bundle - we have no issues with module resolution because our infrastructure operates differently to the scenario you described, whereas There should be some way of opting out of this shared |
I'd recommend you use patch-package to remove it then. |
I just want to reiterate that within a large organisation, it's not particularly scalable or sustainable to have hundreds/thousands of repos all patch this problem using I do understand your reasons for implementing it in this way, but it doesn't account for every possible infrastructure that your package is used within. It's sensible to make it the default behaviour for sure, but to not allow it to be opted out of creates major problems for other use cases. |
I'm open to making this optional if there's a PR. |
Thank you - I'll see what I can do 🙏 |
Have opened a very simple PR (#4125). I tried to avoid introducing any duplication or fragmentation and kept it very simple so that it won't impact future changes or the way that anything else is wired up and simply allowing it to work the way it did prior to |
…4118) (formatjs#4125) Co-authored-by: Raice Hannay <raice.hannay@xero.com>
Which package?
react-intl
, version>= 6.3.0
.Describe the bug
In our organisation, we use a combination of single-page apps (SPAs) and microfrontends (MFEs), each of these projects is completely independent from each other and have their own dependencies, and are loaded via static assets which are compiled with TypeScript via Webpack. The problem with this particular code is that it forces all of them to use the
react-intl
context generated by the first thing to load (the SPA generally), which may be on a completely different version ofreact-intl
to any of the MFEs that are loaded on the page, which means if these versions use an incompatible context, there's no way to engineer around that, as no alternative is provided withinreact-intl
to avoid usingwindow.__REACT_INTL_CONTEXT__
, which leads to errors being thrown when some expected values within thereact-intl
context aren't defined, due to it being generated by a different version ofreact-intl
.It would be very useful to allow some way to override this behaviour, to keep the context strictly to the scope of each bundle without it depending on global values on
window
To Reproduce
You would need to have a SPA using one version and then have it load an MFE that's on a different version that expects a different context to be present.
Codesandbox URL
Unfortunately the codebases are private within my organisation, so cannot be shared.
Expected behavior
I would expect each set of bundled code to use its own
react-intl
context, rather than inheriting whatever is onwindow
.Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
It's not device or browser specific, but rather an issue with relying on globally-exposed values when you can't guarantee consistency within all infrastructures.
The text was updated successfully, but these errors were encountered: