Repository navigation
fix(octane): count passive effects drained before a flushSync render as passive - #1690
Conversation
…dget 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]>
…hain 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]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
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]>
… 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]>
…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]>
Benchmark report
Compares js-framework: 1k/10k row operationsAll 20 timed operations (20 without a verdict)
All 64 work counters are unchanged. Application bundle size (bytes)❌ 26 value(s) exceed their committed budget. Reduce the growth, or raise the budget in a separate pull request that names the bytes and the reason (CONTRIBUTING.md, "Size budgets").
8 other measured values are unchanged. Public-import reachability bundles (bytes)❌ 47 value(s) exceed their committed budget. Reduce the growth, or raise the budget in a separate pull request that names the bytes and the reason (CONTRIBUTING.md, "Size budgets").
35 other measured values are unchanged. |
…/fervent-murdock-c2e0dc # Conflicts: # packages/octane/tests/conformance/_fixtures/update-reconciliation.tsrx # packages/octane/tests/conformance/update-reconciliation.test.ts
#1690 (stacked on #1688) fits every raw and gzip budget that #1689 raised, but measures two brotli values above main's budgets: hydrate-root 48,099 and chat/total 40,951. Raise both to that measurement plus the 256-byte brotli headroom (48,355 and 41,207), so the budgets cover #1688 alone and #1688 + #1690. Budgets only. Co-authored-by: Claude Opus 5.5 <[email protected]>
Summary
Under a
flushSyncdrain, which covers syncact()callbacks as well as a userflushSync, passive effects that run before the next render had their state updates counted against the synchronous-callback budget.scheduleRenderclassified an update as passive only whenCURRENT_EFFECT_PHASE === PASSIVE && !syncFlush. React flushes these effects at no higher than default priority, so their updates never take the sync lane.Concrete failure. A parent's
useEffectadvancesstepto 60. Two children each re-measure in auseLayoutEffect, offset so exactly one publishes per step. Under syncactthe parent's passive updates used up its budget at about step 51 and threw "Maximum update depth exceeded". The same app worked in a normal flush.Changes (all in
packages/octane/src/runtime.ts):!syncFlush || inFlush. Passive effects drained before a render run withinFlush === true. AflushSyncthat a passive effect calls from a post-paint oract()drain runs its callback beforeinFlushis set, soflushSync-in-useEffectloops keep the hard limit.flushSyncnow runs its drain with no effect phase set and restores the phase afterwards. Ref callbacks anduseSyncExternalStorechecks never set the phase. Without this reset, those running in the commit started by a passive effect's ownflushSyncsaw a stale "passive" phase together withinFlush, and counted as passive. A callback-ref loop there took 204 ref calls to throw instead of 102.Tests
All tests are in
tests/conformance/update-reconciliation.test.ts, with fixtures in_fixtures/update-reconciliation.tsrx.finishes a passive cascade with child layout measurements under synchronous act()(PassiveStepSplitMeasure): the repro, run under both sync and asyncact. Before the fix it fails inoctaneandoctane-prod.EFFECT_COMMIT_DEPTH <= 1 && CURRENT_EFFECT_PHASE !== PASSIVE, from fix(octane): give each passive-driven commit a fresh nested-update budget #1688). With the new classification, the two-siblingSynchronousPassiveEffectLoopsfixture no longer reaches this guard: its 51st update arrives with no passive work queued. Two new fixtures join theprevents infinite update loop triggered by synchronous updates in useEffectlist:SynchronousPassiveEffectLoopOverChild: the child loop mounts one step late, and itsflushSynccommit queues its next effect just before the parent's 51st update. That update lands at commit depth 1, in the passive phase, with passive work queued. It pins the phase half.SynchronousPassiveEffectLoopWithMeasure: a child layout measurement spends its 51st update two commits deep (depth 2) with the loop's next effect queued. It pins the depth half, which no test covered before, not even under the old classification.stops a callback-ref loop flushed from useEffect at the usual limit: the same ref loop is committed directly and from aflushSyncinuseEffect. The test requires equal ref-call counts, which pins the phase reset.Validation
pnpm format:check(not run repo-wide;pnpm format:files:checkpasses on the changed files)pnpm typecheck(not run repo-wide;pnpm typecheck:fileson the runtime, test and fixture reports only the fixture's existing untyped-propserrors, none on new lines)pnpm test(not run; left to CI)targeted tests:
update-reconciliation.test.ts, 40/40 in both theoctaneandoctane-prodprojects. Nine neighbouring files also pass inoctane, 238 tests:act,layout-snapshot,audit-hook-behavior,external-store-shared,useref,compiled-ref-detach,strong-state-runtime,root-semantics,hook-fixes.Mutation checks, each turning a test red in both projects:
useEffectloop test…OverChild…WithMeasureBundle sizes, measured against fix(octane): give each passive-driven commit a fresh nested-update budget #1688's head: +23–28 raw and +1–13 gzip per affected client bundle. About 6 bytes are the classification and about 20 the phase reset. The comparative suite moves +28 raw, −4 to +13 gzip.
run-minimal.mjs --budgetsandrun.mjs --budgets octane-tsrx octane-jsxboth fail, but fix(octane): give each passive-driven commit a fresh nested-update budget #1688 alone already fails them: it is 216–248 raw over the minimal client budgets and breaches 26 comparative budgets. This PR adds no new comparative breach beyond achat/totalbrotli number within compression noise.Risk / follow-ups
hydrate-root.brotli(+35) andchat/totalbrotli (+2), still breach until ci(bench): raise two brotli budgets for the stacked #1690 #1692 merges. After it does, mergemaininto this branch again.flushSyncitself is still classified as passive.flushSyncdefers inside a flush, and the normal microtask path already behaved this way before this change. React gives that update the sync lane. So aflushSync-in-useEffectloop throws only when its effect runs after paint or from anactdrain.scheduleRenderreadsinFlushonly when the phase is passive andsyncFlushis set.flushSyncgains two assignments per call.Provenance
agent-authored)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Note
Medium Risk
Touches hot-path update classification in
scheduleRenderandflushSyncdrain behavior; behavior change affects syncact()andflushSyncedge cases but is covered by expanded conformance tests.Overview
Aligns Octane with React when passive effects run before a
flushSyncrender (including synchronousact()): their state updates now use the passive update budget instead of the synchronous one. That fixes false "Maximum update depth exceeded" errors on long passive cascades with child layout measurements that already converged under a normal flush.In
scheduleRender, passive-phase updates count as passive whensyncFlushis on only ifinFlushis set (the pre-render passive drain). AflushSyncinvoked from inside a passive effect still runs beforeinFlush, soflushSync-in-useEffectloops keep the hard limit.flushSynctemporarily clearsCURRENT_EFFECT_PHASEduring its drain so callback refs anduseSyncExternalStorechecks in commits started from an effect’sflushSyncare not misclassified as passive (which had doubled the effective ref-loop budget).Conformance tests add
PassiveStepSplitMeasure(sync/asyncactrepro), extraflushSync/useEffectloop fixtures, and a test that ref loops fromflushSyncinuseEffecthit the same call limit as a direct commit.Reviewed by Cursor Bugbot for commit 3922b1e. Bugbot is set up for automated code reviews on this repo. Configure here.