fix(dev-server-rollup): dedupe imports from outside root #2723
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What I did
Explainer
Same file was imported by a module inside
rootDir
and a module outsiderootDir
in such a way that from the browser perspective it's 2 different files.I ran into this when playing with MDX in the
storybook-builder
, where some deps located in root monorepo node_modules were importing React in a different way to the way I was importing in my subpackage (where subpackage was a root dir).As a result, prebundled React was loaded twice from 2 different URLs:
For
rootDir=packages/storybook-builder/
browser requests looked like:inside
:http://localhost:3000/node_modules/.prebundled_modules/react.mjs
outside
:http://localhost:3000/__wds-outside-root__/2/packages/storybook-builder/node_modules/.prebundled_modules/react.mjs
So basically for outside modules it was resolved relative to their own root path
/__wds-outside-root__/2
.It's not only a React problem, but also:
This was such a rollercoaster this bug, I almost gave up at some point, because I needed to learn lots of details about WDS internals and rollup adapter specifically, fun stuff :D