fix(rsc): handle shadowed local declarations in "use server" closure binding#1151
Open
james-elicx wants to merge 3 commits intovitejs:mainfrom
Open
fix(rsc): handle shadowed local declarations in "use server" closure binding#1151james-elicx wants to merge 3 commits intovitejs:mainfrom
james-elicx wants to merge 3 commits intovitejs:mainfrom
Conversation
hi-ogawa
reviewed
Mar 20, 2026
Contributor
hi-ogawa
left a comment
There was a problem hiding this comment.
Great find and thanks for the fix!
Comment on lines
+544
to
+546
| const result = await testTransform(input) | ||
| expect(result).toContain('.bind(null, config)') | ||
| expect(result).not.toContain('bind(null, cookies') |
Contributor
There was a problem hiding this comment.
Let's use toMatchInlineSnapshot for completeness (though I know AI is allergic to that 😅).
Author
There was a problem hiding this comment.
sorry about that - have done!
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
This PR fixes a bug where periscopic misclassifies block-scoped declarations inside a
"use server"function body as closure variables when the same name exists in a scope, causing a syntax error in the hoisted output (ran into this when testing Payload CMS with Vinext).It essentially collects the names of local declarations from the function's scope and then stop them from being bound.
There's also a few regression tests that were generated by AI.
This is an attempt to upstream a real fix for cloudflare/vinext#527.