Skip to content

fix: preserve server content during document hydration - #1324

Closed
domgan-oai wants to merge 2 commits into
octanejs:mainfrom
openai-oss-forks:fix/1321-document-hydration
Closed

domgan-oai wants to merge 2 commits into
octanejs:mainfrom
openai-oss-forks:fix/1321-document-hydration

Conversation

@domgan-oai

@domgan-oai domgan-oai commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

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.

Validation

  • pnpm format:check (with the interim upstream-source formatter described below)
  • pnpm typecheck (the last full attempt stopped at a missing MDX declaration after passing through Shadcn; the isolated MDX check passed after restoring the missing link, but the full command has not been rerun)
  • pnpm test (Three and Visx prechecks pass; the full browser-capable run was interrupted after Jotai and Motion pristine failures and Mantine Hooks collection failures. The underlying causes and final totals remain undetermined.)
  • Scoped format and five-file typechecks; core and Start source project typechecks.
  • 159 tests across 13 hydration files, and 32 tests across five Start/Router files. The final core fixture has nine failures against the original runtime; the Start integration reproduces duplicate route content and an inert original button on the original runtime.
  • pnpm sync; independent complexity review; local production-build JSDOM component-list timing comparison (no observed regression in this sample).

The focused checks and sync used a task-local interim toolchain: the OXC archives matched the lockfile hashes; the cached core source and a source-built runtime helper matched the upstream release tag, but the helper archive was not byte-identical to the published artifact. The formatter, TypeScript plugin, React compiler, and React runtime were also sourced from their upstream tag; their source-built archives were not verified byte-identical to the locked published artifacts. The integration test uses real Start and Router components in JSDOM; it does not exercise serialized router-state transport or a physical browser. Full-suite attempts used Node 26, while CI uses Node 24; Node 26 emitted localStorage warnings, but their relationship to the failures is unverified.

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)

Codex task · host: com-79386


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 client hydration and keyed list mounting used when boundary components return multiple roots; incorrect cursor or range handling can cause DOM duplication, lost interactivity, or SSR mismatches in document-style apps.

Overview
Fixes hydration when a document shell (e.g. TanStack Start) renders portal siblings (head/scripts) next to a selected body owner whose server HTML lives alone in the hydration root—without server list frames for those logical siblings.

The runtime adds a passthrough list path: while hydration.passthroughRanges is active on a borrowed @for slot, it mints per-item client comment ranges, routes first fill through mountPassthroughListItem, and advances the hydration cursor so the owner adopts existing nodes instead of duplicating them. Related updates cover marker placement, rollback on mount errors, suspense/error fallbacks (mountPassthroughCatch / pending try), and cursor handoff after the list consumes the owner.

Tests: expanded range-boundary hydration fixtures and coverage (nested lists, reorder, empty server HTML, Suspense, ErrorBoundary); new TanStack Start document-hydration test (StartServer → hydrateRoot/StartClient). Eval manifest.jsonl grader digests refresh from the Start vitest plugin change; changeset marks an octane patch.

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

@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix labels Sep 25, 2026
@domgan-oai
domgan-oai marked this pull request as ready for review September 25, 2026 22:05
@domgan-oai
domgan-oai marked this pull request as draft September 25, 2026 22:06
@domgan-oai
domgan-oai marked this pull request as ready for review September 25, 2026 22:07
@domgan-oai domgan-oai closed this Sep 26, 2026
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)

1 participant