[GH-ISSUE #994] Server actions fail with [vite-rsc] invalid server reference on cold-start in dev #217

Open
opened 2026-05-06 12:38:16 +02:00 by BreizhHardware · 0 comments

Originally created by @eashish93 on GitHub (Apr 30, 2026).
Original GitHub issue: https://github.com/cloudflare/vinext/issues/994

Repro: App Router project, 'use client' component statically imports a 'use server' action, action invoked before browser has fetched the action file (e.g. dev-server restart while browser kept stale modules, or any race where the action call lands first).

Cause: @vitejs/plugin-rsc populates serverReferenceMetaMap lazily as files are transformed. Validation runs before the lazy import that would trigger the transform, so cold validation throws [vite-rsc] invalid server reference '/path/to/action.ts' and the action never runs. Tracked upstream as #641.

Workaround (in user's vite.config.ts):

environments: { rsc: { dev: { warmup: ['./lib/actions/**/*.ts'] } } }

Suggested fix: vinext could auto-inject dev.warmup for any file under app/ (and configurable action dirs) containing 'use server'.
Since vinext already scans for App Router files, adding 'use server' detection during that scan is cheap. Users wouldn't need any config.

Originally created by @eashish93 on GitHub (Apr 30, 2026). Original GitHub issue: https://github.com/cloudflare/vinext/issues/994 Repro: App Router project, 'use client' component statically imports a 'use server' action, action invoked before browser has fetched the action file (e.g. dev-server restart while browser kept stale modules, or any race where the action call lands first). Cause: @vitejs/plugin-rsc populates serverReferenceMetaMap lazily as files are transformed. Validation runs before the lazy import that would trigger the transform, so cold validation throws [vite-rsc] invalid server reference '/path/to/action.ts' and the action never runs. Tracked upstream as [#641](https://github.com/vitejs/vite-plugin-react/issues/641). Workaround (in user's vite.config.ts): ``` environments: { rsc: { dev: { warmup: ['./lib/actions/**/*.ts'] } } } ``` Suggested fix: vinext could auto-inject dev.warmup for any file under app/ (and configurable action dirs) containing 'use server'. Since vinext already scans for App Router files, adding 'use server' detection during that scan is cheap. Users wouldn't need any config.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/vinext#217
No description provided.