-
Notifications
You must be signed in to change notification settings - Fork 253
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
Fix shared dependencies loaded multiple times #584
base: main
Are you sure you want to change the base?
Conversation
92eb2c2
to
74c2414
Compare
Hi @wurstbonbon, it seems that CI is failed in serve mode. |
74c2414
to
6a99630
Compare
Hi @flyfishzy, I figured out why the CI was failing. Before my changes the I created a new example / test using react with zustand to demonstrate what has been fixed. |
Hi @flyfishzy, thanks for retriggering the tests. Any chance that failing tests are just a fluke? I've run them locally on macOS with node 16 a couple of times and I can't reproduce the failure. Also strange that it would only fail on macOS with node 16. |
Hi @wurstbonbon I just tried this with the exact same scenario as this: #446. And the fix is not working maybe I am missing somethig. I need to add Happy to help. I still have the same error |
Hi @acollazomayer, are both host and remote using vite? I had to add How is what you are doing different from the example that I added? I tried sharing |
@wurstbonbon any update on the PR? |
@wurstbonbon any updates on this PR? It seems to only be failing on one test now; |
}) | ||
if (importSharedRequired && !importSharedFound) { | ||
magicString.prepend( | ||
`import {importShared} from '/${this.getFileName( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In remotes, if the shared lib is not generated, this import will not work.
I had to replace it with
'./${this.getFileName(
to fix it.
But this PR does resolve a issues I had where react was loaded multiple times, great job.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if I can follow.
getFileName
includes the asset directory so for me the import ends up being.
<HOST>/asset/asset/__federation_fn_import-<HASH>.js
I did change the code to replace the asset directory with a dot to get a relative import. But I don't know it that addresses the problem that you are having. Help is appreciated :)
Great that there is finally something happing here 👍 @Shelrothman |
@wurstbonbon Any updates on this PR? We'd urgently need this fix to be released to get reactflow to work in a remote component |
unfortunately, there are no updates as far as I know. My team has had to shift to a new build tool. Now we are trying to use |
Do you have any news about this fix? Will it be applied, or are there alternatives that can be done until this solution is implemented? |
@Shelrothman can you highlight problems you had with rsbuild? |
Hey @pganster unfortunately, I don't think I can be of much help. rsBuild is fine if all the remote apps use the same build-tool, but ours do not, so it didn't work out. We may revisit later on, but way too much developer time has already been spent on it so it wont be for a while most likely. |
Just a heads up: We've now successfully switched all our services from vite + this module federation plugin to rsbuild. RsBuild builds upon the module-federation/core and is for now better maintained. For now we didn't encounter any major issue that prevented us from switching. |
Description
There are many open issues regarding shared dependencies (often react) that are loaded multiple times:
#446
#478
#429
...
Here is my understanding what is going on and were the problems lies. Correct me if I’m wrong, I’m just stumbling through the code trying to make sense of it.
The last version that work well with React and libraries that depend on React is 1.1.14. With 1.2.0 came this commit 49b6cae It moved the transformation of the shared module imports from
generateBundle
totransform
.This is not working well together with the CommonJS plugin. The
transform
seescommonjsHelpers.js
imports and imports likenode_modules/react/index.js?commonjs-proxy
. It does not transform those imports and they end up as direct imports instead ofimportShared()
calls. This will then cause two instances of e.g. react to be imported one from the host and one from the remote.I made a ham-fisted attempt to fix this by adding a second import conversion round in
generateBundle
. This sort of reverts the changes done in 49b6cae. Honestly I don’t think this makes a lot of sense, but it could be a starting point for a discussion. Note: The fix does not work for SystemJS. Because by the timegenerateBundle
is called for SystemJS the imports from the CommonJS plugin are no longer recognisable as shared imports.The commit mentioned above was introduced to fix this issue #334 I’ve tried to reproduce the issue on the given example repo. Using 1.1.14 and even 1.1.12, but was unable to do so. So I don’t understand what the actually initial problem was. Could be that I'm doing something or that changes in vue cause this to no longer happen.
Maybe a way forward would be to more thoroughly revert back to the initial approach of doing the conversion in
generateBundle
.Additional context
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).