Skip to content

Commit 4a566e4

Browse files
committed
fix(signals): an untracked isPending or latest does not re-derive its reader
Both windows stamped the running computation CONFIG_VERDICT even inside untrack, and a verdict reader re-derives whenever a dependency goes pending. A library that probes pending state untracked (the router's link claim under pendingLinks) therefore made a non-keyed Show rebuild its child on every refetch of its condition. The re-derive half moves to CONFIG_VERDICT_REDERIVE, set only for tracked reads; CONFIG_VERDICT keeps the frame-reader reads, so A10's pairing holds.
1 parent 617d195 commit 4a566e4

10 files changed

Lines changed: 346 additions & 11 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 `isPending` or `latest` read inside `untrack` no longer re-derives the computation it runs in when that computation's dependencies go pending. Both windows marked the running computation a verdict reader even when untracked, so a library that probes pending state inside `untrack`, such as `@solidjs/router`'s link claim with `pendingLinks`, made a non-keyed `Show` rebuild its child each time its condition's source refetched. An untracked verdict read still makes its reader see the committed screen, so `[isPending(x), x()]` keeps A10's pairing.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Status legend: **live** stated and standing · **ruled** carries an explicit rul
5454
| A7 | amended | `docs/SPEC-ASYNC-SEMANTICS.md:163` | — | fuzz-findings-l2.test.ts×1 spec-async-semantics.test.ts×2 visibility-oracle-store.states.ts×1 visibility-oracle.states.ts×1 visibility-oracle.test.ts×1 | [ruled, amended in place] Resolved async never reads `[false, undefined]` — After an async memo resolves, `[isPending(x), latest(x)]` is `[false, resolvedValue]` — never `[false, undefined]`. **Amende… |
5555
| A8 | amended | `docs/SPEC-ASYNC-SEMANTICS.md:171` | — | createMemo.test.ts×1 visibility-oracle-store.states.ts×1 visibility-oracle.states.ts×2 | [ruled, amended in place 2026-07-07] `isPending(() => latest(x))` follows `x`'s own async only — verdicts are per-channel — (**re-ruled 2026-07-07c** — was "tracks the transition the same as `isPendin… |
5656
| A9 | amended | `docs/SPEC-ASYNC-SEMANTICS.md:179` | projection.ts×1 target.ts×1 | spec-async-semantics.test.ts×3 visibility-oracle-store.states.ts×4 visibility-oracle-store.test.ts×1 | [ruled, amended in place 2026-07-07] Store leaves behind a firewall report the firewall's new-question refetch — `isPending` on a store leaf behind a firewall reports the firewall's refetch like any a… |
57-
| A10 | ruled | `docs/SPEC-ASYNC-SEMANTICS.md:187` | core.ts×3 verdict.ts×2 | createMemo.test.ts×1 fuzz-findings-l2.test.ts×1 ispending-memo-unstamped-hold-3457.test.ts×2 latest-isPending-consistency.test.ts×3 verdict-contract.test.ts×2 | [ruled] `[isPending(x), x()]` is atomic within one scope — `[isPending(x), x()]` read in one scope is atomic: a reader that observed the fresh value must not see `pending === true` for it. |
57+
| A10 | ruled | `docs/SPEC-ASYNC-SEMANTICS.md:187` | core.ts×3 verdict.ts×2 | createMemo.test.ts×1 fuzz-findings-l2.test.ts×1 ispending-memo-unstamped-hold-3457.test.ts×2 latest-isPending-consistency.test.ts×3 untracked-verdict-rederive.test.ts×2 verdict-contract.test.ts×2 | [ruled] `[isPending(x), x()]` is atomic within one scope — `[isPending(x), x()]` read in one scope is atomic: a reader that observed the fresh value must not see `pending === true` for it. |
5858
| A11 | ruled | `docs/SPEC-ASYNC-SEMANTICS.md:101` | — | latest-isPending-consistency.test.ts×1 loading-fallback-in-flush-3540.test.ts×1 visibility-oracle-store.states.ts×2 visibility-oracle.states.ts×1 | [ruled] Sync derivations of held sources are visible through `latest()`/`isPending()` — Sync derivations of transition-held sources are visible through `latest()`/`isPending()` (held sync recompute is… |
5959
| A12 | amended | `docs/SPEC-ASYNC-SEMANTICS.md:195` | — | createOptimistic.test.ts×2 spec-async-semantics.test.ts×1 | [ruled, amended in place] Resting optimistic nodes report pending like a plain memo — A resting optimistic node reports pending via exactly the causes a plain async memo does (A19) — a reverting optim… |
6060
| A13 | ruled | `docs/SPEC-ASYNC-SEMANTICS.md:203` | — | spec-async-semantics.test.ts×7 | [ruled 2026-07-06 (promoted from B1)] Resting optimistic ≡ plain async memo at every checkpoint — (was B1) A resting optimistic node (no active override) is observationally identical to a plain async … |

‎packages/signals/src/affects.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {
2727
STATUS_ERROR,
2828
STATUS_PENDING,
2929
CONFIG_SLOT_NODE,
30-
CONFIG_VERDICT,
30+
CONFIG_VERDICT_REDERIVE,
3131
$REFRESH
3232
} from "./core/constants.js";
3333
import { ext } from "./core/core.js";
@@ -54,7 +54,7 @@ function repoll(node: Marked, seen = new Set<Computed<any>>()): void {
5454
const sub = s._sub;
5555
if (seen.has(sub)) continue;
5656
seen.add(sub);
57-
if (sub._config & CONFIG_VERDICT) enqueueSub(sub);
57+
if (sub._config & CONFIG_VERDICT_REDERIVE) enqueueSub(sub);
5858
if (!(sub as any)._type) repoll(sub, seen);
5959
}
6060
}

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
CONFIG_HELD,
77
CONFIG_SYNC,
88
CONFIG_VERDICT,
9+
CONFIG_VERDICT_REDERIVE,
910
EFFECT_TRACKED,
1011
EFFECT_USER,
1112
NOT_PENDING,
@@ -266,7 +267,7 @@ export function settlePendingSource(el: Computed<any>, source: Computed<any> = e
266267
// when the source went pending, `propagateStatus`), and a landing
267268
// equal to the committed value notifies nobody — the source settling
268269
// is its verdict changing: it runs again.
269-
return node._config & CONFIG_VERDICT && enqueueSub(node);
270+
return node._config & CONFIG_VERDICT_REDERIVE && enqueueSub(node);
270271
visited.add(node);
271272
node._time = clock;
272273
const remaining = node._x?._pendingSources?.values().next().value;
@@ -882,9 +883,12 @@ export function propagateStatus(
882883
// answering an errored source (`isPending` false; `latest` throws it).
883884
// Inheriting the error would make a probe's reader errored. A boundary's
884885
// output (CONFIG_REDERIVE, boundaries.ts) the same: content or fallback
885-
// is its pass's call.
886+
// is its pass's call. Re-deriving on pending is a tracked verdict's
887+
// (CONFIG_VERDICT_REDERIVE); an untracked probe's reader still re-derives
888+
// on an error rather than inheriting it.
886889
if (
887-
sub._config & (CONFIG_REDERIVE | CONFIG_VERDICT) ||
890+
sub._config & (CONFIG_REDERIVE | CONFIG_VERDICT_REDERIVE) ||
891+
(status !== STATUS_PENDING && sub._config & CONFIG_VERDICT) ||
888892
(status === STATUS_PENDING && link._gen !== sub._depGen)
889893
) {
890894
enqueueSub(sub);

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ export const CONFIG_GUESS = 1 << 13;
128128
* link does, A30). Set at the window, never cleared: a reader that stopped
129129
* asking re-derives once and goes pending through its own read. */
130130
export const CONFIG_VERDICT = 1 << 14;
131+
/** The verdict was read tracked: a dependency going pending or settling re-derives the pass.
132+
* An untracked verdict read keeps CONFIG_VERDICT (it reads the screen) without this. */
133+
export const CONFIG_VERDICT_REDERIVE = 1 << 19;
131134
/** A dependency's status is a question for this node's pass, not a fact
132135
* about its current one: the propagation re-derives it instead of marking
133136
* it, for errors as for pending (as CONFIG_VERDICT). A boundary's output

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
CONFIG_FRESH_READ,
1515
CONFIG_GUESS,
1616
CONFIG_VERDICT,
17+
CONFIG_VERDICT_REDERIVE,
1718
CONFIG_HELD,
1819
CONFIG_IN_SNAPSHOT_SCOPE,
1920
CONFIG_INPUTS_PUBLISHED,
@@ -314,7 +315,7 @@ export function recompute(el: Computed<any>, create: boolean = false): void {
314315
// committed screen, settle the flight and drop the hold — a superseding
315316
// write's verdict would depend on that probe. Cleared for this pass; a
316317
// probe in the body re-stamps it after the plain reads.
317-
if (el._statusFlags & STATUS_PENDING) el._config &= ~CONFIG_VERDICT;
318+
if (el._statusFlags & STATUS_PENDING) el._config &= ~(CONFIG_VERDICT | CONFIG_VERDICT_REDERIVE);
318319
if (el._config & CONFIG_HELD) {
319320
const tx = txOf(el);
320321
// Held by a blocked lane: the frame joins nothing — a lane never holds
@@ -373,6 +374,9 @@ export function recompute(el: Computed<any>, create: boolean = false): void {
373374
// live writes until the commit that disposes it, so every per-pass wipe
374375
// — here, the finally below, updateIfNecessary — carries it (#3543).
375376
el._flags = REACTIVE_RECOMPUTING_DEPS | (el._flags & REACTIVE_ZOMBIE);
377+
// Re-deriving on a dependency's pending is this pass's call: only a tracked
378+
// verdict read in the body sets it again (`markVerdictReader`).
379+
el._config &= ~CONFIG_VERDICT_REDERIVE;
376380
el._time = clock;
377381
// The pass's previous value: its staging, else the lane's value for a
378382
// lane's node (lanes.ts), else the committed one.
@@ -466,7 +470,7 @@ export function recompute(el: Computed<any>, create: boolean = false): void {
466470
joined = (el._flags & REACTIVE_JOINED) !== 0;
467471
// A verdict reader is one for as long as it probes: a pass that entered
468472
// no window (REACTIVE_PROBED) is an ordinary derivation again.
469-
if (!(el._flags & REACTIVE_PROBED)) el._config &= ~CONFIG_VERDICT;
473+
if (!(el._flags & REACTIVE_PROBED)) el._config &= ~(CONFIG_VERDICT | CONFIG_VERDICT_REDERIVE);
470474
// REACTIVE_DISPOSED survives too (#3621): the pass may have disposed its
471475
// own owner (a memo calling its root's `dispose()`, a cleanup doing so
472476
// #3601/#3606), and `disposeChildren` set the flag on this node

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
CONFIG_OVERRIDE,
77
CONFIG_REDERIVE,
88
CONFIG_STAGED,
9-
CONFIG_VERDICT,
9+
CONFIG_VERDICT_REDERIVE,
1010
EFFECT_RENDER,
1111
EFFECT_TRACKED,
1212
EFFECT_USER,
@@ -816,7 +816,7 @@ export class GlobalQueue implements IQueue {
816816
for (let i = 0; i < zombies.length; i++)
817817
if (
818818
(zombies[i]._flags & (REACTIVE_DISPOSED | REACTIVE_ZOMBIE)) === REACTIVE_ZOMBIE &&
819-
zombies[i]._config & CONFIG_VERDICT
819+
zombies[i]._config & CONFIG_VERDICT_REDERIVE
820820
)
821821
recompute(zombies[i]);
822822
// The unchanged passes' tails stay linked (A30, #3469): their inputs

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
CONFIG_INPUTS_PUBLISHED,
1717
CONFIG_OVERRIDE,
1818
CONFIG_VERDICT,
19+
CONFIG_VERDICT_REDERIVE,
1920
EFFECT_RENDER,
2021
NOT_PENDING,
2122
REACTIVE_DISPOSED,
@@ -224,7 +225,7 @@ function markVerdictReader(window: number): void {
224225
let c = context;
225226
if ((c as Root)?._root) c = (c as Root)._parentComputed;
226227
if (c !== null) {
227-
c._config |= CONFIG_VERDICT;
228+
c._config |= tracking ? CONFIG_VERDICT | CONFIG_VERDICT_REDERIVE : CONFIG_VERDICT;
228229
(c as Computed<any>)._flags |= REACTIVE_PROBED;
229230
// Observe tier: which windows this pass entered (1 `isPending`, 2
230231
// `latest`) — the hold census names the affordance (attribution.ts).
Lines changed: 246 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,246 @@
1+
// An untracked `isPending`/`latest` is a one-off read: it marks its reader a
2+
// verdict reader for how the pass reads (a frame reader sees the screen, A10)
3+
// but not for when the pass runs. A tracked verdict re-derives its reader when
4+
// a dependency goes pending, since the answer changed; an untracked one does
5+
// not, the same as any other untracked read. Before, the window stamped the
6+
// running computation either way, so a library that probes pending state
7+
// inside `untrack` (a router's link claim) made whatever computation created
8+
// it re-run on each of its own dependencies going pending.
9+
10+
import { describe, expect, it } from "vitest";
11+
import {
12+
action,
13+
createEffect,
14+
createMemo,
15+
createRenderEffect,
16+
createRoot,
17+
createSignal,
18+
flush,
19+
isPending,
20+
latest,
21+
untrack
22+
} from "../src/index.js";
23+
24+
function deferred<T>() {
25+
let resolve!: (v: T) => void;
26+
const promise = new Promise<T>(r => (resolve = r));
27+
return { promise, resolve };
28+
}
29+
30+
async function settle() {
31+
await Promise.resolve();
32+
await Promise.resolve();
33+
flush();
34+
}
35+
36+
/** Runs of a memo over an async source while the source refetches. */
37+
async function runsWhilePending(probe: (data: () => string) => void) {
38+
let runs = 0;
39+
let setId!: (v: number) => void;
40+
let cur = deferred<string>();
41+
const seen: string[] = [];
42+
createRoot(() => {
43+
const [id, set] = createSignal(1);
44+
setId = set;
45+
const data = createMemo(() => {
46+
const v = id();
47+
return cur.promise.then(s => `${s}-${v}`);
48+
});
49+
const host = createMemo(() => {
50+
runs++;
51+
const v = data();
52+
probe(data);
53+
return v;
54+
});
55+
createRenderEffect(
56+
() => {
57+
try {
58+
return host();
59+
} catch {
60+
return "pending";
61+
}
62+
},
63+
v => {
64+
seen.push(v);
65+
}
66+
);
67+
});
68+
flush();
69+
cur.resolve("a");
70+
await settle();
71+
const before = runs;
72+
cur = deferred<string>();
73+
setId(2);
74+
flush();
75+
await settle();
76+
const pendingRuns = runs - before;
77+
cur.resolve("b");
78+
await settle();
79+
await settle();
80+
return { pendingRuns, seen };
81+
}
82+
83+
describe("untracked verdict reads", () => {
84+
it("an untracked isPending does not re-derive its reader while a dependency is pending", async () => {
85+
const { pendingRuns, seen } = await runsWhilePending(() => untrack(() => isPending(() => {})));
86+
expect(pendingRuns).toBe(0);
87+
expect(seen.at(-1)).toBe("b-2");
88+
});
89+
90+
it("an untracked latest does not re-derive its reader while a dependency is pending", async () => {
91+
const { pendingRuns, seen } = await runsWhilePending(data => untrack(() => latest(data)));
92+
expect(pendingRuns).toBe(0);
93+
expect(seen.at(-1)).toBe("b-2");
94+
});
95+
96+
it("a tracked isPending still re-derives its reader while a dependency is pending", async () => {
97+
const { pendingRuns, seen } = await runsWhilePending(data => isPending(data));
98+
expect(pendingRuns).toBe(1);
99+
expect(seen.at(-1)).toBe("b-2");
100+
});
101+
102+
it("a reader that stops reading isPending tracked stops re-deriving", async () => {
103+
let runs = 0;
104+
let setId!: (v: number) => void;
105+
let setTracked!: (v: boolean) => void;
106+
let cur = deferred<string>();
107+
createRoot(() => {
108+
const [id, set] = createSignal(1);
109+
const [tracked, setT] = createSignal(true);
110+
setId = set;
111+
setTracked = setT;
112+
const data = createMemo(() => {
113+
const v = id();
114+
return cur.promise.then(s => `${s}-${v}`);
115+
});
116+
const host = createMemo(() => {
117+
runs++;
118+
const v = data();
119+
if (tracked()) isPending(data);
120+
else untrack(() => isPending(data));
121+
return v;
122+
});
123+
createRenderEffect(
124+
() => {
125+
try {
126+
return host();
127+
} catch {
128+
return "pending";
129+
}
130+
},
131+
() => {}
132+
);
133+
});
134+
flush();
135+
cur.resolve("a");
136+
await settle();
137+
setTracked(false);
138+
flush();
139+
const before = runs;
140+
cur = deferred<string>();
141+
setId(2);
142+
flush();
143+
await settle();
144+
expect(runs - before).toBe(0);
145+
cur.resolve("b");
146+
await settle();
147+
});
148+
149+
it("an untracked isPending of a source that rejects before resolving answers false instead of erroring", async () => {
150+
const log: string[] = [];
151+
let reject!: (e: unknown) => void;
152+
createRoot(() => {
153+
const a = createMemo(
154+
() =>
155+
new Promise<string>((_, r) => {
156+
reject = r;
157+
})
158+
);
159+
const probe = createMemo(() => untrack(() => isPending(() => a())));
160+
createRenderEffect(
161+
() => {
162+
try {
163+
return String(probe());
164+
} catch (e) {
165+
return `ERR:${(e as Error)?.message ?? ""}`;
166+
}
167+
},
168+
v => {
169+
log.push(v);
170+
}
171+
);
172+
});
173+
flush();
174+
reject(new Error("boom"));
175+
for (let i = 0; i < 6; i++) await settle();
176+
await new Promise(r => setTimeout(r, 20));
177+
flush();
178+
expect(log.at(-1)).toBe("false");
179+
});
180+
181+
it("A10: an untracked isPending reader never pairs pending with the fresh value", async () => {
182+
const log: string[] = [];
183+
let setX!: (v: number) => void;
184+
let cur = deferred<string>();
185+
const gate = deferred<void>();
186+
createRoot(() => {
187+
const [x, set] = createSignal(1);
188+
setX = set;
189+
const m = createMemo(() => {
190+
const v = x();
191+
return cur.promise.then(s => `${s}-${v}`);
192+
});
193+
const pair = () =>
194+
`[${untrack(() => isPending(() => m()))}, ${(() => {
195+
try {
196+
return m();
197+
} catch {
198+
return "THROWN";
199+
}
200+
})()}]`;
201+
const host = createMemo(pair);
202+
createRenderEffect(
203+
() => {
204+
try {
205+
return host();
206+
} catch {
207+
return "THROWN";
208+
}
209+
},
210+
v => {
211+
log.push(`memo:${v}`);
212+
}
213+
);
214+
createRenderEffect(pair, v => {
215+
log.push(`render:${v}`);
216+
});
217+
createEffect(pair, v => {
218+
log.push(`user:${v}`);
219+
});
220+
});
221+
flush();
222+
cur.resolve("data");
223+
await settle();
224+
225+
const act = action(function* () {
226+
cur = deferred<string>();
227+
setX(2);
228+
yield gate.promise;
229+
});
230+
act();
231+
flush();
232+
await settle();
233+
cur.resolve("data");
234+
await settle();
235+
gate.resolve();
236+
await settle();
237+
await settle();
238+
239+
expect(log.filter(v => v.includes("true, data-2"))).toEqual([]);
240+
expect(log.slice(-3).sort()).toEqual([
241+
"memo:[false, data-2]",
242+
"render:[false, data-2]",
243+
"user:[false, data-2]"
244+
]);
245+
});
246+
});

0 commit comments

Comments
 (0)