cloudflare / cloudflare/vinext

Server actions fail with [vite-rsc] invalid server reference on cold-start in dev

Open
#994 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
8.8k
Forks
406
Avg merge
2d 6h
Merged PRs (30d)
120

Description

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.

Contributor guide

Open the contributing guide

Research direction

Start with vinext's existing App Router file scan and the dev configuration represented by vite.config.ts. Reproduce the cold-start race with a statically imported use server action, then trace where server actions are detected and warmup entries are assembled. Done means eligible action files are automatically warmed in dev, including configurable action directories, without user configuration.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
build-system, developer-experience
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
64/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.