-
-
Notifications
You must be signed in to change notification settings - Fork 276
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
Multiple instances of singleton shared dependencies are fetched and ran in runtime - "Cannot read properties of null (reading 'useEffect')" #3170
Comments
What if you set it to version first for the strategy |
React plugin takes options. Ensure router and runtime are set to false. Inspect types to see exactly what to pass. |
I belive this issue is not specific to react. We had very similar problems with an internal package that we use as a shared dependency, which relies it being a singleton - it exports an instance of a class that needs to be initialized, and occasionally the microfrontend causes a runtime error when it loads a different, un-initialized instance. |
We had that setting when we ran into this issue for the first time - we later changed to loaded-first hoping that it would fix it but unfortunately it didn't. |
Do you use any dynamic remotes that are not import() or import from? |
Okay so doing this: danhorvath/rsbuild-demo#1 I have added window.loaction.reload() to the remote, this will refresh the page perpetually till a hook error happens then stop since useEffect cant be called. With version-first, ensuring i share react/(jsx-dev-runtime|jsx-runtime), and setting the packages to ^ and not pinning them - it i am not able to make it throw an error. If you can use that PR, edit it and make it crash we can take a look further, but i left it for a few min (about 3000 page reloads) without error, soon as i remove version first, within ~60 reloads it would crash depending on what loaded first and causing a missmatch in version. |
even without "react/": { or the ^ on the react and react dom in the package json, it still seems to work - as long as version-first is set. |
I miss to consider the shared is loading ... Okay i fix it on this pr #3176 |
If what you mean by dynamic remotes is a runtime generated remote url, like The fix that @2heal1 provided should work for the exact configuration with However, do you happen to have any intuition on how this could have possibly happened when running with version-first? One thing worth mentioning though was that at the time we were running with the rs-build built-in module federation configuration - which we understood is actually module federation 1.5 (since it's using Unfortunately we were not able to reproduce it easily in a simple repro like the one @danhorvath linked in this issue (it was in our real setup that uses 4 remotes all which had shared dependencies in different versions). |
You're using v2. Otherwise send me an NDA and internal repo. |
I think it's fine, we are not going to downgrade regardless and we'll upgrade the rsbuild plugin to v0.7.0. It was more of a curiosity rather than a real issue. Thanks again for the quick reaction and fix on this 🎉 |
Ah, you're on an older version of RSBuild as a whole. Then yes, it may be a bug in the runtime itself that's been resolved since. If you experience it on the latest versions, let us know and, if possible, make a reproducible sample that we can look at. |
We were on the latest versions at the time of writing. There is one aspect of our production setup that we couldn't model well in the repro, which is that in our setup the chunks (including the shared dependencies) can be cached by the browser, but the remoteEntry is not, so often on the initial page load the remote entry is fetched faster than the shared dependencies of the host, but on subsequent loads most (usually all) shared dependencies are loaded from the disk. I wonder if this is the reason why we experienced the same (or at least very similar) runtime error with the version-first policy too. I will try to adjust the repro with the caching mechanism to check this. But in any case, thank you both for the quick help, it is very much appreciated. We'll verify tomorrow if the latest version resolves our issue. |
Do you have a prod url? If we can repro it in prod, we can possibly place breakpoints there and try to diagnose it. It may be the reason. But version first in general seems to be far more reliable than loaded first. Loaded first is the old v1 mechanism which is less deterministic. You may also want to consider using the json protocol instead of the js remotes instead. Since it is also more robust as well as we can compute the tree before any evaluation takes place. |
We rolled back to use our old webpack setup (with the old module federation) when we noticed this issue so I can't provide a url.
That's good to know. We plan to migrate to using the manifest.json as soon as we stabilized our rsbuild setup. We've been working with the loaded-first strategy mainly to avoid the runtime error (as suggested here #2898 (comment)) and for the performance benefits. Thank you for the suggestion, we'll check if using version-first + ‘manifest.json‘ is stable in our case. |
manifest.json was also designed to be used to control MF at the server side. If you use the json protocol you can render "module snapshots" which are lock files for the runtime - the runtime will never change behavior when a a module snapshot is present, this is how we orchestrate and control our several thousands of remotes at Bytedance. DM me if you want a reference of it, we do not readily supply one since it requires additional infra for user to leverage it. |
Interesting, we'll consider that option, thanks! Regarding this issue - we verified the fix on our end and we don't see the runtime error anymore with the latest module federation runtime. Thanks you for the help! |
Following your advice, we tried switching to the |
Can you share the reproduction with version first. I'd still like us to investigate it! |
We included a link with the reproduction in the new issue that we created, it's in the same repo as above but on a branch called |
Describe the bug
When a host app imports a remote directly without lazy loading, in certain scenarios the shared singleton dependencies (in our case React) get downloaded for both the host and the remote, they can end up each using their own respective versions of that shared dependency.
After some investigation, we think the issue happens when the remote entry files finishes downloading before the host dependencies - see the example below, the host depends on react 18.2.0, the remote on react 18.3.1.
In cases where the react 18.2.0 chunk ends up finishing loading first, we do not see this issue:
![image](https://private-user-images.githubusercontent.com/23309966/382826201-3ebd9079-8255-42b2-a86f-e67afa9b3b5c.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk0NTc5MzUsIm5iZiI6MTczOTQ1NzYzNSwicGF0aCI6Ii8yMzMwOTk2Ni8zODI4MjYyMDEtM2ViZDkwNzktODI1NS00MmIyLWE4NmYtZTY3YWZhOWIzYjVjLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjEzVDE0NDAzNVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTQ2NDYwZTkxNzhlNTljMWZiMzZmZGVlZGVhMzk3NDc3OGY2ZWY3YmQ1MGY4NWVlOTMwODgxZTE4NGFkZTU0NjEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.9rPAhKGj3i3NxX3CY8Ra1FyOBxaTXEnEEg58VGamcpg)
![image](https://private-user-images.githubusercontent.com/23309966/382825638-2d23c307-890b-46df-b139-985e60c64c27.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk0NTc5MzUsIm5iZiI6MTczOTQ1NzYzNSwicGF0aCI6Ii8yMzMwOTk2Ni8zODI4MjU2MzgtMmQyM2MzMDctODkwYi00NmRmLWIxMzktOTg1ZTYwYzY0YzI3LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjEzVDE0NDAzNVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWZiNGQxZDlkNzM5ZTMxNThlMjYxYTI5MjU1ZmMzZjJlMWI5MmI0YzNlOGU5Yzc2ODU1NGM3OWYyOGNhOWEyM2QmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.4SplegjAQy-fhoOU-f3f9qpuZRjMYVHI_MszlKN9_jM)
Reproduction steps:
run
pnpm i
run
pnpm --filter=host dev
run
pnpm --filter=remote dev
Expected: page loads correctly
Actual: page fails to load due to incorrect request for the deps of remote app.
The example config is (using the latest versions from
@rsbuild/core
,@rsbuild/plugin-react
and@module-federation/rsbuild-plugin
):Host
Remote
Reproduction
https://github.com/danhorvath/rsbuild-demo
Used Package Manager
pnpm
System Info
Validations
The text was updated successfully, but these errors were encountered: