-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
fix(ssr): fix live binding of default export declaration and hoist exports getter #19842
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
Merged
sapphi-red
merged 10 commits into
vitejs:main
from
hi-ogawa:fix-export-default-live-binding
Apr 21, 2025
Merged
Changes from 3 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ea37ba4
fix(ssr): fix live binding of default export declaration
hi-ogawa 73fef48
test: add test
hi-ogawa d5dba53
fix(ssr): hoist export default
hi-ogawa cfe14ae
chore: lockfile
hi-ogawa 1b32f51
Merge branch 'main' into fix-export-default-live-binding
hi-ogawa e9848b3
Merge branch 'main' into fix-export-default-live-binding
hi-ogawa 154bd8f
test: test more
hi-ogawa 7ce178e
test: tweak
hi-ogawa 4499cbe
test: more
hi-ogawa 20604c7
test: tweak
hi-ogawa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
packages/vite/src/node/ssr/runtime/__tests__/fixtures/cyclic2/test9/dep.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| import dep from "./index.js" | ||
| export default dep |
2 changes: 2 additions & 0 deletions
2
packages/vite/src/node/ssr/runtime/__tests__/fixtures/cyclic2/test9/index.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| import dep from "./dep.js"; | ||
| export default dep |
7 changes: 7 additions & 0 deletions
7
packages/vite/src/node/ssr/runtime/__tests__/fixtures/live-binding/dep.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| export default function f() { | ||
| return "before"; | ||
| } | ||
|
|
||
| export function update() { | ||
| f = () => "after"; | ||
| } |
6 changes: 6 additions & 0 deletions
6
packages/vite/src/node/ssr/runtime/__tests__/fixtures/live-binding/index.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import f, { update } from "./dep.js"; | ||
|
|
||
| const x = f(); | ||
| update(); | ||
| const y = f(); | ||
| export default [x, y]; |
3 changes: 3 additions & 0 deletions
3
packages/vite/src/node/ssr/runtime/__tests__/fixtures/live-binding/package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "type": "module" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -301,6 +301,25 @@ describe('module runner initialization', async () => { | |
| `[ReferenceError: Cannot access 'dep1' before initialization]`, | ||
| ) | ||
| }) | ||
|
|
||
| it(`live binding default export`, async ({ runner }) => { | ||
| const mod = await runner.import('/fixtures/live-binding/index.js') | ||
| expect(mod.default).toMatchInlineSnapshot(` | ||
| [ | ||
| "before", | ||
| "after", | ||
| ] | ||
| `) | ||
| }) | ||
|
|
||
| it(`export deafult expression is hoisted`, async ({ runner }) => { | ||
| // Node error is `ReferenceError: Cannot access 'dep' before initialization` | ||
| await expect(() => | ||
| runner.import('/fixtures/cyclic2/test9/index.js'), | ||
| ).rejects.toMatchInlineSnapshot( | ||
| `[ReferenceError: Cannot access '__vite_ssr_export_default__' before initialization]`, | ||
| ) | ||
| }) | ||
|
||
| }) | ||
|
|
||
| describe('optimize-deps', async () => { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
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.
Previously this was
["before", "before"].