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; |
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
).