Skip to content

Commit 0d6ca5a

Browse files
committed
fix(signals): an error clears D-25's async posture
A pass that throws a real error answers with no flight of its own, so a verdict source going pending re-derives the memo instead of holding it on its pre-error value (F-1). Pinned, held and unheld. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2
1 parent b9b9800 commit 0d6ca5a

3 files changed

Lines changed: 55 additions & 2 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,8 @@ export function recompute(el: Computed<any>, create: boolean = false): void {
572572
el._config &= ~CONFIG_ASYNC;
573573
parkLoadingWindow(el, e as NotReadyError);
574574
} else {
575+
// An error answers (D-25, verdict.ts `holdWork`): no flight is its own.
576+
if (!notReady) el._config &= ~CONFIG_ASYNC;
575577
// D-41: a pass of a held node, or one that read a staging of this
576578
// flush, stages its error (`stageError`).
577579
if (notReady || !(stagedErr = stageError(el, e, true))) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,8 +530,8 @@ function verdictValue(el: Signal<any> | Computed<any>, c: Computed<any> | null):
530530
function holdWork(n: Computed<any>, source: Computed<any>): unknown {
531531
// CONFIG_ASYNC records an async memo with no window of its own: its last
532532
// answering pass registered a flight (`handleAsync`) and called neither
533-
// `latest` nor `isPending`. A window (`markVerdictReader`) or a sync answer
534-
// clears it; a pass left pending or errored keeps the last answer's.
533+
// `latest` nor `isPending`. A window (`markVerdictReader`), a sync answer or
534+
// an error clears it; a pass left pending keeps the last answer's.
535535
const own = n._config & CONFIG_ASYNC;
536536
return (
537537
own &&

‎packages/signals/tests/verdict-memo-flight-no-reask.test.ts‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,3 +630,54 @@ it("own window: an async memo over latest() of an async memo, read with isPendin
630630
expect(asks).toEqual(["m0:2", "l1", "l2"]);
631631
expect(out).toEqual(["false,1", "false,2"]);
632632
});
633+
634+
// An error is an answer (F-1): after `m1` throws on `m0`'s 5, its pass left
635+
// no flight of its own, so `m0` going pending again re-derives it (D-25,
636+
// verdict.ts `holdWork`). `refresh(m0)` re-asks `m0:5`, `m1` throws again,
637+
// and the boundary keeps the error, never `m1`'s pre-error value as final.
638+
for (const plain of [false, true])
639+
it(`error, then refresh(m0) to the same answer: ${plain ? "unheld" : "held"}, the error stays`, async () => {
640+
const { land, fly } = inFlight();
641+
const [s, setS] = createSignal(1);
642+
const out: string[] = [];
643+
let release = () => {};
644+
let m0!: () => number;
645+
createRoot(() => {
646+
m0 = createMemo(() => fly(1 + latest(s) + s()));
647+
const m1 = createMemo(() => {
648+
const v = m0();
649+
if (v === 5) throw new Error("boom");
650+
return fly(100 + v);
651+
});
652+
const h = createMemo(() =>
653+
plain || s() === 1 ? 1 : new Promise<number>(r => void (release = () => r(1)))
654+
);
655+
createErrorBoundary(
656+
() =>
657+
createLoadingBoundary(
658+
() => {
659+
createRenderEffect(
660+
() => (h(), `${isPending(m1)},${m1()}`),
661+
v => void out.push(v)
662+
);
663+
return null;
664+
},
665+
() => "L"
666+
),
667+
() => (out.push("E"), "E")
668+
);
669+
});
670+
flush();
671+
await land();
672+
setS(2);
673+
flush();
674+
await land(2);
675+
release();
676+
await land();
677+
const atError = out.length;
678+
expect(out[atError - 1]).toBe("E");
679+
refresh(m0);
680+
flush();
681+
await land();
682+
expect(out.slice(atError)).toEqual([]);
683+
});

0 commit comments

Comments
 (0)