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 Microfrontend does not work on an app with different React versions #559
Comments
have you tried setting 'react' & reactdom in the shared property? |
@raffidahmad but what if you dont want to share react version? |
it doesn't share them technically, it just ensures the same version is used and also only loads it once rather than twice |
@raffidahmad Thanks that really works. But it requires to use top level await for using |
Ah you must be using static imports then correct? |
@raffidahmad not sure, actually const RemoteComponent = lazy(() => import('remote/Component')); Looks like dynamic import call. What is another option? |
Tryed to use remote component with static imports, like so import RemoteLocal from 'remote/Component'; and almost the same error with
|
I did, it's in the repo, and the federation plugin downloads both react versions but they get mixed somehow, so one copy is aware of the other and that in react results in errors (only 1 react copy allowed). Ideally, both react versions are donwloaded, and the code from remote only imports from remote's react version and the code from host only imports from host's react version |
Versions
Reproduction
Here is a sandobox:
https://codesandbox.io/p/github/CerealPlayer/react-federation/main?file=%2F.codesandbox%2Ftasks.json%3A17%2C23&workspaceId=5db67876-a84e-4ee6-9441-cef04c6a5078
Repo:
https://github.com/CerealPlayer/react-federation
Steps to reproduce
Clone the repo, npm install in the project's root, run
npm start
to run both apps and click on the button inhttp://localhost:3000
. There's a host app that renders a microfrontend living in the remote app, exposed via Vite Plugin Federation. Both apps run React, except one (the host) is React 17 and the other (the remote) was built with React 18. The remote app's exposed component is wrapped in a Custom Element to try to isolate React in case it is not the same version as the one in the hostWhat is Expected?
Since both apps use different versions of React, the shared react file from the remote is used instead of the one in the host, so both versions on React can live together. If the versions are the same, it would be expected that the host's react file is the only one in use.
What is actually happening?
Both host and remote react files are downloaded but we see this error.
Which seems to indicate that one of the react copies was not properly generated or the libraries are not properly shared.
Is there something that I'm missing? I would expect that since the remote's custom element calls ReactDOM.createRoot(...).render inside a shadow root, host's react shouldn't be aware of it.
The text was updated successfully, but these errors were encountered: