modernweb-dev / web

Guides, tools and libraries for modern web development.
https://modern-web.dev
MIT License
2.15k stars 271 forks source link

fix(dev-server-rollup): dedupe imports from outside root #2723

Closed bashmish closed 2 months ago

bashmish commented 2 months ago

What I did

Explainer

check unit test for even more descriptive example

Same file was imported by a module inside rootDir and a module outside rootDir 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:

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

changeset-bot[bot] commented 2 months ago

🦋 Changeset detected

Latest commit: 8552a4a4054b097d6063f87ec82087ea54609ae1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package | Name | Type | | ---------------------- | ----- | | @web/dev-server-rollup | Patch |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR