[plugin-rsc] No way to wait for, or preload, the client modules an RSC payload references during SSR
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 18/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- react, typescript
- Domain
- full-stack
Research direction
The SSR client-module import happens in packages/plugin-rsc/src/ssr/shared.ts (the load path, with setOnClientReference) behind the memoized __vite_rsc_client_require__ in src/core/ssr.ts. Reproduce with the linked starter and watch the first curl for the Suspense fallback. Done means a public hook that exposes each pending client-module import so a framework can await it before sending the shell, which is a design decision for maintainers first.
Written by the indexing model from the issue text.
Description
Claude Opus 5.5 (high effort) wrote this; Claude Opus 5.5 (medium effort) reviewed it.
During SSR, plugin-rsc imports a client component's module the first time a payload references it, and React renders the closest <Suspense> fallback until that import resolves. So the first response after a server start differs from later ones, and a framework has no way to wait for, or preload, those imports.
How to reproduce
The repro is plugin-rsc 0.5.38's starter with <ClientCounter /> wrapped in <Suspense fallback={<p>loading...</p>}>, and ClientCounter importing its label from a new file, src/label.ts: https://github.com/nitedani-agent/plugin-rsc-repro-ssr-client-load
pnpm i && pnpm devcurl -s http://localhost:5173 | grep -o '<p>loading...</p>'prints<p>loading...</p>on the first request after the server starts.- Run it again, and it prints nothing, because the button is now in the shell.
pnpm build && pnpm preview(port 4173) does the same after each start.
<!-- first response (trimmed) -->
<div class="card"><!--$?--><template id="B:0"></template><p>loading...</p><!--/$--></div>
...
<div hidden id="S:0"><button>Client Counter<!-- -->: <!-- -->0</button></div><script>$RB=[];...
<!-- second response -->
<div class="card"><!--$--><button>Client Counter<!-- -->: <!-- -->0</button><!--/$--></div>
Streaming the fallback and then the content is valid React, but plugin-rsc gives a framework no API to make the first response match the later ones. vike-react-rsc's <Head> content missed the <head> on a fresh dev server's first request for this reason (nitedani/vike-react-rsc#32). Awaiting allReady or dropping the <Suspense> would fix the shell but stop the page from streaming its server-side data, so what I'm after is waiting only for the module loads.
It happens on the first render of each client module after a start, under a <Suspense>, whenever that module's first import takes longer than the shell. With a second client component added to the repro and rendered only on /?b, the first /?b request shows its fallback too, after earlier requests to /. Frameworks on plugin-rsc show it too once the import is slow enough. Each ran from its official RSC starter with the same page, and the counts are server starts:
| App | Request 1 after a start | Request 2 |
|---|---|---|
| This repro, dev cold, dev warm, and preview | fallback (2 of 2, 1 of 1, 2 of 2) | component |
This repro without the <Suspense> |
component, the shell waits for it | component |
| Waku 1.0.0-rc.4, React Router 8.5.1 RSC, TanStack Start 1.169.4 RSC | component, in every dev and prod start | component |
| The same three, the client component importing a chain of 200 small local modules | fallback in dev (each: cold 2 of 2, warm 1 of 1); in Waku's and TanStack Start's prod builds, the component (2 of 2) | component |
| Waku, with a 300 ms wait added before each client module's first import (dev) | fallback (cold 1 of 1, warm 1 of 1) | component |
| Next.js 16.4.3, webpack and Turbopack dev, with the 200-module chain too | component | component |
@vitejs/plugin-rsc 0.5.38, @vitejs/plugin-react 6.1.2, vite 8.3.5
react, react-dom, react-server-dom-webpack (vendored) 19.3.1
Node 26.12.1, Linux, pnpm 12.15.0
The three frameworks ran on plugin-rsc 0.5.38 and vite 8.3.5 (React Router's prod on 0.5.35, remix-run/react-router#15671)
plugin-rsc's SSR load imports the module on first use (ssr/shared.ts#L46-L76) behind a memoized __vite_rsc_client_require__ (core/ssr.ts#L13-L16), and React suspends on the pending import (requireAsyncModule). setOnClientReference reports a reference's assets, but never its pending import, so a framework still can't wait for it. Next.js wraps its client-module require and, in dev and in prerenders with cacheComponents, tracks each pending import (app-render.tsx#L2538-L2558). I think that's why even the 200-module chain doesn't show the fallback there.
I'd like an API that hands the framework each client-module import an SSR render starts (or preloads the modules a payload references), so it can wait for them before it sends the shell. vike-react-rsc wraps the internal __vite_rsc_client_require__ for this today (clientDeps.tsx).
#1476 is about the same SSR require cache (it never evicts), not about waiting on it.
- Dominant language
- TypeScript
- Stars
- 1.2k
- Forks
- 287
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 19
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from vitejs/vite-plugin-react
-
plugin-rsc: a client reference's CSS is linked before the CSS of the chunks it imports (build)Possibly taken @wozhenbang2004 claimed this 6 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
vitejs/vite-plugin-react#1570 ·
Maintainers usually reply within 1 day
-
pending triage
Difficulty 4/5 3-5 days Newbie friendliness 35/100
vitejs/vite-plugin-react#1581 ·
Maintainers usually reply within 1 day
-
[plugin-rsc] Build exits 0, but the app fails at runtime: a server action imported only by browser code is missing from the RSC buildPossibly taken @NeilPant claimed this 3 days ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 48/100
vitejs/vite-plugin-react#1578 ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 42/100
vitejs/vite-plugin-react#1577 ·
Maintainers usually reply within 1 day
-
[plugin-rsc] inline "use server" function declarations lose hoisting and throw TDZ ReferenceErrorPossibly taken @draarivpatel-ui claimed this 2 days ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 55/100
vitejs/vite-plugin-react#1566 · 1 comment ·
Maintainers usually reply within 1 day
All issues in vitejs/vite-plugin-react
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
earendil-works/pi#12615 ·
Maintainers usually reply within 1 day
-
My Caps shows "Shared" on private Caps that were never sharedPossibly taken @AksharP5 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
CapSoftware/Cap#4569 · 1 comment ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
OHDSI/Data2Evidence#3749 ·
Maintainers usually reply within 4 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 63/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Flagsmith/flagsmith-nodejs-client#332 ·
Maintainers usually reply within 2 days