Skip to content

Commit e171fc2

Browse files
authored
Merge pull request #3532 from solidjs/fix/ispending-in-boundary-on
fix(signals): Loading `on` key read as a spectator — no dependency on the pass it runs in (#3528)
2 parents add262b + 84adf0b commit e171fc2

5 files changed

Lines changed: 207 additions & 16 deletions

File tree

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+
Fix a Loading boundary whose `on` key consults `isPending()` through a memo freezing the page (#3528). The key is evaluated from `notify`, inside the pending memo's own pass; reading the pending `isPending` memo there recorded an untracked-pending re-run dependency on that memo, making the async memo depend on a memo that depends on it — every pending mark re-derived it and it never converged. The `on` accessor is now evaluated as a spectator (`spectate`): untracked, and never recorded as a dependency of whichever node's pass it happens to run in.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ Status legend: **live** stated and standing · **ruled** carries an explicit rul
7474
| A27 | ruled | `docs/SPEC-ASYNC-SEMANTICS.md:243` | — | loading-value.test.ts×2 visibility-oracle.states.ts×18 visibility-oracle.test.ts×1 | [ruled 2026-08-10] The commit-#0 loading window is loading-class and verdict-quiet — (**ruled 2026-08-10**) **The commit-#0 loading window is loading-class and verdict-quiet.** A node born committed v… |
7575
| A28 | ruled, mechanism landed | `docs/SPEC-ASYNC-SEMANTICS.md:51` | constants.ts×2 core.ts×20 optimistic.ts×2 scheduler.ts×3 types.ts×1 verdict.ts×6 optimistic.ts×3 store.ts×1 | createOptimistic.test.ts×5 latest-held-till-flush.test.ts×1 optimistic-store-layer-scope.test.ts×1 posture-store-parity.test.ts×5 question-scoped-pending.test.ts×3 snapshot-derived-store-rows.test.ts×1 createOptimisticStore.test.ts×10 shallow.test.ts×1 treeshake.test.ts×2 visibility-oracle-store.states.ts×8 visibility-oracle.states.ts×8 | [ruled, mechanism landed 2026-09-15] A write becomes visible at flush — to every channel — (**ruled 2026-09-08**; supersedes the #2922 mid-tick pull) **A write becomes visible at flush — to every chan… |
7676
| A29 | amended | `docs/SPEC-ASYNC-SEMANTICS.md:75` | action.ts×1 async.ts×1 core.ts×7 effect.ts×1 optimistic.ts×1 scheduler.ts×1 signals.ts×1 store.ts×3 | body-end-supersession-visibility.test.ts×1 born-held.test.ts×3 direct-commit-readers-posture.test.ts×1 held-conditional-memo.test.ts×1 held-frame-dependencies.test.ts×2 latest-held-till-flush.test.ts×2 posture-store-parity.test.ts×4 treeshake.test.ts×1 visibility-oracle-store.states.ts×5 visibility-oracle-store.test.ts×1 visibility-oracle.states.ts×5 visibility-oracle.test.ts×1 write-proposals-3494.test.ts×1 | [ruled, amended in place 2026-09-13 (#3408)] A tracked read served a live transaction's staged value enters that transaction — A tracked computation served a node's staged `_pendingValue` — a value a … |
77-
| A30 | ruled | `docs/SPEC-ASYNC-SEMANTICS.md:207` | async.ts×3 attribution.ts×1 core.ts×2 effect.ts×1 scheduler.ts×4 | async-landing-deps-3461.test.ts×3 held-conditional-effect.test.ts×1 held-conditional-memo.test.ts×1 held-frame-dependencies.test.ts×2 posture-born-held-and-observation.test.ts×1 treeshake.test.ts×2 write-proposals-3494.test.ts×2 | [ruled 2026-09-13 (#3410)] A memo's dependencies are the committed frame's until the frame is replaced — A pass that _staged_ its value has not replaced the committed frame, so the committed value sti… |
77+
| A30 | ruled | `docs/SPEC-ASYNC-SEMANTICS.md:207` | async.ts×3 attribution.ts×1 core.ts×2 effect.ts×1 scheduler.ts×4 | async-landing-deps-3461.test.ts×3 held-conditional-effect.test.ts×1 held-conditional-memo.test.ts×1 held-frame-dependencies.test.ts×2 ispending-in-boundary-on-3528.test.ts×1 posture-born-held-and-observation.test.ts×1 treeshake.test.ts×2 write-proposals-3494.test.ts×2 | [ruled 2026-09-13 (#3410)] A memo's dependencies are the committed frame's until the frame is replaced — A pass that _staged_ its value has not replaced the committed frame, so the committed value sti… |
7878
| A31 | live | `docs/SPEC-ASYNC-SEMANTICS.md:83` | core.ts×2 | ispending-combined-atomic-3442.test.ts×1 | [live 2026-09-14 (#3442)] A memo computes under its own lane posture, never its puller's — A memo's value is one shared slot every reader sees, so its pass runs under the lane posture the memo itself … |
7979
| A32 | ruled | `docs/SPEC-ASYNC-SEMANTICS.md:91` | core.ts×1 store.ts×1 | visibility-oracle-store.states.ts×8 visibility-oracle-store.test.ts×1 visibility-oracle.states.ts×9 visibility-oracle.test.ts×1 | [ruled 2026-09-14] Children-forbidden readers see the frame, not the graph — `createTrackedEffect` and `onSettled` callbacks are effect-phase code that runs after the frame is decided. They read the f… |
80-
| A33 | ruled | `docs/SPEC-ASYNC-SEMANTICS.md:223` | boundaries.ts×2 scheduler.ts×1 | async-chain-supersession.test.ts×2 loading-reset-collects-forwarded-3459.test.ts×3 | [ruled 2026-09-12 (#3375)] A fallback-caught flight holds no transaction; a Loading reset moves the hold onto the boundary — A `<Loading>` boundary showing its fallback is the display of everything un… |
80+
| A33 | ruled | `docs/SPEC-ASYNC-SEMANTICS.md:223` | boundaries.ts×2 scheduler.ts×1 | async-chain-supersession.test.ts×2 ispending-in-boundary-on-3528.test.ts×2 loading-reset-collects-forwarded-3459.test.ts×3 | [ruled 2026-09-12 (#3375)] A fallback-caught flight holds no transaction; a Loading reset moves the hold onto the boundary — A `<Loading>` boundary showing its fallback is the display of everything un… |
8181
| A34 | ruled | `docs/SPEC-ASYNC-SEMANTICS.md:233` | async.ts×1 core.ts×1 scheduler.ts×2 verdict.ts×1 | treeshake.test.ts×1 write-proposals-3494.test.ts×5 | [ruled 2026-09-16 (#3494)] A write is a proposal: one on a held node entangles its tick; one that nets to the committed value is none — A write proposes a value for a node. **Held, both are suggestion… |
8282
## V — fixed violations
8383

‎packages/signals/src/boundaries.ts‎

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { recompute, ext } from "./core/core.js";
1+
import { recompute, ext, spectate } from "./core/core.js";
22
import { unwrapStatusError } from "./core/error.js";
33
import {
44
cleanup,
@@ -296,17 +296,23 @@ export class CollectionQueue extends Queue {
296296
if (!type || (read(this._disabled) && (!_revealUsed || read(this._collapsed)))) return;
297297
return super.run(type);
298298
}
299+
/** The `on` key, or ON_INIT when it throws. Evaluated mid-propagation,
300+
* inside the pending node's own pass: read as a spectator so the key's
301+
* sources never become that node's dependencies (#3528). */
302+
_readOn(): any {
303+
return spectate(() => {
304+
try {
305+
return this._onFn!();
306+
} catch {
307+
return ON_INIT;
308+
}
309+
});
310+
}
299311
notify(node: Effect<any>, type: number, flags: number, error?: any) {
300312
if (!(type & this._collectionType)) return super.notify(node, type, flags, error);
301313

302314
if (this._initialized && this._onFn) {
303-
const currentOn = untrack(() => {
304-
try {
305-
return this._onFn!();
306-
} catch {
307-
return ON_INIT;
308-
}
309-
});
315+
const currentOn = this._readOn();
310316
if (currentOn !== this._prevOn) {
311317
this._prevOn = currentOn;
312318
this._initialized = false;
@@ -425,11 +431,10 @@ export class CollectionQueue extends Queue {
425431
if (__OBSERVE__ && attrHooks !== null && this._collectionType & STATUS_PENDING)
426432
attrHooks.boundaryFallback(this, this._tree, false);
427433
if (this._onFn) {
428-
try {
429-
this._prevOn = untrack(() => this._onFn!());
430-
} catch {
431-
/* value not yet committed — _prevOn stays stale, next notify will reset */
432-
}
434+
// A throw (value not yet committed) leaves _prevOn stale; the next
435+
// notify then resets.
436+
const on = this._readOn();
437+
if (on !== ON_INIT) this._prevOn = on;
433438
}
434439
}
435440
}

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

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1462,6 +1462,33 @@ export function untrack<T>(fn: () => T, strictReadLabel?: string | false): T {
14621462
}
14631463
}
14641464

1465+
/**
1466+
* Set while runtime bookkeeping evaluates a user accessor inside another
1467+
* node's pass (a loading boundary's `on` key, read from `notify` while the
1468+
* node that went pending is still recomputing). `context` is that node, but
1469+
* the read is nobody's: the value is compared, never derived from, so the
1470+
* untracked-pending re-run link (`read`, `!tracking`) must not be recorded on
1471+
* it — it made the key's source a dependency of an unrelated async memo
1472+
* (#3528: `isPending(m2)` through a memo in `on()` linked the memo into `m2`,
1473+
* a cycle that re-derived `m2` on every pending mark and never converged).
1474+
*/
1475+
export let spectating = false;
1476+
1477+
/**
1478+
* Evaluates `fn` untracked and without recording a dependency for the
1479+
* untracked-pending re-run rule on the current `context`. For bookkeeping
1480+
* reads made mid-propagation on behalf of no node — see `spectating`.
1481+
*/
1482+
export function spectate<T>(fn: () => T): T {
1483+
const prev = spectating;
1484+
spectating = true;
1485+
try {
1486+
return untrack(fn);
1487+
} finally {
1488+
spectating = prev;
1489+
}
1490+
}
1491+
14651492
/**
14661493
* Bring a computed to a readable state: lazy/disposed nodes are (re)computed;
14671494
* an isPending() probe (`refresh`) additionally pulls the node fully up to
@@ -1989,7 +2016,10 @@ export function read<T>(el: Signal<T> | Computed<T>): T {
19892016
// lane (#3276); that check rides laneSuspends so floor bundles don't
19902017
// pay for it.
19912018
if (currentOptimisticLane === null || GlobalQueue._laneSuspends!(owner)) {
1992-
if (!tracking && el !== c) link(el, c as Computed<any>);
2019+
// An untracked read of a pending node still re-runs its reader when
2020+
// the node settles — unless nobody is reading (`spectating`, #3528)
2021+
// or the reader is the node itself.
2022+
if (!tracking && !spectating && el !== c) link(el, c as Computed<any>);
19932023
throw owner._x?._error;
19942024
}
19952025
} else if (!c && owner._statusFlags & STATUS_UNINITIALIZED) {
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
import { describe, expect, test } from "vitest";
2+
import {
3+
createLoadingBoundary,
4+
createMemo,
5+
createRenderEffect,
6+
createRoot,
7+
createSignal,
8+
flush,
9+
isPending
10+
} from "../src/index.js";
11+
12+
const sleep = (ms: number) => new Promise<void>(r => setTimeout(r, ms));
13+
14+
// #3528: a boundary whose `on` accessor consults `isPending(dep)` — directly or
15+
// through a memo — over two async memos. `on` is evaluated from `notify`, inside
16+
// the pending memo's own pass; the memo of `isPending(m2)` is marked pending by
17+
// that propagation, and reading it there (untracked, pending) recorded the
18+
// untracked-pending re-run link on `context` — which was `m2`. `m2` then
19+
// depended on a memo that depends on `m2`: every pending mark re-derived `m2`
20+
// (the A30 kept-tail rule), which went pending again, forever, in one flush.
21+
// A click must produce exactly one new flight of the written memo, with the
22+
// new input.
23+
type OnMode = "always" | "memo-isPending" | "fn-isPending";
24+
25+
function build(onMode: OnMode, boundaries: 1 | 2) {
26+
const [count, setCount] = createSignal(0);
27+
const [count2, setCount2] = createSignal(0);
28+
const runs: string[] = [];
29+
const log: string[] = [];
30+
let dispose!: () => void;
31+
createRoot(d => {
32+
dispose = d;
33+
const m2 = createMemo(async () => {
34+
const c = count();
35+
runs.push(`m2(c=${c})`);
36+
if (runs.length > 40) throw new Error("loop guard");
37+
await sleep(30);
38+
return c * 2;
39+
});
40+
const m3 = createMemo(async () => {
41+
const c = count2();
42+
runs.push(`m3(c=${c})`);
43+
if (runs.length > 40) throw new Error("loop guard");
44+
await sleep(30);
45+
return c * 3;
46+
});
47+
const make = (dep: () => unknown, tag: string) => {
48+
let token = {};
49+
let lastOn: object | null = null;
50+
const shouldReset =
51+
onMode === "memo-isPending"
52+
? createMemo(() => isPending(dep))
53+
: onMode === "fn-isPending"
54+
? () => isPending(dep)
55+
: () => true;
56+
const view = createLoadingBoundary(
57+
() => `${m2()} ${m3()}`,
58+
() => "Loading",
59+
{
60+
on() {
61+
if (onMode === "fn-isPending") return shouldReset() ? (lastOn = {}) : lastOn;
62+
if (shouldReset()) token = {};
63+
return token;
64+
}
65+
}
66+
);
67+
createRenderEffect(view, v => void log.push(`${tag}=${v}`));
68+
};
69+
make(m2, "A");
70+
if (boundaries === 2) make(m3, "B");
71+
createRenderEffect(count, v => void log.push(`count=${v}`));
72+
});
73+
flush();
74+
return {
75+
runs,
76+
log,
77+
setCount,
78+
setCount2,
79+
dispose,
80+
async settle() {
81+
for (let t = 0; t < 12; t++) {
82+
await sleep(10);
83+
flush();
84+
}
85+
},
86+
mark(label: string) {
87+
log.push(label);
88+
runs.push(label);
89+
},
90+
since(label: string) {
91+
return {
92+
log: log.slice(log.indexOf(label) + 1),
93+
runs: runs.slice(runs.indexOf(label) + 1)
94+
};
95+
}
96+
};
97+
}
98+
99+
describe("#3528 isPending consulted from a Loading boundary's `on`", () => {
100+
test.each(["always", "fn-isPending", "memo-isPending"] as const)(
101+
"on=%s, one boundary: one click is one flight, and the boundary resets",
102+
async onMode => {
103+
const h = build(onMode, 1);
104+
await h.settle();
105+
h.mark("--click--");
106+
h.setCount(1);
107+
flush();
108+
await h.settle();
109+
h.dispose();
110+
const r = h.since("--click--");
111+
expect(r.runs).toEqual(["m2(c=1)"]);
112+
// The reset frees the boundary's reader from the hold (A33): the count
113+
// publishes with the fallback, and the content reveals when m2 lands.
114+
expect(r.log).toEqual(["count=1", "A=Loading", "A=2 0"]);
115+
}
116+
);
117+
118+
test.each(["fn-isPending", "memo-isPending"] as const)(
119+
"on=%s, two boundaries reading both memos: one click is one flight",
120+
async onMode => {
121+
const h = build(onMode, 2);
122+
await h.settle();
123+
h.mark("--click--");
124+
h.setCount(1);
125+
flush();
126+
await h.settle();
127+
h.dispose();
128+
const r = h.since("--click--");
129+
expect(r.runs).toEqual(["m2(c=1)"]);
130+
// B reads m2 too and is not keyed on it: an outside reader of the
131+
// flight, so the frame stays held until m2 lands (A33) — one reveal.
132+
expect(r.log).toHaveLength(3);
133+
expect(r.log).toEqual(expect.arrayContaining(["count=1", "A=2 0", "B=2 0"]));
134+
}
135+
);
136+
137+
test("the report's shape: two boundaries, both buttons clicked back to back", async () => {
138+
const h = build("memo-isPending", 2);
139+
await h.settle();
140+
h.mark("--clicks--");
141+
h.setCount(1);
142+
h.setCount2(1);
143+
flush();
144+
await h.settle();
145+
h.dispose();
146+
const r = h.since("--clicks--");
147+
expect(r.runs.sort()).toEqual(["m2(c=1)", "m3(c=1)"]);
148+
expect(r.log.filter(l => l.startsWith("A=")).at(-1)).toBe("A=2 3");
149+
expect(r.log.filter(l => l.startsWith("B=")).at(-1)).toBe("B=2 3");
150+
});
151+
});

0 commit comments

Comments
 (0)