Skip to content

Fix first post-hydration update remounting the passthrough-hydrated subtree - #192

Merged
trueadm merged 1 commit into
mainfrom
claude/blissful-zhukovsky-715d3f
Jul 19, 2026
Merged

trueadm merged 1 commit into
mainfrom
claude/blissful-zhukovsky-715d3f

Conversation

@trueadm

@trueadm trueadm commented Jul 19, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

The FIRST router event after SSR hydration (a hash replaceState, router.navigate, or router.load()) remounted the entire route tree in TanStack Start apps — every component under #__app unmounted and remounted, losing all state. Subsequent events behaved correctly.

Root cause

renderReturnedValue's slot-regime choice was unstable across hydration:

  • During passthrough hydration (the Start document-shell model — StartClient stamped HYDRATION_RANGE_BOUNDARY: 'passthrough', Body's HydrationRangeOwner stamped 'owner'), any component-descriptor return routes through the componentSlot regime, so block.slots[0] is a componentSlotSlot. That's how Body's createElement(HydrationRangeOwner, {}, children) — the slot owning everything inside #__app — mounts.
  • On the first post-hydration re-render of Body, activeHydration() is null and HydrationRangeOwner has no $$singleRoot stamp, so the same return now classifies as the childSlot regime. The kind mismatch hit disposeReturnSlot, tearing down the whole adopted subtree and rebuilding it. Every later render is childSlot→childSlot — hence first-event-only.

Fix

The return-slot regime is sticky while the returned component identity is unchanged: a slot mounted through the componentSlot route stays on it instead of being disposed for a mere kind re-classification. Identity changes and genuine shape flips (different component, null, array, portal, text) still dispose, preserving remount semantics. One extra short-circuited comparison on a cold path; no new state.

Tests

  • packages/octane/tests/hydration/post-hydration-update.test.ts + _fixtures/match-shape.tsrx: a router-Match-shaped wrapper chain and a Start-shaped document-shell scenario (passthrough root → transparent layers → Html/Body shell → range owner → provider/boundary chain), driven by a useSyncExternalStore reset key. Pre-fix, the Start-shaped scenario failed with ['mount:inner', 'unmount:inner', 'mount:inner'] and lost DOM identity in both the dev and prod compile projects.
  • website/tests/ssr-hydration.e2e.test.ts: new real-browser test — after hydration, fire history.replaceState(history.state, '', '#…'), require the router to actually process it (loadedAt bump via window.__TSR_ROUTER__ as a positive control against a vacuous pass), and assert header/main DOM identity survives. Verified failing with the fix reverted.

Validation

  • pnpm test: 1212 files / 11623 tests green (clean run on the final tree)
  • pnpm typecheck, pnpm format:check: clean
  • Changeset: octane patch

Residual note: a pre-existing edge remains where a transparent return slot whose value flips shape post-hydration disposes without a whole-container sweep; this change narrows exposure (same-identity no longer disposes) but doesn't audit that path.

🤖 Generated with Claude Code


Note

Medium Risk
Touches core renderReturnedValue slot-regime logic on the hydration boundary; the fix is narrow (same-component identity only) and heavily tested, but incorrect stickiness could affect remount semantics for return-slot shape changes.

Overview
Fixes a first post-hydration update bug where TanStack Start (and similar passthrough-hydration shells) remounted the entire #__app subtree on the first router-driven re-render, wiping component state and replacing DOM nodes.

In renderReturnedValue, passthrough hydration used the componentSlot path for descriptor returns; once hydration ended, the same return was reclassified as childSlot, triggering slot disposal and a full subtree teardown. The change adds a sticky rule: an existing componentSlotSlot whose currentComp still matches the returned component type keeps the componentSlot route instead of flipping regimes.

Adds hydration unit tests (Match-shaped wrapper chain + Start-shaped document shell) and a website e2e that fires history.replaceState after load and asserts header/main DOM identity plus router loadedAt processing. Ships an octane patch changeset.

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

…ubtree

During passthrough hydration (the Start document-shell model), a component-
descriptor return mounts through the componentSlot regime. The first
post-hydration re-render re-classified the same return as the childSlot
regime, and the kind flip disposed the slot — tearing down the entire
adopted subtree (visible as the whole app remounting and losing state on
the first router event after hydration). The return-slot regime is now
sticky while the returned component identity is unchanged; identity changes
and shape flips still dispose.

Co-Authored-By: Claude Fable 5 <[email protected]>
@vercel

vercel Bot commented Jul 19, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
octane-website Ready Ready Preview, Comment Jul 19, 2026 11:00pm
octane-website-mcp Ready Ready Preview, Comment Jul 19, 2026 11:00pm

Request Review

@vercel
vercel Bot temporarily deployed to Preview – octane-website-mcp July 19, 2026 23:00 Inactive
@vercel
vercel Bot temporarily deployed to Preview – octane-website July 19, 2026 23:00 Inactive
@trueadm
trueadm merged commit 25d266b into main Jul 19, 2026
22 checks passed
@trueadm
trueadm deleted the claude/blissful-zhukovsky-715d3f branch July 19, 2026 23:21
trueadm added a commit that referenced this pull request Jul 19, 2026
Main's fix for the first-post-hydration-update remount (#192) makes the
playground's boot-time router.load() prime unnecessary — the first hash
write no longer tears down the route tree. Verified in-browser: the
preview iframe survives the first replaceState and example switches
across hash writes keep the original instance.

Co-Authored-By: Claude Fable 5 <[email protected]>
trueadm added a commit that referenced this pull request Jul 20, 2026
…esm.sh imports (#190)

* Upgrade the website playground: examples, multi-file tabs, Prettier, esm.sh imports

- Examples dropdown: 14 curated workspaces covering the TSRX/TSX surface
  (control flow, branch-local hooks, context, portals, dynamic tags,
  Suspense + use(), multi-file parallel use(), transitions, ViewTransition,
  form actions, zustand via esm.sh, and an OctaneCompat React-host demo),
  each gated by a test that compiles it warning-free through the real pipeline.
- Multi-file workspaces: virtual file tabs with sibling imports, per-file
  undo history and compiled output, and a v2 share-hash format (v1 links
  still decode). `.react.tsx` marks React-host files compiled with sucrase.
- Third-party imports: bare specifiers rewrite to esm.sh with
  `?external=octane`; the sandbox bootstrap installs an import map pinning
  octane (and octane/react) to locally built blob modules, so bindings share
  the singleton runtime. The runtime now ships as a code-split JSON manifest
  (octane + octane/react entries over a shared core chunk) and the sandbox
  CSP permits exactly module loads from esm.sh, nothing else.
- Format button: client-side prettier/standalone + @tsrx/prettier-plugin
  (vite-aliased bare `prettier` to the standalone build), repo style output.
- octane/compiler: vite.js and bundler.js now import node builtins in
  namespace form so evaluating the compiler entry in a browser dev server
  (externalized node:* shims) no longer throws; no behavior change in Node.
- Worked around the first-router-event-after-hydration route-tree remount
  (tracked separately) by priming router.load() at playground boot, and
  added sessionStorage own-hash trust so reloads of your own code never
  re-hit the shared-link consent gate.

Co-Authored-By: Claude Fable 5 <[email protected]>

* Address CI and review feedback: no runtime skip, call-site use() in examples

- The OctaneCompat e2e no longer runtime-skips when esm.sh is unreachable
  (the lint gate bans skip modifiers); an up-front probe now turns an
  unreachable CDN into an immediate, clearly-attributed failure instead.
- Bugbot: the OctaneCompat Island created its fetch promise in the parent
  body every render, so unrelated updates (the click counter) resuspended
  the @Try boundary. The Island — and both Suspense examples, which taught
  the same antipattern — now create the promise AT the use() call site,
  where octane's parallel-use memoization keys it by deps; only changed
  inputs refetch. Verified in-browser: island clicks keep the data visible,
  Refetch still refetches.
- The examples dropdown's "Custom" placeholder is now a static hidden
  option instead of a conditional branch inside <select>, so the option
  list never reconciles.

Co-Authored-By: Claude Fable 5 <[email protected]>

* Stamp sandbox runtime errors with their run generation

Bugbot: a late runtime-error from a superseded run (e.g. a timer firing
after a recompile) could post after the newer run's clean render and stick
in the error banner. The sandbox now stamps runtime-error messages with the
originating run's generation and the parent drops any that don't match the
current run; covered by a unit test driving the postMessage protocol.

Co-Authored-By: Claude Fable 5 <[email protected]>

* Drop the router-prime workaround now that the remount fix landed

Main's fix for the first-post-hydration-update remount (#192) makes the
playground's boot-time router.load() prime unnecessary — the first hash
write no longer tears down the route tree. Verified in-browser: the
preview iframe survives the first replaceState and example switches
across hash writes keep the original instance.

Co-Authored-By: Claude Fable 5 <[email protected]>

* Fetch the web manifest with credentials

Browsers request <link rel=manifest> anonymously by default, so on
SSO-protected Vercel preview deployments the manifest fetch loses its
auth cookie, gets redirected to the vercel.com login, and surfaces as a
CORS error in the console on every page. crossorigin="use-credentials"
makes the manifest request carry cookies; same-origin production
requests are unaffected.

Co-Authored-By: Claude Fable 5 <[email protected]>

* Keep controlled select picks alive across the native input→change task gap

A real browser pick (popup commit, keyboard typeahead) dispatches trusted
`input` and `change` in SEPARATE tasks with microtask checkpoints between
them. The controlled-select restore ran in that gap, snapping the
selection back to the rendered value before `change` dispatched — so
every controlled select's onChange read the OLD value and user picks
could never commit. Synthetic events (tests, Playwright selectOption)
dispatch both in one task and never hit the gap, which is how the whole
suite stayed green while real users couldn't switch the playground's
examples dropdown.

The `input` dispatch now marks the pick in flight on the element (the
same window design as checkable activation): the `change` dispatch owns
the after-handlers restore, and a task fallback settles sequences whose
`change` never completes (stopped propagation below the root, or a
synthetic lone `input`). Regression test drives the real two-task event
sequence and failed before the fix; the input-only settle test moves
from the microtask to the task boundary it now guarantees.

Also gives the playground's example dropdown a custom chevron with
breathing room from the right edge (appearance: none + inline SVG).

Co-Authored-By: Claude Fable 5 <[email protected]>

---------

Co-authored-by: Claude Fable 5 <[email protected]>

This branch was previously deployed

2 inactive deployments
Preview – octane-website — 53c671bd Deployed Jul 19, 2026 by vercel[bot]
Preview – octane-website-mcp — 53c671bd Deployed Jul 19, 2026 by vercel[bot]
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