Skip to content

Commit 4844d77

Browse files
committed
fix(signals): lane work re-based over a parked frame is not re-derived on the committed world (#4577)
Re-derived at the seam, a re-based lane pass paired the frame's new rows with the old filter, and the landing then showed that beside the new filter (F-1, D-34 ¶3). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0117BoWNSSgtemsSYsaX2hXE
1 parent 6b55eb6 commit 4844d77

2 files changed

Lines changed: 139 additions & 5 deletions

File tree

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,14 +1095,20 @@ const laneSeams = (t: Transaction | null): void => {
10951095
// parked: landing at this seam, what it read is the screen (one run,
10961096
// D-22). Not one born into that frame (a held pass's child, ruling A):
10971097
// it has no screen, its reads are the transaction's either way — it
1098-
// runs again at the landing, not now.
1098+
// 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`).
1101+
// Re-derived on the committed world, it paired the new rows with the
1102+
// old inputs, and the landing revealed that beside them (F-1, D-34 ¶3,
1103+
// #4577).
10991104
if (
11001105
r._flags & REACTIVE_DISPOSED ||
11011106
(l?._lane
1102-
? l._parent?._verdict === l &&
1103-
(r._config & CONFIG_VERDICT
1104-
? !(r._flags & REACTIVE_PROBE_UNANSWERED)
1105-
: !blocked(t!) || heldBy(t!, r))
1107+
? (l._parent?._verdict === l &&
1108+
(r._config & CONFIG_VERDICT
1109+
? !(r._flags & REACTIVE_PROBE_UNANSWERED)
1110+
: !blocked(t!) || heldBy(t!, r))) ||
1111+
l.over === t
11061112
: l &&
11071113
!(
11081114
r._flags & REACTIVE_PROBE_UNANSWERED ||
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
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+
14+
const tick = async () => {
15+
for (let i = 0; i < 4; i++) {
16+
await new Promise(r => setTimeout(r, 0));
17+
flush();
18+
}
19+
};
20+
21+
test("F-1 in the #4577 shape: one memo's readers agree, a memo is whole, the screen settles as one", async () => {
22+
const asks: { key: string; res: (v: any) => void }[] = [];
23+
const ask = (key: string) => new Promise<any>(res => asks.push({ key, res }));
24+
const settle = async (key: string, v: any) => {
25+
const i = asks.findIndex(a => a.key === key);
26+
asks.splice(i, 1)[0].res(v);
27+
await tick();
28+
};
29+
const frames: string[] = [];
30+
let f = "",
31+
a = "",
32+
b = "",
33+
s = "",
34+
o = "";
35+
let q = false;
36+
const snap = () => {
37+
if (!q) {
38+
q = true;
39+
queueMicrotask(() => {
40+
q = false;
41+
frames.push(`${f}|${a}|${b}|${s}|${o}`);
42+
});
43+
}
44+
};
45+
let setFilter!: (v: string) => void, closeOne!: (id: number) => unknown, dispose!: () => void;
46+
createRoot(d => {
47+
dispose = d;
48+
const [filter, sf] = createSignal("open");
49+
setFilter = sf;
50+
const [issues, set] = createOptimisticStore<{ id: number }[]>(
51+
() => ask(`issues:${filter()}`),
52+
[],
53+
{ key: "id" }
54+
);
55+
const other = createMemo(() => (issues.length, ask(`other:${filter()}`)));
56+
closeOne = action(function* (id: number) {
57+
set(l => {
58+
const i = l.findIndex(r => r.id === id);
59+
if (i >= 0) l.splice(i, 1);
60+
});
61+
yield ask(`close:${id}`);
62+
refresh(issues);
63+
});
64+
const list = createMemo(() => issues.map(r => `[#${r.id}]`).join(""));
65+
const shared = createMemo(() => `${filter()}:${issues.map(r => `[#${r.id}]`).join("")}`);
66+
createRenderEffect(filter, v => {
67+
f = v;
68+
snap();
69+
});
70+
createRenderEffect(
71+
() => list(),
72+
v => {
73+
a = v;
74+
snap();
75+
}
76+
);
77+
createRenderEffect(
78+
() => list(),
79+
v => {
80+
b = v;
81+
snap();
82+
}
83+
);
84+
createRenderEffect(shared, v => {
85+
s = v;
86+
snap();
87+
});
88+
createRenderEffect(
89+
createErrorBoundary(
90+
() => other(),
91+
() => "ERR"
92+
) as any,
93+
(v: any) => {
94+
o = v;
95+
snap();
96+
}
97+
);
98+
});
99+
await tick();
100+
await settle("issues:open", [{ id: 1 }, { id: 3 }, { id: 4 }]);
101+
await settle("other:open", "O-open");
102+
setFilter("closed");
103+
await tick();
104+
closeOne(1);
105+
await tick();
106+
await settle("issues:closed", [{ id: 1 }, { id: 2 }]);
107+
await settle("other:closed", "O-closed");
108+
await settle("close:1", {});
109+
await settle("issues:closed", [{ id: 2 }]);
110+
for (let k = 0; k < 10 && asks.length; k++) {
111+
const x = asks.shift()!;
112+
x.key.startsWith("other")
113+
? x.res("O-" + x.key.split(":")[1])
114+
: x.key.startsWith("issues:closed")
115+
? x.res([{ id: 2 }])
116+
: x.res({});
117+
await tick();
118+
}
119+
for (let i = 0; i < 5; i++) await tick();
120+
for (const fr of frames) {
121+
const [F, A, B, S, O] = fr.split("|");
122+
if (!A) continue;
123+
expect(A, fr).toBe(B);
124+
expect(S.split(":")[0], fr).toBe(F);
125+
expect(O === "O-closed", fr).toBe(F === "closed");
126+
}
127+
dispose();
128+
});

0 commit comments

Comments
 (0)