Skip to content

test(react-start): cover SPA shell hydration in the spa-mode e2e app - #8474

Open
christian-apollo wants to merge 1 commit into
TanStack:mainfrom
christian-apollo:test/spa-mode-shell-hydration
Open

christian-apollo wants to merge 1 commit into
TanStack:mainfrom
christian-apollo:test/spa-mode-shell-hydration

Conversation

@christian-apollo

@christian-apollo christian-apollo commented Sep 20, 2026

Copy link
Copy Markdown

🎯 Changes

Test-only. Adds the missing coverage for hydrating the SPA shell, which is how #8473 stayed invisible.

The spa-mode e2e app is served by serve dist/client, which answers an unknown address with its own 404 page, so the shell is never loaded at an address it was not prerendered for: the normal case for a deployed SPA. Nothing in the suite listens for uncaught errors either, so the React #418 that / already throws goes unnoticed.

  • spa-server.mjs serves the build the way a static host does: an existing file wins, a directory's index.html wins, anything else falls back to the shell with a 200 (try_files $uri $uri/index.html /index.html). Plain serve cannot reach the fallback and serve --single cannot reach the prerendered /posts/1, so the two cases need this ~40 line server. It also drops an npx serve download from the e2e run.
  • tests/hydration.spec.ts asserts a page load throws nothing uncaught, for three addresses: the prerendered /posts/1, which passes; and the shell at / and at /no-such-address, which are marked test.fail because both throw Minified React error #418 today.

I marked the two rather than leaving CI red: they pass as expected-failures now, and a fix for #8473 makes them pass unexpectedly, which fails the run and is the prompt to drop the marker. Happy to change that to skips, or to drop them entirely and keep only the passing control, if you would rather the bug were tracked only in the issue.

The existing two tests pass unchanged against the new server.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested code changes locally with the relevant test commands, or tests do not apply to this pull request.
  • I fully understand the code in this pull request, including any code generated with AI assistance.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • New Features

    • Added a lightweight static server for SPA mode with support for client-side route fallbacks and configurable ports.
  • Tests

    • Added end-to-end coverage for SPA hydration on prerendered and fallback routes.
    • Added checks for uncaught browser errors and expected page headings.

The spa-mode app is served in its e2e run by `serve dist/client`, which
answers an unknown address with its own 404 page. The shell is therefore
never loaded at an address it was not prerendered for, which is the normal
case for a deployed SPA, and nothing in the suite listens for uncaught
errors, so the React TanStack#418 that `/` already throws goes unnoticed.

`spa-server.mjs` serves the build the way a static host does: an existing
file wins, a directory's index.html wins, anything else falls back to the
shell with a 200. That keeps the prerendered /posts/1 reachable, which
`serve --single` would not, and makes the fallback reachable, which plain
`serve` does not.

The new spec asserts that a page load throws nothing uncaught. The
prerendered page passes. The two shell cases are marked `test.fail`,
since both throw React TanStack#418 today (issue TanStack#8473); removing the marker is
how a fix for that issue proves itself.
@coderabbitai

coderabbitai Bot commented Sep 20, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: TanStack/router/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: c26f3110-b045-48e4-828b-40bc7cd144a6

📥 Commits

Reviewing files that changed from the base of the PR and between ac223be and c1907b9.

📒 Files selected for processing (3)
  • e2e/react-start/spa-mode/package.json
  • e2e/react-start/spa-mode/spa-server.mjs
  • e2e/react-start/spa-mode/tests/hydration.spec.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The SPA test setup now launches a custom Node server instead of serve. The server resolves static files and SPA fallbacks. New end-to-end tests capture page errors and check hydration on selected routes.

Changes

SPA server and hydration

Layer / File(s) Summary
Custom SPA server wiring
e2e/react-start/spa-mode/spa-server.mjs, e2e/react-start/spa-mode/package.json
The start script launches spa-server.mjs. The server resolves files, serves directory and root index.html fallbacks, sets MIME and cache headers, and logs its listening URL.
Route hydration validation
e2e/react-start/spa-mode/tests/hydration.spec.ts
A helper captures uncaught page errors during navigation. Tests require error-free hydration for /posts/1 and mark / and /no-such-address as expected failures.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Other

Sequence Diagram(s)

sequenceDiagram
  participant Browser
  participant spa-server.mjs
  participant Filesystem
  participant hydration.spec.ts
  Browser->>spa-server.mjs: Request SPA route
  spa-server.mjs->>Filesystem: Resolve route file or index.html
  Filesystem-->>spa-server.mjs: Return file path
  spa-server.mjs-->>Browser: Stream response
  hydration.spec.ts->>Browser: Navigate and capture page errors
  Browser-->>hydration.spec.ts: Root heading and error messages
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: adding SPA shell hydration coverage in the React Start end-to-end application.
Description check ✅ Passed The description follows the required template, explains the server and test changes, documents expected failures and their purpose, completes the checklist, and identifies the change as dev-only with …
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. (1 skipped: 1 …
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

1 participant