Skip to content

fix: request root prerender data at /_.data on React Router 8 - #151

Merged
ScriptedAlchemy merged 2 commits into
mainfrom
fix/prerender-root-data-rr8
Sep 25, 2026
Merged

ScriptedAlchemy merged 2 commits into
mainfrom
fix/prerender-root-data-rr8

Conversation

@ScriptedAlchemy

@ScriptedAlchemy ScriptedAlchemy commented Sep 25, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes #150.

When / is prerendered with a loader, the plugin requested root data from the server handler at /_root.data and wrote it to /_.data. React Router 7 handlers need that legacy path, but React Router 8 dropped the /_root.data alias: it only strips /_.data, so the request normalized to /_root and ssr: false builds failed with a 404.

The plugin now checks the react-router version once per prerender build and keeps the /_root.data request only for React Router 7 and older. On React Router 8 it requests /_.data, the same path @react-router/dev 8.4 uses.

The version is resolved from the plugin package, not the app directory, because the prerender worker imports createRequestHandler from the react-router the 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

  • New regression test covers both React Router 8.4 (requests /_.data) and 7.18 (requests /_root.data); the 8.4 case fails without the fix.
  • The reporter's repro (futursolo/rsbuild-react-router-prerender-example) now builds and writes build/client/_.data with the root loader data.
  • All 37 prerender-test.ts integration tests pass locally, including the one the first commit broke in CI.
  • pnpm test (typechecks plus all tests) and pnpm format:check pass.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-25T01:25:42.529061Z 1e7141a PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@pkg-pr-new

pkg-pr-new Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

pnpm add https://pkg.pr.new/rsbuild-plugin-react-router@c10eb26

commit: c10eb26

@github-actions

github-actions Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark results

Case Base Head Delta
build-256-ssr 2411.4 ms 2373.8 ms -1.6%
dev-48-ssr 1056.6 ms 1045.2 ms -1.1%

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread src/prerender-build.ts Outdated
const buildRoutes = createPrerenderRoutes(build.routes);
const legacyRootDataRequest = !getDefaultTrailingSlashAwareDataRequests(
getPackageVersion('react-router', specifier =>
resolveAppPackagePath(specifier, appDirectory)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@codspeed

codspeed Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 1 untouched benchmark
⏩ 2 skipped benchmarks1


Comparing fix/prerender-root-data-rr8 (c10eb26) with main (0ad5302)

Open in CodSpeed

Footnotes

  1. 2 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@ScriptedAlchemy
ScriptedAlchemy merged commit 74c0caf into main Sep 25, 2026
9 of 10 checks passed
@ScriptedAlchemy
ScriptedAlchemy deleted the fix/prerender-root-data-rr8 branch September 25, 2026 02:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prerender is broken when paired with data loader

1 participant