Skip to content

Commit 92e4421

Browse files
committed
fix(signals): an isPending probe wakes a dormant memo outside its window (#4366)
An unowned memo left with no reader goes dormant; the next read wakes it with a recompute. read() ran that wake before dispatching to the verdict window, so when the read was an isPending()/latest() probe the memo's pass read its sources through the probe (committed values): NaN after an async source landed, a stale value after a source recovered from an error. The window now wakes the memo itself with the window closed, as it already did for a pull (A31). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2
1 parent 5f60713 commit 92e4421

8 files changed

Lines changed: 203 additions & 16 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+
An unowned memo with an `isPending()` reader recomputes correctly (#4366). A module-level memo left with no reader goes dormant, and the next read wakes it with a recompute. When that read was an `isPending(m)` probe, the wake ran inside the probe's window, so the memo read its sources as the probe does, at their committed values: after an async source landed it derived from the old value (`undefined + 1`, so `NaN`), and after a source recovered from an error it kept the value from before the error. The wake is the memo's own pass (A31), the same as a pull, so it now runs outside the window.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ Status legend: **live** stated and standing · **ruled** carries an explicit rul
7575
| A28 | ruled, mechanism landed | `docs/SPEC-ASYNC-SEMANTICS.md:95` | constants.ts×1 core.ts×12 lanes.ts×2 scheduler.ts×3 types.ts×1 verdict.ts×2 store.ts×5 | continuation-sibling-reader-4146.test.ts×1 createOptimistic.test.ts×5 fuzz-findings-l2.test.ts×6 held-derivation-not-a-proposal-3612.test.ts×1 issue-3800-repro.test.ts×1 latest-held-till-flush.test.ts×1 posture-store-parity.test.ts×5 question-scoped-pending.test.ts×3 snapshot-derived-store-rows.test.ts×1 createOptimisticStore.test.ts×10 optimistic-draft-visibility-3665.test.ts×5 optimistic-list-mutation-matrix.harness.ts×1 optimistic-list-mutation-matrix.test.ts×2 shallow.test.ts×1 woken-transaction-adopts-staged-bump.test.ts×1 treeshake.test.ts×2 verdict-contract.test.ts×1 visibility-oracle-store.states.ts×8 visibility-oracle.states.ts×8 | [ruled, mechanism landed 2026-09-15] A write becomes visible at flush — to every channel — (**ruled 2026-09-08**; supersedes the #2922 mid-tick pull) **A write becomes visible at flush — to every chan… |
7676
| A29 | amended | `docs/SPEC-ASYNC-SEMANTICS.md:119` | boundaries.ts×1 action.ts×1 constants.ts×1 core.ts×14 effect.ts×1 lanes.ts×1 scheduler.ts×4 signals.ts×1 store.ts×1 | adoption-unchanged-key-read-3706.test.ts×9 body-end-supersession-visibility.test.ts×1 born-held.test.ts×3 boundary-not-born-held-3540.test.ts×4 createProjection.draft-lifetime-3585.test.ts×1 direct-commit-readers-posture.test.ts×1 fuzz-findings-l2.test.ts×6 held-branch-verdict-reader-4010.test.ts×1 held-conditional-memo.test.ts×1 held-frame-dependencies.test.ts×2 held-truth-lane-only.test.ts×3 l2-contract.test.ts×1 latest-held-till-flush.test.ts×2 loading-fallback-in-flush-3540.test.ts×6 loading-on-frame-following-3540.test.ts×1 mount-over-foreign-hold-3761.test.ts×1 optimistic-mount-nested-memo-3835.test.ts×1 optimistic-read-lane-not-transaction-3698.test.ts×3 posture-born-held-and-observation.test.ts×1 posture-store-parity.test.ts×6 derived-presence-async-3726.test.ts×3 optimistic-untracked-reads-f3-f5.test.ts×1 store-unchanged-read-independent-write-3688.test.ts×1 tick-scoped-pass-transaction.test.ts×2 treeshake.test.ts×3 verdict-mount-first-pass-3851.test.ts×2 verdict-mount-loading-flush-loop.test.ts×2 visibility-oracle-store.states.ts×5 visibility-oracle-store.test.ts×1 visibility-oracle.states.ts×9 visibility-oracle.test.ts×1 write-proposals-3494.test.ts×1 | [ruled, amended in place 2026-09-13 (#3408)] A tracked read served a live transaction's staged value enters that transaction — A tracked computation served a node's staged `_pendingValue` — a value a … |
7777
| A30 | ruled | `docs/SPEC-ASYNC-SEMANTICS.md:257` | async.ts×3 attribution.ts×1 constants.ts×1 core.ts×1 effect.ts×1 lanes.ts×1 scheduler.ts×5 projection.ts×1 | async-landing-deps-3461.test.ts×3 fuzz-findings-l2.test.ts×3 held-conditional-effect.test.ts×1 held-conditional-memo.test.ts×1 held-frame-dependencies.test.ts×2 ispending-in-boundary-on-3528.test.ts×1 lane-frame-deferred-run-3662.test.ts×1 lane-frame-held-lane-3662.test.ts×1 posture-born-held-and-observation.test.ts×1 projection-peek-loop-4342.test.ts×1 treeshake.test.ts×2 write-proposals-3494.test.ts×2 zombie-rerun-after-commit-3546.test.ts×2 | [ruled 2026-09-13 (#3410)] A memo's dependencies are the committed frame's until the frame is replaced — A pass that _staged_ its value has not replaced the committed frame, so the committed value sti… |
78-
| A31 | live | `docs/SPEC-ASYNC-SEMANTICS.md:131` | boundaries.ts×1 core.ts×1 lanes.ts×1 verdict.ts×2 | fuzz-findings-l2.test.ts×6 ispending-combined-atomic-3442.test.ts×1 | [live 2026-09-14 (#3442)] A memo computes under its own lane posture, never its puller's — A memo's value is one shared slot every reader sees, so its pass runs under the lane posture the memo itself … |
78+
| A31 | live | `docs/SPEC-ASYNC-SEMANTICS.md:131` | boundaries.ts×1 core.ts×1 lanes.ts×1 verdict.ts×2 | fuzz-findings-l2.test.ts×6 ispending-combined-atomic-3442.test.ts×1 unowned-memo-ispending-reader-4366.test.ts×1 | [live 2026-09-14 (#3442)] A memo computes under its own lane posture, never its puller's — A memo's value is one shared slot every reader sees, so its pass runs under the lane posture the memo itself … |
7979
| A32 | ruled | `docs/SPEC-ASYNC-SEMANTICS.md:139` | core.ts×4 lanes.ts×1 store.ts×1 | visibility-oracle-store.states.ts×8 visibility-oracle-store.test.ts×1 visibility-oracle.states.ts×9 visibility-oracle.test.ts×1 | [ruled 2026-09-14] Children-forbidden readers see the frame, not the graph — `createTrackedEffect` and `onSettled` callbacks are effect-phase code that runs after the frame is decided. They read the f… |
8080
| A33 | ruled | `docs/SPEC-ASYNC-SEMANTICS.md:273` | boundaries.ts×1 scheduler.ts×2 | async-chain-supersession.test.ts×2 boundary-not-born-held-3540.test.ts×2 create-deferred-3710.test.ts×1 fuzz-findings-l2.test.ts×4 ispending-in-boundary-on-3528.test.ts×2 loading-reset-collects-forwarded-3459.test.ts×3 | [ruled 2026-09-12 (#3375)] A fallback-caught flight holds no transaction; a Loading reset moves the hold onto the boundary — A `<Loading>` boundary showing its fallback is the display of everything un… |
8181
| A34 | ruled | `docs/SPEC-ASYNC-SEMANTICS.md:283` | constants.ts×1 core.ts×6 lanes.ts×2 scheduler.ts×2 store.ts×6 | a34-writes-then-derivations.test.ts×2 continuation-sibling-reader-4146.test.ts×1 createMemo.test.ts×1 derived-write-then-derivation-3733.test.ts×1 finalize-reentry.test.ts×2 fuzz-findings-l2.test.ts×5 held-derivation-not-a-proposal-3612.test.ts×6 optimistic-guess-over-held-slot.test.ts×2 optimistic-list-mutation-matrix.test.ts×1 unchanged-presence-no-hold-3743.test.ts×3 woken-transaction-adopts-staged-bump.test.ts×1 transition-corpse-revival.test.ts×1 treeshake.test.ts×2 visibility-oracle.states.ts×2 write-proposals-3494.test.ts×5 | [ruled 2026-09-16 (#3494)] A write is a proposal: one on a held node entangles its tick; one that nets to the committed value is none — A write proposes a value for a node. **Held, both are suggestion… |

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ A tracked computation served a node's staged `_pendingValue` — a value a live
131131
### A31. A memo computes under its own lane posture, never its puller's
132132

133133
**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"
134-
**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)
134+
**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); `tests/unowned-memo-ispending-reader-4366.test.ts` (#4366: a dormant unowned memo woken by an `isPending` probe recomputes outside the probe's window)
135135
**Mechanism (L2, 2026-10-04):** `recompute`'s head sets `passLane` from the **node's own** lane membership — a derived lane node (`CONFIG_OVERRIDE` without `CONFIG_GUESS`) or a member the lane's re-staging dirtied (`REACTIVE_LANE_DIRTY`) runs as the lane's; a written guess's own pass is its truth arriving; anything else runs with no lane — and restores the previous `passLane` after. A memo pulled by lane work (`pullComputed`) recomputes under _its_ posture, not the puller's; the puller's read of the result then decides whether the puller's pass enters the lane (`laneRead`).
136136

137137
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).

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1848,12 +1848,13 @@ export function read<T>(el: Signal<T> | Computed<T>): T {
18481848
// undefined and mask to 0 on every site below.)
18491849
const owner = el as Computed<any>;
18501850

1851-
if (typeof computed._fn === "function") prepareComputed(el as Computed<unknown>, false);
1852-
18531851
// The verdict windows (`latest`, `isPending`; verdict.ts): one cold path,
1854-
// off this one, present only while a window is open.
1852+
// off this one, present only while a window is open. It wakes a lazy or
1853+
// dormant memo itself, outside the window (#4366).
18551854
if (verdict !== null) return verdict(el, c as Computed<any> | null) as T;
18561855

1856+
if (typeof computed._fn === "function") prepareComputed(el as Computed<unknown>, false);
1857+
18571858
if (
18581859
!computed._fn &&
18591860
el._x?._snapshotValue === undefined &&

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import {
3737
creatorPass,
3838
joinPass,
3939
markLateLinker,
40+
prepareComputed,
4041
pullComputed,
4142
setVerdict,
4243
spectating,
@@ -373,17 +374,19 @@ function verdictValue(el: Signal<any> | Computed<any>, c: Computed<any> | null):
373374
const owner = el as Computed<any>;
374375
const owned = !!c && !(c._config & CONFIG_CHILDREN_FORBIDDEN);
375376
const tracked = owned && tracking;
377+
// A31: the pulled memo's pass is its own, not the probe's — it reads
378+
// outside the window, and the probe's read below answers for what the pass
379+
// produced. So is a lazy or dormant memo's wake (an unowned memo with no
380+
// reader left, #4366): woken inside the window, it read its sources as the
381+
// probe does, the committed value under a landing. (A signal has no
382+
// `_flags`: the wake is a no-op for it.)
383+
setVerdict(null);
384+
prepareComputed(owner, false);
376385
if (c && tracking) {
377386
link(el, c);
378-
if ((el as any)._fn) {
379-
// A31: the pulled memo's pass is its own, not the probe's — it reads
380-
// outside the window, and the probe's read below answers for what
381-
// the pass produced.
382-
setVerdict(null);
383-
pullComputed(owner, c);
384-
setVerdict(verdictValue);
385-
}
387+
if ((el as any)._fn) pullComputed(owner, c);
386388
}
389+
setVerdict(verdictValue);
387390
// A live `affects()` mark on the node or a dependency (affects.ts): not
388391
// final by declaration — the value itself is read as below. The verdict is
389392
// display-ahead like any: in a transaction's flush (the declaring action's
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
// #4366: an unowned memo left with no reader goes dormant (its last reader
2+
// was torn down, or it settled with nothing subscribed). The next read wakes
3+
// it with a recompute. When that read is an `isPending(m1)` probe, the wake
4+
// is the memo's own pass (A31), not the probe's: it must read its sources as
5+
// any pass does. Woken inside the probe window, it read them as the probe
6+
// does, the committed value, so `m1` derived from the screen under a
7+
// landing (`undefined + 1`) or from the value before an error recovered.
8+
import { expect, it } from "vitest";
9+
import {
10+
createErrorBoundary,
11+
createLoadingBoundary,
12+
createMemo,
13+
createRenderEffect,
14+
createRoot,
15+
createSignal,
16+
flush,
17+
isPending,
18+
latest
19+
} from "../src/index.js";
20+
21+
const tick = async () => {
22+
for (let i = 0; i < 8; i++) await Promise.resolve();
23+
flush();
24+
};
25+
26+
// Show: a condition memo, and a branch created when it turns truthy.
27+
function show(when: () => unknown, content: () => () => string, fallback = "[F]") {
28+
const cond = createMemo(() => !!when());
29+
const branch = createMemo(() => (cond() ? content() : null));
30+
return () => branch()?.() ?? fallback;
31+
}
32+
33+
function mount(view: () => unknown) {
34+
let out: unknown;
35+
createRoot(() =>
36+
createRenderEffect(
37+
() => {
38+
const v = view();
39+
return typeof v === "function" ? v() : v;
40+
},
41+
v => {
42+
out = v;
43+
}
44+
)
45+
);
46+
return () => out;
47+
}
48+
49+
for (const probe of [true, false]) {
50+
const text = (m1: () => number) => () =>
51+
createMemo(() => `${probe ? String(isPending(m1)) + " " : ""}${String(m1())}`);
52+
53+
it(`an unowned memo over an async source lands its value${probe ? " with an isPending reader" : ""} (#4366)`, async () => {
54+
let release!: (v: number) => void;
55+
const m0 = createMemo(() => new Promise<number>(r => (release = r)));
56+
const m1 = createMemo(() => m0() + 1);
57+
const out = mount(() =>
58+
createLoadingBoundary(
59+
() => show(m0, text(m1)),
60+
() => "[L]"
61+
)
62+
);
63+
flush();
64+
expect(out()).toBe("[L]");
65+
release(2);
66+
await tick();
67+
expect(out()).toBe(probe ? "false 3" : "3");
68+
});
69+
70+
it(`an unowned memo re-derives after its source recovers from an error${probe ? " with an isPending reader" : ""} (#4366)`, () => {
71+
const [s0, set0] = createSignal(3);
72+
const [s1, set1] = createSignal(3);
73+
const m0 = createMemo(() => {
74+
const v = s1() + s0() + 1;
75+
if (v % 4 === 2) throw new Error("m0:" + v);
76+
return v;
77+
});
78+
const m1 = createMemo(() => m0() + 1);
79+
const out = mount(() =>
80+
createErrorBoundary(
81+
() => show(() => latest(m0), text(m1)),
82+
e => `[E ${(e() as Error)?.message}]`
83+
)
84+
);
85+
flush();
86+
expect(out()).toBe(probe ? "false 8" : "8");
87+
set1(2);
88+
flush();
89+
expect(out()).toBe("[E m0:6]");
90+
set0(2);
91+
flush();
92+
expect(out()).toBe(probe ? "false 6" : "6");
93+
});
94+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/**
2+
* @jsxImportSource @solidjs/web
3+
* @vitest-environment jsdom
4+
*/
5+
// #4366: module-level (unowned) memos, a reader that probes `isPending(m1)`
6+
// before reading `m1()`. The probe must not cost `m1` its recompute.
7+
import { expect, test } from "vitest";
8+
import {
9+
Errored,
10+
Loading,
11+
Show,
12+
createMemo,
13+
createSignal,
14+
flush,
15+
isPending,
16+
latest
17+
} from "solid-js";
18+
import { render } from "../src/index.js";
19+
20+
const tick = async () => {
21+
for (let i = 0; i < 8; i++) await Promise.resolve();
22+
flush();
23+
};
24+
25+
test("unowned memo over an async source lands its value with an isPending reader (#4366)", async () => {
26+
let release!: (v: number) => void;
27+
const m0 = createMemo(() => new Promise<number>(r => (release = r)));
28+
const m1 = createMemo(() => m0() + 1);
29+
const el = document.createElement("div");
30+
const dispose = render(
31+
() => (
32+
<Loading fallback="[L]">
33+
<Show when={m0()}>
34+
<span>
35+
{String(isPending(m1))} {String(m1())}
36+
</span>
37+
</Show>
38+
</Loading>
39+
),
40+
el
41+
);
42+
flush();
43+
expect(el.textContent).toBe("[L]");
44+
release(2);
45+
await tick();
46+
expect(el.textContent).toBe("false 3");
47+
dispose();
48+
});
49+
50+
test("unowned memo re-derives after its source recovers from an error, with an isPending reader (#4366)", () => {
51+
const [s0, set0] = createSignal(3);
52+
const [s1, set1] = createSignal(3);
53+
const m0 = createMemo(() => {
54+
const v = s1() + s0() + 1;
55+
if (v % 4 === 2) throw new Error("m0:" + v);
56+
return v;
57+
});
58+
const m1 = createMemo(() => m0() + 1);
59+
const el = document.createElement("div");
60+
const dispose = render(
61+
() => (
62+
<Errored fallback={(e: any) => `[E ${e()?.message}]`}>
63+
<Show when={latest(m0)} fallback="[F]">
64+
<span>
65+
{String(isPending(m1))} {String(m1())}
66+
</span>
67+
</Show>
68+
</Errored>
69+
),
70+
el
71+
);
72+
flush();
73+
expect(el.textContent).toBe("false 8");
74+
set1(2);
75+
flush();
76+
expect(el.textContent).toBe("[E m0:6]");
77+
set0(2);
78+
flush();
79+
expect(el.textContent).toBe("false 6");
80+
dispose();
81+
});

0 commit comments

Comments
 (0)