Skip to content

fix: address useLayoutSnapshot review findings - #1686

Merged
trueadm merged 11 commits into
mainfrom
fix/layout-snapshot-review
Oct 3, 2026
Merged

trueadm merged 11 commits into
mainfrom
fix/layout-snapshot-review

Conversation

@trueadm

@trueadm trueadm commented Oct 3, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #1677. This branch is #1677's head merged with current main, plus commits that fix the 12 review findings from that PR and the commit-time cases raised in review here. Land #1677 first, then this (or land this in its place, since it contains #1677). The budget raise it needed, #1685, has merged.

Scheduler (root cause)

  • Commit-time updates are urgent again, matching React. inCommitCallback() keeps updates from insertion and layout effects and callback refs out of an in-flight Action's batch and out of transition priority. commitEffects, and completeDeferredLayouts for a View Transition's deferred refs and layout effects, clear the ambient TRANSITION_DEPTH and ACTIVE_TRANSITION_ACTION_BATCH, as React clears its transition for a commit.
  • External store updates needed no change: scheduleStoreRender was already urgent and never joins an Action.
  • Before this, the old code held a plain useLayoutEffect(() => setHeight(…)), or a setState from the ref callback of a newly mounted element, until a pending async Action settled. A commit flushed inside startTransition, including one that interrupts a deferred View Transition layout, made the layout cascade a transition.
  • useLayoutSnapshot therefore no longer flips syncFlush, ACTIVE_TRANSITION_ACTION_BATCH and TRANSITION_DEPTH, and no longer re-arms the microtask flush by hand.

Non-convergence

  • The commit finishes before the error. The development-only throw from inside the layout effect is gone, so a non-converging snapshot reports through the existing nestedUpdateError path in both modes, after the commit completes.
  • Correct attribution. The "did not converge" note is attached only when that hook's measurement changed on every pass of the exhausted budget. A snapshot that settles between passes of another loop keeps the generic message.

Hook implementation

  • The slot is resolved once per render.
  • The box is created on mount, with no per-render initializer closure.
  • The server keeps a plain record instead of a stateHook cell with a queue and dispatcher.

Types

  • LayoutSnapshotOptions<T> loses the internal Previous parameter.
  • New LayoutSnapshotOptionsWithInitial<T> lets a reusable, annotated options object keep the T return type (from octane and octane/server).

Strong mode

  • New OCTANE_STRONG_LAYOUT_SNAPSHOT_ASYNC rejects async and generator measurements, which return a new object on every commit and never converge.
  • Promise continuations and resource leaks in a measurement get snapshot-specific messages instead of "release it in the returned cleanup".

Docs

  • Document that the measurement runs in hook order with the component's other layout effects.
  • Explain that an observer should update state so the component commits and measures again; this replaces the "use it in addition to the observer" guidance.
  • The changeset is now minor (new feature), plus a patch changeset for the scheduler fix.

Validation

  • Each new or changed test fails before the fix and passes after it:
    • 10 tests on feat: add useLayoutSnapshot #1677's code with this PR's source changes stashed.
    • The flushSync inside startTransition case with the commit-level clearing removed.
    • Both callback-ref cases, including the reviewer's repro of an urgent click that mounts an element whose ref callback sets state, without the ref clause.
    • The interrupted deferred View Transition layout (view-transition-matching.test.ts) without the clearing in completeDeferredLayouts.
    • The external store write from a layout effect passes on both sides; it pins existing behavior.
  • Targeted: layout-snapshot.test.ts, the new layout-effect-update-priority.test.ts, compiler/layout-snapshot.test.ts, and view-transition-matching.test.ts.
  • Nearby scheduler, transition, action, effect-order, view-transition, Suspense-effect, ref and SSR-witness suites, plus compiler/strong-effects.test.ts.
  • octane-tsc -p packages/octane/tsconfig.json -p packages/octane/typetests/tsconfig.json, pnpm typecheck:files, pnpm format:files:check, pnpm error-codes:check, pnpm changeset:check, pnpm sync (no generated changes).
  • Bundle budgets: run-minimal.mjs --budgets and run.mjs --budgets octane-tsrx octane-jsx pass on the head merged with main (which now includes ci(bench): raise byte budgets for urgent layout-effect updates #1685). The View Transition fix lives in the optional deferred-layout driver and adds nothing to the measured bundles.
  • pnpm test, pnpm typecheck, pnpm format:check (repository-wide): not run locally; left to CI.

Risk / follow-ups

  • Scheduler change for every app. Updates from layout and insertion effects and callback refs no longer join a pending Action or take transition priority, and work inside commitEffects or completeDeferredLayouts no longer inherits an ambient transition. This matches React. Anything that relied on the old entanglement now commits urgently.
  • Not changed here.
    • Passive-effect updates during a pending Action keep their current entanglement.
    • flushSync inside startTransition still stages the flushSync callback's own updates into the transition.
    • The nested-update budget still accumulates across a long passive-effect cascade, where React resets it per commit.
  • Size. About +85–115 raw and +33–73 gzip bytes in core bundles, including apps that never use the new hook. That is the cost of the shared scheduler fix: the inCommitCallback() check is about half, and clearing the transition once per commit is the rest. The alternative is feat: add useLayoutSnapshot #1677's hook-only override, which costs no core bytes but leaves ordinary layout effects and refs held behind a pending Action. The budgets were raised in ci(bench): raise byte budgets for urgent layout-effect updates #1685.

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
Scheduler changes affect all layout/insertion effect and ref-callback updates globally (now urgent vs pending Actions/transitions); the new hook adds commit-phase measurement loops bounded by update-depth limits.

Overview
Ships useLayoutSnapshot as a public DOM hook: measure after commit (layout timing), compare with Object.is or equal, SSR/hydration via initial, and dev attribution when measurements never converge. Adds LayoutSnapshotOptionsWithInitial for typed reusable options; compiler slot handling matches other state hooks (including spread args).

Scheduler parity fix: updates from insertion/layout effects and callback refs run at urgent priority again—inCommitCallback() opts them out of in-flight Action batches and transition tagging, and commitEffects temporarily clears ambient transition state so a flushSync inside startTransition does not absorb commit-phase work.

Strong mode: treats snapshot callbacks like effect setup (with snapshot-specific leak/fetch messages), adds OCTANE_STRONG_LAYOUT_SNAPSHOT_ASYNC for async/generator measurements, and generalizes comparator-options tracking beyond useLinkedState.

Docs, website, changesets (minor + patch), and broad unit/browser/compiler tests cover the hook and priority behavior.

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

domgan-oai and others added 8 commits October 3, 2026 18:41
- Clear the ambient transition for a commit and keep insertion/layout effect
  updates out of an in-flight Action's batch, as React does. The hook no longer
  overrides scheduler globals or re-arms the flush itself.
- Report a non-converging snapshot through the existing depth error after the
  commit finishes, and name the hook only when it changed on every pass.
- Resolve the hook slot once and create the box on mount; the server keeps a
  plain record instead of a dispatchable state cell.
- Add LayoutSnapshotOptionsWithInitial for reusable options with an initial
  value.
- Strong mode rejects async or generator measurements and stops suggesting a
  cleanup return for snapshot continuations and resources.
- Document hook ordering and how observers trigger a new measurement; mark the
  feature as a minor release.

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

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Commit refs still join Actions
    • Extended inCommitCallback() to also check REF_CALLBACK_DEPTH > 0 and STORE_SYNC_DEPTH > 0, so callback refs and store consistency checks no longer fall through to the in-flight Action batch or transition-priority path.

Create PR

Or push these changes by commenting:

@cursor push 7b74a2d4dc
Preview (7b74a2d4dc)
diff --git a/packages/octane/src/runtime.ts b/packages/octane/src/runtime.ts
--- a/packages/octane/src/runtime.ts
+++ b/packages/octane/src/runtime.ts
@@ -2686,14 +2686,18 @@
 }
 
 /**
- * Insertion and layout effect callbacks run synchronously inside a commit, so no
- * post-await Action continuation can be on the stack. Like React, their updates
- * are urgent and never join an in-flight Action; commitEffects also clears any
- * transition the commit inherited. A transition started inside the callback
- * still owns its own updates.
+ * Insertion and layout effect callbacks, callback refs and store consistency
+ * checks run synchronously inside a commit, so no post-await Action continuation
+ * can be on the stack. Like React, their updates are urgent and never join an
+ * in-flight Action; commitEffects also clears any transition the commit
+ * inherited. A transition started inside the callback still owns its own updates.
  */
 function inCommitCallback(): boolean {
-	return EFFECT_BODY_DEPTH > 0 && CURRENT_EFFECT_PHASE !== PASSIVE;
+	return (
+		(EFFECT_BODY_DEPTH > 0 && CURRENT_EFFECT_PHASE !== PASSIVE) ||
+		REF_CALLBACK_DEPTH > 0 ||
+		STORE_SYNC_DEPTH > 0
+	);
 }
 
 function transitionActionBatchForUpdate(): TransitionActionBatch | null {

You can send follow-ups to the cloud agent here.

Reviewed by Cursor Bugbot for commit f90a5c3. Configure here.

Comment thread packages/octane/src/runtime.ts Resolved
@domgan-oai

Copy link
Copy Markdown
Contributor

I like the move to a shared scheduler fix: it removes hook-specific scheduler manipulation and also addresses the priority issue for ordinary layout effects. Since the scheduler change affects all applications, the commit-time edge cases deserve explicit coverage.

One gap in the current description's claim that callback refs become urgent: I reproduced an urgent click mounting an element whose ref callback calls a state setter while an unrelated async Action is pending. In both development and production builds, the state update remains pending until the Action resolves; the equivalent React 19.2.7 case updates before it resolves. I reproduced the same Octane behavior with the base-main runtime, so this is a preexisting parity gap rather than a regression introduced by this PR. It appears inCommitCallback() recognizes effect bodies but not callback refs in this path. Could we add a regression test and fix that case, or narrow the claim and track it separately? Store synchronization appears to follow the same excluded path, but I have not reproduced that case independently.

I'd also add a test for a deferred View Transition interrupted inside a transition while its deferred layout effect schedules an update. The source suggests that callback could retain transition priority, but I haven't reproduced a failure, so this is a coverage concern rather than a confirmed bug.

The current failed CI shard stops at the bundle-size gate before its tests: the starter is 59 raw bytes over its current budget. #1685 addresses the budget, and the reported core bundle increase is worth evaluating as a cost of the shared scheduler fix, including for applications that do not use the new hook.

@github-actions

github-actions Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark report

  • 🔴 bundle-size: 37 value(s) increased within budget
  • 🔴 bundle-reachability: 64 value(s) increased within budget

Compares 425a32a5f, the merge commit's first parent with a0c0a600c on the same runner. A byte value over its committed budget or any increase in a js-framework work counter fails this check. Wall time is a report: base and head samples alternate in one browser, and an operation is called slower or faster only when the 95% confidence interval of its ratio excludes ±3%. Workflow run

js-framework: 1k/10k row operations

target operation base ms head ms head/base 95% CI
octane-tsrx select_lots 0.005 0.005 −6.7% −7.3% … −4.9% 🟢 faster
All 20 timed operations (19 without a verdict)
target operation base ms head ms head/base 95% CI
octane-tsrx run 2.958 2.725 +3.8% −7.0% … +5.3% ⚪ within noise
octane-tsrx replace 6.225 6.175 +2.5% −1.7% … +6.1% ⚪ within noise
octane-tsrx add 2.433 2.408 ±0.0% −3.6% … +8.0% ⚪ within noise
octane-tsrx update 0.117 0.119 +2.0% +0.6% … +2.9% ⚪ within noise
octane-tsrx select 0.005 0.005 +0.5% ±0.0% … +1.6% ⚪ within noise
octane-tsrx swap 0.034 0.034 ±0.0% −1.0% … +0.0% ⚪ within noise
octane-tsrx remove 0.016 0.016 +0.0% −1.6% … +1.6% ⚪ within noise
octane-tsrx runlots 22.450 23.467 −1.1% −3.4% … +3.2% ⚪ within noise
octane-tsrx select_lots 0.005 0.005 −6.7% −7.3% … −4.9% 🟢 faster
octane-tsrx clear 41.625 41.692 −1.4% −2.8% … +1.0% ⚪ within noise
octane-jsx run 3.175 3.142 −0.0% −2.9% … ±0.0% ⚪ within noise
octane-jsx replace 5.617 5.642 +0.8% −3.6% … +3.6% ⚪ within noise
octane-jsx add 2.917 2.925 ±0.0% −1.6% … +0.0% ⚪ within noise
octane-jsx update 0.231 0.231 +0.7% −0.0% … +1.3% ⚪ within noise
octane-jsx select 0.117 0.117 +0.0% ±0.0% … +0.9% ⚪ within noise
octane-jsx swap 0.217 0.212 −1.1% −2.3% … −0.0% ⚪ within noise
octane-jsx remove 0.168 0.169 ±0.0% −0.6% … +0.6% ⚪ within noise
octane-jsx runlots 27.017 27.358 +0.2% −1.8% … +3.9% ⚪ within noise
octane-jsx select_lots 1.416 1.406 −0.6% −0.9% … +0.6% ⚪ within noise
octane-jsx clear 45.325 46.008 ±0.0% −0.5% … +1.0% ⚪ within noise

All 64 work counters are unchanged.

Application bundle size (bytes)

target metric base head Δ
octane-tsrx js_raw 125,251 125,342 +91 (+0.1%) 🔴
octane-tsrx js_gzip 41,375 41,427 +52 (+0.1%) 🔴
octane-tsrx js_brotli 36,542 36,563 +21 (+0.1%) 🔴
octane-tsrx app_gzip 2,562 2,563 +1 (+0.0%) 🔴
octane-tsrx app_brotli 2,226 2,227 +1 (+0.0%) 🔴
octane-tsrx fw_raw 117,739 117,830 +91 (+0.1%) 🔴
octane-tsrx fw_gzip 38,813 38,864 +51 (+0.1%) 🔴
octane-tsrx fw_brotli 34,316 34,336 +20 (+0.1%) 🔴
octane-tsrx todo_js_raw 140,728 140,819 +91 (+0.1%) 🔴
octane-tsrx todo_js_gzip 46,441 46,478 +37 (+0.1%) 🔴
octane-tsrx todo_js_brotli 40,816 40,803 −13 (−0.0%) 🟢
octane-tsrx todo_app_brotli 2,118 2,117 −1 (−0.0%) 🟢
octane-tsrx todo_fw_raw 135,618 135,709 +91 (+0.1%) 🔴
octane-tsrx todo_fw_gzip 43,964 44,001 +37 (+0.1%) 🔴
octane-tsrx todo_fw_brotli 38,698 38,686 −12 (−0.0%) 🟢
octane-tsrx chat_js_raw 139,848 139,939 +91 (+0.1%) 🔴
octane-tsrx chat_js_gzip 46,341 46,405 +64 (+0.1%) 🔴
octane-tsrx chat_js_brotli 40,693 40,762 +69 (+0.2%) 🔴
octane-tsrx chat_app_gzip 2,979 2,977 −2 (−0.1%) 🟢
octane-tsrx chat_app_brotli 2,635 2,634 −1 (−0.0%) 🟢
octane-tsrx chat_fw_raw 133,195 133,286 +91 (+0.1%) 🔴
octane-tsrx chat_fw_gzip 43,362 43,428 +66 (+0.2%) 🔴
octane-tsrx chat_fw_brotli 38,058 38,128 +70 (+0.2%) 🔴
octane-tsrx weather_js_raw 176,826 176,917 +91 (+0.1%) 🔴
octane-tsrx weather_js_gzip 57,788 57,847 +59 (+0.1%) 🔴
octane-tsrx weather_js_brotli 50,315 50,419 +104 (+0.2%) 🔴
octane-tsrx weather_app_gzip 9,034 9,035 +1 (+0.0%) 🔴
octane-tsrx weather_app_brotli 7,556 7,595 +39 (+0.5%) 🔴
octane-tsrx weather_fw_raw 150,147 150,238 +91 (+0.1%) 🔴
octane-tsrx weather_fw_gzip 48,754 48,812 +58 (+0.1%) 🔴
octane-tsrx weather_fw_brotli 42,759 42,824 +65 (+0.2%) 🔴
octane-tsrx bindings_js_raw 718,810 718,907 +97 (+0.0%) 🔴
octane-tsrx bindings_js_gzip 240,407 240,420 +13 (+0.0%) 🔴
octane-tsrx bindings_js_brotli 204,738 204,615 −123 (−0.1%) 🟢
octane-tsrx bindings_app_gzip 121,728 121,716 −12 (−0.0%) 🟢
octane-tsrx bindings_app_brotli 101,836 101,626 −210 (−0.2%) 🟢
octane-tsrx bindings_fw_raw 362,889 362,986 +97 (+0.0%) 🔴
octane-tsrx bindings_fw_gzip 118,679 118,704 +25 (+0.0%) 🔴
octane-tsrx bindings_fw_brotli 102,902 102,989 +87 (+0.1%) 🔴
octane-jsx js_raw 227,064 227,161 +97 (+0.0%) 🔴
octane-jsx js_gzip 72,457 72,489 +32 (+0.0%) 🔴
octane-jsx js_brotli 62,728 62,815 +87 (+0.1%) 🔴
octane-jsx fw_raw 218,605 218,702 +97 (+0.0%) 🔴
octane-jsx fw_gzip 69,521 69,553 +32 (+0.0%) 🔴
octane-jsx fw_brotli 60,223 60,310 +87 (+0.1%) 🔴

9 other measured values are unchanged.

Public-import reachability bundles (bytes)

target metric base head Δ
cli-spa-starter raw 115,043 115,140 +97 (+0.1%) 🔴
cli-spa-starter gzip 38,817 38,877 +60 (+0.2%) 🔴
cli-spa-starter brotli 33,943 34,015 +72 (+0.2%) 🔴
root-static-specialized raw 76,977 77,071 +94 (+0.1%) 🔴
root-static-specialized gzip 25,537 25,589 +52 (+0.2%) 🔴
root-static-specialized brotli 22,763 22,797 +34 (+0.1%) 🔴
root-chained-jsx raw 84,303 84,398 +95 (+0.1%) 🔴
root-chained-jsx gzip 27,865 27,915 +50 (+0.2%) 🔴
root-chained-jsx brotli 24,820 24,867 +47 (+0.2%) 🔴
root-static raw 203,303 203,400 +97 (+0.0%) 🔴
root-static gzip 64,638 64,672 +34 (+0.1%) 🔴
root-static brotli 56,047 56,119 +72 (+0.1%) 🔴
root-static-local raw 76,980 77,074 +94 (+0.1%) 🔴
root-static-local gzip 25,524 25,572 +48 (+0.2%) 🔴
root-static-local brotli 22,753 22,794 +41 (+0.2%) 🔴
hooks-state raw 89,041 89,131 +90 (+0.1%) 🔴
hooks-state gzip 29,538 29,601 +63 (+0.2%) 🔴
hooks-state brotli 26,319 26,301 −18 (−0.1%) 🟢
prop-attributes raw 95,655 95,745 +90 (+0.1%) 🔴
prop-attributes gzip 31,695 31,751 +56 (+0.2%) 🔴
prop-attributes brotli 28,173 28,223 +50 (+0.2%) 🔴
context raw 109,129 109,220 +91 (+0.1%) 🔴
context gzip 36,057 36,117 +60 (+0.2%) 🔴
context brotli 31,956 31,988 +32 (+0.1%) 🔴
hydrate-root raw 173,265 173,362 +97 (+0.1%) 🔴
hydrate-root gzip 54,916 54,977 +61 (+0.1%) 🔴
hydrate-root brotli 47,933 47,942 +9 (+0.0%) 🔴
deferred-hydration raw 236,613 236,710 +97 (+0.0%) 🔴
deferred-hydration gzip 74,795 74,838 +43 (+0.1%) 🔴
deferred-hydration brotli 64,567 64,566 −1 (−0.0%) 🟢
suspense-transition raw 165,071 165,167 +96 (+0.1%) 🔴
suspense-transition gzip 52,970 53,020 +50 (+0.1%) 🔴
suspense-transition brotli 46,374 46,473 +99 (+0.2%) 🔴
component-owned-effects raw 81,491 81,586 +95 (+0.1%) 🔴
component-owned-effects gzip 26,822 26,880 +58 (+0.2%) 🔴
component-owned-effects brotli 23,890 23,940 +50 (+0.2%) 🔴
binding-hooks raw 87,556 87,649 +93 (+0.1%) 🔴
binding-hooks gzip 29,298 29,341 +43 (+0.1%) 🔴
binding-hooks brotli 26,095 26,069 −26 (−0.1%) 🟢
binding-base-ui-vite raw 213,534 213,631 +97 (+0.0%) 🔴
binding-base-ui-vite gzip 68,212 68,279 +67 (+0.1%) 🔴
binding-base-ui-vite brotli 59,093 59,204 +111 (+0.2%) 🔴
binding-base-ui-esbuild raw 211,479 211,576 +97 (+0.0%) 🔴
binding-base-ui-esbuild gzip 68,150 68,210 +60 (+0.1%) 🔴
binding-base-ui-esbuild brotli 59,105 59,184 +79 (+0.1%) 🔴
binding-aria-esbuild brotli 2,980 2,979 −1 (−0.0%) 🟢
binding-radix-vite raw 215,466 215,563 +97 (+0.0%) 🔴
binding-radix-vite gzip 68,752 68,807 +55 (+0.1%) 🔴
binding-radix-vite brotli 59,634 59,687 +53 (+0.1%) 🔴
binding-radix-esbuild raw 213,370 213,467 +97 (+0.0%) 🔴
binding-radix-esbuild gzip 68,753 68,797 +44 (+0.1%) 🔴
binding-radix-esbuild brotli 59,663 59,778 +115 (+0.2%) 🔴
binding-mantine-hooks-vite raw 96,138 96,228 +90 (+0.1%) 🔴
binding-mantine-hooks-vite gzip 31,872 31,912 +40 (+0.1%) 🔴
binding-mantine-hooks-vite brotli 28,306 28,397 +91 (+0.3%) 🔴
binding-mantine-hooks-esbuild raw 95,741 95,831 +90 (+0.1%) 🔴
binding-mantine-hooks-esbuild gzip 32,014 32,073 +59 (+0.2%) 🔴
binding-mantine-hooks-esbuild brotli 28,486 28,508 +22 (+0.1%) 🔴
binding-apollo-client-vite raw 358,526 358,623 +97 (+0.0%) 🔴
binding-apollo-client-vite gzip 112,298 112,365 +67 (+0.1%) 🔴
binding-apollo-client-vite brotli 98,049 98,044 −5 (−0.0%) 🟢
binding-apollo-client-esbuild raw 361,463 361,560 +97 (+0.0%) 🔴
binding-apollo-client-esbuild gzip 114,490 114,544 +54 (+0.0%) 🔴
binding-apollo-client-esbuild brotli 99,812 99,791 −21 (−0.0%) 🟢
binding-usehooks-ts-vite raw 96,919 97,009 +90 (+0.1%) 🔴
binding-usehooks-ts-vite gzip 32,111 32,154 +43 (+0.1%) 🔴
binding-usehooks-ts-vite brotli 28,582 28,613 +31 (+0.1%) 🔴
binding-usehooks-ts-esbuild raw 96,507 96,597 +90 (+0.1%) 🔴
binding-usehooks-ts-esbuild gzip 32,251 32,311 +60 (+0.2%) 🔴
binding-usehooks-ts-esbuild brotli 28,647 28,713 +66 (+0.2%) 🔴

35 other measured values are unchanged.

trueadm and others added 3 commits October 3, 2026 20:23
Callback refs run inside the commit like layout effects, so their updates are
urgent and never join an in-flight Action. Store consistency checks already
schedule urgently through scheduleStoreRender.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…tion

completeDeferredLayouts runs a View Transition's deferred refs and layout
effects outside commitEffects, so it clears the ambient transition too. A
commit flushed inside startTransition that interrupts the pending layout no
longer leaves the layout cascade at transition priority.

Also covers an update from the ref callback of a newly mounted element and an
external store write from a layout effect while an async Action is pending.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@trueadm

trueadm commented Oct 3, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks, I worked through each point:

  • Callback refs: fixed. inCommitCallback() now also covers callback refs (REF_CALLBACK_DEPTH > 0). layout-effect-update-priority.test.ts has your repro: an urgent click mounts an element whose ref callback sets state while an unrelated async Action is pending. It also covers a ref that re-attaches on update. Both fail without the change and pass with it, under both dev and prod compiles.
  • Store sync: no fix was needed. Every external-store update goes through scheduleStoreRender, which zeroes TRANSITION_DEPTH/ASYNC_TRANSITION_COUNT and never consults the Action batch. A new test pins it: a layout effect writes the store while an Action is pending, and the consumer updates before the Action settles. It passes on the base too.
  • Deferred View Transition: your reading was right, and it reproduced. completeDeferredLayouts runs deferred refs and layout effects outside commitEffects. When a commit flushed inside startTransition interrupted it, layout:1:0 ran but the cascade it scheduled stayed in the transition. completeDeferredLayouts now clears the ambient transition the same way. The new test is in view-transition-matching.test.ts. That code is in the optional deferred-layout driver, so the measured bundles don't move.
  • Size: CI failed only on the bundle-size gate. ci(bench): raise byte budgets for urgent layout-effect updates #1685 has merged and the head now includes it; the size checks pass locally. The cost is about +85–115 raw / +33–73 gzip bytes in every core bundle, including apps that don't use the hook. Roughly half is the inCommitCallback() check and half is clearing the transition per commit. The zero-byte alternative is feat: add useLayoutSnapshot #1677's hook-local override, but it leaves ordinary layout effects and refs held behind a pending Action. I've put this trade-off in the description.

The description no longer claims more than the code does. Changes are in 69b771f and b830a7f.

🤖 Addressed by Claude Code

trueadm added a commit that referenced this pull request Oct 3, 2026
Main gained #1685, which raised 51 budgets for the useLayoutSnapshot
commit-phase priority fix (#1686), and #1681/#1665. Re-measured on main
425a32a: each of #1663, #1664 and #1666 merged alone, and all three
plus #1686 merged together. Each budget is the larger of main's value and
the largest measured value plus 32 (raw/gzip) or 256 (brotli), so the
three perf PRs and #1686 can land in any order.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@trueadm
trueadm merged commit 00f8304 into main Oct 3, 2026
31 checks passed
@trueadm
trueadm deleted the fix/layout-snapshot-review branch October 3, 2026 19:52
trueadm added a commit that referenced this pull request Oct 3, 2026
Resolve the useLayoutSnapshot (#1686) overlap. useLayoutSnapshot joins the
new SPREAD_PATH_SLOT_HOOKS set only, so a spread call takes its slot from the
call path while empty calls and non-numeric slots keep its existing ABI.
Strong keeps its measure callback at the syntactic position visitEffect reads,
and useLinkedState uses the renamed visitHookComparators. Both docs sections
are kept, and the core-apis a11y selectors shift by both new sections (+10).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
trueadm added a commit that referenced this pull request Oct 4, 2026
…dget (#1688)

* fix(octane): give each passive-driven commit a fresh nested-update budget

A passive effect that advances state once per commit, next to a layout
effect that publishes one converging measurement per commit, threw
"Maximum update depth exceeded" around step 50. The synchronous-callback
budget was keyed by UPDATE_CHAIN_ID, which passive updates deliberately
never bump, and passive effects drained ahead of each re-render merged
into it, so no commit ever settled.

The budget now has its own chain, reset after any outermost commit with
no synchronous-callback update since the previous one (React's
commitRootImpl rule). When a block exhausts it while passive effects
wait, those effects are held for one render: a passive-driven cascade
settles and continues after paint with a dev warning, a real loop
schedules again and throws. Layout, ref-callback, store-sync and
flushSync-in-useEffect loops still throw.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(octane): key useLayoutSnapshot attribution on the nested-update chain

useLayoutSnapshot's "did not converge" note (#1686) compared its record
with block.nestedUpdateChain, which now holds the nested-update chain.
Key both on it. A snapshot that converges once per passive step now
finishes the cascade instead of throwing with that note.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* docs(changeset): mention useLayoutSnapshot in the passive-cascade fix

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(octane): never strand passive effects held for a nested-update probe

completeDeferredLayouts runs deferred layout effects at commit depth 1,
where a hold can arm, but commits its follow-up renders at depth 2, where
finishNestedUpdateCommit never runs. A probe that settled there left the
hold set, and every later passive drain returned early.

A passive drain that finds the hold set with no render queued now closes
the chain itself: the probe it waited for has already run. While the
probe is still queued, the drain keeps holding.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* perf(octane): add no function calls to the commit path for the update budget

The PR benchmark counts every production function call per operation, and
each js-framework operation made 4 more: hasPendingPassiveWork() in
commitEffects and drainPassivesBeforeRender, and finishNestedUpdateCommit()
on every commit. Restore the inline passive-queue checks and close the
sync-callback chain inline; only a settled hold calls out of line.

Pin the ordinary per-commit reset with a cascade whose effect advances only
after each measurement commits: every step settles without a hold, and
removing the reset makes it throw at step 51.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
trueadm added a commit that referenced this pull request Oct 4, 2026
…as passive (#1690)

* fix(octane): give each passive-driven commit a fresh nested-update budget

A passive effect that advances state once per commit, next to a layout
effect that publishes one converging measurement per commit, threw
"Maximum update depth exceeded" around step 50. The synchronous-callback
budget was keyed by UPDATE_CHAIN_ID, which passive updates deliberately
never bump, and passive effects drained ahead of each re-render merged
into it, so no commit ever settled.

The budget now has its own chain, reset after any outermost commit with
no synchronous-callback update since the previous one (React's
commitRootImpl rule). When a block exhausts it while passive effects
wait, those effects are held for one render: a passive-driven cascade
settles and continues after paint with a dev warning, a real loop
schedules again and throws. Layout, ref-callback, store-sync and
flushSync-in-useEffect loops still throw.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(octane): key useLayoutSnapshot attribution on the nested-update chain

useLayoutSnapshot's "did not converge" note (#1686) compared its record
with block.nestedUpdateChain, which now holds the nested-update chain.
Key both on it. A snapshot that converges once per passive step now
finishes the cascade instead of throwing with that note.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* docs(changeset): mention useLayoutSnapshot in the passive-cascade fix

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(octane): never strand passive effects held for a nested-update probe

completeDeferredLayouts runs deferred layout effects at commit depth 1,
where a hold can arm, but commits its follow-up renders at depth 2, where
finishNestedUpdateCommit never runs. A probe that settled there left the
hold set, and every later passive drain returned early.

A passive drain that finds the hold set with no render queued now closes
the chain itself: the probe it waited for has already run. While the
probe is still queued, the drain keeps holding.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* perf(octane): add no function calls to the commit path for the update budget

The PR benchmark counts every production function call per operation, and
each js-framework operation made 4 more: hasPendingPassiveWork() in
commitEffects and drainPassivesBeforeRender, and finishNestedUpdateCommit()
on every commit. Restore the inline passive-queue checks and close the
sync-callback chain inline; only a settled hold calls out of line.

Pin the ordinary per-commit reset with a cascade whose effect advances only
after each measurement commits: every step settles without a hold, and
removing the reset makes it throw at step 51.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(octane): count passive effects drained before a flushSync render as passive

Under a flushSync drain (sync act(), or a user flushSync), passive effects
that run ahead of the next render had their updates counted against the
synchronous-callback budget, because the classification only checked
`!syncFlush`. React flushes those effects at no higher than default
priority. A passive cascade measured by child layout effects therefore threw
"Maximum update depth exceeded" around step 51 under sync act() while the
same app worked in an ordinary flush.

Passive updates now count as passive when `!syncFlush || inFlush`. A
flushSync that a passive effect calls from a post-paint or act() drain runs
its callback before inFlush is set, so flushSync-in-useEffect loops keep the
hard limit.

flushSync also drains with no effect phase set and restores it afterwards.
Otherwise ref callbacks and store checks in the commit started by a passive
effect's own flushSync saw a stale passive phase together with inFlush, and a
callback-ref loop there took twice as many calls to throw.

The two-sibling flushSync loop no longer reaches the passive hold guard, so
two fixtures now pin each half of it: a loop whose own flushSync spends the
last update while its child's effect is queued (phase half), and a loop whose
child layout measurement spends it two commits deep (depth half).

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

2 participants