Skip to content

Commit a887ad0

Browse files
committed
fix(signals): a lane's pending leaf re-runs as the lane's work (#3766)
A render effect that read a memo over isPending(source) and then went pending on a second async memo became the verdict lane's work. The landing re-ran it outside the lane, where the uninitialized probe memo had nothing to show, so it threw with no source to wake it and the lane stayed blocked on its own reader.
1 parent 6f77b1b commit a887ad0

6 files changed

Lines changed: 238 additions & 5 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 render effect that reads a memo over `isPending(source)` and then a second async memo mounts once both first flights land (#3766). The effect went pending as work of the verdict lane, and the landing re-ran it outside the lane, where the uninitialized probe memo had nothing to show: it threw with no source to wake it, and the lane stayed blocked on its own reader. A leaf that ends a pass pending as a lane's work now runs its next pass as that lane's.

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import {
4646
REACTIVE_FRAME_READ,
4747
REACTIVE_IN_HEAP,
4848
REACTIVE_JOINED,
49+
REACTIVE_LANE_DIRTY,
4950
REACTIVE_LANE_READ,
5051
REACTIVE_PROBE_UNANSWERED,
5152
REACTIVE_SCREEN_READ,
@@ -325,6 +326,8 @@ export function laneStage(
325326
// leaves the guess.
326327
if (!errored) el._config &= ~CONFIG_GUESS;
327328
}
329+
// A leaf has no lane value to seat it: its next pass is the lane's (#3766).
330+
else if (errored) el._flags |= REACTIVE_LANE_DIRTY;
328331
list(el, l);
329332
return true;
330333
}
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
import {
2+
createMemo,
3+
createRenderEffect,
4+
createRoot,
5+
createSignal,
6+
flush,
7+
isPending
8+
} from "../src/index.js";
9+
10+
const delay = <T>(value: T, ms: number): Promise<T> =>
11+
new Promise(resolve => setTimeout(() => resolve(value), ms));
12+
const wait = (ms: number) => new Promise(r => setTimeout(r, ms));
13+
14+
describe("#3766 memo over isPending read beside a second async memo", () => {
15+
for (const variant of ["memo-first", "gate-first", "inline"] as const) {
16+
it(`initial mount: ${variant}`, async () => {
17+
const seen: string[] = [];
18+
createRoot(() => {
19+
const source = createMemo(() => delay(10, 10));
20+
const gate = createMemo(() => delay(100, 20));
21+
const pending = createMemo(() => isPending(source));
22+
createRenderEffect(
23+
() =>
24+
variant === "memo-first"
25+
? `${pending()} | ${gate()}`
26+
: variant === "gate-first"
27+
? `${gate()} | ${pending()}`
28+
: `${isPending(source)} | ${gate()}`,
29+
v => {
30+
seen.push(v);
31+
}
32+
);
33+
});
34+
flush();
35+
await wait(100);
36+
flush();
37+
expect(seen).toEqual([variant === "gate-first" ? "100 | false" : "false | 100"]);
38+
});
39+
}
40+
41+
it("initial mount: a second reader still waiting holds the first", async () => {
42+
const seen: string[] = [];
43+
createRoot(() => {
44+
const source = createMemo(() => delay(10, 10));
45+
const gate = createMemo(() => delay(100, 20));
46+
const late = createMemo(() => delay(200, 40));
47+
const pending = createMemo(() => isPending(source));
48+
createRenderEffect(
49+
() => `a ${pending()} | ${gate()}`,
50+
v => {
51+
seen.push(v);
52+
}
53+
);
54+
createRenderEffect(
55+
() => `b ${pending()} | ${late()}`,
56+
v => {
57+
seen.push(v);
58+
}
59+
);
60+
});
61+
flush();
62+
await wait(100);
63+
flush();
64+
expect(seen).toEqual(["a false | 100", "b false | 200"]);
65+
});
66+
67+
it("initial mount: a plain write while the reader waits on gate", async () => {
68+
const seen: string[] = [];
69+
let setLabel!: (v: string) => void;
70+
createRoot(() => {
71+
const [label, set] = createSignal("a");
72+
setLabel = set;
73+
const source = createMemo(() => delay(10, 10));
74+
const gate = createMemo(() => delay(100, 60));
75+
const pending = createMemo(() => isPending(source));
76+
createRenderEffect(
77+
() => `${label()} ${pending()} | ${gate()}`,
78+
v => {
79+
seen.push(v);
80+
}
81+
);
82+
});
83+
flush();
84+
await wait(30);
85+
setLabel("b");
86+
flush();
87+
expect(seen).toEqual([]);
88+
await wait(100);
89+
flush();
90+
expect(seen).toEqual(["b false | 100"]);
91+
});
92+
93+
it("update: two readers of gate agree", async () => {
94+
let a = "";
95+
let b = "";
96+
let setCount!: (v: number) => void;
97+
createRoot(() => {
98+
const [count, set] = createSignal(1);
99+
setCount = set;
100+
const source = createMemo(() => delay(count(), 10));
101+
const gate = createMemo(() => delay(count() * 100, 20));
102+
const pending = createMemo(() => isPending(source));
103+
const slow = createMemo(() => {
104+
const value = pending();
105+
return delay(value, value ? 30 : 300);
106+
});
107+
createRenderEffect(
108+
() => `${pending()} | ${gate()}`,
109+
v => {
110+
a = v;
111+
}
112+
);
113+
createRenderEffect(
114+
() => `${slow()} | ${gate()}`,
115+
v => {
116+
b = v;
117+
}
118+
);
119+
});
120+
flush();
121+
await wait(400);
122+
flush();
123+
expect([a, b]).toEqual(["false | 100", "false | 100"]);
124+
setCount(2);
125+
flush();
126+
for (let i = 0; i < 50; i++) {
127+
await wait(10);
128+
expect(a.split(" | ")[1]).toBe(b.split(" | ")[1]);
129+
}
130+
expect([a, b]).toEqual(["false | 200", "false | 200"]);
131+
});
132+
});
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/**
2+
* @jsxImportSource @solidjs/web
3+
* @vitest-environment jsdom
4+
*/
5+
6+
import { describe, expect, test } from "vitest";
7+
import { createMemo, createSignal, flush, isPending } from "solid-js";
8+
import { render } from "@solidjs/web";
9+
10+
const delay = <T,>(value: T, ms: number): Promise<T> =>
11+
new Promise(resolve => setTimeout(() => resolve(value), ms));
12+
const wait = (ms: number) => new Promise(r => setTimeout(r, ms));
13+
14+
// Port of https://s.olid.uk/id/lg40u1dpQkC5mIUmTn_Grw, delays divided by 10.
15+
describe("#3766 memo over isPending read beside a second async memo", () => {
16+
test("mounts once both first flights land", async () => {
17+
const div = document.createElement("div");
18+
const dispose = render(() => {
19+
const source = createMemo(() => delay(10, 10));
20+
const gate = createMemo(() => delay(100, 20));
21+
const pending = createMemo(() => isPending(source));
22+
return <p>{`${pending()} | ${gate()}`}</p>;
23+
}, div);
24+
await wait(100);
25+
flush();
26+
expect(div.querySelector("p")?.textContent).toBe("false | 100");
27+
dispose();
28+
});
29+
30+
test("two readers of gate never disagree across an update", async () => {
31+
const div = document.createElement("div");
32+
let setCount!: (v: number) => void;
33+
const dispose = render(() => {
34+
const [count, set] = createSignal(1);
35+
setCount = set;
36+
const source = createMemo(() => delay(count(), 10));
37+
const gate = createMemo(() => delay(count() * 100, 20));
38+
const pending = createMemo(() => isPending(source));
39+
const slow = createMemo(() => {
40+
const value = pending();
41+
return delay(value, value ? 30 : 300);
42+
});
43+
return (
44+
<>
45+
<p id="status">{`${pending()} | ${gate()}`}</p>
46+
<p id="slow">{`${slow()} | ${gate()}`}</p>
47+
</>
48+
);
49+
}, div);
50+
const rows = () => Array.from(div.querySelectorAll("p")).map(p => p.textContent!.split(" | "));
51+
await wait(400);
52+
flush();
53+
expect(rows()).toEqual([
54+
["false", "100"],
55+
["false", "100"]
56+
]);
57+
setCount(2);
58+
flush();
59+
for (let i = 0; i < 50; i++) {
60+
await wait(10);
61+
const [a, b] = rows();
62+
expect(a[1]).toBe(b[1]);
63+
}
64+
expect(rows()).toEqual([
65+
["false", "200"],
66+
["false", "200"]
67+
]);
68+
dispose();
69+
});
70+
});

‎scripts/size/floor-caps.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"signals: core floor (createSignal/Memo/Effect/Root/flush)": "7.33 KB",
33
"app: render + one signal (the simple-app floor)": "9.83 KB",
44
"app: hydrating (no stores) with Show/For/Loading/Errored/lazy": "17.66 KB",
5-
"page: base server components (hydrating + dynamic + frames + sf reference)": "44.78 KB",
6-
"page: live server components (base + live/GET + action + isPending/latest)": "48.45 KB",
5+
"page: base server components (hydrating + dynamic + frames + sf reference)": "44.80 KB",
6+
"page: live server components (base + live/GET + action + isPending/latest)": "48.50 KB",
77
"server: floor (getRequestEvent + isServer)": "1.34 KB",
88
"server: renderToString (the server-render floor)": "20.42 KB"
99
}

‎scripts/size/scenarios.js‎

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,7 +1097,11 @@ module.exports = [
10971097
// Lowered (#3774, 2026-10-04): 12.16 -> 9.45 KB, measured at 9.44 KB by CI
10981098
// at 22c3d3e14 — the hold model (L2): the signals core rebuilt from its
10991099
// rulings. Lowering is the ratchet; raise only with a Size-Exception.
1100-
limit: "9.45 KB",
1100+
// Size-Exception (#3766, 2026-10-05): 9.45 -> 9.46 KB, measured at
1101+
// 9,452 B against `next` @ 6f77b1bd9's 9,446 (+6 B; +14 B minified).
1102+
// A lane's pending leaf re-runs as the lane's work: one flag write in
1103+
// `laneStage` (lanes.ts). Not accepted by the maintainer yet.
1104+
limit: "9.46 KB",
11011105
alias
11021106
},
11031107
{
@@ -2215,7 +2219,12 @@ module.exports = [
22152219
// Lowered (#3774, 2026-10-04): 14.94 -> 12.82 KB, measured at 12.81 KB by CI
22162220
// at 22c3d3e14 — the hold model (L2): the signals core rebuilt from its
22172221
// rulings. Lowering is the ratchet; raise only with a Size-Exception.
2218-
limit: "12.82 KB",
2222+
// Size-Exception (#3766, 2026-10-05): 12.82 -> 12.83 KB, measured at
2223+
// 12,826 B against `next` @ 6f77b1bd9's 12,807 (+19 B; +0 B minified).
2224+
// No byte of this bundle changed length: the same lanes.ts edit shifts
2225+
// the property mangle order, and the growth is brotli layout. Not
2226+
// accepted by the maintainer yet.
2227+
limit: "12.83 KB",
22192228
alias
22202229
},
22212230
{
@@ -2479,7 +2488,12 @@ module.exports = [
24792488
// Lowered (#3774, 2026-10-04): 16.48 -> 14.39 KB, measured at 14.38 KB by CI
24802489
// at 22c3d3e14 — the hold model (L2): the signals core rebuilt from its
24812490
// rulings. Lowering is the ratchet; raise only with a Size-Exception.
2482-
limit: "14.39 KB",
2491+
// Size-Exception (#3766, 2026-10-05): 14.39 -> 14.40 KB, measured at
2492+
// 14,396 B against `next` @ 6f77b1bd9's 14,389 (+7 B; +0 B minified).
2493+
// No byte of this bundle changed length: the same lanes.ts edit shifts
2494+
// the property mangle order, and the growth is brotli layout. Not
2495+
// accepted by the maintainer yet.
2496+
limit: "14.40 KB",
24832497
alias: observeAlias
24842498
},
24852499
{
@@ -3223,6 +3237,11 @@ module.exports = [
32233237
// solid, web and the sf client is attribution drift. Accepted by the
32243238
// maintainer (2026-10-04). The cap is frozen again at 44.78 KB (head +
32253239
// 10 B).
3240+
// Size-Exception (#3766, 2026-10-05): 44.78 -> 44.80 KB, measured at
3241+
// 44,792 B against `next` @ 6f77b1bd9's 44,762 (+30 B; +0 B minified).
3242+
// No byte of this bundle changed length: the same lanes.ts edit shifts
3243+
// the property mangle order, and the growth is brotli layout. Not
3244+
// accepted by the maintainer yet.
32263245
limit: floorCaps["page: base server components (hydrating + dynamic + frames + sf reference)"],
32273246
alias: pageAlias
32283247
},
@@ -3315,6 +3334,10 @@ module.exports = [
33153334
// cap; +2,265 B minified, frames client +2,044). The same staging bytes
33163335
// as the base page. Accepted by the maintainer (2026-10-04). The cap is
33173336
// frozen again at 48.45 KB (head + 10 B).
3337+
// Size-Exception (#3766, 2026-10-05): 48.45 -> 48.50 KB, measured at
3338+
// 48,493 B against `next` @ 6f77b1bd9's 48,436 (+57 B; +18 B minified).
3339+
// A lane's pending leaf re-runs as the lane's work: one flag write in
3340+
// `laneStage` (lanes.ts). Not accepted by the maintainer yet.
33183341
limit: floorCaps["page: live server components (base + live/GET + action + isPending/latest)"],
33193342
alias: pageAlias
33203343
},

0 commit comments

Comments
 (0)