-
-
Notifications
You must be signed in to change notification settings - Fork 274
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
Sharescopes do not work #3448
Comments
@ScriptedAlchemy can you have a look? the feature is not very documented in detail |
@itd-cba provide a repo |
I think I'm seeing this same issue. I'm using nx and we just bumped past 19.5.0 where they started consuming @module-federation's packages. I'm seeing separate scopes as well, and I'm trying to nail down the evidence. Will work towards providing a repo if I can. At a minimum will see if I can get the devtools screenshot like you have, @itd-cba |
@RichFinn-WTW if you do end up getting a repo together please feel free to tag me and @Coly010 to take a peek. |
Thanks @zackarychapple - I'm getting closer. I'm able to prove that the issue was introduced in nx 19.5.0. It's behind the |
I think I've found it. Not exactly what @itd-cba is seeing, but can prove that We were stuck after having upgraded to nx v20.4.0 (ng 19.1.3) from nx v18.1.2. To continue moving forward we downgraded I'll work on getting a repo out there that contains branches with the different configurations we have to demonstrate the path we took as well as the issue. |
I've created a repository that demonstrates the issue as I see it using nx 20.4.2: https://github.com/RichFinn-WTW/nx-mfe-scope-issue The readme sets the stage and describes what's happening. Thanks for taking a look. |
Describe the bug
Issue: Module Federation shareScopes Not Working as Expected
Description
We are currently migrating our large application to Module Federation and need to utilize the
shareScopes
feature because we cannot upgrade all microfrontends to new React versions simultaneously. Our approach is to have ashareScope
for each React version currently in use and include all additional dependencies in the same React scope.However, we are encountering an issue where sharing a scope that is not the "default" is not working. We can see the different scopes in the
window.__FEDERATION
variable, but two microfrontends using thereact19
scope are not sharing their dependencies correctly and end up loading their own React instances.Current Setup
We have a main app that integrates all remotes. The remotes define their shared dependencies via the
rsbuild
plugin. The main app registers the remotes at runtime with the following code:The main app defines its shared dependencies at build time using the following configuration:
For microfrontends that use React 19, we use the following configuration and attempt to leverage the
shareScope
feature:After the microfrondends got registered by the main app they will be loaded via
loadRemote
when they are actually needed. The "filterfalcon" gets loaded right after the remotes got registered and the second microfrontend is loaded when its route gets called.Observed Behavior
At runtime, both React 19 microfrontends have the
react19
shareScope, but they do not share dependencies correctly. Here is a snapshot of the window__FEDERATION__SHARE__
.And here the broken part:
![Image](https://private-user-images.githubusercontent.com/87694273/404933489-a926dc44-4b0c-464f-841d-f8ead7054cba.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkzNTg3NDIsIm5iZiI6MTczOTM1ODQ0MiwicGF0aCI6Ii84NzY5NDI3My80MDQ5MzM0ODktYTkyNmRjNDQtNGIwYy00NjRmLTg0MWQtZjhlYWQ3MDU0Y2JhLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTIlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjEyVDExMDcyMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWM3YTg2MTk4Nzg5MmQzOWJkMDhhNjJiMWMzNWM4NzFmN2Y0MjRjNmRjOGY2NzY2NzI3MGFlYzQzNGFlZTA3YzkmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.8l1B0ars_7npBTXD551xcE1GKZamy30TB5R73inRhKY)
Here we can see that both have the same scope but still both load their own dependencies.
Expected Behavior
Microfrontends using the same
react19
scope should share the React instance instead of loading separate copies.Questions
Any guidance or insights would be greatly appreciated!
Used Package Manager
pnpm
System Info
- Module Federation Version: 0.8.9 - React Versions: 18.3.1, 19.0.0 - Build Tool: `rsbuild`
Validations
The text was updated successfully, but these errors were encountered: