Skip to content

Commit b68942c

Browse files
ryansolidclaude
andauthored
fix(signals): a held on change's fallback folds back when its readers land in that hold later (#4379) (#4392)
`<Loading on={filter()}>` showed its fallback when a `filter` change held with an action (D-34, #4336) committed under that action's own `refresh()`. The re-arm stages the fallback into the hold; its readers (the rows' `id` holes, an ordinary pending read over the new question) land inside the same hold a flush later. The seam's fold-back (D-16, U-9) only ran in the re-arm's own flush (`b._armed`), so the boundary stayed collecting, the staged fallback committed with the action, and the refresh's pending, caught by the collecting boundary, kept it up until the refresh answered. A refresh is quiet (F-9). The fold-back now runs at any seam: a fallback staged into the hold its readers landed in is dropped, and the content is ready when the hold commits (D-15). The closed-only case passed only because its answer dropped the rows (their effects died). Tests: signals `loading-on-held-filter-refresh-4379.test.ts` (toggle and same-rows forms fail on next), web `loading-on-held-filter-refresh-4379.spec.tsx` (the issue's four on x toggle combos; on=true toggle=true fails on next). Size: -5 B minified on every boundary scenario, floors unchanged. Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2 Co-authored-by: Claude <[email protected]>
1 parent 2861ab8 commit b68942c

5 files changed

Lines changed: 345 additions & 2 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 on>` boundary no longer shows its fallback when a held `on` change commits under an action's own `refresh()` (#4379). When an `on` change is held with an action (an input changed under its optimistic guess, #4336) and the content's new answer lands inside that hold a flush after the change, the boundary now folds the staged fallback back, as it already did when the content was ready at the change. The action's commit shows the content, and the quiet `refresh()` that follows keeps it on screen until it answers.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ Whether a fallback is seen depends on whether the boundary is on screen. A fresh
120120

121121
A flight whose only observers are render effects behind a fallback holds no change — a memo under the boundary that no render effect reads was never an observer at all, and one rendered by an effect outside the boundary is that effect's read (F-3). In both orders: a render effect created under a fallback never counts, and a reader that counted while the boundary showed content stops counting the moment `on` sends it back to the fallback. Writes the hold kept for those readers alone commit at once (`Boundary: Loading... | Sum: 2` publishes as one frame); a reader outside the boundary still holds (`Sum` waits until `details` lands). The wait does not vanish; it moves onto the boundary: after the reset the fallback stays until every reader under it has settled — including readers whose flights started before the reset — then one coherent reveal.
122122

123-
**Collapses:** [A33](./SPEC-ASYNC-SEMANTICS.md#a33-a-fallback-caught-flight-holds-no-transaction-a-loading-reset-moves-the-hold-onto-the-boundary) (#3375, #3459), §23.1 item 1, recovery 2.2. **Status:** standing. The nested form — an outer `on`-reset boundary not waiting for a flight its nested `on`-reset boundary catches — is built (U-4, 2026-10-13: a reader a nested collecting boundary holds is that boundary's alone; `tests/fuzz-findings-l2.test.ts`, fuzzer finding F1). The re-arm over a hold is built (U-9, 2026-10-14): content an earlier hold staged under the boundary, or that reads a hold after the re-arm, is the boundary's — the fallback shows now and the content reveals at that hold's commit, which does not wait for it; no redraw loop (`tests/loading-fallback-in-flush-3540.test.ts`, the re-armed shapes; `tests/loading-on-frame-following-3540.test.ts` §3b, §3c).
123+
**Collapses:** [A33](./SPEC-ASYNC-SEMANTICS.md#a33-a-fallback-caught-flight-holds-no-transaction-a-loading-reset-moves-the-hold-onto-the-boundary) (#3375, #3459), §23.1 item 1, recovery 2.2. **Status:** standing. The nested form — an outer `on`-reset boundary not waiting for a flight its nested `on`-reset boundary catches — is built (U-4, 2026-10-13: a reader a nested collecting boundary holds is that boundary's alone; `tests/fuzz-findings-l2.test.ts`, fuzzer finding F1). The re-arm over a hold is built (U-9, 2026-10-14): content an earlier hold staged under the boundary, or that reads a hold after the re-arm, is the boundary's — the fallback shows now and the content reveals at that hold's commit, which does not wait for it; no redraw loop (`tests/loading-fallback-in-flush-3540.test.ts`, the re-armed shapes; `tests/loading-on-frame-following-3540.test.ts` §3b, §3c). A fallback staged into the hold its readers land in folds back at any seam, not only the re-arm's own: readers still pending at the re-arm land into that hold a flush later, and the content is ready when it commits (#4379, `tests/loading-on-held-filter-refresh-4379.test.ts`).
124124

125125
### D-15. `on` is a dependency list; the swap lands with the frame of the change that caused it
126126

‎packages/signals/src/boundaries.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,12 @@ function boundarySeam(): void {
382382
if (flags & REACTIVE_ZOMBIE) continue;
383383
prune(b, false);
384384
const o = b._output!;
385+
// A fallback staged into the very hold its readers landed in folds back
386+
// (D-16, U-9): the content is ready when that hold commits (D-15). Not
387+
// only at the re-arm's own seam: readers pending then land, held, a
388+
// flush later (#4379 — the staged fallback otherwise commits with the
389+
// hold, and a quiet refresh then caught keeps it up, F-9).
385390
if (
386-
b._armed &&
387391
!b._initialized &&
388392
o._config & CONFIG_HELD &&
389393
[...b._readers].every(
Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
/**
2+
* #4379 (ReactiveScript tracker eval): a keyed `createOptimisticStore` list
3+
* whose question reads `filter()`, under `<Loading on={filter()}>`, with a
4+
* render effect per row (as `<For>` binds each row's text). An action
5+
* guesses a row, yields, then `refresh()`es the list. A plain `filter`
6+
* write while the action is out is held with it (D-34, #4336), so the
7+
* boundary's swap is staged into that hold (D-15) and the screen keeps the
8+
* old list.
9+
*
10+
* Once the new question's answer lands, held with the same action, the
11+
* content is ready inside the hold the fallback was staged into: the seam
12+
* folds the fallback back (D-16, U-9), as it does when the readers are
13+
* already landed at the re-arm. When the action ends, its own `refresh()`
14+
* is quiet (F-9): it must not pull the fallback on screen. On `next` the
15+
* fold only ran in the re-arm's own flush (`_armed`); the rows' effects
16+
* survive the answer (same keys) and land a flush later, so the staged
17+
* fallback committed with the action, and the refresh's pending, caught by
18+
* a boundary still collecting, showed it until the refresh answered.
19+
*/
20+
import { describe, expect, it } from "vitest";
21+
import {
22+
action,
23+
createLoadingBoundary,
24+
createOptimisticStore,
25+
createRenderEffect,
26+
createRoot,
27+
createSignal,
28+
flush,
29+
mapArray,
30+
refresh,
31+
untrack
32+
} from "../src/index.js";
33+
34+
const tick = async () => {
35+
for (let i = 0; i < 4; i++) {
36+
await new Promise(r => setTimeout(r, 0));
37+
flush();
38+
}
39+
};
40+
type Issue = { id: number; assignee: string | null };
41+
const OPEN: Issue[] = [
42+
{ id: 1, assignee: null },
43+
{ id: 3, assignee: null }
44+
];
45+
const ASSIGNED: Issue[] = [
46+
{ id: 1, assignee: null },
47+
{ id: 3, assignee: "ann" }
48+
];
49+
50+
function page(on: boolean) {
51+
const asks: { key: string; res: (v: any) => void }[] = [];
52+
const ask = (key: string) => new Promise<any>(res => asks.push({ key, res }));
53+
const land = async (key: string, v: any) => {
54+
const i = asks.findIndex(a => a.key === key);
55+
if (i < 0) throw new Error(`not asked: ${key}; asked: ${asks.map(a => a.key)}`);
56+
// A fresh answer each time, as a fetch gives.
57+
asks.splice(i, 1)[0].res(structuredClone(v));
58+
await tick();
59+
};
60+
const frames: string[] = [];
61+
let setFilter!: (f: string) => void;
62+
let assign!: (id: number, who: string) => void;
63+
createRoot(() => {
64+
const [filter, sf] = createSignal("open");
65+
setFilter = sf;
66+
const [issues, setIssues] = createOptimisticStore<Issue[]>(
67+
async (d: Issue[]) => {
68+
const r: Issue[] = await ask(`fetchIssues:${filter()}`);
69+
d.length = r.length;
70+
r.forEach((x, i) => ((d as any)[i] = x));
71+
},
72+
[],
73+
{ key: "id" } as any
74+
);
75+
assign = action(function* (id: number, who: string) {
76+
const i = issues.findIndex(t => t.id === id);
77+
setIssues((d: Issue[]) => {
78+
d[i].assignee = who;
79+
});
80+
yield ask(`assign:${id},${who}`);
81+
refresh(issues);
82+
}) as any;
83+
const list = untrack(() =>
84+
createLoadingBoundary(
85+
() => {
86+
const m = mapArray(
87+
() => issues,
88+
(i: any) => {
89+
// Frame readers per row, under the boundary (`<For>`'s text
90+
// holes). The `id` read is not served by the guess: over the
91+
// new question it is an ordinary pending read (#4336
92+
// `stands`), recorded by the boundary, and it lands held.
93+
createRenderEffect(
94+
() => i.id,
95+
() => {}
96+
);
97+
createRenderEffect(
98+
() => i.assignee,
99+
() => {}
100+
);
101+
return () => `#${i.id}(${i.assignee ?? "-"})`;
102+
}
103+
);
104+
return () =>
105+
m()
106+
.map(f => f())
107+
.join(" ");
108+
},
109+
() => "loading",
110+
on ? { on: () => filter() } : undefined
111+
)
112+
);
113+
createRenderEffect(
114+
() => {
115+
const v: any = list();
116+
return typeof v === "function" ? v() : v;
117+
},
118+
v => {
119+
if (frames.at(-1) !== v) frames.push(v);
120+
}
121+
);
122+
});
123+
return {
124+
land,
125+
asks,
126+
frames,
127+
screen: () => frames.at(-1),
128+
setFilter: async (f: string) => {
129+
setFilter(f);
130+
flush();
131+
await tick();
132+
},
133+
assign: async (id: number, who: string) => {
134+
assign(id, who);
135+
flush();
136+
await tick();
137+
}
138+
};
139+
}
140+
141+
const MOUNT = ["loading", "#1(-) #3(-)"];
142+
143+
describe("#4379 a held `on` change whose content lands inside the hold", () => {
144+
for (const on of [true, false]) {
145+
it(`toggled back while held: the action's refresh shows no fallback (on=${on})`, async () => {
146+
const p = page(on);
147+
await tick();
148+
await p.land("fetchIssues:open", OPEN);
149+
await p.assign(3, "ann");
150+
await p.setFilter("closed");
151+
await p.setFilter("open");
152+
expect(p.screen()).toBe("#1(-) #3(ann)");
153+
await p.land("fetchIssues:closed", []);
154+
await p.land("fetchIssues:open", OPEN);
155+
expect(p.screen()).toBe("#1(-) #3(ann)");
156+
await p.land("assign:3,ann", undefined);
157+
expect(p.screen()).toBe("#1(-) #3(ann)");
158+
await p.land("fetchIssues:open", ASSIGNED);
159+
expect(p.frames).toEqual([...MOUNT, "#1(-) #3(ann)"]);
160+
expect(p.asks).toEqual([]);
161+
});
162+
163+
// The same seam without the toggle: the new question's answer keeps the
164+
// rows (same keys), so their effects survive and land held.
165+
it(`a new question whose answer keeps the rows: no fallback (on=${on})`, async () => {
166+
const p = page(on);
167+
await tick();
168+
await p.land("fetchIssues:open", OPEN);
169+
await p.assign(3, "ann");
170+
await p.setFilter("closed");
171+
expect(p.screen()).toBe("#1(-) #3(ann)");
172+
await p.land("fetchIssues:closed", OPEN);
173+
expect(p.screen()).toBe("#1(-) #3(ann)");
174+
await p.land("assign:3,ann", undefined);
175+
expect(p.screen()).toBe("#1(-) #3(ann)");
176+
await p.land("fetchIssues:closed", ASSIGNED);
177+
expect(p.frames).toEqual([...MOUNT, "#1(-) #3(ann)"]);
178+
expect(p.asks).toEqual([]);
179+
});
180+
}
181+
182+
// Control (passes on `next`): the answer drops the rows, so their effects
183+
// die and the boundary's own pass finds nothing left to wait on.
184+
it("control: an answer that drops the rows holds the old list to the refresh", async () => {
185+
const p = page(true);
186+
await tick();
187+
await p.land("fetchIssues:open", OPEN);
188+
await p.assign(3, "ann");
189+
await p.setFilter("closed");
190+
await p.land("fetchIssues:closed", []);
191+
await p.land("assign:3,ann", undefined);
192+
expect(p.screen()).toBe("#1(-) #3(ann)");
193+
await p.land("fetchIssues:closed", []);
194+
expect(p.frames).toEqual([...MOUNT, "#1(-) #3(ann)", ""]);
195+
});
196+
197+
// Control: nothing holds the change — the fallback shows with it (D-15).
198+
it("control: no hold — the fallback shows with the change and clears at its answer", async () => {
199+
const p = page(true);
200+
await tick();
201+
await p.land("fetchIssues:open", OPEN);
202+
await p.setFilter("closed");
203+
expect(p.screen()).toBe("loading");
204+
await p.land("fetchIssues:closed", OPEN);
205+
expect(p.frames).toEqual([...MOUNT, "loading", "#1(-) #3(-)"]);
206+
});
207+
});
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/**
2+
* @jsxImportSource @solidjs/web
3+
* @vitest-environment jsdom
4+
*/
5+
// #4379 — an action guesses a row of a keyed optimistic store, yields, then
6+
// `refresh()`es it. A `filter` change made meanwhile (closed, then back to
7+
// open) holds with the action (D-34). When the action ends, the held change
8+
// commits while the action's own refresh is still in flight; a refresh is
9+
// quiet (F-9), so `<Loading on={filter()}>` keeps the list up, as it does
10+
// without `on` and for the closed-only change. The signals-side pin is
11+
// `packages/signals/tests/loading-on-held-filter-refresh-4379.test.ts`.
12+
import { expect, test } from "vitest";
13+
import {
14+
Loading,
15+
Errored,
16+
For,
17+
action,
18+
createOptimisticStore,
19+
createSignal,
20+
flush,
21+
refresh
22+
} from "solid-js";
23+
import { render } from "../src/index.js";
24+
25+
const tick = async () => {
26+
for (let i = 0; i < 4; i++) {
27+
await new Promise(r => setTimeout(r, 0));
28+
flush();
29+
}
30+
};
31+
type Issue = { id: number; assignee: string | null };
32+
33+
for (const useOn of [true, false])
34+
for (const toggle of [true, false])
35+
test(`on=${useOn} toggle=${toggle}: the action's refresh never shows the fallback`, async () => {
36+
const asks: { key: string; res: (v: any) => void }[] = [];
37+
const ask = (key: string) => new Promise<any>(res => asks.push({ key, res }));
38+
const land = async (key: string, v: any) => {
39+
const i = asks.findIndex(a => a.key === key);
40+
if (i < 0) throw new Error(`not asked ${key}: ${asks.map(a => a.key)}`);
41+
asks.splice(i, 1)[0].res(v);
42+
await tick();
43+
};
44+
const container = document.body.appendChild(document.createElement("div"));
45+
const frames: string[] = [];
46+
const snap = () => frames.push(container.textContent!);
47+
let setFilter!: (f: string) => void;
48+
let assign!: (id: number, who: string) => void;
49+
const dispose = render(() => {
50+
const [filter, sf] = createSignal("open");
51+
setFilter = sf;
52+
const [issues, setIssues] = createOptimisticStore<Issue[]>(
53+
async (d: Issue[]) => {
54+
const r: Issue[] = await ask(`fetchIssues:${filter()}`);
55+
d.length = r.length;
56+
r.forEach((x, i) => ((d as any)[i] = x));
57+
},
58+
[],
59+
{ key: "id" } as any
60+
);
61+
assign = action(function* (id: number, who: string) {
62+
try {
63+
const i = issues.findIndex(t => t.id === id);
64+
setIssues((d: Issue[]) => {
65+
d[i].assignee = who;
66+
});
67+
yield ask(`assign:${id},${who}`);
68+
refresh(issues);
69+
} catch {}
70+
});
71+
return (
72+
<Errored fallback={(e: any) => <p>err {String(e()?.message ?? e())}</p>}>
73+
<Loading on={useOn ? filter() : undefined} fallback={<p>loading {filter()}</p>}>
74+
<For each={issues}>
75+
{(it: any) => (
76+
<i>
77+
#{it.id}({it.assignee ?? "-"})
78+
</i>
79+
)}
80+
</For>
81+
</Loading>
82+
</Errored>
83+
);
84+
}, container);
85+
await tick();
86+
await land("fetchIssues:open", [
87+
{ id: 1, assignee: null },
88+
{ id: 3, assignee: null }
89+
]);
90+
snap();
91+
assign(3, "ann");
92+
flush();
93+
await tick();
94+
snap();
95+
setFilter("closed");
96+
flush();
97+
await tick();
98+
if (toggle) {
99+
setFilter("open");
100+
flush();
101+
await tick();
102+
}
103+
snap();
104+
await land("fetchIssues:closed", []);
105+
if (toggle)
106+
await land("fetchIssues:open", [
107+
{ id: 1, assignee: null },
108+
{ id: 3, assignee: null }
109+
]);
110+
snap();
111+
await land("assign:3,ann", undefined);
112+
snap();
113+
await land(
114+
`fetchIssues:${toggle ? "open" : "closed"}`,
115+
toggle
116+
? [
117+
{ id: 1, assignee: null },
118+
{ id: 3, assignee: "ann" }
119+
]
120+
: []
121+
);
122+
snap();
123+
dispose();
124+
container.remove();
125+
const held = "#1(-)#3(ann)";
126+
expect(frames).toEqual(["#1(-)#3(-)", held, held, held, held, toggle ? "#1(-)#3(ann)" : ""]);
127+
});

0 commit comments

Comments
 (0)