Skip to content

fix(signals): load the browser's own query selection over a seed for another request - #1618

Merged
trueadm merged 1 commit into
mainfrom
fix/hydration-changed-query-request
Oct 2, 2026
Merged

trueadm merged 1 commit into
mainfrom
fix/hydration-changed-query-request

Conversation

@trueadm

@trueadm trueadm commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes main, which has been red since #1601. Main CI run 37067163551 fails 6 of 8 cases in returned-jsx-query-resume.test.ts (octane and octane-prod), and every open PR inherits the failure.

Root cause: an engine defect that predates #1601, not the retry-owner cache.

Fix: under hydration, the frame leaves such a read to the live graph, just like a request the server never seeded. readHistoricalNode already uses undefined to mean "read live" for non-seedable owners.

  • The client loads its own selection once.
  • The boundary, or the root when there is none, waits for that load.
  • Adoption keeps the server's nodes and reports the changed text as a recoverable hydration mismatch.
  • The check runs before the frame creates or reports its historical source, so the live read carries no stale historical subscription or misleading inspection entry.
  • An explicit scope.beginAdoption() frame keeps the error, since it has no live fallback; signals-serialization.test.ts still pins that.

Why not recovery

The alternative was to throw NativeAdoptionMiss, the documented recovery for a missing channel. I prototyped it in the same scenarios. It:

  • client-rendered the whole root over the server DOM;
  • loaded 'b' twice, because the discarded attempt had already started its load;
  • in the .tsrx-Field case, left the boundary showing its fallback after the data settled.

It also fails #1607's tests as written. The read-live behavior matches the docs' "a matching completed resource seed avoids a duplicate client load": a seed that doesn't match doesn't avoid the load. The adoption paragraph in docs/signals.md now states this case.

Changes

  • packages/octane/src/signals/engine.ts: under hydration, AdoptionFrameImpl.read returns undefined (read live) for a resource seed of another request, checked before the historical source is created. An explicit frame still throws 145.
  • packages/octane/tests/hydration/returned-jsx-query-resume.test.ts: new test, "loads the browser's own selection over a seed for another request", 12 cases. It covers .tsx, .tsrx and boundary-free .tsrx Apps × .tsx and .tsrx Field × dev and prod compile. It asserts one load of 'b', the server <output> adopted (same node), the text 'browser b', and only hydration-mismatch reports.
  • docs/signals.md: documents the behavior.
  • Changeset: octane patch.

Validation

  • pnpm format:check: not run. Ran scoped pnpm format:files:check on the 4 changed files, which passed.
  • pnpm typecheck: not run. Ran scoped pnpm typecheck:files on the engine and test files, which passed.
  • pnpm test: not run, to limit local load. Left to CI.
  • targeted tests (--project octane unless noted):
  • Bundle gate: node benchmarks/bundle-size/run-minimal.mjs --budgets root-static-local root-chained-jsx hooks-state prop-attributes context passes. The output is byte-identical to main (root-chained-jsx 86002 raw / 28544 gzip), because the signals engine isn't in these bundles. hydrate-root is also byte-identical to main (169643 raw), so its existing budget failure on main is unchanged.
  • pnpm sync: no generated changes.

Risk / follow-ups

  • During hydration, one owner can now present some nodes from history while a query whose request changed reads live. The mixed state lasts only until the frame is released, after which normal live reconciliation runs. Any visible text difference is reported as a hydration mismatch, so it is never silent.
  • A missing seed entry, as opposed to a seed for another request, still triggers NativeAdoptionMiss recovery, unchanged. That recovery path has no test coverage. The prototype above showed a double load and a stuck fallback there, which could be worth a follow-up.

Provenance

  • An agent produced this diff (agent-authored)

🤖 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

Medium Risk
Changes hydration adoption for async queries when server seed and client selection diverge; behavior is documented and heavily tested but mixes historical and live reads briefly during adoption.

Overview
Hydration no longer hard-fails when the client’s query$ selection differs from the server-seeded request under the same signal owner. Instead of SignalFrameError(145) (“The presented query definition does not match”), AdoptionFrameImpl.read returns undefined during native hydration so the graph reads the query live, loads the browser’s current selection once, keeps the server DOM nodes, and surfaces text differences as recoverable hydration mismatches.

Explicit scope.beginAdoption() frames still throw 145 (no live fallback). The mismatch check runs before a historical read source is registered, avoiding stale subscriptions.

Docs (signals.md) and a patch changeset describe the behavior. Tests add 12 matrix cases in returned-jsx-query-resume.test.ts (tsx/tsrx apps and fields, with/without Suspense, dev/prod).

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

…another request

A hydration frame rejected a resource seed whose request no longer matched the
client's selection with a hard SignalFrameError ("The presented query
definition does not match"), even under the native adoption resolver. The live
binding already treats a seed for another request as no seed and starts the
client load, so only the historical read failed.

The frame now leaves such a read to the live graph during hydration, exactly
like a request the server never seeded: the client loads its own selection once,
the boundary (or root) waits for it, and adoption keeps the server's nodes while
reporting changed text as a recoverable hydration mismatch. An explicit
`beginAdoption` frame keeps the error, since it has no live fallback.

The defect predates #1601: a `.tsrx` app whose props select another request
than the server's already failed. #1601 gave `.tsx` returned-JSX components the
server's owner key, which exposed it to #1607's tests, whose browser-only
selection previously landed under an unseeded owner.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@trueadm
trueadm marked this pull request as ready for review October 2, 2026 23:10
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix labels Oct 2, 2026
@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Benchmark report

🟢 No size increases and no timing regressions outside noise.

Compares 6ea582e37 with 16d966525 on the same runner. Timing verdicts require a change beyond the combined margin of error (at least 5%) and one 0.1ms timer tick, with the fastest sample also moving beyond that margin. Workflow run

js-framework: 1k/10k row operations (ms, lower is better)

All 20 timed operations (20 within noise)
target operation base head Δ noise
octane-tsrx run 3.46 4.55 +31.5% ±35% ⚪ within noise
octane-tsrx replace 6.86 8.59 +25.2% ±18% ⚪ within noise
octane-tsrx add 3.67 3.92 +6.8% ±16% ⚪ within noise
octane-tsrx update 0.38 0.42 +10.5% ±73% ⚪ within noise
octane-tsrx select 0.14 0.17 +21.4% ±105% ⚪ within noise
octane-tsrx swap 0.30 0.40 +33.3% ±72% ⚪ within noise
octane-tsrx remove 0.32 0.32 −0.0% ±56% ⚪ within noise
octane-tsrx runlots 36.31 40.17 +10.6% ±23% ⚪ within noise
octane-tsrx select_lots 0.19 0.21 +10.5% ±67% ⚪ within noise
octane-tsrx clear 31.14 38.36 +23.2% ±23% ⚪ within noise
octane-jsx run 4.98 5.01 +0.6% ±87% ⚪ within noise
octane-jsx replace 9.66 8.34 −13.7% ±32% ⚪ within noise
octane-jsx add 5.03 3.64 −27.6% ±69% ⚪ within noise
octane-jsx update 0.88 0.55 −37.5% ±49% ⚪ within noise
octane-jsx select 0.45 0.39 −13.3% ±41% ⚪ within noise
octane-jsx swap 1.04 0.66 −36.5% ±64% ⚪ within noise
octane-jsx remove 0.61 0.54 −11.5% ±46% ⚪ within noise
octane-jsx runlots 36.18 33.30 −8.0% ±15% ⚪ within noise
octane-jsx select_lots 3.09 2.82 −8.7% ±29% ⚪ within noise
octane-jsx clear 38.15 35.76 −6.3% ±31% ⚪ within noise

Application bundle size (bytes)

No changes across 45 measured values.

Public-import reachability bundles (bytes)

No changes across 105 measured values.

@trueadm
trueadm merged commit 62e76bf into main Oct 2, 2026
49 of 52 checks passed
@trueadm
trueadm deleted the fix/hydration-changed-query-request branch October 2, 2026 23:36
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.

1 participant