Skip to content

Commit 7e150bf

Browse files
committed
fix(signals): a pass that is the hold's own work lands in one frame (#4648)
A pass that reads the hold's flight (D-25) re-runs in the flush that lands it, before the commit. Its untracked probe read the committed value there, and that run went out with this flush's own effect runs, ahead of the landing re-derivation: {0,0,false} -> {5,0,false} -> {5,5,false}. When nothing blocks the hold any more, the probe now reads the landed world and the pass is final in the landing frame (F-1). If a node computed later in that flush blocks the hold again, the seam re-runs the pass, held, on the committed value (watchVerdict; ruling on #4662), and the screen keeps the old frame until the hold that remains lands. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0117BoWNSSgtemsSYsaX2hXE
1 parent 2d7116c commit 7e150bf

2 files changed

Lines changed: 157 additions & 0 deletions

File tree

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,16 @@ function verdictValue(el: Signal<any> | Computed<any>, c: Computed<any> | null):
596596
// its re-run would ask the hold's question again (F-9).
597597
if (probing)
598598
if (c?._config! & CONFIG_HELD) {
599+
// In the flush that lands the hold (nothing blocks it now: the
600+
// pass is the hold's own work, D-25), the probe reads the landed
601+
// world and the pass is final in the landing frame (F-1). If a
602+
// later node blocks the hold again, the seam re-runs it, held, on
603+
// the committed value (`watchVerdict`; ruling on #4662).
604+
if (el._pendingValue !== NOT_PENDING && !blocked(t)) {
605+
watchVerdict(c!);
606+
if (__TEST__) shadowActual(SLOT_P);
607+
return staged(el);
608+
}
599609
if (!c!._x!._q) staleReader(c!, t);
600610
} else {
601611
if (heldNotFinal(owner)) probeFound = true;
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
/**
2+
* #4648 (review of #4667). A pass that is the hold's own work (D-25: it reads
3+
* the hold's flight) re-runs in the flush that lands it. Its untracked probe
4+
* of the held write then answers for the landed world: the hold lands at
5+
* this seam, so the probe reads the staging and the pass is final in the
6+
* landing frame. The render effect and the user effect both show
7+
* `{0,0,false}` then `{5,5,false}` — never the stale pass first (F-1).
8+
*
9+
* If a node computed later in that flush blocks the hold again (a new
10+
* flight starts at the landing), the hold is up again: the pass re-runs on
11+
* the committed value — `inner: 0` while held (ruling on #4662) — and the
12+
* screen keeps the old frame until the hold that remains lands, with no
13+
* value shown and then retracted, and no `p: true` beside `v: 5` (D-23).
14+
*
15+
* Every case runs in both read orders.
16+
*/
17+
import { describe, expect, it } from "vitest";
18+
import {
19+
createEffect,
20+
createMemo,
21+
createRenderEffect,
22+
createSignal,
23+
flush,
24+
isPending,
25+
untrack
26+
} from "../src/index.js";
27+
28+
type Row = { v: number; inner: unknown; p: unknown };
29+
type Order = "probe after read" | "probe before read";
30+
const orders: Order[] = ["probe after read", "probe before read"];
31+
32+
const tick = async () => {
33+
for (let i = 0; i < 4; i++) {
34+
await new Promise(r => setTimeout(r));
35+
flush();
36+
}
37+
};
38+
39+
const initial = { v: 0, inner: 0, p: false };
40+
const landed = { v: 5, inner: 5, p: false };
41+
42+
function probePass(order: Order, cond: () => number, after: () => void, log: Row[]) {
43+
return createMemo(() => {
44+
let v = 0,
45+
inner: unknown,
46+
p: unknown;
47+
const probeIt = () => (p = untrack(() => isPending(() => (inner = cond()))));
48+
if (order === "probe before read") probeIt();
49+
v = cond();
50+
if (order === "probe after read") probeIt();
51+
after();
52+
const r = { v, inner, p };
53+
log.push(r);
54+
return r;
55+
});
56+
}
57+
58+
describe.each(orders)("a pass that reads the hold's flight (%s)", order => {
59+
for (const hold of [false, true])
60+
it(`lands in one frame (${hold ? "held by its own flight" : "no hold"})`, async () => {
61+
const screen: Row[] = [];
62+
const effects: Row[] = [];
63+
const log: Row[] = [];
64+
let res!: (v: number) => void;
65+
const [open, setOpen] = createSignal(0);
66+
const cond = createMemo(() => open());
67+
const a = createMemo(async () => {
68+
const v = open();
69+
if (v && hold) await new Promise<number>(r => (res = r));
70+
return v;
71+
});
72+
const pass = probePass(order, cond, () => void (hold && a()), log);
73+
createRenderEffect(pass, r => void screen.push(r));
74+
createEffect(pass, r => void effects.push(r));
75+
flush();
76+
await tick();
77+
setOpen(5);
78+
flush();
79+
if (hold) {
80+
expect(screen).toEqual([initial]);
81+
res(5);
82+
}
83+
await tick();
84+
expect(screen).toEqual([initial, landed]);
85+
expect(effects).toEqual([initial, landed]);
86+
});
87+
});
88+
89+
describe.each(["same pass", "sibling", "deep sibling"] as const)(
90+
"a later node blocks the hold again in the landing flush (%s)",
91+
where => {
92+
describe.each(orders)("%s", order => {
93+
it("keeps the old frame, reads the committed value while held, and lands once", async () => {
94+
const screen: Row[] = [];
95+
const effects: Row[] = [];
96+
const log: Row[] = [];
97+
let resA!: (v: number) => void, resB!: (v: number) => void;
98+
const [open, setOpen] = createSignal(0);
99+
const cond = createMemo(() => open());
100+
const a = createMemo(async () => {
101+
const v = open();
102+
if (v) await new Promise<number>(r => (resA = r));
103+
return v;
104+
});
105+
// `deep sibling`: computed after the pass in the landing flush, so
106+
// the pass's probe ran while the hold was not yet blocked again.
107+
const m1 = createMemo(() => a());
108+
const m2 = createMemo(() => m1());
109+
const m3 = createMemo(() => m2());
110+
const b = createMemo(async () => {
111+
const v = where === "deep sibling" ? m3() : a();
112+
if (v) await new Promise<number>(r => (resB = r));
113+
return v;
114+
});
115+
const pass = probePass(
116+
order,
117+
cond,
118+
() => {
119+
a();
120+
if (where === "same pass") b();
121+
},
122+
log
123+
);
124+
createRenderEffect(pass, r => void screen.push(r));
125+
createEffect(pass, r => void effects.push(r));
126+
if (where !== "same pass") createRenderEffect(b, () => {});
127+
flush();
128+
await tick();
129+
expect(screen).toEqual([initial]);
130+
log.length = 0;
131+
setOpen(5);
132+
flush();
133+
resA(5);
134+
await tick();
135+
// `b`'s new flight holds the change: nothing shown, and the held
136+
// pass's last run read the committed value (D-23: final, `p: false`).
137+
expect(screen).toEqual([initial]);
138+
expect(effects).toEqual([initial]);
139+
if (log.length) expect(log.at(-1)).toEqual({ v: 5, inner: 0, p: false });
140+
resB(5);
141+
await tick();
142+
expect(screen).toEqual([initial, landed]);
143+
expect(effects).toEqual([initial, landed]);
144+
});
145+
});
146+
}
147+
);

0 commit comments

Comments
 (0)