[plugin-rsc] No way to wait for, or preload, the client modules an RSC payload references during SSR
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 18/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Bastante claro
- Estado de actividad
- Activo
- Stack tecnológico
- react, typescript
- Área
- full-stack
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- TypeScript
- Estrellas
- 1.2k
- Forks
- 287
- Merge medio
- 1 d 17 h
- PR fusionados (30 d)
- 19
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de vitejs/vite-plugin-react
-
plugin-rsc: a client reference's CSS is linked before the CSS of the chunks it imports (build)Posiblemente ocupada @wozhenbang2004 la tomó hace 6 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
vitejs/vite-plugin-react#1570 ·
Los mantenedores suelen responder en 1 día
-
pending triage
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
vitejs/vite-plugin-react#1581 ·
Los mantenedores suelen responder en 1 día
-
[plugin-rsc] Build exits 0, but the app fails at runtime: a server action imported only by browser code is missing from the RSC buildPosiblemente ocupada @NeilPant la tomó hace 3 días. Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
vitejs/vite-plugin-react#1578 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 3-5 días Aptitud para principiantes 42/100
vitejs/vite-plugin-react#1577 ·
Los mantenedores suelen responder en 1 día
-
[plugin-rsc] inline "use server" function declarations lose hoisting and throw TDZ ReferenceErrorPosiblemente ocupada @draarivpatel-ui la tomó hace 2 días. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 55/100
vitejs/vite-plugin-react#1566 · 1 comentario ·
Los mantenedores suelen responder en 1 día
Todos los issues de vitejs/vite-plugin-react
Issues similares
-
ui
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
mermaid-js/mermaid-v13#1370 ·
Los mantenedores suelen responder en 1 día
-
compiler: the island_chunks_not_emitted report gives a count but not which islands were skippedAbiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
-
Broken Website
Dificultad 2/5 1-3 horas Aptitud para principiantes 64/100
darkreader/darkreader#16259 ·
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
ARTPARK-SAHAI-ORG/calibrate-frontend#919 ·
Los mantenedores suelen responder en 1 día