Repository navigation
fix: address useLayoutSnapshot review findings - #1686
Conversation
…eview Co-Authored-By: Claude Opus 5.5 <[email protected]>
- 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]>
…eview Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
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.
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.
|
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 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. |
Benchmark report
Compares js-framework: 1k/10k row operations
All 20 timed operations (19 without a verdict)
All 64 work counters are unchanged. Application bundle size (bytes)
9 other measured values are unchanged. Public-import reachability bundles (bytes)
35 other measured values are unchanged. |
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]>
…eview Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks, I worked through each point:
The description no longer claims more than the code does. Changes are in 69b771f and b830a7f. 🤖 Addressed by Claude Code |
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]>
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]>
…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]>
…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]>


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)
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, andcompleteDeferredLayoutsfor a View Transition's deferred refs and layout effects, clear the ambientTRANSITION_DEPTHandACTIVE_TRANSITION_ACTION_BATCH, as React clears its transition for a commit.scheduleStoreRenderwas already urgent and never joins an Action.useLayoutEffect(() => setHeight(…)), or asetStatefrom the ref callback of a newly mounted element, until a pending async Action settled. A commit flushed insidestartTransition, including one that interrupts a deferred View Transition layout, made the layout cascade a transition.useLayoutSnapshottherefore no longer flipssyncFlush,ACTIVE_TRANSITION_ACTION_BATCHandTRANSITION_DEPTH, and no longer re-arms the microtask flush by hand.Non-convergence
nestedUpdateErrorpath in both modes, after the commit completes.Hook implementation
stateHookcell with a queue and dispatcher.Types
LayoutSnapshotOptions<T>loses the internalPreviousparameter.LayoutSnapshotOptionsWithInitial<T>lets a reusable, annotated options object keep theTreturn type (fromoctaneandoctane/server).Strong mode
OCTANE_STRONG_LAYOUT_SNAPSHOT_ASYNCrejectsasyncand generator measurements, which return a new object on every commit and never converge.Docs
minor(new feature), plus apatchchangeset for the scheduler fix.Validation
flushSyncinsidestartTransitioncase with the commit-level clearing removed.view-transition-matching.test.ts) without the clearing incompleteDeferredLayouts.layout-snapshot.test.ts, the newlayout-effect-update-priority.test.ts,compiler/layout-snapshot.test.ts, andview-transition-matching.test.ts.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).run-minimal.mjs --budgetsandrun.mjs --budgets octane-tsrx octane-jsxpass 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
commitEffectsorcompleteDeferredLayoutsno longer inherits an ambient transition. This matches React. Anything that relied on the old entanglement now commits urgently.flushSyncinsidestartTransitionstill stages theflushSynccallback's own updates into the transition.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
agent-authored)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith 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
useLayoutSnapshotas a public DOM hook: measure after commit (layout timing), compare withObject.isorequal, SSR/hydration viainitial, and dev attribution when measurements never converge. AddsLayoutSnapshotOptionsWithInitialfor 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, andcommitEffectstemporarily clears ambient transition state so aflushSyncinsidestartTransitiondoes not absorb commit-phase work.Strong mode: treats snapshot callbacks like effect setup (with snapshot-specific leak/fetch messages), adds
OCTANE_STRONG_LAYOUT_SNAPSHOT_ASYNCfor async/generator measurements, and generalizes comparator-options tracking beyonduseLinkedState.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.