[Bug]: dev server build embedded in a custom server/index bundle keeps a stale, content-addressed browser manifest (0.8.x)

Ouverte
#159 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Évaluation

Difficulté
4/5
Temps estimé
3-5 jours
Accessibilité débutants
22/100
Type d'issue
Bug
Clarté
Plutôt claire
Activité
Active
Stack technique
express, react, typescript
Domaine
build-system

Piste de recherche

Start with loadReactRouterServerBuild(devServer) and the server-manifest.json cache under node_modules/.cache/react-router/<hash>/, then compare where the embedded virtual/react-router/server-build manifest is generated relative to the web compilation. Reproduce with the examples/epic-stack layout, checking that the manifest-*.js URL in the SSR HTML matches the one the web environment emits. Done means the embedded and published manifest versions match after source edits, or the docs state the supported server/index setup. The maintainers still have to decide which of the two options in the issue is supported.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

Plugin version: 0.8.2 (works on 0.7.2) · @rsbuild/core: 2.2.12 · @rspack/core: 2.2.8 · react-router: 7.18.4

Problem

With pluginReactRouter({ customServer: true }) and a server/index.ts entry that imports virtual/react-router/server-build itself (the layout examples/epic-stack uses), the dev SSR HTML references a browser manifest the dev server does not serve:

<link rel="modulepreload" href="/static/js/manifest-2492e836.js"/>
GET /static/js/manifest-2492e836.js -> 200 text/html   (falls through to the SSR handler)
GET /static/js/manifest-6dd56d97.js -> 200 text/javascript

The page never hydrates.

The server build embedded in the static/js/app bundle carries a manifest that was generated before the web compilation finished. Its route css arrays are empty, so its sha256 version differs from the published browser manifest:

static/js/app (server/index.ts)      version 2492e836  routes.root.css: []
loadReactRouterServerBuild(devServer) version 6dd56d97  routes.root.css: ["/static/css/root.css.__react_router_css_<hash>.css"]

The embedded copy is never regenerated. It stays at 2492e836 after source edits that rebuild both environments, and after the content of node_modules/.cache/react-router/<hash>/server-manifest.json changes (it holds the correct 6dd56d97 snapshot). loadReactRouterServerBuild(devServer) returns the correct pair the whole time.

0.7.2 used a fixed dev manifest URL (static/js/virtual/react-router/browser-manifest.js?v=...), so the stale embedded copy still loaded. Since #138 (0.8.0), dev manifest filenames are content-addressed, so the mismatch breaks the page.

Reproduction
// server/index.ts (bundled as static/js/app)
import { createRequestHandler } from '@react-router/express';
export const handler = createRequestHandler({
  build: () => import('virtual/react-router/server-build'),
});

// server/start.js
const devServer = await rsbuild.createDevServer();
app.use(devServer.middlewares);
app.all('/{*splat}', async (req, res, next) => {
  const mod = await devServer.environments.node.loadBundle('static/js/app');
  await mod.handler(req, res, next);
});

Start the dev server with an empty node_modules/.cache/react-router, request a page, and compare the manifest-*.js URL in the HTML with the one the web environment emits.

Workaround

Keep the routes and server setup from the server/index bundle, and take assets from the plugin's paired build:

const mod = await devServer.environments.node.loadBundle('static/js/app');
const paired = await loadReactRouterServerBuild(devServer);
// build = { ...embeddedServerBuild, assets: paired.assets }

Using the paired build wholesale isn't an option for us. static/js/react-router-server-build is a separate bundle with its own module instances, so singletons initialized by server/index.ts (a logger, in our case) are uninitialized in the route modules it evaluates.

Question

Which setup is supported for a server/index entry in dev?

  1. server/index may import virtual/react-router/server-build (as examples/epic-stack does), and the embedded manifest should stay paired with the published browser manifest. That makes this a bug.
  2. server/index must take its build from loadReactRouterServerBuild(devServer). In that case, is there a way for the paired build to share module instances with the server/index bundle, or should the docs say that server/index must not read its own embedded server build?
Langage dominant
TypeScript
Étoiles
145
Forks
13
Métriques de merge des PR
Aucune PR mergée en 30 j

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de rstackjs/rsbuild-plugin-react-router

Toutes les issues de rstackjs/rsbuild-plugin-react-router

Issues similaires

Plus d'issues TypeScript

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.