Skip to content

Commit 4ae0bc7

Browse files
committed
Merge remote-tracking branch 'origin/next' into claude/project-thread-x1ore2-4374
2 parents 4d31bda + 957f065 commit 4ae0bc7

9 files changed

Lines changed: 345 additions & 38 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+
An `<Errored>` heals when the last reader that caught its error is disposed. The boundary waits on what threw only while a reader holding the error is alive, so a `<Show when={isPending(m)}>` that closes over `m()` once the action that made `m` throw settles no longer leaves the fallback up (#4373).

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,9 @@ The optimistic world is the screen plus the action's guesses: derivations of a g
334334

335335
**From:** F-12, F-3, F-1. **Scenarios:** S-38.
336336

337-
An `<Errored>` flipping to its fallback is a boundary going back to its fallback: the nodes behind it stop holding (unless read elsewhere, where they error too), and non-errored nodes that lose their only visible consumer that way stop holding as well. The error stays on screen until a new answer replaces the errored one — a pending is not a value: over `Errored > Loading(never shown)`, a write publishes beside the old error (`0 | Fetch error for 0` → `1 | Fetch error for 0` → `1 | Fetch error for 1`); the inner fallback is hidden behind the error. `Errored` builds its function fallback in its own scope, like `Show`, once per show: a re-derive of the boundary while the fallback shows — a second reader caught, the same error propagated again, a retry pending after `reset()`, a later error — keeps the built fallback, its DOM and focus with it; a later error reaches it through the error accessor; the fallback is disposed once the content that replaces it is on screen — at the commit, when the swap is held (#3991).
337+
An `<Errored>` flipping to its fallback is a boundary going back to its fallback: the nodes behind it stop holding (unless read elsewhere, where they error too), and non-errored nodes that lose their only visible consumer that way stop holding as well. The error stays on screen until a new answer replaces the errored one — a pending is not a value: over `Errored > Loading(never shown)`, a write publishes beside the old error (`0 | Fetch error for 0` → `1 | Fetch error for 0` → `1 | Fetch error for 1`); the inner fallback is hidden behind the error. `Errored` builds its function fallback in its own scope, like `Show`, once per show: a re-derive of the boundary while the fallback shows — a second reader caught, the same error propagated again, a retry pending after `reset()`, a later error — keeps the built fallback, its DOM and focus with it; a later error reaches it through the error accessor; the fallback is disposed once the content that replaces it is on screen — at the commit, when the swap is held (#3991). A fallback that no live reader holds heals: the boundary waits on what threw only while a reader that caught the error is alive, so when the last one is disposed (a `<Show when={isPending(m)}>` closing over `m()` as the action that made `m` throw settles) the content shows again — what a fresh render with the same inputs shows, since nothing on it reads the error (ruled 2026-10-28, #4373).
338338

339-
**Collapses:** §23.1 items 2–3, §27 7b (2026-10-02; the top-level `isPending(count)` affordance was lost by this ruling, knowingly), recovery 9.1–9.3. **Status:** standing. Once per show: `tests/createErrorBoundary.test.ts` ("instantiates the fallback once per show"), `packages/web/test/errored-show-retry-3991.spec.tsx`; the held swap: `tests/boundary-fallback-held-swap-3991.test.ts`.
339+
**Collapses:** §23.1 items 2–3, §27 7b (2026-10-02; the top-level `isPending(count)` affordance was lost by this ruling, knowingly), recovery 9.1–9.3. **Status:** standing. Once per show: `tests/createErrorBoundary.test.ts` ("instantiates the fallback once per show"), `packages/web/test/errored-show-retry-3991.spec.tsx`; the held swap: `tests/boundary-fallback-held-swap-3991.test.ts`; healing when the last reader is disposed: `tests/errored-heal-disposed-reader-4373.test.ts`, `packages/web/test/errored-heal-disposed-reader-4373.spec.tsx`.
340340

341341
---
342342

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ Status legend: **live** stated and standing · **ruled** carries an explicit rul
9696
| B2 | live | `docs/SPEC-ASYNC-SEMANTICS.md:213` | — | createRevealOrder.test.ts×16 derived-write-then-derivation-3733.test.ts×1 onCleanup.test.ts×2 spec-async-semantics.test.ts×2 | PROMOTED → A14 (A14's section carries the ruling). |
9797
| B3 | live | `docs/SPEC-ASYNC-SEMANTICS.md:249` | — | spec-async-semantics.test.ts×2 | PROMOTED → A15 (A15's section carries the ruling). |
9898
| B4 | live | `docs/SPEC-ASYNC-SEMANTICS.md:81` | — | derived-write-then-derivation-3733.test.ts×1 spec-async-semantics.test.ts×2 | PROMOTED → A18 (A18's section carries the ruling). |
99-
| B5 | live | `docs/SPEC-ASYNC-SEMANTICS.md:221` | boundaries.ts×2 | derived-write-then-derivation-3733.test.ts×1 fuzz-findings-l2.test.ts×3 spec-async-semantics.test.ts×2 | PROMOTED → A16 (A16's section carries the ruling). |
99+
| B5 | live | `docs/SPEC-ASYNC-SEMANTICS.md:221` | boundaries.ts×2 | derived-write-then-derivation-3733.test.ts×1 errored-over-rearmed-loading-4384.test.ts×1 fuzz-findings-l2.test.ts×3 spec-async-semantics.test.ts×2 | PROMOTED → A16 (A16's section carries the ruling). |
100100
## C — tier C
101101

102102
| id | status | defined | cited in src | cited in tests | statement (at definition) |

‎packages/signals/src/boundaries.ts‎

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,9 @@ interface Boundary {
9999
/** Null during the output's first pass (its post-check decides then). */
100100
_output: Computed<any> | null;
101101
/** Frame readers under it carrying its status: caught, or (loading,
102-
* showing content) forwarded — the `on` re-arm collects those. */
103-
_readers: Set<Computed<any>>;
102+
* showing content) forwarded — the `on` re-arm collects those. Each maps
103+
* to what it waits on: itself, or (error) the source that threw. */
104+
_readers: Map<Computed<any>, Computed<any>>;
104105
/** Loading: has shown content. Fresh again after an `on` re-arm found
105106
* something pending. */
106107
_initialized: boolean;
@@ -172,28 +173,29 @@ const isCollecting = (b: Boundary): boolean =>
172173
b._type === STATUS_ERROR || !b._initialized || b._armed;
173174

174175
/** A reader `b` waits on: recorded for its `on`, and `b` visited at the seam. */
175-
function record(b: Boundary, node: Computed<any>): void {
176-
b._readers.add(node);
176+
function record(b: Boundary, node: Computed<any>, source = node): void {
177+
b._readers.set(node, source);
177178
collecting.add(b);
178179
}
179180

180181
/** The reader goes to the fallback: recorded, and the output re-derives
181182
* (a no-op while the output's own pass is running — its post-check
182183
* decides). */
183-
function caught(b: Boundary, node: Computed<any>, error: unknown): void {
184+
function caught(b: Boundary, node: Computed<any>, error: unknown, source = node): void {
184185
if (b._type === STATUS_ERROR) {
185186
// An error boundary waits on what THREW (`StatusError.source`), not on
186187
// the reader that saw it: the reader recovers the moment a refetch
187188
// starts (its boundary catches the pending), while the error is settled
188-
// only when its source is neither errored nor in flight. `reset` re-runs
189-
// the same node.
189+
// only when its source is neither errored nor in flight — or when the
190+
// reader is disposed: a source no live reader holds holds nothing
191+
// (#4373). `reset` re-runs the source.
190192
error ??= node._x?._error;
191-
node = (error as { source?: Computed<any> })?.source ?? node;
193+
source = (error as { source?: Computed<any> })?.source ?? node;
192194
const caught = unwrapStatusError(error);
193195
setSignal(b._error!, caught);
194-
reportClientError(caught, b._owner, node);
196+
reportClientError(caught, b._owner, source);
195197
}
196-
record(b, node);
198+
record(b, node, source);
197199
if (b._armed) flip(b);
198200
// Already showing the fallback: one more reader to wait on changes
199201
// nothing on screen. The fallback is instantiated once per show — a later
@@ -246,7 +248,7 @@ function catchStatus(
246248
if (collecting.size !== 0)
247249
for (let b: Boundary | null | undefined = boundaryOf(node); b; b = b._parent)
248250
if (
249-
!(node._statusFlags & (b._type | STATUS_PENDING)) &&
251+
!((b._readers.get(node)?._statusFlags as number) & (b._type | STATUS_PENDING)) &&
250252
b._readers.delete(node) &&
251253
b._readers.size === 0
252254
) {
@@ -325,17 +327,17 @@ function release(b: Boundary): void {
325327
* error boundary (`_type` is the status it catches). */
326328
export function prune(b: Boundary, pass: boolean): number {
327329
const mask = b._type | STATUS_PENDING;
328-
for (const r of b._readers) {
329-
if (!(r._flags & REACTIVE_DISPOSED)) {
330+
for (const [r, s] of b._readers) {
331+
if (!((r._flags | s._flags) & REACTIVE_DISPOSED)) {
330332
// An error staged on its source (D-41, `stageError`) is not settled:
331333
// it publishes with the commit. A reader that threw it now (a lane
332334
// pass, a reader of a node born staged) reached the boundary first
333335
// (#4364).
334-
if (r._statusFlags & mask || (mask & STATUS_ERROR && r._config & CONFIG_STAGED_ERROR))
336+
if (s._statusFlags & mask || (mask & STATUS_ERROR && s._config & CONFIG_STAGED_ERROR))
335337
continue;
336338
if (
337-
(r !== b._tree || b._armed) &&
338-
(r._config & (CONFIG_HELD | CONFIG_OVERRIDE)) === CONFIG_HELD
339+
(s !== b._tree || b._armed) &&
340+
(s._config & (CONFIG_HELD | CONFIG_OVERRIDE)) === CONFIG_HELD
339341
) {
340342
// Landed, held: the content is that transaction's — the output's
341343
// pass enters it and the reveal lands with the reader's run. The
@@ -345,7 +347,7 @@ export function prune(b: Boundary, pass: boolean): number {
345347
// the reader is committed (#3540: what a fresh boundary catches holds
346348
// nothing outside it).
347349
if (!pass || !b._initialized) continue;
348-
joinFuture(txOf(r));
350+
joinFuture(txOf(s));
349351
}
350352
}
351353
b._readers.delete(r);
@@ -391,7 +393,8 @@ function boundarySeam(): void {
391393
!b._initialized &&
392394
o._config & CONFIG_HELD &&
393395
[...b._readers].every(
394-
r => !(r._statusFlags & STATUS_PENDING) && r._config & CONFIG_HELD && txOf(r) === txOf(o)
396+
([, s]) =>
397+
!(s._statusFlags & STATUS_PENDING) && s._config & CONFIG_HELD && txOf(s) === txOf(o)
395398
)
396399
) {
397400
b._readers.clear();
@@ -429,7 +432,7 @@ function reportOutsideHold(b: Boundary): void {
429432
if (o === b) return false;
430433
return true;
431434
};
432-
for (const r of b._readers) {
435+
for (const r of b._readers.keys()) {
433436
const sources = r._x?._pendingSources;
434437
if (sources === undefined) continue;
435438
for (const source of sources) {
@@ -507,7 +510,7 @@ function arm(b: Boundary): void {
507510
collecting.add(b);
508511
const n = b._readers.size;
509512
heldUnder(b._owner, flushTransaction, r => record(b, r));
510-
for (const r of b._readers) {
513+
for (const [r] of b._readers) {
511514
if (
512515
b._readers.size !== n ||
513516
(r._statusFlags & STATUS_PENDING && !(r._flags & REACTIVE_DISPOSED))
@@ -517,7 +520,9 @@ function arm(b: Boundary): void {
517520
// It is this boundary's alone now (B5, the nearest catcher): an outer
518521
// re-armed by the same tick does not wait for it (D-14, U-4).
519522
for (let a = b._parent; a !== null; a = a._parent)
520-
for (const o of b._readers) a._readers.delete(o);
523+
// An outer error boundary keys its readers too, but waits on their
524+
// sources: a re-armed Loading taking the pending does not settle it.
525+
if (a._type & STATUS_PENDING) for (const [o] of b._readers) a._readers.delete(o);
521526
flip(b);
522527
redraw(b);
523528
return;
@@ -529,7 +534,7 @@ function arm(b: Boundary): void {
529534
* names a signal — nothing to re-run). */
530535
function reset(b: Boundary): void {
531536
// A snapshot: a source failing again is caught — and re-added — mid-walk.
532-
for (const r of [...b._readers])
537+
for (const r of new Set(b._readers.values()))
533538
if (r._fn !== undefined && !(r._flags & REACTIVE_DISPOSED)) recompute(r);
534539
schedule();
535540
}
@@ -583,7 +588,7 @@ function createBoundary<T>(
583588
_owner: owner,
584589
_tree: null!,
585590
_output: null,
586-
_readers: new Set(),
591+
_readers: new Map(),
587592
_initialized: false,
588593
_armed: false,
589594
_armLane: null,

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -273,13 +273,11 @@ export function enterLane(l: Transaction, c: Computed<any>): void {
273273
// `stagedRead`): it has no committed world to re-derive on (#3969).
274274
// (A pass not joined: a held write beside a guess, #4336.)
275275
if (c._flags & REACTIVE_STAGED_READ && (guessed || c._flags & REACTIVE_JOINED)) stagedRead(c);
276-
return;
276+
} else if (sameLane(p, l)) setPassLane(l);
277+
else if (!under(p, l)) {
278+
if (!under(l, p)) linkLanes(p, l);
279+
setPassLane(l);
277280
}
278-
if (sameLane(p, l)) return setPassLane(l);
279-
if (under(p, l)) return;
280-
if (under(l, p)) return setPassLane(l);
281-
linkLanes(p, l);
282-
setPassLane(l);
283281
}
284282
/** Is `l` nested under `a` (an ancestor lane)? */
285283
function under(l: Transaction, a: Transaction): boolean {
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import { expect, it } from "vitest";
2+
import {
3+
action,
4+
createErrorBoundary,
5+
createMemo,
6+
createRenderEffect,
7+
createRoot,
8+
createSignal,
9+
flush,
10+
isPending
11+
} from "../src/index.js";
12+
13+
// #4373 (ruled): an error boundary heals when the reader that threw is
14+
// disposed and no other live reader holds the error — a reader that is no
15+
// longer the display holds nothing (F-3), and the error fallback is a
16+
// fallback (F-12). The shape: `<Errored><Show when={isPending(m)}><span>
17+
// {m()}</span></Show></Errored>`, an action whose write makes `m` throw.
18+
const tick = async () => {
19+
for (let i = 0; i < 8; i++) await Promise.resolve();
20+
flush();
21+
};
22+
23+
function mount(extraReader: boolean) {
24+
let release!: () => void;
25+
const [s, setS] = createSignal(3);
26+
const act = action(function* (v: number) {
27+
setS(v);
28+
yield new Promise<void>(r => (release = r));
29+
});
30+
const screen: { branch?: unknown; extra?: unknown; view?: unknown } = {};
31+
const dispose = createRoot(dispose => {
32+
const m = createMemo(() => {
33+
if (s() === 1) throw new Error("boom");
34+
return s();
35+
});
36+
const view = createErrorBoundary(
37+
() => {
38+
// `<Show when={isPending(m)}>`: the branch owns the reader of `m()`.
39+
const open = createMemo(() => isPending(m));
40+
const branch = createMemo(() => {
41+
if (!open()) return undefined;
42+
createRenderEffect(
43+
() => m(),
44+
v => {
45+
screen.branch = v;
46+
}
47+
);
48+
return "span";
49+
});
50+
if (extraReader)
51+
createRenderEffect(
52+
() => m(),
53+
v => {
54+
screen.extra = v;
55+
}
56+
);
57+
return branch;
58+
},
59+
() => "[ERR]"
60+
);
61+
createRenderEffect(
62+
() => view(),
63+
v => {
64+
screen.view = v;
65+
}
66+
);
67+
return dispose;
68+
});
69+
return { act, release: () => release(), screen, dispose };
70+
}
71+
72+
it("heals once the only reader that threw is disposed (#4373)", async () => {
73+
const t = mount(false);
74+
flush();
75+
expect(t.screen.view).toBe(undefined);
76+
t.act(1);
77+
flush();
78+
await tick();
79+
t.release();
80+
await tick();
81+
await tick();
82+
// The branch closed with the action's settle: nothing reads `m()` — the
83+
// screen of a fresh render with `s = 1`.
84+
expect(t.screen.view).toBe(undefined);
85+
t.dispose();
86+
});
87+
88+
it("stays errored while another live reader holds the error", async () => {
89+
const t = mount(true);
90+
flush();
91+
expect(t.screen.extra).toBe(3);
92+
t.act(1);
93+
flush();
94+
await tick();
95+
t.release();
96+
await tick();
97+
await tick();
98+
expect(t.screen.view).toBe("[ERR]");
99+
t.dispose();
100+
});
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// #4373 follow-up (D-39: a pending is not a value). Shape:
2+
// `<Errored><Loading on={key}>{renderEffect(m1())}</Loading></Errored>`, where m1 is
3+
// an async memo gated by a manually released promise and rejects for s === 1.
4+
// After the error shows, a refetch (setS(2)) in the same flush as a key change
5+
// re-arms the Loading. `arm` hands the Loading's pending readers to it alone
6+
// (B5) by deleting them from outer loading boundaries; an outer error
7+
// boundary keys the same readers but waits on their sources, so it keeps the
8+
// error while m1 is still in flight.
9+
import { expect, it } from "vitest";
10+
import {
11+
createErrorBoundary,
12+
createLoadingBoundary,
13+
createMemo,
14+
createRenderEffect,
15+
createRoot,
16+
createSignal,
17+
flush
18+
} from "../src/index.js";
19+
20+
const tick = async () => {
21+
for (let i = 0; i < 8; i++) await Promise.resolve();
22+
flush();
23+
};
24+
25+
it("an Errored over a re-armed Loading keeps the error while the refetch is in flight", async () => {
26+
const [s, setS] = createSignal(0);
27+
const [key, setKey] = createSignal(0);
28+
const gates: Array<() => void> = [];
29+
let out = "";
30+
const dispose = createRoot(dispose => {
31+
const m1 = createMemo(async () => {
32+
const v = s();
33+
await new Promise<void>(r => gates.push(r));
34+
if (v === 1) throw new Error("boom");
35+
return v;
36+
});
37+
const view = createErrorBoundary(
38+
() =>
39+
createLoadingBoundary(
40+
() => {
41+
createRenderEffect(
42+
() => m1(),
43+
() => {}
44+
);
45+
return "content";
46+
},
47+
() => "[L]",
48+
{ on: () => key() }
49+
),
50+
(e: () => any) => `[E ${e()?.message}]`
51+
);
52+
createRenderEffect(
53+
() => {
54+
const v = view();
55+
return typeof v === "function" ? (v as () => unknown)() : v;
56+
},
57+
v => void (out = String(v))
58+
);
59+
return dispose;
60+
});
61+
flush();
62+
expect(out).toBe("[L]");
63+
gates.shift()!(); // m1 resolves to 0
64+
await tick();
65+
expect(out).toBe("content");
66+
setS(1); // refetch in flight: the Loading has shown content, so it holds
67+
flush();
68+
expect(out).toBe("content");
69+
gates.shift()!(); // m1 rejects
70+
await tick();
71+
expect(out).toBe("[E boom]");
72+
setS(2); // refetch, still gated...
73+
setKey(1); // ...and the Loading re-arms in the same flush
74+
flush();
75+
expect(out).toBe("[E boom]"); // PR head 0104feff: "[L]"
76+
await tick();
77+
expect(out).toBe("[E boom]");
78+
gates.shift()!(); // m1 resolves to 2
79+
await tick();
80+
expect(out).toBe("content");
81+
dispose();
82+
});

0 commit comments

Comments
 (0)