Skip to content

Commit 8e718d6

Browse files
committed
fix(signals): a re-based lane reads its frame's world in every flush, through merges (#4577)
A second async change merged into the parked filter frame mid-hold; the lane's later passes then read the screen and re-asked over the old filter, and the landing committed that beside the new one (F-1, D-9). This also covers #4576, so laneServed is back to its next form. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0117BoWNSSgtemsSYsaX2hXE
1 parent 4844d77 commit 8e718d6

5 files changed

Lines changed: 279 additions & 15 deletions

File tree

‎.changeset/lane-served-retires-carried-pending.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"@solidjs/signals": patch
33
---
44

5-
fix(signals): a lane pass served the committed value of a refreshing source retires that source's pending from the readers it carried it to, so a held change commits once its last async answers (#4576)
5+
fix(signals): lane work re-based over a held change's answer reads that change's world in every flush and is not re-derived on the committed world while it is parked, so a refresh or a second entangled change no longer commits a derivation over the old inputs beside the new ones, and the held change lands once its last async answers (#4576, #4577)

‎packages/signals/node_modules‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/home/user/solid/packages/signals/node_modules

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ import {
149149
schedule,
150150
setPassLane,
151151
txOf,
152+
resolveTx,
152153
inEffectCallback,
153154
effectCallbackEvent,
154155
ANY_EVENT,
@@ -1353,9 +1354,16 @@ function frameRead(c: Computed<any>, el: Signal<any> | Computed<any>): boolean {
13531354
// Lane work and verdict readers are never the transaction's pass, whichever
13541355
// flush runs it: a node T holds re-enters T when it re-runs (`recompute`'s
13551356
// head), and the pass may then read a guess and become the lane's.
1356-
// Except a lane re-based over this transaction's answer, in its flush: its
1357-
// rows are that answer's, so its work reads the rest of it (#4536).
1358-
if ((t === flushTransaction && (!lane || passLane!.over === t) && !verdict) || bornInto(c, t))
1357+
// Except a lane re-based over this transaction's answer (merged since or
1358+
// not), in whichever flush: its rows are that answer's, so its work reads
1359+
// the rest of it (#4536). Served the screen outside that flush, a refresh
1360+
// or another change's flush re-derived it over the old inputs, and the
1361+
// landing committed that beside the new ones (F-1, D-34 ¶3, #4576, #4577).
1362+
if (
1363+
((lane ? passLane!.over && resolveTx(passLane!.over) === t : t === flushTransaction) &&
1364+
!verdict) ||
1365+
bornInto(c, t)
1366+
)
13591367
return false;
13601368
staleReader(c, t);
13611369
// Lane work or a verdict reader no longer waits on `el`'s flight (lanes.ts

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

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ import {
6868
isThenable,
6969
notifyStatus,
7070
releaseFlightTeardown,
71-
removePendingSource,
72-
settlePendingSource
71+
removePendingSource
7372
} from "./async.js";
7473
import { laneValueOf } from "./truth.js";
7574
import { enqueueSub } from "./heap.js";
@@ -1096,8 +1095,9 @@ const laneSeams = (t: Transaction | null): void => {
10961095
// D-22). Not one born into that frame (a held pass's child, ruling A):
10971096
// it has no screen, its reads are the transaction's either way — it
10981097
// runs again at the landing, not now. Nor lane work re-based over this
1099-
// frame's answer (#4536): its rows are that answer's, so its other
1100-
// reads are too, and the lane holds while the frame does (`laneSeam`).
1098+
// frame's answer (#4536, merged since or not): its rows are that
1099+
// answer's, so its other reads are too (core.ts `frameRead`), and the
1100+
// lane holds while the frame does (`laneSeam`).
11011101
// Re-derived on the committed world, it paired the new rows with the
11021102
// old inputs, and the landing revealed that beside them (F-1, D-34 ¶3,
11031103
// #4577).
@@ -1108,7 +1108,7 @@ const laneSeams = (t: Transaction | null): void => {
11081108
(r._config & CONFIG_VERDICT
11091109
? !(r._flags & REACTIVE_PROBE_UNANSWERED)
11101110
: !blocked(t!) || heldBy(t!, r))) ||
1111-
l.over === t
1111+
(l.over && liveTx(l.over) === t)
11121112
: l &&
11131113
!(
11141114
r._flags & REACTIVE_PROBE_UNANSWERED ||
@@ -1198,14 +1198,10 @@ const adoptParked = (r: Computed<any>): boolean => {
11981198
* included) is not this pass's — the landing re-derives it (`reruns`).
11991199
* Kept, a pass that went pending on another source never woke when that
12001200
* source settled (#4397). Only a reader something made pending has anything
1201-
* to drop. What the drop retires is retired from the dependents that carried
1202-
* it through `c` too: the source's own landing walk stops at `c`, which no
1203-
* longer has it, and a render effect left marked would hold its transaction
1204-
* on a flight that has landed (D-11, F-2, #4576). */
1201+
* to drop. */
12051202
const laneServed = (c: Computed<any>, el: Signal<any> | Computed<any>): void => {
12061203
const from = (el as Computed<any>)._x?._pendingSources;
1207-
if (from && c._x?._pendingSources)
1208-
for (const s of from) if (removePendingSource(c, s)) settlePendingSource(c, s);
1204+
if (from && c._x?._pendingSources) for (const s of from) removePendingSource(c, s);
12091205
};
12101206
/** Render effects that read a verdict and entered a lane before its seam (#4284). */
12111207
const entered: Computed<any>[] = [];
Lines changed: 259 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,259 @@
1+
import { expect, test } from "vitest";
2+
import {
3+
action,
4+
createErrorBoundary,
5+
createMemo,
6+
createOptimisticStore,
7+
createRenderEffect,
8+
createRoot,
9+
createSignal,
10+
flush,
11+
refresh
12+
} from "../src/index.js";
13+
const tick = async () => {
14+
for (let i = 0; i < 4; i++) {
15+
await new Promise(r => setTimeout(r, 0));
16+
flush();
17+
}
18+
};
19+
test("#4577 with a second async change entangled mid-hold: the screen settles as one (F-1, D-9)", async () => {
20+
const asks: { key: string; res: (v: any) => void }[] = [];
21+
const ask = (key: string) => new Promise<any>(res => asks.push({ key, res }));
22+
const settle = async (pre: string, v: any) => {
23+
asks
24+
.splice(
25+
asks.findIndex(a => a.key.startsWith(pre)),
26+
1
27+
)[0]
28+
.res(v);
29+
await tick();
30+
};
31+
const frames: string[] = [];
32+
let f = "",
33+
l = "",
34+
o = "";
35+
let q = false;
36+
const snap = () => {
37+
if (!q) {
38+
q = true;
39+
queueMicrotask(() => {
40+
q = false;
41+
frames.push(`${f}: ${l} | ${o}`);
42+
});
43+
}
44+
};
45+
let setFilter!: (v: string) => void,
46+
setTag!: (v: string) => void,
47+
closeOne!: (id: number) => unknown,
48+
dispose!: () => void;
49+
createRoot(d => {
50+
dispose = d;
51+
const [filter, sf] = createSignal("open");
52+
setFilter = sf;
53+
const [tag, st] = createSignal("t0");
54+
setTag = st;
55+
const [issues, set] = createOptimisticStore<{ id: number }[]>(
56+
() => ask(`issues:${filter()}`),
57+
[],
58+
{ key: "id" }
59+
);
60+
const other = createMemo(() => (issues.length, ask(`other:${filter()}:${tag()}`)));
61+
const tagv = createMemo(() => ask(`tag:${tag()}`));
62+
closeOne = action(function* (id: number) {
63+
set(xs => {
64+
const i = xs.findIndex(t => t.id === id);
65+
if (i >= 0) xs.splice(i, 1);
66+
});
67+
yield ask(`close:${id}`);
68+
refresh(issues);
69+
});
70+
const list = createMemo(() => issues.map(r => `[#${r.id}]`).join(""));
71+
createRenderEffect(filter, v => {
72+
f = v;
73+
snap();
74+
});
75+
createRenderEffect(list, v => {
76+
l = v;
77+
snap();
78+
});
79+
createRenderEffect(
80+
createErrorBoundary(
81+
() => other(),
82+
() => "ERR"
83+
) as any,
84+
(v: any) => {
85+
o = String(v);
86+
snap();
87+
}
88+
);
89+
createRenderEffect(
90+
createErrorBoundary(
91+
() => String(tagv()),
92+
() => "ERR"
93+
) as any,
94+
() => {}
95+
);
96+
});
97+
await tick();
98+
await settle("issues:open", [{ id: 1 }, { id: 3 }, { id: 4 }]);
99+
await settle("other:open", "O-open");
100+
await settle("tag:t0", "t0");
101+
setFilter("closed");
102+
await tick();
103+
closeOne(1);
104+
await tick();
105+
setTag("t1");
106+
await tick();
107+
await settle("issues:closed", [{ id: 1 }, { id: 2 }]);
108+
await settle("other:closed", "O-closed");
109+
await settle("close:1", {});
110+
await settle("issues:closed", [{ id: 2 }]);
111+
for (let k = 0; k < 20 && asks.length; k++) {
112+
const a = asks.shift()!;
113+
const p = a.key.split(":");
114+
a.res(
115+
p[0] === "other" ? `O-${p[1]}` : p[0] === "tag" ? p[1] : p[0] === "issues" ? [{ id: 2 }] : {}
116+
);
117+
await tick();
118+
}
119+
for (let i = 0; i < 5; i++) await tick();
120+
for (const fr of frames)
121+
if (fr.includes("|") && !fr.endsWith("| "))
122+
expect(fr.startsWith("closed"), fr).toBe(fr.includes("O-closed"));
123+
expect(`${f}: ${l} | ${o}`).toBe("closed: [#2] | O-closed");
124+
dispose();
125+
});
126+
127+
// The matrix around it: when the second change starts (before the guess,
128+
// after it, after the filter's answer lands), whether `other` reads the
129+
// guessed list, and whether filter and list share one render effect.
130+
for (const when of ["beforeGuess", "afterGuess", "afterLanding"] as const)
131+
for (const reader of ["readsList", "plain"] as const)
132+
for (const shape of ["shared", "split"] as const)
133+
test(`#4577 entangled matrix: tag ${when}, other ${reader}, ${shape} (F-1, D-9)`, async () => {
134+
const asks: { key: string; res: (v: any) => void }[] = [];
135+
const ask = (key: string) => new Promise<any>(res => asks.push({ key, res }));
136+
const settle = async (pre: string, v: any) => {
137+
asks
138+
.splice(
139+
asks.findIndex(a => a.key.startsWith(pre)),
140+
1
141+
)[0]
142+
.res(v);
143+
await tick();
144+
};
145+
const frames: string[] = [];
146+
let f = "",
147+
l = "",
148+
o = "";
149+
let q = false;
150+
const snap = () => {
151+
if (!q) {
152+
q = true;
153+
queueMicrotask(() => {
154+
q = false;
155+
frames.push(`${f}: ${l} | ${o}`);
156+
});
157+
}
158+
};
159+
let setFilter!: (v: string) => void,
160+
setTag!: (v: string) => void,
161+
closeOne!: (id: number) => unknown,
162+
dispose!: () => void;
163+
createRoot(d => {
164+
dispose = d;
165+
const [filter, sf] = createSignal("open");
166+
setFilter = sf;
167+
const [tag, st] = createSignal("t0");
168+
setTag = st;
169+
const [issues, set] = createOptimisticStore<{ id: number }[]>(
170+
() => ask(`issues:${filter()}`),
171+
[],
172+
{ key: "id" }
173+
);
174+
const other = createMemo(
175+
() => (reader === "readsList" && issues.length, ask(`other:${filter()}:${tag()}`))
176+
);
177+
const tagv = createMemo(() => ask(`tag:${tag()}`));
178+
closeOne = action(function* (id: number) {
179+
set(xs => {
180+
const i = xs.findIndex(t => t.id === id);
181+
if (i >= 0) xs.splice(i, 1);
182+
});
183+
yield ask(`close:${id}`);
184+
refresh(issues);
185+
});
186+
const list = createMemo(() => issues.map(r => `[#${r.id}]`).join(""));
187+
if (shape === "shared")
188+
createRenderEffect(
189+
() => [filter(), list()] as const,
190+
([a, b]) => {
191+
f = a;
192+
l = b;
193+
snap();
194+
}
195+
);
196+
else {
197+
createRenderEffect(filter, v => {
198+
f = v;
199+
snap();
200+
});
201+
createRenderEffect(list, v => {
202+
l = v;
203+
snap();
204+
});
205+
}
206+
createRenderEffect(
207+
createErrorBoundary(
208+
() => other(),
209+
() => "ERR"
210+
) as any,
211+
(v: any) => {
212+
o = String(v);
213+
snap();
214+
}
215+
);
216+
createRenderEffect(
217+
createErrorBoundary(
218+
() => String(tagv()),
219+
() => "ERR"
220+
) as any,
221+
() => {}
222+
);
223+
});
224+
await tick();
225+
await settle("issues:open", [{ id: 1 }, { id: 3 }, { id: 4 }]);
226+
await settle("other:open", "O-open");
227+
await settle("tag:t0", "t0");
228+
setFilter("closed");
229+
await tick();
230+
if (when === "beforeGuess") (setTag("t1"), await tick());
231+
closeOne(1);
232+
await tick();
233+
if (when === "afterGuess") (setTag("t1"), await tick());
234+
await settle("issues:closed", [{ id: 1 }, { id: 2 }]);
235+
if (when === "afterLanding") (setTag("t1"), await tick());
236+
await settle("other:closed", "O-closed");
237+
await settle("close:1", {});
238+
await settle("issues:closed", [{ id: 2 }]);
239+
for (let k = 0; k < 20 && asks.length; k++) {
240+
const a = asks.shift()!;
241+
const p = a.key.split(":");
242+
a.res(
243+
p[0] === "other"
244+
? `O-${p[1]}`
245+
: p[0] === "tag"
246+
? p[1]
247+
: p[0] === "issues"
248+
? [{ id: 2 }]
249+
: {}
250+
);
251+
await tick();
252+
}
253+
for (let i = 0; i < 5; i++) await tick();
254+
for (const fr of frames)
255+
if (fr.includes("|") && !fr.endsWith("| "))
256+
expect(fr.startsWith("closed"), fr).toBe(fr.includes("O-closed"));
257+
expect(`${f}: ${l} | ${o}`).toBe("closed: [#2] | O-closed");
258+
dispose();
259+
});

0 commit comments

Comments
 (0)