Skip to content

fix: preserve server content during document hydration - #1331

Merged
trueadm merged 3 commits into
mainfrom
fix/1321-document-hydration-owner
Sep 26, 2026
Merged

trueadm merged 3 commits into
mainfrom
fix/1321-document-hydration-owner

Conversation

@trueadm

@trueadm trueadm commented Sep 26, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Replaces #1324, whose head lives on an org-owned fork that maintainers cannot push to. It carries that PR's commits unchanged, plus a follow-up commit fixing its CI failures and two hydration defects found in review.

Fixes #1321. A TanStack Start document shell can place a head portal alongside the selected body hydration owner. The client now adopts the server route in that list, keeping the original interactive DOM instead of duplicating it.

Why

The selected container does not contain server list frames for the shell's logical siblings. Treating them as ordinary server list items consumes the body's hydration cursor before the owner reaches it.

Changes

  • Give passthrough list items bounded client ranges while preserving the selected owner's server range, including nested lists and initially empty containers.
  • Preserve ownership through keyed updates, mismatch recovery, suspension, caught errors, and renderer-owned style sidecars.
  • Add core regressions and an integration test using StartServer, StartClient, and the router; regenerate the evaluation manifest affected by the test configuration.
  • Follow-up commit (this PR):
    • A client-only list item (for example host content after the owner) marks its content fresh, so finishRoot() no longer sweeps it as stale server remainder. Before this, a shell returning a bare array with a host sibling after the owner lost that sibling and later crashed on reorder (moveBlockBefore on a detached marker).
    • childSlot ends passthrough when it reaches the owner, as componentSlot already did. An owner that is itself a keyed list item previously left passthrough on, so a later sibling suspending inside Suspense retried after hydration and duplicated the server content (the [tanstack-start] Initial document hydration duplicates the route and leaves the SSR button inert (Octane 0.5.0) #1321 symptom).
    • The server-fixture harness (scripts/react-parity/server-fixtures.mjs) resolves extensionless relative imports by exact filename. esbuild matches directory entries case-insensitively, so ./link resolved to Link.tsrx ahead of link.ts: wrong on macOS and ENOENT on Linux CI.
    • mountPassthroughCatch binds its parent to a local so the staged-DOM lint recognises the guarded lastChild read.

Validation

  • Follow-up regressions: 5 new range-boundary cases (dev and prod). They cover a bare-array shell with client-only host content, suspending at the root and within Suspense, and a directly keyed owner item. All fail on the previous head and pass now; reverting either runtime fix individually turns its cases red.
  • packages/octane/tests/hydration, packages/tanstack-start/tests, packages/tanstack-router/tests: 178 files / 2478 tests pass.
  • Lint-job checks run locally: ci:workflow:test (including check-staged-dom), test:markers:check, changeset:check, error-codes:check, tsrx-decls:check, rules:check, packages:inventory:check, context:budget:check, redact-audit:check.
  • pnpm sync (no generated changes), pnpm format:files:check, scoped typecheck:files (tsrx-tsc).
  • The harness change removes esbuild's different-path-case warning for ./link when bundling the Start fixture.
  • Full suite in the CI shard layout (vitest.ci-sharded.config.js, 4/4 shards, CI exclusions): 2,256 files / 31,788 tests pass. An unsharded local pnpm test ran out of heap in the Vitest main process (4 GB) without any test failures.

Risk / follow-ups

Pre-existing limitations remain when a boundary suspends before visiting a later owner, when single-owner passthrough hydration encounters an unframed single root, when renderer styles are interspersed among multiple server roots, and when an error boundary resets after fallback. These were reproduced independently on the original runtime and are outside this fix.

Provenance

  • An agent produced this diff (agent-authored)

Original commits: Codex task · host: com-79386

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Note

High Risk
Touches core hydration and list mounting in runtime.ts, which can affect SSR adoption, suspense/error recovery, and keyed updates across apps using range boundaries.

Overview
Fixes document-shell hydration when the client tree is a passthrough list/array with portal siblings and a selected body hydration owner (e.g. TanStack Start StartClient beside head content). The server HTML only contains the owner’s range, so list reconciliation no longer treats shell siblings as normal server list frames and steal the hydration cursor before the owner runs.

The runtime now mounts passthrough list items with bounded client comment ranges, smarter anchor insertion (including borrowed lists and renderer style sidecars), and advances the hydration cursor after the list. Reaching a non-transparent owner through a value slot ends passthrough like componentSlot already did. Try/catch paths can mark fresh fallback DOM during passthrough handoff, with rollback on mount failure.

Adds broad hydration regressions (range-boundary), a TanStack Start SSR→hydrate integration test, a changeset patch, refreshed eval grader digests, and a server-fixture resolver tweak so extensionless imports prefer exact filenames over case-insensitive directory matches on Linux CI.

Reviewed by Cursor Bugbot for commit 23972ff. Bugbot is set up for automated code reviews on this repo. Configure here.

domgan-oai and others added 3 commits September 25, 2026 21:51
…t hydration

- Mark a client-only passthrough list item's content fresh so finishRoot()
  does not sweep it as stale server remainder.
- End passthrough in childSlot when it reaches the selected owner, matching
  componentSlot, so a keyed owner item hands off the server cursor.
- Resolve extensionless fixture imports by exact filename: esbuild matches
  directory entries case-insensitively, so `./link` picked `Link.tsrx`
  (ENOENT on Linux).
- Bind the catch fallback parent locally for the staged-DOM lint.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@trueadm
trueadm marked this pull request as ready for review September 26, 2026 11:50
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix labels Sep 26, 2026
@trueadm
trueadm merged commit 5a05767 into main Sep 26, 2026
47 of 50 checks passed
@trueadm
trueadm deleted the fix/1321-document-hydration-owner branch September 26, 2026 12:03
@trueadm trueadm mentioned this pull request Sep 27, 2026
5 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[tanstack-start] Initial document hydration duplicates the route and leaves the SSR button inert (Octane 0.5.0)

2 participants