Skip to content

fix(rsc): handle shadowed local declarations in "use server" closure binding#1151

Open
james-elicx wants to merge 3 commits intovitejs:mainfrom
james-elicx:james/fix-use-server-scope-collision
Open

fix(rsc): handle shadowed local declarations in "use server" closure binding#1151
james-elicx wants to merge 3 commits intovitejs:mainfrom
james-elicx:james/fix-use-server-scope-collision

Conversation

@james-elicx
Copy link

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.

@hi-ogawa hi-ogawa self-requested a review March 20, 2026 06:04
Copy link
Contributor

@hi-ogawa hi-ogawa left a comment

Choose a reason for hiding this comment

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

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')
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's use toMatchInlineSnapshot for completeness (though I know AI is allergic to that 😅).

Copy link
Author

Choose a reason for hiding this comment

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

sorry about that - have done!

@hi-ogawa hi-ogawa self-assigned this Mar 20, 2026
@james-elicx james-elicx requested a review from hi-ogawa March 20, 2026 07:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants