fix: request root prerender data at /_.data on React Router 8 - #151
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
commit: |
Benchmark results
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1e7141abd1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const buildRoutes = createPrerenderRoutes(build.routes); | ||
| const legacyRootDataRequest = !getDefaultTrailingSlashAwareDataRequests( | ||
| getPackageVersion('react-router', specifier => | ||
| resolveAppPackagePath(specifier, appDirectory) |
There was a problem hiding this comment.
Resolve the version from the server-build root
When a custom appDirectory resolves a different react-router installation than the Rsbuild root, this selects the data URL for the wrong major version. The classic server build is explicitly aliased to the package resolved from api.context.rootPath in createReactRouterPackageAliases, whereas this lookup starts at appDirectory; for example, a root using React Router 7 with an app directory that resolves React Router 8 will now request /_.data, which the actual React Router 7 handler does not support. Pass the root-resolved version/major into prerendering or perform this lookup from the same root used to build the handler.
Useful? React with 👍 / 👎.
Merging this PR will not alter performance
Comparing Footnotes
|
Summary
Fixes #150.
When
/is prerendered with a loader, the plugin requested root data from the server handler at/_root.dataand wrote it to/_.data. React Router 7 handlers need that legacy path, but React Router 8 dropped the/_root.dataalias: it only strips/_.data, so the request normalized to/_rootandssr: falsebuilds failed with a 404.The plugin now checks the
react-routerversion once per prerender build and keeps the/_root.datarequest only for React Router 7 and older. On React Router 8 it requests/_.data, the same path@react-router/dev8.4 uses.The version is resolved from the plugin package, not the app directory, because the prerender worker imports
createRequestHandlerfrom thereact-routerthe plugin resolves. The first commit resolved from the app directory. That broke this repo's own integration fixtures, where the app has React Router 8.3 but the plugin (and therefore the handler) resolves 7.18.Verification
/_.data) and 7.18 (requests/_root.data); the 8.4 case fails without the fix.futursolo/rsbuild-react-router-prerender-example) now builds and writesbuild/client/_.datawith the root loader data.prerender-test.tsintegration tests pass locally, including the one the first commit broke in CI.pnpm test(typechecks plus all tests) andpnpm format:checkpass.