Skip to content

Commit f53d927

Browse files
ryansolidclaude
andauthored
fix(signals): an error-boundary output reaching only hidden effects holds nothing through memos and nested boundaries (#4639 follow-up) (#4655)
* fix(signals): an error-boundary output reaching only hidden effects holds nothing through memos and nested boundaries (#4639 follow-up) #4639 made an error-boundary output transparent only to its direct readers. A memo or a second error boundary built outside the `<Loading>` between it and the content still held the frame, and so did an output nobody reads. `hiddenBy` now walks through every non-effect node below a boundary output to the render effects it reaches, and an output reaching none holds nothing (Vocabulary "Reader", F-3, F-4, D-14). The DEV LOADING_ON_OUTSIDE_HOLD report no longer fires for a reader under such a boundary while the re-armed fallback is on screen (D-16). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0117BoWNSSgtemsSYsaX2hXE * fix(signals): bound the error-boundary output walk, skip user effects, trim (#4639 follow-up review) - hiddenBy walks each node once per walk (seen set): a memo lattice below an error-boundary output costs its size, not its paths. - A user effect reached through the output is never a reader (Vocabulary "Reader"): it holds nothing, as a plain read of the source. - DEV LOADING_ON_OUTSIDE_HOLD: the output check applies only when the reader is that boundary's tree (a header render effect inside it still reports). - s !== null -> s (trim). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0117BoWNSSgtemsSYsaX2hXE * refactor(signals): shorter visited check and effect terminal in hiddenBy Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0117BoWNSSgtemsSYsaX2hXE * perf(signals): fold the effect terminal into the hiddenBy walk's seed (#4639 follow-up review trim) Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0117BoWNSSgtemsSYsaX2hXE --------- Co-authored-by: Claude <[email protected]>
1 parent dd5f9d1 commit f53d927

5 files changed

Lines changed: 317 additions & 9 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+
An error boundary output read only behind fallbacks now holds nothing when it reaches them through a memo or another error boundary built outside the `<Loading>`, or is not read at all; `LOADING_ON_OUTSIDE_HOLD` no longer fires while the re-armed fallback is on screen.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Status legend: **live** stated and standing · **ruled** carries an explicit rul
5050
| A3 | ruled | `docs/SPEC-ASYNC-SEMANTICS.md:337` | async.ts×1 core.ts×2 | derived-write-then-derivation-3733.test.ts×5 equals-comparator-errors.test.ts×1 | [ruled] Comparator throws are compute-phase errors — Errors thrown by a user `equals` comparator behave exactly like compute-phase errors (boundary-containable; loud halt without a boundary). |
5151
| A4 | ruled | `docs/SPEC-ASYNC-SEMANTICS.md:345` | — | derived-write-then-derivation-3733.test.ts×1 equals-comparator-errors.test.ts×1 | [ruled] A custom `equals` never sees `undefined` prev on first commit — A custom `equals` is never invoked with `undefined` previous value on a node's first commit. |
5252
| A5 | ruled | `docs/SPEC-ASYNC-SEMANTICS.md:353` | — | derived-write-then-derivation-3733.test.ts×1 errorHalt.test.ts×1 | [ruled] An error escaping every boundary halts the system — An error escaping every boundary permanently halts the system with `REACTIVITY_HALTED`; later writes log "Update ignored". |
53-
| A6 | ruled | `docs/SPEC-ASYNC-SEMANTICS.md:361` | boundaries.ts×4 | derived-write-then-derivation-3733.test.ts×1 enforceLoadingBoundary.test.ts×1 | [ruled] `ASYNC_OUTSIDE_LOADING_BOUNDARY` is warn-only — `ASYNC_OUTSIDE_LOADING_BOUNDARY` is a warn-only diagnostic; an `Errored` above must not swallow it and must not show its fallback for a pending. |
53+
| A6 | ruled | `docs/SPEC-ASYNC-SEMANTICS.md:361` | boundaries.ts×4 | derived-write-then-derivation-3733.test.ts×1 enforceLoadingBoundary.test.ts×1 loading-on-errorboundary-through-4639.test.ts×1 | [ruled] `ASYNC_OUTSIDE_LOADING_BOUNDARY` is warn-only — `ASYNC_OUTSIDE_LOADING_BOUNDARY` is a warn-only diagnostic; an `Errored` above must not swallow it and must not show its fallback for a pending. |
5454
| A7 | amended | `docs/SPEC-ASYNC-SEMANTICS.md:167` | seat.ts×1 truth.ts×1 verdict.ts×1 | fuzz-findings-l2.test.ts×1 latest-uninitialized-over-latest-4362.test.ts×2 spec-async-semantics.test.ts×2 visibility-oracle-store.states.ts×1 visibility-oracle.states.ts×1 visibility-oracle.test.ts×1 | [ruled, amended in place] Resolved async never reads `[false, undefined]` — After an async memo resolves, `[isPending(x), latest(x)]` is `[false, resolvedValue]` — never `[false, undefined]`. **Amende… |
5555
| A8 | amended | `docs/SPEC-ASYNC-SEMANTICS.md:175` | — | create-deferred-3710.test.ts×1 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:183` | async.ts×1 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… |

‎packages/signals/src/boundaries.ts‎

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -307,17 +307,29 @@ function armedOver(node: Computed<any>): boolean | undefined {
307307

308308
/** The nearest boundary on `r`'s chain showing its fallback, if any
309309
* (`hiddenHook`: `r` is behind a fallback). */
310-
function hiddenBy(r: Computed<any>): Boundary | undefined {
310+
function hiddenBy(r: Computed<any>, seen?: Set<Computed<any>>): Boundary | undefined {
311311
for (let b: Boundary | null | undefined = boundaryOf(r); b; b = b._parent)
312312
if (b._fallback) return b;
313313
// A boundary output passing a pending by (CONFIG_REDERIVE: an error
314-
// boundary, A6) is transparent: on screen only through its readers. Read
315-
// only behind fallbacks — an error boundary built outside the `<Loading>`
316-
// whose content reads it — it holds nothing (F-4, D-14, #4638).
317-
let h: Boundary | undefined,
314+
// boundary, A6) is transparent: on screen only through the render effects
315+
// it reaches — through a memo or another error boundary, wherever they
316+
// were created (Reader, F-3). Reaching none, or only effects behind
317+
// fallbacks — an error boundary built outside the `<Loading>` whose
318+
// content reads it — it holds nothing (F-4, D-14, #4638). Reaching none,
319+
// `h` is `1`: hidden with no boundary to name, only ever for a non-effect
320+
// (`heldRun` asks about effects). Inside the walk a user effect reached
321+
// through the output reads nothing on screen (Reader: never a reader), and
322+
// a node already walked is not walked again (`seen`: had it reached a
323+
// shown effect the walk would have stopped), so a memo lattice below the
324+
// output costs its size, not its paths.
325+
let h: any,
318326
s = r._subs;
319-
if (r._config & CONFIG_REDERIVE && !(r as any)._type)
320-
while (s !== null && (h = hiddenBy(s._sub))) s = s._nextSub;
327+
if (seen || r._config & CONFIG_REDERIVE)
328+
for (
329+
seen ||= new Set(), h = (r as any)._type != EFFECT_RENDER;
330+
s && (h = seen.size == seen.add(s._sub).size || hiddenBy(s._sub, seen));
331+
)
332+
s = s._nextSub;
321333
return h;
322334
}
323335

@@ -543,7 +555,12 @@ function reportOutsideHold(b: Boundary): void {
543555
if (outside(s._sub, false)) return true;
544556
return false;
545557
}
546-
if (hiddenBy(reader)) return false;
558+
// Behind a fallback, or under a boundary whose output only such content
559+
// reads — an error boundary built outside `b`: the fallback is seen
560+
// (D-16, #4639).
561+
const rb = boundaryOf(reader);
562+
if (hiddenBy(reader) || (rb?._tree === reader && rb._output && hiddenBy(rb._output)))
563+
return false;
547564
for (let o: Boundary | null | undefined = boundaryOf(reader); o; o = o._parent)
548565
if (o === b) return false;
549566
return true;
Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
/**
2+
* #4639 follow-up to #4638 — an error boundary built in the component body
3+
* (outside `<Loading on={sel()}>`) passes its source's pending by (A6). Its
4+
* output is on screen only through the render effects it reaches (Vocabulary
5+
* "Reader": a memo counts only through the render effects that read it,
6+
* wherever it was created, and a pending value no render effect reaches holds
7+
* nothing; F-3: "where the memo was created does not matter"). Reached only
8+
* by content behind the re-armed fallback, it holds nothing outside it (F-4,
9+
* D-14): the fallback shows with the change's frame, beside the sibling's.
10+
*
11+
* - memo: a memo built outside the Loading between the output and the content;
12+
* - nested: an error boundary over an error boundary, both built outside;
13+
* - unread: an error boundary nobody reads, beside the content's plain read;
14+
* - header: the output also rendered outside — a reader that is the display
15+
* (D-16): the frame waits for `detail`, and DEV reports
16+
* LOADING_ON_OUTSIDE_HOLD. Only then: with the fallback on screen the
17+
* report would be false (D-16, "the fallback can never be seen").
18+
* - ueff: the output also read by a user effect outside — never a reader
19+
* (Vocabulary "Reader"), so it holds nothing, as a plain read of `detail`;
20+
* - lattice: a diamond memo lattice 2 wide × 30 deep below the output, read
21+
* by nothing on screen — each node is walked once, not once per path;
22+
* - header-tree: a header render effect inside an error boundary built
23+
* outside, the boundary's output mounted untracked — the header is the
24+
* display (D-16): the frame waits and DEV reports, as `header`.
25+
*/
26+
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
27+
import {
28+
createEffect,
29+
createErrorBoundary,
30+
createLoadingBoundary,
31+
createMemo,
32+
createRenderEffect,
33+
createRoot,
34+
createSignal,
35+
flush,
36+
untrack,
37+
OBSERVE
38+
} from "../src/index.js";
39+
40+
beforeEach(() => vi.useFakeTimers());
41+
afterEach(() => {
42+
vi.useRealTimers();
43+
vi.restoreAllMocks();
44+
});
45+
46+
type Mode = "direct" | "memo" | "nested" | "unread" | "ueff" | "lattice" | "header" | "header-tree";
47+
48+
function part(read: () => string) {
49+
const el = { text: "-" };
50+
createRenderEffect(read, v => {
51+
el.text = v;
52+
});
53+
return el;
54+
}
55+
56+
function page(mode: Mode) {
57+
const asks: { key: string; res: (v: any) => void; rej: (e: any) => void }[] = [];
58+
const ask = (key: string) => new Promise<any>((res, rej) => asks.push({ key, res, rej }));
59+
const view: {
60+
header: string;
61+
headerEl?: { text: string };
62+
detail: { text: string } | null;
63+
comments: { text: string } | null;
64+
} = { header: "", detail: null, comments: null };
65+
const [sel, setSel] = createSignal(3);
66+
let dispose!: () => void;
67+
createRoot(d => {
68+
dispose = d;
69+
const detail = createMemo(() => ask(`detail:${sel()}`), { name: "detail" });
70+
const eb = (src: () => any): (() => any) =>
71+
untrack(() =>
72+
createErrorBoundary(
73+
() => src(),
74+
() => ({ title: "ERR" })
75+
)
76+
);
77+
let shown: () => any = mode === "unread" ? detail : eb(detail);
78+
if (mode === "unread") eb(detail);
79+
if (mode === "nested") shown = eb(shown);
80+
let title = () => shown()?.title as string;
81+
if (mode === "memo") title = createMemo(title, { name: "title" });
82+
if (mode === "ueff")
83+
createEffect(
84+
() => shown()?.title,
85+
() => {}
86+
);
87+
if (mode === "lattice") {
88+
let layer = [shown, shown];
89+
for (let i = 0; i < 30; i++) {
90+
const [l, r] = layer;
91+
layer = [createMemo(() => [l(), r()]), createMemo(() => [r(), l()])];
92+
}
93+
}
94+
if (mode === "header-tree") {
95+
const out = untrack(() =>
96+
createErrorBoundary(
97+
() => part(() => detail().title),
98+
() => ({ text: "ERR" })
99+
)
100+
);
101+
const el = untrack(out) as { text: string };
102+
view.headerEl = el;
103+
}
104+
if (mode === "header")
105+
createRenderEffect(
106+
() => shown()?.title,
107+
v => {
108+
view.header = `${v} / `;
109+
}
110+
);
111+
const comments = createMemo(() => ask(`comments:${sel()}`), { name: "comments" });
112+
const a = untrack(() =>
113+
createLoadingBoundary(
114+
() => part(title),
115+
() => part(() => `loading #${sel()}`),
116+
{ on: () => sel() }
117+
)
118+
);
119+
createRenderEffect(a, v => {
120+
view.detail = v;
121+
});
122+
const b = untrack(() =>
123+
createLoadingBoundary(
124+
() => part(() => `comments ${(comments() as any[]).length}`),
125+
() => part(() => "loading comments"),
126+
{ on: () => sel() }
127+
)
128+
);
129+
createRenderEffect(b, v => {
130+
view.comments = v;
131+
});
132+
});
133+
const settle = async (key: string, v?: any, reject?: boolean) => {
134+
const i = asks.findIndex(a => a.key === key);
135+
if (i >= 0) {
136+
const x = asks.splice(i, 1)[0];
137+
reject ? x.rej(new Error("boom")) : x.res(v);
138+
}
139+
for (let k = 0; k < 4; k++) {
140+
await vi.advanceTimersByTimeAsync(0);
141+
flush();
142+
}
143+
};
144+
const t = (el: { text: string } | null) => (el ? el.text : "-");
145+
const screen = () =>
146+
`${view.headerEl ? `${view.headerEl.text} / ` : view.header}${t(view.detail)} | ${t(view.comments)}`;
147+
return { setSel, settle, screen, dispose };
148+
}
149+
150+
function captureWarnings() {
151+
vi.spyOn(console, "warn").mockImplementation(() => {});
152+
const capture = OBSERVE!.diagnostics.capture();
153+
return {
154+
codes: () => capture.events.map(e => e.code).filter(c => c === "LOADING_ON_OUTSIDE_HOLD"),
155+
stop: () => capture.stop()
156+
};
157+
}
158+
159+
describe("#4639 an error boundary output reached only behind fallbacks holds nothing", () => {
160+
for (const mode of ["direct", "memo", "nested", "unread", "ueff", "lattice"] as Mode[])
161+
for (const reject of mode === "unread" || mode === "lattice" ? [false] : [false, true])
162+
test(`${mode}${reject ? ", detail rejects" : ""}: both fallbacks show now, no LOADING_ON_OUTSIDE_HOLD`, async () => {
163+
const d = captureWarnings();
164+
const p = page(mode);
165+
flush();
166+
await p.settle("detail:3", { title: "Crash" });
167+
await p.settle("comments:3", [1]);
168+
expect(p.screen()).toBe("Crash | comments 1");
169+
p.setSel(1);
170+
flush();
171+
await p.settle("");
172+
expect(p.screen()).toBe("loading #1 | loading comments");
173+
await p.settle("detail:1", { title: "One" }, reject);
174+
const shown = reject ? "ERR" : "One";
175+
expect(p.screen()).toBe(`${shown} | loading comments`);
176+
await p.settle("comments:1", [1, 2]);
177+
expect(p.screen()).toBe(`${shown} | comments 2`);
178+
expect(d.codes()).toEqual([]);
179+
d.stop();
180+
p.dispose();
181+
});
182+
183+
for (const mode of ["header", "header-tree"] as Mode[])
184+
test(`${mode} (D-16): the output rendered outside holds the frame; LOADING_ON_OUTSIDE_HOLD once`, async () => {
185+
const d = captureWarnings();
186+
const p = page(mode);
187+
flush();
188+
await p.settle("detail:3", { title: "Crash" });
189+
await p.settle("comments:3", [1]);
190+
expect(p.screen()).toBe("Crash / Crash | comments 1");
191+
p.setSel(1);
192+
flush();
193+
await p.settle("");
194+
expect(p.screen()).toBe("Crash / Crash | comments 1");
195+
expect(d.codes()).toEqual(["LOADING_ON_OUTSIDE_HOLD"]);
196+
await p.settle("detail:1", { title: "One" });
197+
expect(p.screen()).toBe("One / One | loading comments");
198+
await p.settle("comments:1", [1, 2]);
199+
expect(p.screen()).toBe("One / One | comments 2");
200+
d.stop();
201+
p.dispose();
202+
});
203+
});
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/**
2+
* @jsxImportSource @solidjs/web
3+
* @vitest-environment jsdom
4+
*
5+
* #4639 follow-up to #4638 (Vocabulary "Reader", F-3, F-4, D-14): an error
6+
* boundary built in the component body is on screen only through the render
7+
* effects it reaches, wherever the memo or boundary between was created. Read
8+
* through a memo or another error boundary built outside the
9+
* `<Loading on={sel()}>`, or not read at all, it holds nothing: a `sel` write
10+
* shows both fallbacks with the change's frame.
11+
* The signals-only twin: `packages/signals/tests/loading-on-errorboundary-through-4639.test.ts`.
12+
*/
13+
import { expect, test } from "vitest";
14+
import { Loading, createMemo, createSignal, flush, untrack } from "solid-js";
15+
import { createErrorBoundary } from "solid-js/internal";
16+
import { render } from "../src/index.js";
17+
18+
const tick = async () => {
19+
for (let i = 0; i < 4; i++) {
20+
await new Promise(r => setTimeout(r, 0));
21+
flush();
22+
}
23+
};
24+
25+
type Mode = "memo" | "nested" | "unread";
26+
27+
for (const mode of ["memo", "nested", "unread"] as Mode[])
28+
test(`switch key (error boundary, ${mode}): both fallbacks show now`, async () => {
29+
const asks: { key: string; res: (v: any) => void }[] = [];
30+
const ask = (key: string) => new Promise<any>(res => asks.push({ key, res }));
31+
const settle = async (key: string, v: any) => {
32+
asks
33+
.splice(
34+
asks.findIndex(a => a.key === key),
35+
1
36+
)[0]
37+
.res(v);
38+
await tick();
39+
};
40+
const c = document.body.appendChild(document.createElement("div"));
41+
let select!: (n: number) => void;
42+
const dispose = render(() => {
43+
const [sel, setSel] = createSignal(3);
44+
select = setSel;
45+
const detail = createMemo(() => ask(`detail:${sel()}`));
46+
const eb = (src: () => any): (() => any) =>
47+
untrack(() =>
48+
createErrorBoundary(
49+
() => src(),
50+
() => null
51+
)
52+
);
53+
let shown: () => any = mode === "unread" ? detail : eb(detail);
54+
if (mode === "unread") eb(detail);
55+
if (mode === "nested") shown = eb(shown);
56+
let title = (): string => shown()?.title;
57+
if (mode === "memo") title = createMemo(title);
58+
const comments = createMemo(() => ask(`comments:${sel()}`));
59+
return (
60+
<>
61+
<Loading on={sel()} fallback={<i>loading #{sel()}</i>}>
62+
<b>{title()}</b>
63+
</Loading>
64+
<Loading on={sel()} fallback={<i> loading comments</i>}>
65+
<u> comments {(comments() as any[]).length}</u>
66+
</Loading>
67+
</>
68+
);
69+
}, c);
70+
await tick();
71+
await settle("detail:3", { title: "Crash" });
72+
await settle("comments:3", [1]);
73+
expect(c.textContent).toBe("Crash comments 1");
74+
select(1);
75+
await tick();
76+
expect(c.textContent).toBe("loading #1 loading comments");
77+
await settle("detail:1", { title: "One" });
78+
expect(c.textContent).toBe("One loading comments");
79+
await settle("comments:1", [1, 2]);
80+
expect(c.textContent).toBe("One comments 2");
81+
dispose();
82+
c.remove();
83+
});

0 commit comments

Comments
 (0)