Repository navigation
fix(octane): bound render loops driven by a component's own signals - #1755
Merged
Merged
Conversation
A local derived$ or query$ that captures a value the body creates on every render runs again on every render. When its result never compares equal, accepting each render notified its readers, and that re-render started a fresh user update chain, so NESTED_UPDATE_LIMIT never applied. Outside act() the microtask loop froze the page with no error. A native read notification delivered during a flush now spends the flush's nested-update budget, like an update from a layout effect, so the cycle fails with "Maximum update depth exceeded" in production too. In development the message names the component and the likely cause. promoteDeclarationView no longer publishes a view whose result committed readers cannot tell apart: the same value or error, or a pending read waiting on exactly the dependencies the cell already waits on while the cell is current. Otherwise the cell could keep a wakeup that resolves while it stays pending. Co-Authored-By: Claude Opus 5.5 <[email protected]>
2 of 5 tasks
trueadm
marked this pull request as ready for review
October 5, 2026 11:08
2 of 5 tasks
4 of 5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #1750. A component-local
derived$orquery$that captures a value its body creates on every render (an inline object, for example) runs again on every render. When its result never compares equal, accepting each render notified its readers, and the reader's render declared it again. These renders were never counted by the nested-update guard, so outsideact()the cycle ran as an endless microtask chain and froze the tab with no error, as #1735, #1736 and #1737 did.On main, one click renders this component without end. The repro test bounds it at 300 renders.
Why the guard never fired. Declaration acceptance runs in
commitRootRenders(promoteDeclarationView). It notifies native read observers, which callscheduleRenderwhile the flush is still on the stack, but withCURRENT_BLOCK === nulland outside any effect body.scheduleRendertreated each of those as a fresh user update and reset the chain, so every pass got a newNESTED_UPDATE_LIMITbudget. Herev$keeps its value (1), butd$'s new object marks it pending, and native observers render on that propagation without comparing values.Changes
scheduleNativeRead→scheduleRender). A native read notification delivered during a flush now takes the nested-update path, just as an update from a layout effect, ref callback or store sync does. It spends the flush's budget and keeps the chain open across the commit. A cycle that never settles now fails with "Maximum update depth exceeded" through the ordinary render-error path: an error boundary can catch it, and otherwise the root unmounts. Events, query resolutions and other microtask-driven signal writes happen outside a flush and still start their own chain.useLayoutSnapshothint, renamedUPDATE_DEPTH_CAUSES.promoteDeclarationView). A view whose result committed readers cannot tell apart from the cell's no longer publishes. Before, any new snapshot object counted as a change. Now the cell keeps its own snapshot when the result issameState-equal (the same value or error with the same activity), or when both are pending with the same activity. The pending case also requires the cell to be current (not Dirty/Pending) and to have read exactly the view's dependencies. The pending, rejected and same-value captured-object cases now settle rather than loop.docs/signals.mdafter the local-declaration rules, and a patch changeset.Waiting-promise hazards (assessed)
notifyresolves the wakeup), the cell would sit clean and pending on a resolved promise. A reader that retries on it, such as an asyncderived$doingawait read(x$)(thereadValueloop), would spin. Two tests pin both conditions: dropping either one makes a pending read throw an already-settled promise.presentDefinitionreturns early), and a query view always differs inrequestKey. TheirresolveWaitingand old-attemptstop()paths are unchanged.evaluate()and inreevaluateNode'snode.wakeup ??=reuse. After a changed promotion,node.wakeupstill belongs to the replaced definition whilestate.waitingis the view's. I did not touch either.Validation
pnpm format:check: not run repo-wide.format:filesran on every changed file.pnpm typecheck: not run repo-wide.typecheck:filespassed onruntime.ts,graph.ts, the new test and its.tsrxfixture.pnpm test: not run locally; CI runs it.packages/octane/tests/signals-update-depth.test.ts: 7/7 inoctane-signals,octane-signals-prodandoctane-signals-strong.act(), and withNODE_ENV=production.octane-signals:signals-local-chains,signals-local,signals-rendering,signals-hook-declarations,signals-unified,signals-memos(126 tests).signal-local-selectors(133).octane:layout-snapshot,act(57).run-minimal.mjs: +4 raw bytes in the scenarios that reachscheduleNativeRead(hooks-state,hydrate-root,suspense-transition;deferred-hydration+5). An equivalent rewrite of theholdsNativeRead(...) === trueline offsets part of the cost.suspense-transitionraw breaches its budget by 1 byte (165,473 vs 165,472; main measures 165,469). That budget is raised in its own PR, ci(bench): raise the suspense-transition raw budget for the signal update-depth fix #1756, per CONTRIBUTING "Size budgets". Merge it first, then merge main into this branch.run.mjs --budgets octane-tsrx octane-jsxholds.Risk / follow-ups
setStateaccounting is unchanged.@{ }block resolve its component's localderived$/query$handles in its own signal instance. It started a secondloadand computed from a separatesignal$cell.docs/signals.mdcovers directive arms and rows but not nested blocks, so this may be a gap; I will raise it separately.Provenance
agent-authored)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Note
Medium Risk
Changes renderer scheduling and signal declaration commit semantics; broad enough to affect any native read notified mid-flush, though intended paths should converge quickly.
Overview
Signal-driven self-loops from component-local
derived$/query$that capture per-render values (inline objects) and publish unequal results no longer freeze the tab. Renders scheduled by native signal notifications during a commit flush now consume the same nested-update budget as layout-effect updates, so runaway cycles throw Maximum update depth exceeded in dev and production (with a dev hint naming the component and likely cause viaUPDATE_DEPTH_CAUSES).Declaration promotion in the signal graph skips notifying readers when an accepted redeclaration is observably unchanged—same ready/error state, or pending with the same dependencies and wakeup semantics—so pending/rejected query cases with captured inline objects settle instead of looping.
Docs and a patch changeset describe the behavior; new tests cover the loop error, production minified error,
act()failure, and pending/rejected/switched-pending edge cases.Reviewed by Cursor Bugbot for commit 4276661. Bugbot is set up for automated code reviews on this repo. Configure here.