Skip to content

fix(octane): bound render loops driven by a component's own signals - #1755

Merged
trueadm merged 1 commit into
mainfrom
fix/signal-update-depth
Oct 5, 2026
Merged

trueadm merged 1 commit into
mainfrom
fix/signal-update-depth

Conversation

@trueadm

@trueadm trueadm commented Oct 5, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #1750. A component-local derived$ or query$ 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 outside act() the cycle ran as an endless microtask chain and froze the tab with no error, as #1735, #1736 and #1737 did.

const opts = { n: 1 };
const d$ = derived$(() => ({ v: base$.get(), opts }));
const v$ = derived$(() => d$.get().v);
<output>{v$.get()}</output>

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 call scheduleRender while the flush is still on the stack, but with CURRENT_BLOCK === null and outside any effect body. scheduleRender treated each of those as a fresh user update and reset the chain, so every pass got a new NESTED_UPDATE_LIMIT budget. Here v$ keeps its value (1), but d$'s new object marks it pending, and native observers render on that propagation without comparing values.

Changes

  • Runtime (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.
  • Production stops too. The loop never yields, so a frozen tab is worse than an error. Production throws minified error Add changeset for the vyre→octane rename release #1, the same as every other synchronous nested-update loop and as React. In development, the message gets a hint naming the component, its source location and the likely cause. This uses the same per-chain attribution map as the useLayoutSnapshot hint, renamed UPDATE_DEPTH_CAUSES.
  • Graph (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 is sameState-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. A paragraph in docs/signals.md after the local-declaration rules, and a patch changeset.

Waiting-promise hazards (assessed)

  • A naive pending equivalence is unsafe. Each node waits on its own wakeup, which follows the thenable that node's evaluation threw. If the cell kept its old wakeup after the view read a different query, or after a write had already invalidated the cell (notify resolves the wakeup), the cell would sit clean and pending on a resolved promise. A reader that retries on it, such as an async derived$ doing await read(x$) (the readValue loop), would spin. Two tests pin both conditions: dropping either one makes a pending read throw an already-settled promise.
  • Async attempts and query views never reach the pending branch. An asynchronous cell gets no view (presentDefinition returns early), and a query view always differs in requestKey. Their resolveWaiting and old-attempt stop() paths are unchanged.
  • Pre-existing, unchanged. A derived that throws a thenable not tied to any graph dependency (a user-created promise) still leaves a resolved wakeup on a clean pending node, both in evaluate() and in reevaluateNode's node.wakeup ??= reuse. After a changed promotion, node.wakeup still belongs to the replaced definition while state.waiting is the view's. I did not touch either.

Validation

  • pnpm format:check: not run repo-wide. format:files ran on every changed file.
  • pnpm typecheck: not run repo-wide. typecheck:files passed on runtime.ts, graph.ts, the new test and its .tsrx fixture.
  • pnpm test: not run locally; CI runs it.
  • targeted tests:
    • packages/octane/tests/signals-update-depth.test.ts: 7/7 in octane-signals, octane-signals-prod and octane-signals-strong.
    • Each source change is pinned by a test that fails without it:
      • Runtime guard reverted: the 3 loop tests fail. They hit the fixture's 200-render bound instead of the depth error, in dev, inside act(), and with NODE_ENV=production.
      • Graph change reverted: the pending and rejected tests fail. The first hits the depth error; in the second the root unmounts.
      • Dependency match dropped: "waits on the query a redeclared definition reads" fails (the thrown promise had already settled).
      • Dirty/Pending check dropped: "waits on the current read when the committed definition is out of date" fails the same way.
    • Neighbors, run once while machine load was low:
      • 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).
  • Bundle size.
    • run-minimal.mjs: +4 raw bytes in the scenarios that reach scheduleNativeRead (hooks-state, hydrate-root, suspense-transition; deferred-hydration +5). An equivalent rewrite of the holdsNativeRead(...) === true line offsets part of the cost.
    • suspense-transition raw 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-jsx holds.

Risk / follow-ups

  • Scope of the new counting. Any native read notification scheduled during a flush now counts as nested, including one delivered mid-render, for example by scope retirement during reconciliation. Render bodies cannot write signals, so a legitimate sequence converges in a few passes. Only 50 consecutive same-block passes in one chain trip the guard. Hook setState accounting is unchanged.
  • A new-object result still loops; it is now bounded. The deeper cause is that native observers are notified on any upstream propagation without checking the value they read. A fix there (validating the reader's witness before scheduling) would stop the loop entirely, but it changes native-read semantics and is out of scope here.
  • Possible gap, not changed here. While building fixtures, I saw a nested @{ } block resolve its component's local derived$/query$ handles in its own signal instance. It started a second load and computed from a separate signal$ cell. docs/signals.md covers directive arms and rows but not nested blocks, so this may be a gap; I will raise it separately.

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 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 via UPDATE_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.

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]>
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix labels Oct 5, 2026
@trueadm
trueadm marked this pull request as ready for review October 5, 2026 11:08
@trueadm
trueadm merged commit 8b97478 into main Oct 5, 2026
38 of 49 checks passed
@trueadm
trueadm deleted the fix/signal-update-depth branch October 5, 2026 11:15
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