Skip to content
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(ssr): named export should overwrite export all #19534

Merged
merged 1 commit into from
Mar 2, 2025

Conversation

hi-ogawa
Copy link
Collaborator

@hi-ogawa hi-ogawa commented Feb 28, 2025

Description

This change should also help when named export is hoisted in #18983.

Comment on lines +302 to +316
// ESM spec doesn't allow conflicting `export *` and such duplicate exports are removed (in this case "d"),
// but this is likely not possible to support due to Vite dev SSR's lazy nature.
// [Node]
// $ node -e 'import("./packages/vite/src/node/ssr/__tests__/fixtures/named-overwrite-all/main.js").then(console.log)'
// [Module: null prototype] { a: 'main-a', b: 'dep1-b', c: 'main-c' }
// [Rollup]
// Conflicting namespaces: "main.js" re-exports "d" from one of the modules "dep1.js" and "dep2.js" (will be ignored).
expect(mod).toMatchInlineSnapshot(`
{
"a": "main-a",
"b": "dep1-b",
"c": "main-c",
"d": "dep1-d",
}
`)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just learned that ESM spec says duplicate names from export * from ... should be removed entirely 😮 (Didn't actually read the spec but it's on MDN https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export#specifications:~:text=If%20there%20are%20two%20wildcard%20exports%20statements%20that%20implicitly%20re%2Dexport%20the%20same%20name%2C%20neither%20one%20is%20re%2Dexported.)

I think this case is hard to handle on Vite SSR model, so the behavior here is that first export * wins.

@hi-ogawa
Copy link
Collaborator Author

/ecosystem-ci run

Copy link

pkg-pr-new bot commented Feb 28, 2025

Open in Stackblitz

npm i https://pkg.pr.new/vite@19534

commit: 7748fc7

@hi-ogawa hi-ogawa changed the title fix(ssr): named export should overwrites export all fix(ssr): named export should overwrite export all Feb 28, 2025
@hi-ogawa hi-ogawa marked this pull request as ready for review February 28, 2025 03:16
@sapphi-red sapphi-red added p3-minor-bug An edge case that only affects very specific usage (priority) feat: ssr labels Feb 28, 2025
@patak-dev patak-dev merged commit 2fd2fc1 into vitejs:main Mar 2, 2025
21 checks passed
@hi-ogawa hi-ogawa deleted the fix-named-export-vs-export-all branch March 2, 2025 23:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: ssr p3-minor-bug An edge case that only affects very specific usage (priority) trigger: preview
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Vite SSR doesn't overwrite * re-export by named export
3 participants