Skip to content

Commit 2da0f8e

Browse files
authored
Merge pull request #4059 from solidjs/claude/u9-rearm-boundary-scope
signals: a re-armed boundary owns content another hold staged (U-9)
2 parents 9f3af34 + af6186a commit 2da0f8e

13 files changed

Lines changed: 405 additions & 309 deletions
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@solidjs/signals": patch
3+
---
4+
5+
A Loading boundary re-armed by `on` owns the content under it that reads a hold another change made (D-14, D-16, U-9). Before, that content joined the hold, so no fallback showed and the boundary reported pending, and a held tree under a re-armed boundary could redraw forever. Now the fallback shows with the re-arming change and the content reveals at the hold's commit, which no longer waits for it. A re-arm whose own change joins that hold still shows no fallback (the frame waits on the same data), and `LOADING_ON_OUTSIDE_HOLD` is reported only for a flight the change itself started.

‎packages/signals/docs/OPEN-QUESTIONS.md‎

Lines changed: 11 additions & 11 deletions
Large diffs are not rendered by default.

‎packages/signals/docs/RULES-DERIVED.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ Whether a fallback is seen depends on whether the boundary is on screen. A fresh
120120

121121
A flight whose only observers are render effects behind a fallback holds no change — a memo under the boundary that no render effect reads was never an observer at all, and one rendered by an effect outside the boundary is that effect's read (F-3). In both orders: a render effect created under a fallback never counts, and a reader that counted while the boundary showed content stops counting the moment `on` sends it back to the fallback. Writes the hold kept for those readers alone commit at once (`Boundary: Loading... | Sum: 2` publishes as one frame); a reader outside the boundary still holds (`Sum` waits until `details` lands). The wait does not vanish; it moves onto the boundary: after the reset the fallback stays until every reader under it has settled — including readers whose flights started before the reset — then one coherent reveal.
122122

123-
**Collapses:** [A33](./SPEC-ASYNC-SEMANTICS.md#a33-a-fallback-caught-flight-holds-no-transaction-a-loading-reset-moves-the-hold-onto-the-boundary) (#3375, #3459), §23.1 item 1, recovery 2.2. **Status:** standing. The nested form — an outer `on`-reset boundary not waiting for a flight its nested `on`-reset boundary catches — is built (U-4, 2026-10-13: a reader a nested collecting boundary holds is that boundary's alone; `tests/fuzz-findings-l2.test.ts`, fuzzer finding F1).
123+
**Collapses:** [A33](./SPEC-ASYNC-SEMANTICS.md#a33-a-fallback-caught-flight-holds-no-transaction-a-loading-reset-moves-the-hold-onto-the-boundary) (#3375, #3459), §23.1 item 1, recovery 2.2. **Status:** standing. The nested form — an outer `on`-reset boundary not waiting for a flight its nested `on`-reset boundary catches — is built (U-4, 2026-10-13: a reader a nested collecting boundary holds is that boundary's alone; `tests/fuzz-findings-l2.test.ts`, fuzzer finding F1). The re-arm over a hold is built (U-9, 2026-10-14): content an earlier hold staged under the boundary, or that reads a hold after the re-arm, is the boundary's — the fallback shows now and the content reveals at that hold's commit, which does not wait for it; no redraw loop (`tests/loading-fallback-in-flush-3540.test.ts`, the re-armed shapes; `tests/loading-on-frame-following-3540.test.ts` §3b, §3c).
124124

125125
### D-15. `on` is a dependency list; the swap lands with the frame of the change that caused it
126126

‎packages/signals/docs/RULES-INDEX.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Status legend: **live** stated and standing · **ruled** carries an explicit rul
5555
| A8 | amended | `docs/SPEC-ASYNC-SEMANTICS.md:173` | — | createMemo.test.ts×1 visibility-oracle-store.states.ts×1 visibility-oracle.states.ts×2 | [ruled, amended in place 2026-07-07] `isPending(() => latest(x))` follows `x`'s own async only — verdicts are per-channel — (**re-ruled 2026-07-07c** — was "tracks the transition the same as `isPendin… |
5656
| A9 | amended | `docs/SPEC-ASYNC-SEMANTICS.md:181` | projection.ts×1 target.ts×1 | spec-async-semantics.test.ts×3 visibility-oracle-store.states.ts×4 visibility-oracle-store.test.ts×1 | [ruled, amended in place 2026-07-07] Store leaves behind a firewall report the firewall's new-question refetch — `isPending` on a store leaf behind a firewall reports the firewall's refetch like any a… |
5757
| A10 | ruled | `docs/SPEC-ASYNC-SEMANTICS.md:189` | core.ts×3 verdict.ts×2 | createMemo.test.ts×1 fuzz-findings-l2.test.ts×1 ispending-memo-unstamped-hold-3457.test.ts×2 latest-isPending-consistency.test.ts×3 verdict-contract.test.ts×2 | [ruled] `[isPending(x), x()]` is atomic within one scope — `[isPending(x), x()]` read in one scope is atomic: a reader that observed the fresh value must not see `pending === true` for it. |
58-
| A11 | ruled | `docs/SPEC-ASYNC-SEMANTICS.md:103` | — | latest-isPending-consistency.test.ts×1 loading-fallback-in-flush-3540.test.ts×1 visibility-oracle-store.states.ts×2 visibility-oracle.states.ts×1 | [ruled] Sync derivations of held sources are visible through `latest()`/`isPending()` — Sync derivations of transition-held sources are visible through `latest()`/`isPending()` (held sync recompute is… |
58+
| A11 | ruled | `docs/SPEC-ASYNC-SEMANTICS.md:103` | — | latest-isPending-consistency.test.ts×1 loading-fallback-in-flush-3540.test.ts×2 visibility-oracle-store.states.ts×2 visibility-oracle.states.ts×1 | [ruled] Sync derivations of held sources are visible through `latest()`/`isPending()` — Sync derivations of transition-held sources are visible through `latest()`/`isPending()` (held sync recompute is… |
5959
| A12 | amended | `docs/SPEC-ASYNC-SEMANTICS.md:197` | — | createOptimistic.test.ts×2 spec-async-semantics.test.ts×1 | [ruled, amended in place] Resting optimistic nodes report pending like a plain memo — A resting optimistic node reports pending via exactly the causes a plain async memo does (A19) — a reverting optim… |
6060
| A13 | ruled | `docs/SPEC-ASYNC-SEMANTICS.md:205` | — | spec-async-semantics.test.ts×7 | [ruled 2026-07-06 (promoted from B1)] Resting optimistic ≡ plain async memo at every checkpoint — (was B1) A resting optimistic node (no active override) is observationally identical to a plain async … |
6161
| A14 | amended | `docs/SPEC-ASYNC-SEMANTICS.md:213` | — | spec-async-semantics.test.ts×1 | [ruled, amended in place 2026-07-06 (promoted from B2)] Companion nodes get child lanes that do not merge with the owner — (was B2) `isPending`/`latest` companion nodes get child lanes that do not mer… |

‎packages/signals/src/boundaries.ts‎

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ import {
4848
EFFECT_RENDER,
4949
EFFECT_TRACKED,
5050
EFFECT_USER,
51-
NOT_PENDING,
5251
REACTIVE_DISPOSED,
5352
REACTIVE_LANE_READ,
5453
REACTIVE_ZOMBIE,
@@ -64,17 +63,20 @@ import { link } from "./core/graph.js";
6463
import { enqueueSub } from "./core/heap.js";
6564
import { cleanup, createOwner, dispose, getOwner } from "./core/owner.js";
6665
import {
66+
clock,
6767
flushTransaction,
6868
GlobalQueue,
6969
globalQueue,
7070
haltReactivity,
71+
heldUnder,
7172
joinFuture,
7273
passLane,
7374
passTx,
7475
resolveTx,
7576
schedule,
7677
setPassLane,
7778
txOf,
79+
unhold,
7880
type Transaction
7981
} from "./core/scheduler.js";
8082
import { attrHooks } from "./core/attribution-hooks.js";
@@ -199,6 +201,8 @@ function caught(b: Boundary, node: Computed<any>, error: unknown): void {
199201
function flip(b: Boundary): void {
200202
b._initialized = false;
201203
b._lane = b._armLane;
204+
const o = b._output!;
205+
if (!b._lane && o._config & CONFIG_HELD && txOf(o) !== flushTransaction) unhold(o);
202206
if (b._lane !== null && b._output !== null)
203207
GlobalQueue._laneStage!(b._output, b._lane, true, false);
204208
}
@@ -249,6 +253,13 @@ function catchStatus(
249253
return false;
250254
}
251255

256+
/** The nearest loading boundary that would catch `node` was re-armed this
257+
* flush. */
258+
function armedOver(node: Computed<any>): boolean | undefined {
259+
for (let b: Boundary | null | undefined = boundaryOf(node); b; b = b._parent)
260+
if (b._type & STATUS_PENDING && isCollecting(b)) return b._armed;
261+
}
262+
252263
/** The nearest boundary on `r`'s chain showing its fallback, if any
253264
* (GlobalQueue._hidden: `r` is behind a fallback). */
254265
function hiddenBy(r: Computed<any>): Boundary | undefined {
@@ -306,7 +317,10 @@ export function prune(b: Boundary, pass: boolean): number {
306317
for (const r of b._readers) {
307318
if (r._flags & REACTIVE_DISPOSED) b._readers.delete(r);
308319
else if (!(r._statusFlags & mask)) {
309-
if (r !== b._tree && (r._config & (CONFIG_HELD | CONFIG_OVERRIDE)) === CONFIG_HELD) {
320+
if (
321+
(r !== b._tree || b._armed) &&
322+
(r._config & (CONFIG_HELD | CONFIG_OVERRIDE)) === CONFIG_HELD
323+
) {
310324
// Landed, held: the content is that transaction's — the output's
311325
// pass enters it and the reveal lands with the reader's run. The
312326
// seam, past its park decision, waits for the commit instead. (A
@@ -351,6 +365,18 @@ function boundarySeam(): void {
351365
// A parked frame's boundary (zombie) keeps its state for its revival.
352366
if (flags & REACTIVE_ZOMBIE) continue;
353367
prune(b, false);
368+
const o = b._output!;
369+
if (
370+
b._armed &&
371+
!b._initialized &&
372+
o._config & CONFIG_HELD &&
373+
[...b._readers].every(
374+
r => !(r._statusFlags & STATUS_PENDING) && r._config & CONFIG_HELD && txOf(r) === txOf(o)
375+
)
376+
) {
377+
b._readers.clear();
378+
b._initialized = true;
379+
}
354380
if (__DEV__ && b._armed && !b._initialized && !b._ahead) reportOutsideHold(b);
355381
b._armed = false;
356382
if (b._readers.size === 0) {
@@ -387,6 +413,9 @@ function reportOutsideHold(b: Boundary): void {
387413
const sources = r._x?._pendingSources;
388414
if (sources === undefined) continue;
389415
for (const source of sources) {
416+
// Only the flight the change itself started (D-16): an outside reader
417+
// of an earlier write's flight holds nothing the change waits on.
418+
if (source._time !== clock) continue;
390419
for (let s = source._subs; s !== null; s = s._nextSub) {
391420
if (!outside(s._sub, true)) continue;
392421
const name = (source as any)._name as string | undefined;
@@ -459,8 +488,13 @@ function arm(b: Boundary): void {
459488
b._armLane = lane;
460489
if (__DEV__) b._ahead = lane !== null;
461490
collecting.add(b);
491+
const n = b._readers.size;
492+
heldUnder(b._owner, flushTransaction, r => record(b, r));
462493
for (const r of b._readers) {
463-
if (r._statusFlags & STATUS_PENDING && !(r._flags & REACTIVE_DISPOSED)) {
494+
if (
495+
b._readers.size !== n ||
496+
(r._statusFlags & STATUS_PENDING && !(r._flags & REACTIVE_DISPOSED))
497+
) {
464498
// What it collects was forwarded through it to the boundaries above
465499
// too (`catchStatus` records a reader in every boundary on the way).
466500
// It is this boundary's alone now (B5, the nearest catcher): an outer
@@ -821,7 +855,8 @@ export function createErrorBoundary<T, U>(
821855
// boundary. An app without one pays the three null checks and nothing else.
822856
GlobalQueue._catch = catchStatus;
823857
GlobalQueue._fresh = (node, held) =>
824-
!held && node._statusFlags & STATUS_UNINITIALIZED && catchStatus(node, STATUS_PENDING);
858+
!held &&
859+
(node._statusFlags & STATUS_UNINITIALIZED ? catchStatus(node, STATUS_PENDING) : armedOver(node));
825860
GlobalQueue._hidden = hiddenBy;
826861
GlobalQueue._boundarySeam = boundarySeam;
827862
GlobalQueue._heldRun = heldRun;

‎packages/signals/src/core/async.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,8 @@ export function propagateStatus(
907907
if (
908908
passLane === null &&
909909
(sub._config & (CONFIG_HELD | CONFIG_OVERRIDE)) === CONFIG_HELD &&
910-
globalQueue._running
910+
globalQueue._running &&
911+
!GlobalQueue._fresh?.(sub, pendingSource._time === clock)
911912
)
912913
joinFuture(txOf(sub));
913914
return;

‎packages/signals/src/core/core.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,8 @@ export function recompute(el: Computed<any>, create: boolean = false): void {
325325
// a sync write (#3460). The pass is the lane's if it reads the lane's
326326
// world (`read`), and has left it otherwise.
327327
if (tx._lane) {
328-
} else if (isEffect !== EFFECT_RENDER && !(el._config & CONFIG_VERDICT)) joinPassTx(tx);
328+
} else if (isEffect !== EFFECT_RENDER && !(el._config & CONFIG_VERDICT))
329+
joinPassTx(tx, GlobalQueue._fresh?.(el, el._statusFlags & STATUS_UNINITIALIZED));
329330
else if (
330331
tx !== flushTransaction &&
331332
!(el._statusFlags & STATUS_UNINITIALIZED || el._config & CONFIG_HELD_FRAME)

‎packages/signals/src/core/effect.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ function runEffect(node: Effect<any>, type: number): void {
159159
// hidden subtree. The synchronous first render on creation is not a queued
160160
// run and goes through. `_modified` stays set; the boundary re-queues the
161161
// run (`release`).
162-
if (GlobalQueue._heldRun && GlobalQueue._heldRun(node)) return;
162+
if (GlobalQueue._heldRun?.(node)) return;
163163
// Error arm (#2840), user effects only: a compute-phase error that is still
164164
// the node's settled state at effect time runs the bundle's error handler in
165165
// this same imperative, writable scope. Unwrap the StatusError used for
@@ -262,7 +262,7 @@ export function trackedEffect(fn: () => void | (() => void), options?: NodeOptio
262262
// pass, but several passes in one flush each enqueue `_run` into the same
263263
// user queue, and this gate is what collapses them into one run.
264264
if (!node._modified || node._flags & REACTIVE_DISPOSED) return;
265-
if (GlobalQueue._heldRun && GlobalQueue._heldRun(node)) return;
265+
if (GlobalQueue._heldRun?.(node)) return;
266266
if (__DEV__) setTrackedQueueCallback(true);
267267
try {
268268
node._modified = false;

‎packages/signals/src/core/scheduler.ts‎

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,7 @@ export function blocked(t: Transaction): boolean {
256256
judge ??= t;
257257
// An action still running in it holds it open (action.ts). Its lanes
258258
// (lanes.ts): a lane under `t` blocks it while blocked itself.
259-
const r =
260-
t._open !== 0 ||
261-
blockedBy(t._nodes, t) ||
262-
(!!GlobalQueue._lanesBlocked && GlobalQueue._lanesBlocked(t));
259+
const r = t._open !== 0 || blockedBy(t._nodes, t) || !!GlobalQueue._lanesBlocked?.(t);
263260
judge = prev;
264261
return r;
265262
}
@@ -354,10 +351,7 @@ function blockedBy(nodes: Signal<any>[], owner: Transaction, own = false): boole
354351
* everything under it, so a reader there is not on screen and holds
355352
* nothing — boundaries.ts). */
356353
function onScreen(r: Computed<any>, t: Transaction): boolean {
357-
return (
358-
!(r._flags & REACTIVE_ZOMBIE && removalStagedBy(r, t)) &&
359-
!(GlobalQueue._hidden && GlobalQueue._hidden(r))
360-
);
354+
return !(r._flags & REACTIVE_ZOMBIE && removalStagedBy(r, t)) && !GlobalQueue._hidden?.(r);
361355
}
362356
/** A15 (#3463): a reader whose removal is staged — a zombie, parked by a
363357
* pass awaiting its commit — is still on screen and live for every hold,
@@ -367,10 +361,9 @@ function onScreen(r: Computed<any>, t: Transaction): boolean {
367361
* the nearest non-zombie ancestor. */
368362
function removalStagedBy(r: Computed<any>, t: Transaction): boolean {
369363
let o: Owner | null = r;
370-
while (o !== null && (o as any)._flags & REACTIVE_ZOMBIE) o = o._parent;
364+
while ((o as any)?._flags & REACTIVE_ZOMBIE) o = o!._parent;
371365
return (
372-
o !== null &&
373-
(o._config & CONFIG_HELD) !== 0 &&
366+
!!((o?._config as number) & CONFIG_HELD) &&
374367
(o as any)._x?._transaction != null &&
375368
txOf(o as any) === resolveTx(t)
376369
);
@@ -437,6 +430,26 @@ function holdFrame(owner: Owner, t: Transaction): void {
437430
}
438431
}
439432

433+
/** The nodes under `owner` a transaction other than `t` holds (boundaries.ts:
434+
* what an earlier hold staged under a re-armed boundary). */
435+
export function heldUnder(
436+
owner: Owner,
437+
t: Transaction | null,
438+
fn: (n: Computed<any>) => void
439+
): void {
440+
for (let c = owner._firstChild; c !== null; c = c._nextSibling) {
441+
if ((c._config & (CONFIG_HELD | CONFIG_OVERRIDE)) === CONFIG_HELD && txOf(c as any) !== t)
442+
fn(c as Computed<any>);
443+
heldUnder(c, t, fn);
444+
}
445+
}
446+
447+
/** `n` leaves the hold it was staged in: its next pass publishes mainline. */
448+
export function unhold(n: Signal<any>): void {
449+
n._x!._transaction = null;
450+
n._config &= ~CONFIG_HELD;
451+
}
452+
440453
export const dirtyQueue: Heap = {
441454
_heap: new Array(2000).fill(undefined),
442455
_marked: false,
@@ -956,7 +969,7 @@ export class GlobalQueue implements IQueue {
956969
* first: a fallback catches what is not ready under it, and the root
957970
* never hears of it. */
958971
notify(node: Computed<any>, mask: number, flags: number, error?: any): boolean {
959-
if (GlobalQueue._catch && GlobalQueue._catch(node, flags & mask, error)) return true;
972+
if (GlobalQueue._catch?.(node, flags & mask, error)) return true;
960973
if (mask & STATUS_PENDING) {
961974
if (flags & STATUS_PENDING) {
962975
if (__DEV__ && _enforceLoadingBoundary) _hitUnhandledAsync = true;

0 commit comments

Comments
 (0)