mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[PR #527] [MERGED] fix: use server closure variable collision with local declarations #647
Labels
No labels
enhancement
enhancement
good first issue
help wanted
nextjs-tracking
nextjs-tracking
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/vinext#647
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/cloudflare/vinext/pull/527
Author: @james-elicx
Created: 3/13/2026
Status: ✅ Merged
Merged: 3/16/2026
Merged by: @james-elicx
Base:
main← Head:opencode/curious-tiger📝 Commits (10+)
26b73bafix:use serverclosure variable collision with local declarationsddcd284fix type errordab3bf8address commentsfb6e175more tweaksa966383more tweaks3cb7bccmore tweaks12c80f2fix: address remaining edge cases in use-server-closure-collision plugin2b561c2fix: handle ClassDeclaration in collectAllDeclaredNamesa14a1a0Merge remote-tracking branch 'origin/main' into opencode/curious-tigerd6ca338chore: update test imports to vite-plus/test and vite-plus📊 Changes
2 files changed (+1410 additions, -0 deletions)
View changed files
📝
packages/vinext/src/index.ts(+444 -0)➕
tests/use-server-closure-collision.test.ts(+966 -0)📄 Description
This was observed in the wild with Payload CMS.
Fix
Add a
"pre"-enforced Vite plugin (vinext:fix-use-server-closure-collision) that runs beforeplugin-rscsees the file. For any"use server"function whose body declares a variable that shadows an outer-scope name, it renames the inner declaration and all its usages within that function body to__local_<name>. The outer binding is untouched.After the rename,
periscopicno longer seescookiesreferenced inside the action, so it is not added tobindVarsat all. Only genuinely-closed-over variables (likeconfig, which is not redeclared inside the action) remain.Tests
tests/use-server-closure-collision.test.ts— unit tests that exercise the plugin transform directly:transformHoistInlineDirectiveon raw source and confirming the duplicate declaration🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.