Skip to content

Commit 97e1826

Browse files
ryansolidclaude
andauthored
fix(signals): a fresh Loading waits on the hold its content derives from (#4593, #4591) (#4611)
* 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 * perf(signals): shrink the fresh-Loading hold wait (#4593, #4591) One inline loop at the boundary seam instead of `waitHeld` and its two closures: no `.some`/`forEach`, no CONFIG_OVERRIDE mask or lane check, no held-output guard (a swap held in the same hold folds back as before), every held input recorded rather than the first. The #2937 exemption is now `!txOf(h)._open`: a first load re-asked under an open action reveals at its landing; under a plain write's hold (parked only while a flight the screen waits on is out) it waits for the commit. Hydrating (Show/For/Loading/Errored/lazy), local rolldown: +257 -> +145 B minified over next; floors unchanged. 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 3ace826 commit 97e1826

5 files changed

Lines changed: 470 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 re-asked under an open action still reveals at its landing (#2937).

‎packages/signals/src/boundaries.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,25 @@ function boundarySeam(): void {
427427
}
428428
// A parked frame's boundary (zombie) keeps its state for its revival.
429429
if (flags & REACTIVE_ZOMBIE) continue;
430+
// A fresh boundary's content that derives from a write a hold keeps
431+
// reveals with that hold's commit (F-7, D-12): the boundary waits on
432+
// the held node, kept like a held reader until it commits (`prune`).
433+
// The node a settled reader reads: an answer staged there — a staged
434+
// error marks no frame reader (D-41) — left the reader settled on its
435+
// stale committed value (#4591). The node a first load it waits on
436+
// reads: the seam keeps a loading source out of every hold (#2937,
437+
// D-6), so its answer landed mainline, torn from the frame a write's
438+
// hold keeps on screen (F-1, #4593); under an open action it still
439+
// reveals at its landing (#2937). Not a held reader: it reveals with its
440+
// own commit.
441+
if (!b._initialized)
442+
for (const [r] of b._readers)
443+
for (const n of r._statusFlags & STATUS_PENDING ? r._x?._pendingSources || [] : [r])
444+
if (!(n._config & CONFIG_HELD))
445+
for (let d = n._deps; d; d = d._nextDep) {
446+
const h = d._dep as Computed<any>;
447+
if (h._config & CONFIG_HELD && (n === r || !txOf(h)._open)) record(b, h);
448+
}
430449
prune(b);
431450
const o = b._output!;
432451
// 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+
});
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/**
2+
* @jsxImportSource @solidjs/web
3+
* @vitest-environment jsdom
4+
*
5+
* #4591 (F-2, F-5, F-12, D-41): under an armed `<Loading on={s0()}>`, `a0`'s
6+
* new question (for `s1 = 2`) rejects while `a1`, read outside the boundary,
7+
* still holds the `s1 = 2` write. The rejection is an answer for `s1 = 2`: it
8+
* shows when a value for that question would — at the hold's commit. Until
9+
* then the boundary keeps its fallback, `s1` stays uncommitted, and `a0`'s
10+
* answer for `s1 = 0` never shows beside `s1=2`.
11+
*/
12+
import { render } from "../src/index.js";
13+
import { createMemo, createSignal, Errored, flush, Loading, Show } from "solid-js";
14+
import { expect, it } from "vitest";
15+
16+
const tick = async () => {
17+
for (let i = 0; i < 2; i++) {
18+
await new Promise(r => setTimeout(r, 0));
19+
flush();
20+
}
21+
};
22+
23+
async function run(wrapOutside: boolean) {
24+
const flights = new Map<string, { resolve: (v: number) => void; reject: (e: Error) => void }>();
25+
const ask = (key: string) =>
26+
new Promise<number>((resolve, reject) => flights.set(key, { resolve, reject }));
27+
const [s0, setS0] = createSignal(0);
28+
const [s1, setS1] = createSignal(0);
29+
const el = document.createElement("div");
30+
const frames: string[] = [];
31+
const dispose = render(() => {
32+
const a0 = createMemo(() => ask("a0:" + s1()));
33+
const a1 = createMemo(() => ask("a1:" + s1()));
34+
return (
35+
<Errored fallback={<p>error</p>}>
36+
{wrapOutside ? (
37+
<Show when={s1() > 0} fallback={<p>[a1={a1()}]</p>}>
38+
<p>[a1={a1()}]</p>
39+
</Show>
40+
) : (
41+
<p>[a1={a1()}]</p>
42+
)}
43+
<Loading on={s0()} fallback={<p>loading</p>}>
44+
<p>[a0={a0()}]</p>
45+
<p>[s1={s1()}]</p>
46+
</Loading>
47+
</Errored>
48+
);
49+
}, el);
50+
await tick();
51+
flights.get("a1:0")!.resolve(9);
52+
flights.get("a0:0")!.resolve(10);
53+
await tick();
54+
frames.push(el.textContent!);
55+
setS0(1);
56+
setS1(1);
57+
flush();
58+
await tick();
59+
frames.push(el.textContent!);
60+
flights.get("a1:1")!.resolve(11);
61+
await tick();
62+
frames.push(el.textContent!);
63+
setS0(2);
64+
setS1(2);
65+
flush();
66+
await tick();
67+
frames.push(el.textContent!);
68+
flights.get("a0:2")!.reject(new Error("boom"));
69+
await tick();
70+
frames.push(el.textContent!);
71+
flights.get("a1:2")!.resolve(12);
72+
await tick();
73+
frames.push(el.textContent!);
74+
dispose();
75+
return frames;
76+
}
77+
78+
const expected = [
79+
"[a1=9][a0=10][s1=0]",
80+
"[a1=9][a0=10][s1=0]",
81+
"[a1=11]loading",
82+
"[a1=11]loading",
83+
"[a1=11]loading",
84+
"error"
85+
];
86+
87+
it("a rejection under an armed <Loading on> does not reveal a stale value or commit a held write", async () => {
88+
expect(await run(false)).toEqual(expected);
89+
});
90+
91+
it("the same with the outside reader under <Show when={s1() > 0}>", async () => {
92+
expect(await run(true)).toEqual(expected);
93+
});

0 commit comments

Comments
 (0)