Skip to content

Commit 42c2568

Browse files
committed
fix(signals): a memo over a verdict memo shows the verdict beside a held value (U-10, solidjs#4050)
A memo's tracked read of a verdict reader's value makes it a verdict reader from that pass's end, as if it probed inline: it reads held values as the screen and re-derives in the verdict lane. CONFIG_VERDICT moves to REACTIVE_PROBED's bit so the carry is one OR. boundaries.ts drops its own dep walk (`verdictDerived`): the `on` pass's mark carries the same fact. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01TeskUj1ZrY9rZWsgrU9NNv
1 parent 9f3af34 commit 42c2568

8 files changed

Lines changed: 196 additions & 33 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 memo that reads a verdict memo (`isPending`/`latest`) shows the verdict now, beside a held value it also reads (F-6, U-10, #4050). Before, it re-entered the hold with that value and the verdict waited for the landing: a Provider's children memo over a router shell `[<Feedback/>, outlet]` never showed delayed pending feedback during a held navigation. It now behaves as the same probe read inline, or a render effect reading both, already did.

‎packages/signals/docs/OPEN-QUESTIONS.md‎

Lines changed: 12 additions & 11 deletions
Large diffs are not rendered by default.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,9 @@ An armed boundary catches a lane the same way it catches a transition (D-12, D-1
204204

205205
**From:** F-6, F-1. **Scenarios:** S-29.
206206

207-
What is rendered from a display-ahead read reveals together with it: an async memo over `latest(x)` holds the `latest` view's reveal until it lands; a combined `isPending(() => [fast(), copy()])` over two async memos, one wrapped in a sync memo, stays `true` until both land, because a memo's value is one shared slot — it computes under its own hold posture, never under the posture of whichever reader pulled it. A node whose fetch a hold is waiting on is that hold's work, not a verdict reader: a pass that re-runs it while its fetch is in flight reads plainly — following the change it is fetching for — even if an earlier pass of it called `isPending` or `latest` (#3884).
207+
What is rendered from a display-ahead read reveals together with it: an async memo over `latest(x)` holds the `latest` view's reveal until it lands; a combined `isPending(() => [fast(), copy()])` over two async memos, one wrapped in a sync memo, stays `true` until both land, because a memo's value is one shared slot — it computes under its own hold posture, never under the posture of whichever reader pulled it. A node whose fetch a hold is waiting on is that hold's work, not a verdict reader: a pass that re-runs it while its fetch is in flight reads plainly — following the change it is fetching for — even if an earlier pass of it called `isPending` or `latest` (#3884). A memo's posture is what it reads: one that reads a verdict reader's value is a derivation of a display-ahead read, and a verdict reader itself — `createMemo(() => [held(), V()])` with `V = createMemo(() => isPending(x) && latest(e))` shows `V`'s verdict now, beside the screen's `held()`, as the inline probe and a render effect reading both do (#4050: a Provider's children memo over a router shell).
208208

209-
**Collapses:** [A31](./SPEC-ASYNC-SEMANTICS.md#a31-a-memo-computes-under-its-own-lane-posture-never-its-pullers) (#3442), §20.1 question 3 ("Yeah definitely it is held. Consistent with any optimistic update"), OL-R24/R25/R34, recovery 6.2. **Status:** standing.
209+
**Collapses:** [A31](./SPEC-ASYNC-SEMANTICS.md#a31-a-memo-computes-under-its-own-lane-posture-never-its-pullers) (#3442), §20.1 question 3 ("Yeah definitely it is held. Consistent with any optimistic update"), OL-R24/R25/R34, recovery 6.2. **Status:** standing. A memo over a verdict memo: `tests/verdict-memo-under-held-memo-4050.test.ts`, `packages/web/test/held-shell-pending-feedback-4050.spec.tsx` (U-10).
210210

211211
### D-26. A `latest()`/optimistic reader mounted or re-run mid-hold shows the committed value and reveals with the lane
212212

‎packages/signals/src/boundaries.ts‎

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -414,16 +414,6 @@ function reportOutsideHold(b: Boundary): void {
414414
}
415415
}
416416

417-
/** The `on` pass is a verdict's: it probed itself (CONFIG_VERDICT), or it
418-
* read a memo that did (#3528's `createMemo(() => isPending(m2))`) — its
419-
* swap is display-ahead either way. */
420-
function verdictDerived(c: Computed<any>): boolean {
421-
if (c._config & CONFIG_VERDICT) return true;
422-
for (let d = c._deps; d !== null; d = d._nextDep)
423-
if (d._dep._config & CONFIG_VERDICT) return true;
424-
return false;
425-
}
426-
427417
/** `on` changed after the mount: fresh again if anything under it is
428418
* pending now; collecting for the rest of the flush either way. */
429419
function arm(b: Boundary): void {
@@ -447,12 +437,17 @@ function arm(b: Boundary): void {
447437
return;
448438
}
449439
b._armed = true;
450-
// A verdict read in `on` (`isPending`) whose frame has no transaction
451-
// yet: the swap is still display-ahead — the frame gets one now (it lands
440+
// A verdict read in `on` (`isPending`, or a memo of one — #3528's
441+
// `createMemo(() => isPending(m2))`: the mark carries, core.ts `read`)
442+
// whose frame has no transaction yet: the swap is still display-ahead — the frame gets one now (it lands
452443
// at this very seam if nothing holds it), and the swap is its verdict
453444
// lane's work, shown ahead of the frame's own runs (#3528).
454445
let lane = passLane;
455-
if (lane === null && globalQueue._running && verdictDerived(getOwner() as Computed<any>)) {
446+
if (
447+
lane === null &&
448+
globalQueue._running &&
449+
(getOwner() as Computed<any>)._config & CONFIG_VERDICT
450+
) {
456451
joinFuture(null);
457452
lane = GlobalQueue._verdictLane!(flushTransaction!);
458453
}

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,15 +131,17 @@ export const CONFIG_GUESS = 1 << 13;
131131
* pending is a question for its next pass — the verdict changed — so the
132132
* propagation re-derives it instead of marking it pending (as a kept-tail
133133
* link does, A30). Set at the window, never cleared: a reader that stopped
134-
* asking re-derives once and goes pending through its own read. */
135-
export const CONFIG_VERDICT = 1 << 14;
134+
* asking re-derives once and goes pending through its own read. The same
135+
* bit as REACTIVE_PROBED: a pass's probe (or a read of a verdict memo,
136+
* core.ts `read`) carries into the config at its end without a shift. */
137+
export const CONFIG_VERDICT = 1 << 15;
136138
/** A dependency's status is a question for this node's pass, not a fact
137139
* about its current one: the propagation re-derives it instead of marking
138140
* it, for errors as for pending (as CONFIG_VERDICT). A boundary's output
139141
* (show the content, or the fallback) and its `on` node (boundaries.ts); a
140142
* promise over an expression (`resolve`/`until`, signals.ts: the pass reads
141143
* the error and rejects, or re-asks a pending source). */
142-
export const CONFIG_REDERIVE = 1 << 15;
144+
export const CONFIG_REDERIVE = 1 << 14;
143145
/** The reader wants the truth, not the lane's guess (`until`, signals.ts):
144146
* a read of displayed optimism serves the base the guess covers, makes the
145147
* pass no lane's, and the truth landing wakes it even when it confirms the

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -471,9 +471,10 @@ export function recompute(el: Computed<any>, create: boolean = false): void {
471471
// bookkeeping, and those marks are correctly discarded here.
472472
missedWake = (el._flags & REACTIVE_MISSED_WAKE) !== 0;
473473
joined = (el._flags & REACTIVE_JOINED) !== 0;
474-
// A verdict reader is one for as long as it probes: a pass that entered
475-
// no window (REACTIVE_PROBED) is an ordinary derivation again.
476-
if (!(el._flags & REACTIVE_PROBED)) el._config &= ~CONFIG_VERDICT;
474+
// A verdict reader is one for as long as it probes, or reads a memo
475+
// that does (`read`): a pass that did neither (REACTIVE_PROBED, the same
476+
// bit) is an ordinary derivation again.
477+
el._config = (el._config & ~CONFIG_VERDICT) | (el._flags & REACTIVE_PROBED);
477478
// REACTIVE_DISPOSED survives too (#3621): the pass may have disposed its
478479
// own owner (a memo calling its root's `dispose()`, a cleanup doing so
479480
// #3601/#3606), and `disposeChildren` set the flag on this node
@@ -1728,7 +1729,15 @@ export function read<T>(el: Signal<T> | Computed<T>): T {
17281729
if (c) {
17291730
if (tracking) {
17301731
link(el, c as Computed<any>);
1731-
if ((owner as Computed<unknown>)._fn) pullComputed(owner, c as Computed<any>);
1732+
if ((owner as Computed<unknown>)._fn) {
1733+
pullComputed(owner, c as Computed<any>);
1734+
// F-6 (#4050): a memo over a verdict reader's value derives from a
1735+
// display-ahead read — a verdict reader from this pass's end, as if
1736+
// it probed inline: it reads held values as the screen and shows the
1737+
// verdict now. Not an effect: a render effect is a frame reader
1738+
// already, and a user effect's posture is its own reads'.
1739+
if (!(c as any)._type) (c as Computed<any>)._flags |= owner._config & CONFIG_VERDICT;
1740+
}
17321741
}
17331742
// L2, as in the fast block above (tracked or not). A node born into the
17341743
// future (uninitialized) has no committed value: every reader derives
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// #4050 (U-10): a memo that reads a verdict memo (`isPending`/`latest`) is
2+
// itself a derivation of a display-ahead read (F-6): it shows the verdict now,
3+
// beside the held value it also reads (the screen's), exactly as it would with
4+
// the probe inline — and as a render effect reading the same two does (F-1: a
5+
// memo between is not a reason to wait). Before, it re-entered the hold with
6+
// its held source and the verdict waited for the landing: a Provider's
7+
// children memo over a router shell `[<Feedback/>, outlet]` never showed the
8+
// feedback.
9+
import { expect, it } from "vitest";
10+
import {
11+
createMemo,
12+
createRenderEffect,
13+
createRoot,
14+
createSignal,
15+
flush,
16+
isPending,
17+
latest
18+
} 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+
const shapes: Record<
26+
string,
27+
(h: () => number, verdict: () => boolean, e: () => boolean) => () => [number, boolean]
28+
> = {
29+
"render effect [h, V]": (h, verdict) => () => [h(), verdict()],
30+
"memo [h, inline probe]": (h, _v, e) => createMemo(() => [h(), isPending(h) && latest(e)]),
31+
"memo [h, V]": (h, verdict) => createMemo(() => [h(), verdict()]),
32+
"memo over a memo [h, V]": (h, verdict) => {
33+
const m = createMemo(() => [h(), verdict()] as [number, boolean]);
34+
return createMemo(() => m());
35+
}
36+
};
37+
38+
for (const [name, shape] of Object.entries(shapes))
39+
it(`${name}: the verdict shows beside the held value, then lands with it`, async () => {
40+
const log: string[] = [];
41+
const [route, setRoute] = createSignal(0);
42+
let release!: () => void;
43+
const h = createMemo(async () => {
44+
const r = route();
45+
if (r) await new Promise<void>(res => (release = res));
46+
return r;
47+
}) as () => number;
48+
const [e, setE] = createSignal(false);
49+
createRoot(() => {
50+
const verdict = createMemo(() => isPending(h) && latest(e));
51+
createRenderEffect(shape(h, verdict, e), v => void log.push(v.join(",")));
52+
});
53+
await tick();
54+
setRoute(1);
55+
flush();
56+
await tick();
57+
log.push("|");
58+
setE(true);
59+
flush();
60+
await tick();
61+
expect(log[log.length - 1]).toBe("0,true");
62+
log.push("|");
63+
setE(false);
64+
release();
65+
await tick();
66+
expect(log[log.length - 1]).toBe("1,false");
67+
expect(log).not.toContain("1,true");
68+
});
69+
70+
it("memo [V, h] reads the verdict first: shows it now too", async () => {
71+
const log: string[] = [];
72+
const [route, setRoute] = createSignal(0);
73+
let release!: () => void;
74+
const h = createMemo(async () => {
75+
const r = route();
76+
if (r) await new Promise<void>(res => (release = res));
77+
return r;
78+
}) as () => number;
79+
const [e, setE] = createSignal(false);
80+
createRoot(() => {
81+
const verdict = createMemo(() => isPending(h) && latest(e));
82+
const m = createMemo(() => {
83+
const v = verdict();
84+
return `${h()},${v}`;
85+
});
86+
createRenderEffect(m, v => void log.push(v));
87+
});
88+
await tick();
89+
setRoute(1);
90+
flush();
91+
await tick();
92+
setE(true);
93+
flush();
94+
await tick();
95+
expect(log[log.length - 1]).toBe("0,true");
96+
setE(false);
97+
release();
98+
await tick();
99+
expect(log[log.length - 1]).toBe("1,false");
100+
});
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* @jsxImportSource @solidjs/web
3+
* @vitest-environment jsdom
4+
*/
5+
// #4050: a Provider's children are one memo. A router shell `[<Feedback/>,
6+
// outlet]` under it reads the held outlet and the feedback `Show` together;
7+
// the feedback is a display-ahead read (F-6) and shows now, beside the held
8+
// page — as it does without the Provider.
9+
import { expect, test } from "vitest";
10+
import { Show, createContext, createMemo, createSignal, flush, isPending, latest } from "solid-js";
11+
import { render } from "../src/index.js";
12+
const tick = async () => {
13+
for (let i = 0; i < 8; i++) await Promise.resolve();
14+
flush();
15+
};
16+
17+
for (const provider of [true, false])
18+
test(`held navigation shows delayed feedback beside the old page${provider ? " under a Provider" : ""}`, async () => {
19+
const container = document.createElement("div");
20+
const Ctx = createContext(0);
21+
const [route, setRoute] = createSignal(0);
22+
let release!: () => void;
23+
const page = createMemo(async () => {
24+
const r = route();
25+
if (r) await new Promise<void>(res => (release = res));
26+
return `page ${r}`;
27+
});
28+
const [elapsed, setElapsed] = createSignal(false);
29+
const Feedback = () => (
30+
<Show when={isPending(page) && latest(elapsed)}>
31+
<b>waiting</b>
32+
</Show>
33+
);
34+
const Outlet = () => <Show when={page()}>{p => <p>{p()}</p>}</Show>;
35+
const Shell = () => [<Feedback />, <Outlet />];
36+
render(() => (provider ? <Ctx value={1}>{<Shell />}</Ctx> : <Shell />), container);
37+
await tick();
38+
expect(container.innerHTML).toBe("<p>page 0</p>");
39+
setRoute(1);
40+
flush();
41+
await tick();
42+
expect(container.innerHTML).toBe("<p>page 0</p>");
43+
setElapsed(true);
44+
flush();
45+
await tick();
46+
expect(container.innerHTML).toBe("<b>waiting</b><p>page 0</p>");
47+
setElapsed(false);
48+
release();
49+
await tick();
50+
expect(container.innerHTML).toBe("<p>page 1</p>");
51+
});

0 commit comments

Comments
 (0)