Skip to content

Commit f46d008

Browse files
committed
fix(signals): a fresh Loading waits on the hold its content derives from (#4593, #4591)
A boundary that has not shown content decided its reveal from its readers' pending status alone, without consulting the hold their inputs belong to: - #4593: a first load the held write re-asked is kept out of every hold (#2937), so its answer landed mainline and the boundary revealed it beside a screen still showing the frame before the write. - #4591: a rejection staged in the hold (D-41) clears its readers' pending without re-running them, so the seam judged the content settled and the re-armed boundary revealed its stale committed value, outside the hold. At the seam, such a boundary now records the held node its content reads (a settled reader's input, or a re-asked first load's) and keeps it like a held reader until that commit (F-7, F-1, D-12, D-41). A first load whose held write the screen shows nowhere still reveals at its landing (#2937, action-loading-rail). Boundary engine only: no core-path bytes. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0117BoWNSSgtemsSYsaX2hXE
1 parent 5ddac94 commit f46d008

5 files changed

Lines changed: 490 additions & 0 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+
A `<Loading>` that has not shown content no longer reveals content derived from a write still held outside it (F-7, F-1). Two reveals did not consult the hold: a first load the held write re-asked (kept out of every hold, #2937) landed mainline and revealed its answer beside a screen still showing the frame before the write (#4593); and a reader settled by an answer staged in the hold — a rejection, which marks no frame reader (D-41) — revealed the content's stale committed value under a re-armed `on` boundary and let the held write commit early (#4591). The boundary now waits on the held node and reveals with that hold's commit; the rejection shows when a value for the same question would. A first load whose held write the screen shows nowhere still reveals at its landing (#2937).

‎packages/signals/src/boundaries.ts‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,27 @@ function release(b: Boundary): void {
334334
b._runs = null;
335335
}
336336

337+
/** `b` waits on the first node `n` reads that a transaction holds (`n`
338+
* itself not held), kept like a held reader until that commit (`prune`).
339+
* `shown`: only when the screen shows that hold's old frame — a render
340+
* effect it holds on screen, or a stale reader it re-derives — so the
341+
* content would show beside it (F-1). */
342+
function waitHeld(b: Boundary, n: Computed<any>, shown?: boolean): void {
343+
if (!(n._config & CONFIG_HELD))
344+
for (let d = n._deps; d; d = d._nextDep) {
345+
const h = d._dep as Computed<any>;
346+
const t = (h._config & (CONFIG_HELD | CONFIG_OVERRIDE)) === CONFIG_HELD && txOf(h);
347+
if (
348+
t &&
349+
!t._lane &&
350+
(!shown ||
351+
t._reruns.length ||
352+
t._nodes.some(r => (r as any)._type === EFFECT_RENDER && !hiddenBy(r as Computed<any>)))
353+
)
354+
return record(b, h);
355+
}
356+
}
357+
337358
/** Drop the readers that settled or died. Settled: a loading reader no
338359
* longer pending; an error's source neither errored nor in flight. A reader
339360
* that landed but is held (its value staged in a transaction) is not: the
@@ -421,6 +442,24 @@ function boundarySeam(): void {
421442
}
422443
// A parked frame's boundary (zombie) keeps its state for its revival.
423444
if (flags & REACTIVE_ZOMBIE) continue;
445+
// A fresh boundary's content that derives from a write a hold keeps
446+
// belongs to that hold and reveals with its commit, not before (F-7,
447+
// D-12): the boundary waits on the held node (`waitHeld`). A reader
448+
// settled by an answer staged in the hold — a staged error marks no
449+
// frame reader (D-41), and the reveal showed the content's committed,
450+
// stale value beside the held write (#4591). A first load the write
451+
// re-asked: the seam keeps a loading source out of every hold (#2937,
452+
// D-6), so its answer lands mainline — beside a screen that still shows
453+
// the frame before the write, a torn frame (F-1, #4593); with nothing
454+
// on screen from that hold, it reveals at its landing (#2937). Not a
455+
// held reader or a held swap: those reveal with their own commit.
456+
if (!b._initialized && !(b._output!._config & CONFIG_HELD))
457+
for (const [r] of b._readers)
458+
if (!(r._statusFlags & STATUS_PENDING)) waitHeld(b, r);
459+
else
460+
r._x?._pendingSources?.forEach(
461+
n => n._statusFlags & STATUS_UNINITIALIZED && waitHeld(b, n, true)
462+
);
424463
prune(b);
425464
const o = b._output!;
426465
// A fallback staged into the very hold its readers landed in folds back
Lines changed: 262 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,262 @@
1+
/**
2+
* #4593 / #4591 (F-7, F-1, F-2, F-5, F-12, D-41): a `<Loading>` does not
3+
* reveal content derived from a write still held outside it.
4+
*
5+
* #4593: a first-load boundary's content (`b`, by `s`) lands for `s = 1`
6+
* while the `s` write is held on `a:1`, read outside. `b=21` belongs to that
7+
* hold and reveals with its commit, never beside `s=0`.
8+
* #4591: under an armed `on` boundary, the content's rejection for `s1 = 2`
9+
* is an answer for that question: it shows when a value would — at the
10+
* hold's commit — and does not drop the fallback or commit the held write.
11+
*/
12+
import { describe, expect, test } from "vitest";
13+
import {
14+
createErrorBoundary,
15+
createLoadingBoundary,
16+
createMemo,
17+
createRenderEffect,
18+
createRoot,
19+
createSignal,
20+
flush,
21+
untrack
22+
} from "../src/index.js";
23+
24+
const tick = async () => {
25+
for (let i = 0; i < 2; i++) {
26+
await new Promise(r => setTimeout(r, 0));
27+
flush();
28+
}
29+
};
30+
31+
type Flight = { resolve: (v: number) => void; reject: (e: Error) => void };
32+
33+
describe("a Loading does not reveal content derived from a write held outside it", () => {
34+
test("#4593: first load, the content's answer for the held write waits for its commit", async () => {
35+
const flights = new Map<string, Flight>();
36+
const ask = (key: string) =>
37+
new Promise<number>((resolve, reject) => flights.set(key, { resolve, reject }));
38+
const [s, setS] = createSignal(0);
39+
const screen = { a: "", s: "", b: "" };
40+
const frames: string[] = [];
41+
const frame = () => frames.push(`a=${screen.a}s=${screen.s}${screen.b}`);
42+
const dispose = createRoot(d => {
43+
const a = createMemo(() => ask("a:" + s()));
44+
const b = createMemo(() => ask("b:" + s()));
45+
createRenderEffect(a, v => void (screen.a = String(v)));
46+
createRenderEffect(s, v => void (screen.s = String(v)));
47+
const out = untrack(() =>
48+
createLoadingBoundary(
49+
() => "b=" + b(),
50+
() => "loading b"
51+
)
52+
);
53+
createRenderEffect(out, v => void (screen.b = String(v)));
54+
return d;
55+
});
56+
flush();
57+
await tick();
58+
flights.get("a:0")!.resolve(10);
59+
await tick();
60+
frame();
61+
setS(1);
62+
flush();
63+
await tick();
64+
frame();
65+
flights.get("b:1")!.resolve(21);
66+
await tick();
67+
frame();
68+
flights.get("a:1")!.resolve(11);
69+
await tick();
70+
frame();
71+
dispose();
72+
expect(frames).toEqual([
73+
"a=10s=0loading b",
74+
"a=10s=0loading b",
75+
"a=10s=0loading b",
76+
"a=11s=1b=21"
77+
]);
78+
});
79+
80+
test("#4593: the hold commits first — the content stays loading until its own answer", async () => {
81+
const flights = new Map<string, Flight>();
82+
const ask = (key: string) =>
83+
new Promise<number>((resolve, reject) => flights.set(key, { resolve, reject }));
84+
const [s, setS] = createSignal(0);
85+
const screen = { a: "", s: "", b: "" };
86+
const frames: string[] = [];
87+
const frame = () => frames.push(`a=${screen.a}s=${screen.s}${screen.b}`);
88+
const dispose = createRoot(d => {
89+
const a = createMemo(() => ask("a:" + s()));
90+
const b = createMemo(() => ask("b:" + s()));
91+
createRenderEffect(a, v => void (screen.a = String(v)));
92+
createRenderEffect(s, v => void (screen.s = String(v)));
93+
const out = untrack(() =>
94+
createLoadingBoundary(
95+
() => "b=" + b(),
96+
() => "loading b"
97+
)
98+
);
99+
createRenderEffect(out, v => void (screen.b = String(v)));
100+
return d;
101+
});
102+
flush();
103+
await tick();
104+
flights.get("a:0")!.resolve(10);
105+
await tick();
106+
frame();
107+
setS(1);
108+
flush();
109+
await tick();
110+
frame();
111+
flights.get("a:1")!.resolve(11);
112+
await tick();
113+
frame();
114+
flights.get("b:1")!.resolve(21);
115+
await tick();
116+
frame();
117+
dispose();
118+
expect(frames).toEqual([
119+
"a=10s=0loading b",
120+
"a=10s=0loading b",
121+
"a=11s=1loading b",
122+
"a=11s=1b=21"
123+
]);
124+
});
125+
126+
test("#4591: a rejection under an armed `on` boundary shows with the held write's commit", async () => {
127+
const flights = new Map<string, Flight>();
128+
const ask = (key: string) =>
129+
new Promise<number>((resolve, reject) => flights.set(key, { resolve, reject }));
130+
const [s0, setS0] = createSignal(0);
131+
const [s1, setS1] = createSignal(0);
132+
const cell = { a1: "", inner: "" };
133+
let screen = "";
134+
const frames: string[] = [];
135+
const dispose = createRoot(d => {
136+
const a0 = createMemo(() => ask("a0:" + s1()));
137+
const a1 = createMemo(() => ask("a1:" + s1()));
138+
const out = untrack(() =>
139+
createErrorBoundary(
140+
() => {
141+
createRenderEffect(a1, v => void (cell.a1 = `[a1=${v}]`));
142+
const inner = untrack(() =>
143+
createLoadingBoundary(
144+
() => `[a0=${a0()}][s1=${s1()}]`,
145+
() => "loading",
146+
{ on: () => s0() }
147+
)
148+
);
149+
createRenderEffect(inner, v => void (cell.inner = String(v)));
150+
return "ok";
151+
},
152+
() => "error"
153+
)
154+
);
155+
createRenderEffect(out, v => void (screen = String(v)));
156+
return d;
157+
});
158+
const view = () => (screen === "error" ? "error" : cell.a1 + cell.inner);
159+
flush();
160+
await tick();
161+
flights.get("a1:0")!.resolve(9);
162+
flights.get("a0:0")!.resolve(10);
163+
await tick();
164+
frames.push(view());
165+
setS0(1);
166+
setS1(1);
167+
flush();
168+
await tick();
169+
frames.push(view());
170+
flights.get("a1:1")!.resolve(11);
171+
await tick();
172+
frames.push(view());
173+
setS0(2);
174+
setS1(2);
175+
flush();
176+
await tick();
177+
frames.push(view());
178+
flights.get("a0:2")!.reject(new Error("boom"));
179+
await tick();
180+
frames.push(view());
181+
flights.get("a1:2")!.resolve(12);
182+
await tick();
183+
frames.push(view());
184+
dispose();
185+
expect(frames).toEqual([
186+
"[a1=9][a0=10][s1=0]",
187+
"[a1=9][a0=10][s1=0]",
188+
"[a1=11]loading",
189+
"[a1=11]loading",
190+
"[a1=11]loading",
191+
"error"
192+
]);
193+
});
194+
test("#4591 control: a value under an armed `on` boundary shows with the held write's commit", async () => {
195+
const flights = new Map<string, Flight>();
196+
const ask = (key: string) =>
197+
new Promise<number>((resolve, reject) => flights.set(key, { resolve, reject }));
198+
const [s0, setS0] = createSignal(0);
199+
const [s1, setS1] = createSignal(0);
200+
const cell = { a1: "", inner: "" };
201+
let screen = "";
202+
const frames: string[] = [];
203+
const dispose = createRoot(d => {
204+
const a0 = createMemo(() => ask("a0:" + s1()));
205+
const a1 = createMemo(() => ask("a1:" + s1()));
206+
const out = untrack(() =>
207+
createErrorBoundary(
208+
() => {
209+
createRenderEffect(a1, v => void (cell.a1 = `[a1=${v}]`));
210+
const inner = untrack(() =>
211+
createLoadingBoundary(
212+
() => `[a0=${a0()}][s1=${s1()}]`,
213+
() => "loading",
214+
{ on: () => s0() }
215+
)
216+
);
217+
createRenderEffect(inner, v => void (cell.inner = String(v)));
218+
return "ok";
219+
},
220+
() => "error"
221+
)
222+
);
223+
createRenderEffect(out, v => void (screen = String(v)));
224+
return d;
225+
});
226+
const view = () => (screen === "error" ? "error" : cell.a1 + cell.inner);
227+
flush();
228+
await tick();
229+
flights.get("a1:0")!.resolve(9);
230+
flights.get("a0:0")!.resolve(10);
231+
await tick();
232+
frames.push(view());
233+
setS0(1);
234+
setS1(1);
235+
flush();
236+
await tick();
237+
frames.push(view());
238+
flights.get("a1:1")!.resolve(11);
239+
await tick();
240+
frames.push(view());
241+
setS0(2);
242+
setS1(2);
243+
flush();
244+
await tick();
245+
frames.push(view());
246+
flights.get("a0:2")!.resolve(20);
247+
await tick();
248+
frames.push(view());
249+
flights.get("a1:2")!.resolve(12);
250+
await tick();
251+
frames.push(view());
252+
dispose();
253+
expect(frames).toEqual([
254+
"[a1=9][a0=10][s1=0]",
255+
"[a1=9][a0=10][s1=0]",
256+
"[a1=11]loading",
257+
"[a1=11]loading",
258+
"[a1=11]loading",
259+
"[a1=12][a0=20][s1=2]"
260+
]);
261+
});
262+
});

0 commit comments

Comments
 (0)