Skip to content

Commit fda83a3

Browse files
ryansolidclaude
andauthored
fix(signals): a chain's settle walk keeps the staged-error mark mid-hold (#4562) (#4582)
When a superseded flight's error is staged in a hold (D-41, `stageError`), `settlePendingSource` retired each dependent's pending state on its first arrival and only stage-marked a node it reached a second time. A diamond's join is revisited and so carried the staging; a chain's join is reached once, read as settled, and its view re-showed `false:3` while the hold was still open. Graph shape was observable. The walk now marks every node it fully settles from a staged error too, so the chain shows the diamond's frames: `isPending` stays true until the commit (F-9) and the screen keeps what it showed (F-2); the derivation of a staged error carries it (D-41). `stageMark` moves from core into the verdict engine (verdict.ts) behind a new `stageMarkHook` installed by `installVerdictHooks`, so core carries only the hook calls. Spec: tests/settle-diamond-revisit.test.ts pins the chain alongside the diamond. Claude-Session: https://claude.ai/code/session_0117BoWNSSgtemsSYsaX2hXE Co-authored-by: Claude <[email protected]>
1 parent f0471e8 commit fda83a3

5 files changed

Lines changed: 101 additions & 35 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 chain's verdict no longer flips to `false` mid-hold where a diamond's stays `true` (#4562). When a superseded flight's error is staged in a hold (D-41), the settle walk now marks every derivation it fully settles with the staging, not only a join it reaches a second time, so `isPending` stays `true` until the commit whatever the graph shape (F-9, F-2). The mark moved behind the verdict engine's hooks (`installVerdictHooks`), so builds without `isPending`/`latest` carry none of it.

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

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
CONFIG_STAGED_ERROR,
1111
CONFIG_SYNC,
1212
CONFIG_VERDICT,
13-
EFFECT_TRACKED,
1413
EFFECT_USER,
1514
NOT_PENDING,
1615
REACTIVE_DIRTY,
@@ -55,6 +54,7 @@ import {
5554
txOf,
5655
freshHook,
5756
holdWorkHook,
57+
stageMarkHook,
5858
guessing,
5959
laneStageHook,
6060
storeParkHook
@@ -255,32 +255,6 @@ export function stageError(el: Computed<any>, error: any, inPass?: boolean): boo
255255
return true;
256256
}
257257

258-
/** D-41: a derivation of a staged error carries it, staged with the same
259-
* frame — marked, not re-run, as a published error marks it (a re-run would
260-
* replace the frame its content owns) — and its own verdict readers
261-
* re-derive (the settle walk). Only a verdict reads a derivation's staging
262-
* before its commit, so only the verdict engine marks. Not a boundary's
263-
* output, an async memo, an effect or a boundary's tree (`EFFECT_TRACKED <<
264-
* 23` spans CONFIG_FRAME and every effect type), nor one already carrying a
265-
* staged error: the commit's publish reaches them. A pending mark supersedes
266-
* the staging (`propagateStatus`). */
267-
function stageMark(node: Computed<any>, el: Computed<any>): void {
268-
if (
269-
!(
270-
node._config &
271-
(CONFIG_REDERIVE | CONFIG_STAGED_ERROR | CONFIG_ASYNC | (EFFECT_TRACKED << 23))
272-
)
273-
) {
274-
node._pendingValue = el._pendingValue;
275-
node._config |= CONFIG_STAGED_ERROR;
276-
queuePendingNode(node);
277-
// A derived store's readers are its family's (store/projection.ts): they
278-
// re-derive from the staging, as from the derive's status (#4189).
279-
(node as any)._fam?.st(STATUS_ERROR);
280-
settlePendingSource(node);
281-
}
282-
}
283-
284258
export function settleErroredDependents(el: Computed<any>, error: any): void {
285259
let scheduled = false;
286260
walkDependents(el, (node, seen) => {
@@ -376,12 +350,10 @@ export function settlePendingSource(el: Computed<any>, source: Computed<any> = e
376350
// equal to the committed value notifies nobody — the source settling
377351
// is its verdict changing: it runs again. (Verdict readers exist only
378352
// with the verdict engine installed.)
379-
// D-41: a derivation of a staged error carries it (`stageMark`).
353+
// D-41: a derivation of a staged error carries it (verdict.ts `stageMark`).
380354
return (
381355
holdWorkHook &&
382-
(node._config & CONFIG_VERDICT
383-
? enqueueSub(node)
384-
: el._config & CONFIG_STAGED_ERROR && stageMark(node, el)),
356+
(node._config & CONFIG_VERDICT ? enqueueSub(node) : stageMarkHook!(node, el)),
385357
false
386358
);
387359
node._time = clock;
@@ -417,6 +389,10 @@ export function settlePendingSource(el: Computed<any>, source: Computed<any> = e
417389
// again at release time — deferred so unobserved() can't unlink subs
418390
// lists this walk is still iterating.
419391
if (!node._subs && node._config & CONFIG_AUTO_DISPOSE) (released ??= []).push(node);
392+
// D-41: and a node fully settled here carries the staging as well — a
393+
// chain's single arrival marks what a diamond's second arrival does
394+
// (F-9, F-2: graph shape is not observable, #4562).
395+
stageMarkHook?.(node, el);
420396
}
421397
});
422398

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,17 @@ export let observeFlightHook: ((c: Computed<any>, el: Computed<any>) => boolean)
183183
/** D-25's hold work (verdict.ts `holdWork`): on `source` going pending,
184184
* whether verdict reader `n` waits on it instead of re-deriving. */
185185
export let holdWorkHook: ((n: Computed<any>, source: Computed<any>) => unknown) | null = null;
186+
/** D-41's staged-error mark (verdict.ts `stageMark`): the settle walk's
187+
* reached node `n` carries staged error source `el`'s staging. */
188+
export let stageMarkHook: ((n: Computed<any>, el: Computed<any>) => void) | null = null;
186189
export function installVerdictHooks(
187190
observeFlight: NonNullable<typeof observeFlightHook>,
188-
holdWork: NonNullable<typeof holdWorkHook>
191+
holdWork: NonNullable<typeof holdWorkHook>,
192+
stageMark: NonNullable<typeof stageMarkHook>
189193
): void {
190194
observeFlightHook = observeFlight;
191195
holdWorkHook = holdWork;
196+
stageMarkHook = stageMark;
192197
}
193198
/** External-source bridge (wired by enableExternalSource(); undefined while
194199
* no config is active — including after _resetExternalSourceConfig()). */

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

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ import {
1717
CONFIG_HELD_FRAME,
1818
CONFIG_INPUTS_PUBLISHED,
1919
CONFIG_OVERRIDE,
20+
CONFIG_REDERIVE,
2021
CONFIG_STAGED_ERROR,
2122
CONFIG_VERDICT,
2223
EFFECT_RENDER,
24+
EFFECT_TRACKED,
2325
NOT_PENDING,
2426
REACTIVE_DISPOSED,
2527
REACTIVE_FRAME_READ,
@@ -51,6 +53,7 @@ import {
5153
unflushedValue,
5254
verdict
5355
} from "./core.js";
56+
import { settlePendingSource } from "./async.js";
5457
import { forgetThrownRead, warnStrictReadUntracked } from "./dev.js";
5558
import { NotReadyError } from "./error.js";
5659
import { link } from "./graph.js";
@@ -666,7 +669,37 @@ function holdWork(n: Computed<any>, source: Computed<any>): unknown {
666669
// Installed at module evaluation — present exactly when something imports
667670
// `latest` or `isPending`. (`read` dispatches to `verdictValue` through
668671
// `verdict`, set while a window is open.)
669-
installVerdictHooks(observeFlight, holdWork);
672+
/** D-41: a derivation of a staged error carries it, staged with the same
673+
* frame — marked, not re-run, as a published error marks it (a re-run would
674+
* replace the frame its content owns) — and its own verdict readers
675+
* re-derive (the settle walk). Only a verdict reads a derivation's staging
676+
* before its commit, so only the verdict engine marks. Not a boundary's
677+
* output, an async memo, an effect or a boundary's tree (`EFFECT_TRACKED <<
678+
* 23` spans CONFIG_FRAME and every effect type), nor one already carrying a
679+
* staged error: the commit's publish reaches them. A pending mark supersedes
680+
* the staging (`propagateStatus`). Installed as `stageMarkHook`: the settle
681+
* walk (`settlePendingSource`) marks every node it reaches from a staged
682+
* error — a diamond's revisited join and a chain's single arrival alike
683+
* (#4562). */
684+
function stageMark(node: Computed<any>, el: Computed<any>): void {
685+
if (
686+
el._config & CONFIG_STAGED_ERROR &&
687+
!(
688+
node._config &
689+
(CONFIG_REDERIVE | CONFIG_STAGED_ERROR | CONFIG_ASYNC | (EFFECT_TRACKED << 23))
690+
)
691+
) {
692+
node._pendingValue = el._pendingValue;
693+
node._config |= CONFIG_STAGED_ERROR;
694+
queuePendingNode(node);
695+
// A derived store's readers are its family's (store/projection.ts): they
696+
// re-derive from the staging, as from the derive's status (#4189).
697+
(node as any)._fam?.st(STATUS_ERROR);
698+
settlePendingSource(node);
699+
}
700+
}
701+
702+
installVerdictHooks(observeFlight, holdWork, stageMark);
670703
/** A store read inside an untracked `isPending` probe found a live mark on
671704
* a record with no node to carry it (store/affects.ts): not final. */
672705
GlobalQueue._witnessMark = () => {

‎packages/signals/tests/settle-diamond-revisit.test.ts‎

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,15 @@
44
* re-run, a staged error's mark): sharing the walk with the other dependent
55
* walks (#4560) once skipped it, and the join re-showed its committed value
66
* between the held error's staging and its commit (an extra "false:3").
7-
* Pins `next`'s diamond output. The chain's extra "false:3" is the separate
8-
* graph-shape question (#4562), not pinned here.
7+
* Pins `next`'s diamond output.
8+
*
9+
* The chain (#4562): its join is reached once, and that single arrival used
10+
* to retire the pending state without the staged-error mark, so the view
11+
* re-showed `false:3` mid-hold. F-9: `isPending(D)` stays true while the
12+
* staged answer waits in the hold — no new answer has been committed; F-2:
13+
* the screen keeps `true:3` until the commit; D-41: the derivation of a
14+
* staged error carries it. Graph shape is not observable: the chain shows
15+
* the diamond's frames.
916
*/
1017
import { afterEach, expect, it } from "vitest";
1118
import {
@@ -66,3 +73,43 @@ it("a diamond's join revisited by the settle walk keeps the early-return branch"
6673
expect(log).toEqual(["false:3", "true:3", "E:boomA", "false:9"]);
6774
dispose();
6875
});
76+
77+
it("a chain's single arrival keeps the staged mark, as a diamond's second arrival does (#4562)", async () => {
78+
const [s, setS] = createSignal(0);
79+
const log: unknown[] = [];
80+
let release!: () => void;
81+
const dispose = createRoot(d => {
82+
const A = createMemo(async () => {
83+
const v = s();
84+
await Promise.resolve();
85+
if (v === 2) throw new Error("boomA");
86+
return v;
87+
});
88+
const B = createMemo(() => A() + 1);
89+
const C = createMemo(() => B() + 2);
90+
const D = createMemo(() => C());
91+
const view = createErrorBoundary(
92+
() => `${isPending(D)}:` + D(),
93+
e => `E:${(e() as Error).message}`
94+
);
95+
createRenderEffect(view, v => void log.push(v));
96+
return d;
97+
});
98+
await tick();
99+
setS(1);
100+
flush();
101+
action(function* () {
102+
setS(2);
103+
yield new Promise<void>(r => (release = r));
104+
})();
105+
await tick();
106+
release();
107+
await tick();
108+
await tick();
109+
setS(3);
110+
flush();
111+
await tick();
112+
await tick();
113+
expect(log).toEqual(["false:3", "true:3", "E:boomA", "false:6"]);
114+
dispose();
115+
});

0 commit comments

Comments
 (0)