Skip to content

Commit a5d8eae

Browse files
brenelzBrenley Dueckclaude
authored
fix(signals): a memo computes under its own lane posture, never its puller's (#3442) (#3445)
A combined `isPending(() => [fast(), copy()])` over two async memos, with `copy` a sync memo wrapping the slow one, released the hold as soon as the fast flight landed: `Fast: 1` beside `Slow: 0` with `Pending: false`, then `Slow: 1` a second later. The probe effect carries the companion lane of the pending signals it reads, and its pull of `copy` ran under that lane — where a pending node on no lane serves its committed value instead of throwing — so `copy` published a stale settled `0`, dropped its pending status, and its readers stopped holding `slow`: the transaction settled on `fast`'s landing with `slow` still in flight. A plain getter in place of `copy` never had the gap (the probe read `slow` directly, and a probe observes without deriving). recompute now clears the ambient lane for a non-effect node before the lane branches re-establish the posture the memo itself owns (OPT-dirty, or adopted through its deps). A memo's value is one shared slot every reader sees, so the puller's lane carve-outs must not shape it; effects keep the ambient lane, since their runs are the lane's own view. Both values now reveal together, with the probe reporting pending until they do. Spec rule A31. +12 B core floor (noted, no bump); two brotli caps ratcheted 0.05 KB with measurements against `next`. Rules index regenerated, changeset included. Co-authored-by: Brenley Dueck <[email protected]> Co-authored-by: Claude Fable 5.1 <[email protected]>
1 parent 63560a1 commit a5d8eae

8 files changed

Lines changed: 248 additions & 37 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@solidjs/signals": patch
3+
---
4+
5+
A memo computes under its own lane posture, never its puller's (#3442).
6+
7+
A combined `isPending(() => [fast(), copy()])` over two async memos, with `copy` a sync memo wrapping the slow one, released the hold as soon as the fast flight landed: `Fast: 1` beside `Slow: 0` with `Pending: false`, then `Slow: 1` a second later. The probe effect carries the companion lane of the pending signals it reads, and its pull of `copy` ran under that lane — where a pending node on no lane serves its committed value instead of throwing — so `copy` published a stale settled value, dropped its pending status, and its readers stopped holding the slow flight. `recompute` now runs a memo plain unless the memo itself is lane-dirty or adopts a lane through its dependencies; effects keep the ambient lane, since their runs are the lane's own view. Both values now reveal together, with the probe reporting pending until they do.

‎packages/signals/docs/RULES-INDEX.md‎

Lines changed: 38 additions & 37 deletions
Large diffs are not rendered by default.

‎packages/signals/docs/SPEC-ASYNC-SEMANTICS.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ Sync derivations of transition-held sources are visible through `latest()`/`isPe
7272

7373
A tracked computation served a node's staged `_pendingValue` — a value a live transaction holds — derives from that transaction's world, so its pass enters the transaction and its result is held with it. This is the read twin of the two entries that already existed, `setSignal` on a stamped node and `recompute` of a stamped node, and closes the gap between them: a conditional memo whose branch flipped mainline (`panel = show() ? count() : "hidden"`) started reading a held `count`, was served the staged value (non-stale readers keep speculation), and published a value derived from the held world into the mainline frame — `Panel: 1` beside `Count: 0`. A stale (render) reader is unchanged: the reveal carve-out (A15) serves it the committed value with no entanglement, which is why the same shape written as a plain JSX expression already showed a coherent frame. A probe (`isPending(() => x())`) observes, it does not derive, so it enters nothing (A23).
7474

75+
### A31. A memo computes under its own lane posture, never its puller's
76+
77+
**Status:** **live** 2026-09-14 (#3442) — stated by the fix; the lane-side twin of A29's "a value derived from the held world is that transaction's work"
78+
**Pinned by:** `tests/ispending-combined-atomic-3442.test.ts` (#3442: a combined `isPending` over two async memos, one wrapped by a sync memo, holds both until both land)
79+
**Mechanism (index, 2026-09-14):** `recompute` clears `currentOptimisticLane` for a non-effect node before the lane branches (`recomputeLane(el, true)` for an OPT-dirty node, `recomputeLane(el, false)` adoption through deps) re-establish the memo's own posture; effects keep the ambient lane.
80+
81+
A memo's value is one shared slot every reader sees, so its pass runs under the lane posture the memo itself owns — OPT-dirty, or adopted through its dependencies — and never under the lane of whichever reader happened to pull it. Lane posture changes what a read serves: under a lane, a pending node on no lane (or another lane) serves its committed value instead of throwing, and the entanglement gates serve committed values for the lane's own view. Those carve-outs are sound for the lane's effects, whose runs are that view, and unsound for a memo, whose result is cached for everyone. Before: the probe effect of `isPending(() => [fast(), copy()])` carried the companion lane of the pending signals it reads, and its pull of `copy = createMemo(() => slow())` ran under it; `copy` read the in-flight `slow` as its committed `0`, published a clean value, dropped its pending status, and its readers stopped holding `slow` — the transaction settled on `fast`'s landing with `slow` still in flight (`Fast: 1` beside `Slow: 0`, `Pending: false`). Now the pull throws `NotReady` as a plain reader would, `copy` stays pending, and the hold lasts until both flights land. A plain getter in place of `copy` never had the gap: the probe read `slow` directly, and a probe observes without deriving (A23).
82+
7583
## Verdicts — `isPending()` and `latest()`
7684

7785
### A19. `isPending(x)` ≡ the observable value is not final (three causes)

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,17 @@ export function recompute(el: Computed<any>, create: boolean = false): void {
318318
// covers creation-time computes and flushes that run inside the window.
319319
const prevLatestRead = latestReadActive;
320320
latestReadActive = false;
321+
// A memo computes under its OWN lane posture, never the puller's (A31,
322+
// #3442): its value is one shared slot every reader sees, so a pull from a
323+
// lane-carrying reader (a probe effect on its companion lane pulling a sync
324+
// memo) must not run it with that lane's read carve-outs — under a lane, a
325+
// pending node on no lane serves its committed value instead of throwing,
326+
// and the memo then published a stale "settled" value, dropped its
327+
// pending status, and stopped holding its transaction. The branches below
328+
// re-establish the posture the memo itself owns (OPT-dirty, or adopted
329+
// through its deps). Effects keep the ambient lane: their runs are the
330+
// lane's own view.
331+
if (!isEffect) currentOptimisticLane = null;
321332
// Lane posture lives with the engine: OPTIMISTIC_DIRTY is only ever set by
322333
// engine-driven paths, and _optimisticNodes is only pushed by
323334
// _optimisticWrite, so the hook is installed whenever either gate holds.
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
import { describe, expect, it } from "vitest";
2+
import {
3+
createMemo,
4+
createRenderEffect,
5+
createRoot,
6+
createSignal,
7+
flush,
8+
isPending
9+
} from "../src/index.js";
10+
11+
let now = 0;
12+
let timers: { at: number; run: () => void }[] = [];
13+
function delay<T>(ms: number, value?: T): Promise<T> {
14+
return new Promise<T>(r => timers.push({ at: now + ms, run: () => r(value as T) }));
15+
}
16+
async function settle() {
17+
for (let r = 0; r < 3; r++) {
18+
for (let i = 0; i < 10; i++) await Promise.resolve();
19+
flush();
20+
}
21+
}
22+
async function advanceTo(t: number) {
23+
while (true) {
24+
timers.sort((a, b) => a.at - b.at);
25+
const next = timers[0];
26+
if (!next || next.at > t) break;
27+
timers.shift();
28+
now = next.at;
29+
next.run();
30+
await settle();
31+
}
32+
now = t;
33+
await settle();
34+
}
35+
function frames(log: string[], when: number[]): string[] {
36+
const byTime = new Map<number, string[]>();
37+
log.forEach((v, i) => (byTime.get(when[i]) ?? byTime.set(when[i], []).get(when[i])!).push(v));
38+
return [...byTime].map(([t, vs]) => `${t}: ${vs.sort().join(" | ")}`);
39+
}
40+
function text(fn: () => string, log: string[], when: number[]) {
41+
let last: string | undefined;
42+
createRenderEffect(fn, v => {
43+
if (v !== last) {
44+
last = v;
45+
log.push(v);
46+
when.push(now);
47+
}
48+
});
49+
}
50+
51+
async function scenario(variant: "issue" | "no-pending" | "getter") {
52+
now = 0;
53+
timers = [];
54+
const log: string[] = [];
55+
const when: number[] = [];
56+
let setCount!: (v: number) => void;
57+
createRoot(() => {
58+
const [count, sC] = createSignal(0);
59+
setCount = sC;
60+
const slow = createMemo(() => delay(1000, count()));
61+
const fast = createMemo(async () => count());
62+
const copy = variant === "getter" ? () => slow() : createMemo(() => slow());
63+
if (variant !== "no-pending")
64+
text(() => `Pending: ${isPending(() => [fast(), copy()])}`, log, when);
65+
text(() => `Fast: ${fast()}`, log, when);
66+
text(() => `Slow: ${copy()}`, log, when);
67+
});
68+
flush();
69+
await settle();
70+
await advanceTo(2000);
71+
setCount(1);
72+
await settle();
73+
await advanceTo(5000);
74+
return frames(log, when);
75+
}
76+
77+
describe("combined isPending read across two async memos (#3442)", () => {
78+
// The write (2000) starts two flights; `fast` lands in a microtask and is
79+
// held with `slow` (1000ms). The probe effect carries the companion lane of
80+
// the pending signals it reads, and its pull of `copy` (a sync memo over
81+
// `slow`) used to run under that lane, where a pending node on no lane
82+
// serves its committed value instead of throwing: `copy` published a
83+
// stale settled `0`, dropped its pending status, and its readers stopped
84+
// holding `slow` — the hold released with `slow` still in flight
85+
// (`Fast: 1` beside `Slow: 0`, `Pending: false`). A memo now computes
86+
// under its own lane posture only.
87+
const atomic = [
88+
"1000: Fast: 0 | Pending: false | Slow: 0",
89+
"2000: Pending: true",
90+
"3000: Fast: 1 | Pending: false | Slow: 1"
91+
];
92+
it("A31 / #3442 isPending(() => [fast(), copy()]) with copy a sync memo holds both flights", async () => {
93+
expect(await scenario("issue")).toEqual(atomic);
94+
});
95+
it("control: copy is a plain getter", async () => {
96+
expect(await scenario("getter")).toEqual(atomic);
97+
});
98+
it("control: no pending read", async () => {
99+
expect(await scenario("no-pending")).toEqual([
100+
"1000: Fast: 0 | Slow: 0",
101+
"3000: Fast: 1 | Slow: 1"
102+
]);
103+
});
104+
});

‎packages/signals/tests/treeshake.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,9 @@ describe("pay-for-use tree-shaking (#2883)", () => {
283283
// recompute's tail keeps an effect's dependency tail while a run is owed
284284
// (`_modified`), and runEffect trims it once the run applies. Measured
285285
// at 23,353 post-change.
286+
// NOTE (2026-09-14, no bump): +12 B for memo lane posture (#3442) — one
287+
// assignment at recompute's head runs a memo plain unless it owns or
288+
// adopts a lane. Measured at 23,365 on top of #3438 (23,353 → 23,365).
286289
expect(minifiedBytes).toBeLessThan(23_400);
287290
});
288291

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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 = void,>(ms: number, value?: T) =>
11+
new Promise<T>(r => setTimeout(r, ms, value as T));
12+
13+
function snapshot(div: HTMLElement) {
14+
return Array.from(div.querySelectorAll("p"))
15+
.map(p => p.textContent)
16+
.join(" | ");
17+
}
18+
19+
// Exact port of https://s.olid.uk/id/P4Zyb5IlR_Gmz8H0dvcBUQ, 1000ms -> 100ms.
20+
function App(props: { variant: "issue" | "no-pending" | "getter" }) {
21+
const [count, setCount] = createSignal(0);
22+
const slow = createMemo(() => delay(100, count()));
23+
const fast = createMemo(async () => count());
24+
const copy = props.variant === "getter" ? () => slow() : createMemo(() => slow());
25+
return (
26+
<>
27+
<button onClick={() => setCount(1)}>Run</button>
28+
{props.variant === "no-pending" ? (
29+
<p>Pending: n/a</p>
30+
) : (
31+
<p>Pending: {String(isPending(() => [fast(), copy()]))}</p>
32+
)}
33+
<p>Fast: {fast()}</p>
34+
<p>Slow: {copy()}</p>
35+
</>
36+
);
37+
}
38+
39+
async function run(variant: "issue" | "no-pending" | "getter") {
40+
const div = document.createElement("div");
41+
document.body.appendChild(div);
42+
const dispose = render(() => <App variant={variant} />, div);
43+
await delay(150);
44+
flush();
45+
const initial = snapshot(div);
46+
div.querySelector("button")!.dispatchEvent(new MouseEvent("click", { bubbles: true }));
47+
const log: string[] = [];
48+
for (let t = 0; t <= 140; t += 20) {
49+
flush();
50+
log.push(`t=${t}: ${snapshot(div)}`);
51+
await delay(20);
52+
}
53+
process.stderr.write(`ISSUE-3442 ${variant}\ninitial: ${initial}\n${log.join("\n")}\n`);
54+
dispose();
55+
div.remove();
56+
expect(initial).toMatch(/Fast: 0 \| Slow: 0$/);
57+
expect(log.at(-1)).toMatch(/Fast: 1 \| Slow: 1$/);
58+
// Fast and Slow must never disagree in a published frame, and while they
59+
// are held the combined probe reports pending.
60+
for (const line of log) {
61+
expect(line, line).not.toMatch(/Fast: 1 \| Slow: 0/);
62+
if (variant !== "no-pending" && / Fast: 0 \| Slow: 0$/.test(line))
63+
expect(line, line).toMatch(/Pending: true/);
64+
}
65+
}
66+
67+
describe("combined isPending read across two async memos (#3442)", () => {
68+
test("issue: isPending(() => [fast(), copy()]) with copy = createMemo(() => slow())", () =>
69+
run("issue"));
70+
test("control: no pending read", () => run("no-pending"));
71+
test("control: copy is a plain getter", () => run("getter"));
72+
});

‎scripts/size/.size-limit.js‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,9 @@ module.exports = [
443443
// 15636 B against `next`'s 15580 (+56 brotli on +35 B minified — the
444444
// `_modified` gate on recompute's trim and runEffect's trim); see the
445445
// core floor note.
446+
// Memo lane posture (#3442, 2026-09-14): no bump, measured at 15624 B on
447+
// the rebase over #3438 (+12 B minified — one assignment in recompute's
448+
// head; brotli noise absorbs it; see the core floor note).
446449
limit: "15.65 KB",
447450
modifyEsbuildConfig
448451
},
@@ -749,6 +752,8 @@ module.exports = [
749752
// Effect arm of A30 (#3438, 2026-09-14): 18.85 -> 18.90 KB, measured at
750753
// 18880 B against `next`'s 18816 (+64 brotli on +35 B minified); see the
751754
// core floor note.
755+
// Memo lane posture (#3442, 2026-09-14): no bump, measured at 18854 B on
756+
// the rebase over #3438 (+12 B minified; brotli noise absorbs it).
752757
limit: "18.90 KB",
753758
modifyEsbuildConfig
754759
},

0 commit comments

Comments
 (0)