[Feature]: Support on-demand compilation of SSR dynamic imports without reloading unrelated pages
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 35/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Bastante claro
- Estado de actividad
- Activo
- Stack tecnológico
- react, typescript
- Área
- backend, build-system, web-dev
Línea de trabajo
Start with the proposed generate-optional.mjs graph, app/routes/catalog.tsx, and app/routes.ts, then inspect createDevServer, the Router server runtime, and the lazy middleware. Verify that rsbuild dev starts without compiling unused server leaves, that opening /catalog/17 resumes the in-flight SSR request, and that the first page remains intact. Confirm HMR, data revalidation, failure handling, and ESM/CJS behavior while preserving the existing last-good-build contract.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Request
Please add an opt-in development mode that keeps React Router server entries,
loaders and SSR working while compiling server-side dynamic imports only when
they are first requested. It should preserve the in-flight SSR request across
that compilation and retain normal HMR and hot data revalidation for actual
source edits.
This is a feature request, not a claim that an existing SSR-lazy option is
broken. With Rsbuild 2.2.9 and rsbuild-plugin-react-router 0.8.1,
dev.lazyCompilation is applied only to target: 'web'. The server
compiler still traverses dynamic imports on a cold build even when no request
will use them. Large SSR applications with many optional React.lazy
components therefore pay for both browser startup and eager server compilation.
It differs from skipping server reevaluation when output is unchanged: the
first use of a deferred server import deliberately changes the Node module
graph and must resolve a Promise that is already held by a live SSR request.
Public demonstration for evaluating the feature
The following graph can be added to a standard SSR example using
pluginReactRouter() and pluginReact(), with ssr: true and
dev.lazyCompilation: { entries: false, imports: true }. It is proposed
test input, not a benchmark that has already been run.
Create generate-optional.mjs in the example root:
import { mkdir, writeFile } from 'node:fs/promises';
const count = Number(process.argv[2] ?? 1000);
await mkdir('app/generated', { recursive: true });
await Promise.all(Array.from({ length: count }, (_, i) =>
writeFile(`app/generated/optional-${i}.tsx`,
`export default function Optional() {
return <p className="optional">Optional item ${i}</p>;
}\n`)
));
await writeFile('app/generated/registry.tsx',
"import { lazy } from 'react';\nexport const optional = [\n" +
Array.from({ length: count }, (_, i) =>
` lazy(() => import('./optional-${i}')),`).join('\n') +
'\n];\n');
Create app/routes/catalog.tsx:
import { Suspense } from 'react';
import { useLoaderData, type LoaderFunctionArgs } from 'react-router';
import { optional } from '../generated/registry';
import './catalog.css';
export function loader({ params }: LoaderFunctionArgs) {
return { item: Number(params.item ?? 0) };
}
export default function Catalog() {
const { item } = useLoaderData<typeof loader>();
const Selected = optional[item];
return <Suspense fallback={<p>Loading item</p>}><Selected /></Suspense>;
}
Create app/routes/catalog.css:
.optional { color: darkslateblue; }
Add route("catalog/:item", "routes/catalog.tsx") to the example's
app/routes.ts, alongside an ordinary index route with a text field. Run:
node generate-optional.mjs 1000
rsbuild dev
For a cold comparison, use a new persistent-cache directory for each run.
Measure time from process launch to the first index page with the text field
usable, and also count compiled Node modules under app/generated/. Then
open /catalog/17 in a second tab. Record time to first SSR content and to
interactivity for that request separately. Repeat at 100 and 1,000 leaves to
see how cold startup scales; do not add startup and request timings together
or count a test timeout as bundler work.
Current source predicts all referenced Node leaves enter the first build.
The desired implementation should build only the required SSR shell at cold
startup, compile item 17 on the request that needs it, and leave unused items
deferred. The first tab should not reload or lose its text merely because the
second tab activates a server import.
Required ownership and correctness
- Keep the React Router server entry eager. Deferring it can deadlock
createDevServer()before the lazy compilation middleware is listening. - The Router runtime needs to distinguish an actual Node lazy activation from
an unknown invalidation. An empty source-file list alone is insufficient:
build errors, a superseded generation or failed Web compilation must not be
accepted as a valid server update. - Resume the suspended SSR import only after the corresponding Node update
commits against a successful, settled Web manifest. On failure or shutdown,
reject its waiters; avoid hanging requests or exposing a half-applied runtime. - Actual loader/action/dependency edits must still run both required compilers
and revalidate data. CSS edits/imports and dynamically visited routes must
retain the correct stylesheet and HMR behavior. - If Node evaluation calls a dynamic import before HTTP listen, support a
safe in-process activation path, or reject an unsupported configuration
clearly. Awaiting the HTTP lazy endpoint before it exists is not sufficient.
Suggested implementation boundary
Rspack already exposes lazyCompilation for a Node compiler and supplies a
Node lazy client; Rsbuild currently installs the lazy middleware for any
compiler with that option. The missing part is ownership in the Router server
runtime: retained Node evaluation/HMR, safe lazy-activation attribution, and
settling the pending import with the paired Web generation. The existing
last-good-build contract should continue to protect failed builds.
An opt-in option is appropriate until these cases work in both ESM and CJS
plugin consumption. If Rspack does not expose enough structured information to
attribute activations or delay their resolution, please request a small typed
hook there rather than using log-message matching.
Scope and verification
This request is based on the public compiler configuration and server-lifecycle behavior described above. The example graph is proposed test input, not a completed stock/candidate benchmark. No numeric performance improvement is claimed here. Please measure with stock dependencies and the same generated input before and after an implementation.
This differs from #140, which avoids reevaluating already built, unchanged Node output. Both features may be useful, but one does not implement the other.
- Lenguaje dominante
- TypeScript
- Estrellas
- 145
- Forks
- 13
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin 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 rstackjs/rsbuild-plugin-react-router
-
Dificultad 4/5 3-5 días Aptitud para principiantes 22/100
-
blocked
Dificultad 5/5 Más de una semana Aptitud para principiantes 30/100
rstackjs/rsbuild-plugin-react-router#140 · 1 comentario ·
Todos los issues de rstackjs/rsbuild-plugin-react-router
Issues similares
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Dificultad 1/5 Menos de una hora Aptitud para principiantes 80/100
lingdojo/kana-dojo#34664 · 1 comentario · 5 reacciones ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
-
bug: achievement job reports success when its Slack announcements failPosiblemente ocupada @Aadithya-kl la tomó hoy. Abiertoapp: slackbot good first issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
enhancement help wanted
Dificultad 2/5 Medio día Aptitud para principiantes 62/100
plagor44-ux/liam-e#168 ·
Los mantenedores suelen responder en 1 día
-
documentation
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
jerney-nexus/epikrise#364 ·
Los mantenedores suelen responder en 1 día