Skip to content

Commit c8d6fd2

Browse files
ryansolidclaude
andauthored
fix(signals): a lane's held reader settling never makes the flush join the lane (#4440) (#4477)
* fix(signals): a lane's held reader settling never makes the flush join the lane (#4440) A landing's settle walk joins the flush to the transaction of each held reader it releases (`joinFuture(txOf(node))`). A render or user effect a guess's lane holds has that lane as its transaction, so the flush took the lane as its transaction. The lane was dissolved later in the same flush (a correction), and every node born held after that (the rows `<For>` mounted for the refreshed list) was listed on the dead lane and never committed: the row rendered with every hole empty. Lane work never makes its node the transaction's (D-37), so the walk now skips a reader held by a lane. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2 * chore(size): record #4440's sizes over next @ 7135a77 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2 * chore(size): record #4440's sizes over next @ 131ceb8 The simple-app floor goes over its frozen cap (9,789 B brotli, +22 B minified over the recorded) and needs a Size-Exception in the PR body. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2 * chore(size): re-record #4440's sizes over next @ e49b0c7 Two frozen floors go over their caps (each +24 B minified over the recorded): the simple-app floor (9,790 B brotli) and the hydrating (no stores) floor (18,758 B). Both need a Size-Exception in the PR body. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2 * chore(size): re-record #4440's sizes over next @ ab3d2ad Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2 * fix(signals): guard joinFuture against a lane's transaction, gated on lanes The merge of next above also moved the #4440 guard from the settle walk into joinFuture (`laneStageHook && t?._lane`), so it covers every held-node joinFuture call and bundles without lanes pay 0 B. This commit re-records the lane bundles' sizes; the floor raises and Size-Exception are gone. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2 * chore(size): re-record over next @ d0fc285 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2 --------- Co-authored-by: Claude <[email protected]>
1 parent d0fc285 commit c8d6fd2

6 files changed

Lines changed: 275 additions & 6 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 landing that settles a reader held by an optimistic lane no longer makes the flush join that lane as its transaction: rows a list guess mounted over a pending refresh render instead of staying empty.

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,8 @@ export function settlePendingSource(el: Computed<any>, source: Computed<any> = e
369369
// L2: a landing resumes the transaction waiting on it (maintainer: "it
370370
// resumes the sync frame") — a held reader's re-pass over the landed
371371
// value is that transaction's work, and the flush that carries it
372-
// parks into it.
372+
// parks into it. A lane's held reader is the lane's (D-37): the flush
373+
// never takes a lane as its transaction (#4440).
373374
if (node._config & CONFIG_HELD) joinFuture(txOf(node));
374375
if (node._x?._blocked) {
375376
enqueueSub(node);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,8 @@ export function resolveTx(t: Transaction): Transaction {
395395
* went pending with nothing held). Joining a second one merges it into the
396396
* flush's: the work that touched both entangles them (A15). */
397397
export function joinFuture(t: Transaction | null): void {
398+
// A lane is never the flush's transaction (D-37, #4440).
399+
if (laneStageHook && t?._lane) return;
398400
const f = flushTransaction;
399401
if (f === null) {
400402
flushTransaction = t === null ? newTransaction(false) : resolveTx(t);
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
import { expect, it } from "vitest";
2+
import {
3+
action,
4+
createEffect,
5+
createLoadingBoundary,
6+
createOptimisticStore,
7+
createRenderEffect,
8+
createRoot,
9+
createSignal,
10+
flush,
11+
mapArray,
12+
refresh,
13+
untrack
14+
} from "../src/index.js";
15+
16+
// #4440: a per-key guess whose action landed, its `refresh` in the air; a
17+
// second action replaces the list. The refresh's landing settles readers a
18+
// guess's lane holds: the flush must not join that lane as its transaction
19+
// (the lane dissolves in the same flush), or the rows born in it are held by
20+
// a dead lane and never render.
21+
const tick = async () => {
22+
for (let i = 0; i < 4; i++) {
23+
await new Promise(r => setTimeout(r, 0));
24+
flush();
25+
}
26+
};
27+
28+
for (const withCount of [false, true])
29+
for (const withAssign of [false, true])
30+
it(`a new row renders after a list guess joins a pending refresh (count=${withCount}, assign=${withAssign})`, async () => {
31+
const asks: { key: string; res: (v: any) => void }[] = [];
32+
const ask = (key: string) => new Promise<any>(res => asks.push({ key, res }));
33+
const land = async (key: string, v: any) => {
34+
for (const a of asks.filter(a => a.key === key)) {
35+
asks.splice(asks.indexOf(a), 1);
36+
a.res(v);
37+
}
38+
await tick();
39+
};
40+
let assignTo!: (id: number) => any;
41+
let closeOne!: (id: number) => any;
42+
let view: () => string = () => "";
43+
createRoot(() => {
44+
const [issues, set] = createOptimisticStore(
45+
async (d: any[]) => {
46+
const r = await ask("fetch");
47+
d.length = r.length;
48+
r.forEach((x: any, i: number) => {
49+
d[i] = x;
50+
});
51+
},
52+
[] as any[],
53+
{ key: "id" }
54+
);
55+
assignTo = action(function* (id: number) {
56+
const i = untrack(() => issues.findIndex((t: any) => t.id === id));
57+
set((d: any) => {
58+
d[i].assignee = "guest";
59+
});
60+
yield ask(`assign:${id}`);
61+
refresh(issues);
62+
});
63+
closeOne = action(function* (id: number) {
64+
const next = untrack(() => issues.filter((t: any) => t.id !== id));
65+
set((d: any) => {
66+
d.length = next.length;
67+
next.forEach((x: any, i: number) => {
68+
d[i] = x;
69+
});
70+
});
71+
yield ask(`close:${id}`);
72+
refresh(issues);
73+
});
74+
const [count, setCount] = createSignal(-1);
75+
if (withCount)
76+
createEffect(
77+
() => issues.length,
78+
(n: number) => {
79+
setCount(n);
80+
}
81+
);
82+
const b = createLoadingBoundary(
83+
() =>
84+
mapArray(
85+
() => issues,
86+
(it: any) => {
87+
const s = { id: "", a: "" };
88+
createRenderEffect(
89+
() => it.id,
90+
v => {
91+
s.id = v;
92+
}
93+
);
94+
createRenderEffect(
95+
() => it.assignee,
96+
v => {
97+
s.a = v;
98+
}
99+
);
100+
return s;
101+
}
102+
),
103+
() => "loading"
104+
);
105+
createRenderEffect(
106+
() => {
107+
const v: any = b();
108+
return typeof v === "function" ? v() : v;
109+
},
110+
(v: any) => {
111+
view = () =>
112+
typeof v === "string" ? v : v.map((s: any) => `[#${s.id} ${s.a}]`).join("");
113+
}
114+
);
115+
createRenderEffect(count, () => {});
116+
});
117+
await tick();
118+
await land("fetch", [
119+
{ id: 1, assignee: "ann" },
120+
{ id: 3, assignee: "bob" },
121+
{ id: 4, assignee: "dana" }
122+
]);
123+
if (withAssign) {
124+
assignTo(4);
125+
await tick();
126+
await land("assign:4", {});
127+
}
128+
closeOne(3);
129+
await tick();
130+
await land("close:3", {});
131+
await land("fetch", [
132+
{ id: 1, assignee: "ann" },
133+
{ id: 4, assignee: withAssign ? "guest" : "dana" }
134+
]);
135+
expect(view()).toBe(`[#1 ann][#4 ${withAssign ? "guest" : "dana"}]`);
136+
});
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/**
2+
* @jsxImportSource @solidjs/web
3+
* @vitest-environment jsdom
4+
*/
5+
// #4440: a per-key guess whose action landed and whose `refresh` is still in
6+
// the air; a second action replaces the list. With a `Loading` around the
7+
// list and an effect reading the list's length, row #1 rendered empty.
8+
import { expect, test } from "vitest";
9+
import {
10+
Loading,
11+
For,
12+
action,
13+
createOptimisticStore,
14+
createSignal,
15+
createEffect,
16+
flush,
17+
refresh,
18+
untrack
19+
} from "solid-js";
20+
import { render } from "../src/index.js";
21+
22+
const tick = async () => {
23+
for (let i = 0; i < 4; i++) {
24+
await new Promise(r => setTimeout(r, 0));
25+
flush();
26+
}
27+
};
28+
29+
for (const withCount of [false, true])
30+
for (const withAssign of [false, true])
31+
test(`list guess over a pending refresh (count effect=${withCount}, assign first=${withAssign})`, async () => {
32+
const asks: { key: string; res: (v: any) => void }[] = [];
33+
const ask = (key: string) => new Promise<any>(res => asks.push({ key, res }));
34+
const land = async (key: string, v: any) => {
35+
for (const a of asks.filter(a => a.key === key)) {
36+
asks.splice(asks.indexOf(a), 1);
37+
a.res(v);
38+
}
39+
await tick();
40+
};
41+
const container = document.body.appendChild(document.createElement("div"));
42+
let assignTo!: (id: number) => any;
43+
let closeOne!: (id: number) => any;
44+
const dispose = render(() => {
45+
const [issues, set] = createOptimisticStore(
46+
async (d: any[]) => {
47+
const r = await ask("fetch");
48+
d.length = r.length;
49+
r.forEach((x: any, i: number) => {
50+
d[i] = x;
51+
});
52+
},
53+
[] as any[],
54+
{ key: "id" }
55+
);
56+
assignTo = action(function* (id: number) {
57+
const i = untrack(() => issues.findIndex((t: any) => t.id === id));
58+
set((d: any) => {
59+
d[i].assignee = "guest";
60+
});
61+
yield ask(`assign:${id}`);
62+
refresh(issues);
63+
});
64+
closeOne = action(function* (id: number) {
65+
const next = untrack(() => issues.filter((t: any) => t.id !== id));
66+
set((d: any) => {
67+
d.length = next.length;
68+
next.forEach((x: any, i: number) => {
69+
d[i] = x;
70+
});
71+
});
72+
yield ask(`close:${id}`);
73+
refresh(issues);
74+
});
75+
const [count, setCount] = createSignal(-1);
76+
if (withCount)
77+
createEffect(
78+
() => issues.length,
79+
(n: number) => {
80+
setCount(n);
81+
}
82+
);
83+
return (
84+
<>
85+
<b>({count()})</b>
86+
<Loading fallback={<p>loading</p>}>
87+
<For each={issues}>
88+
{(it: any) => (
89+
<i>
90+
[#{it.id} {it.assignee}]
91+
</i>
92+
)}
93+
</For>
94+
</Loading>
95+
</>
96+
);
97+
}, container);
98+
await tick();
99+
await land("fetch", [
100+
{ id: 1, assignee: "ann" },
101+
{ id: 3, assignee: "bob" },
102+
{ id: 4, assignee: "dana" }
103+
]);
104+
if (withAssign) {
105+
assignTo(4);
106+
await tick();
107+
await land("assign:4", {});
108+
}
109+
closeOne(3);
110+
await tick();
111+
await land("close:3", {});
112+
await land("fetch", [
113+
{ id: 1, assignee: "ann" },
114+
{ id: 4, assignee: withAssign ? "guest" : "dana" }
115+
]);
116+
expect(container.textContent).toBe(
117+
`(${withCount ? 2 : -1})[#1 ann][#4 ${withAssign ? "guest" : "dana"}]`
118+
);
119+
dispose();
120+
container.remove();
121+
});

0 commit comments

Comments
 (0)