Skip to content

Commit 02f88bb

Browse files
committed
fix(signals): a re-armed Loading leaves an outer Errored's readers alone (#4373 review)
arm() hands a re-armed Loading's pending readers to it alone by deleting them from outer boundaries. With readers keyed by reader, that also deleted an outer error boundary's entry, so the Errored healed while its source was still in flight (D-39). Only outer loading boundaries drop them now. The held fold-back in boundarySeam tests each entry's source, as it did before the map. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2
1 parent 0104fef commit 02f88bb

4 files changed

Lines changed: 94 additions & 10 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ Status legend: **live** stated and standing · **ruled** carries an explicit rul
9696
| B2 | live | `docs/SPEC-ASYNC-SEMANTICS.md:213` | — | createRevealOrder.test.ts×16 derived-write-then-derivation-3733.test.ts×1 onCleanup.test.ts×2 spec-async-semantics.test.ts×2 | PROMOTED → A14 (A14's section carries the ruling). |
9797
| B3 | live | `docs/SPEC-ASYNC-SEMANTICS.md:249` | — | spec-async-semantics.test.ts×2 | PROMOTED → A15 (A15's section carries the ruling). |
9898
| B4 | live | `docs/SPEC-ASYNC-SEMANTICS.md:81` | — | derived-write-then-derivation-3733.test.ts×1 spec-async-semantics.test.ts×2 | PROMOTED → A18 (A18's section carries the ruling). |
99-
| B5 | live | `docs/SPEC-ASYNC-SEMANTICS.md:221` | boundaries.ts×2 | derived-write-then-derivation-3733.test.ts×1 fuzz-findings-l2.test.ts×3 spec-async-semantics.test.ts×2 | PROMOTED → A16 (A16's section carries the ruling). |
99+
| B5 | live | `docs/SPEC-ASYNC-SEMANTICS.md:221` | boundaries.ts×2 | derived-write-then-derivation-3733.test.ts×1 errored-over-rearmed-loading-4384.test.ts×1 fuzz-findings-l2.test.ts×3 spec-async-semantics.test.ts×2 | PROMOTED → A16 (A16's section carries the ruling). |
100100
## C — tier C
101101

102102
| id | status | defined | cited in src | cited in tests | statement (at definition) |

‎packages/signals/src/boundaries.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,8 @@ function boundarySeam(): void {
394394
!b._initialized &&
395395
o._config & CONFIG_HELD &&
396396
[...b._readers].every(
397-
([r]) =>
398-
!(r._statusFlags & STATUS_PENDING) && r._config & CONFIG_HELD && txOf(r) === txOf(o)
397+
([, s]) =>
398+
!(s._statusFlags & STATUS_PENDING) && s._config & CONFIG_HELD && txOf(s) === txOf(o)
399399
)
400400
) {
401401
b._readers.clear();
@@ -521,7 +521,9 @@ function arm(b: Boundary): void {
521521
// It is this boundary's alone now (B5, the nearest catcher): an outer
522522
// re-armed by the same tick does not wait for it (D-14, U-4).
523523
for (let a = b._parent; a !== null; a = a._parent)
524-
for (const [o] of b._readers) a._readers.delete(o);
524+
// An outer error boundary keys its readers too, but waits on their
525+
// sources: a re-armed Loading taking the pending does not settle it.
526+
if (a._type & STATUS_PENDING) for (const [o] of b._readers) a._readers.delete(o);
525527
flip(b);
526528
redraw(b);
527529
return;
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// #4373 follow-up (D-39: a pending is not a value). Shape:
2+
// `<Errored><Loading on={key}>{renderEffect(m1())}</Loading></Errored>`, where m1 is
3+
// an async memo gated by a manually released promise and rejects for s === 1.
4+
// After the error shows, a refetch (setS(2)) in the same flush as a key change
5+
// re-arms the Loading. `arm` hands the Loading's pending readers to it alone
6+
// (B5) by deleting them from outer loading boundaries; an outer error
7+
// boundary keys the same readers but waits on their sources, so it keeps the
8+
// error while m1 is still in flight.
9+
import { expect, it } from "vitest";
10+
import {
11+
createErrorBoundary,
12+
createLoadingBoundary,
13+
createMemo,
14+
createRenderEffect,
15+
createRoot,
16+
createSignal,
17+
flush
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+
it("an Errored over a re-armed Loading keeps the error while the refetch is in flight", async () => {
26+
const [s, setS] = createSignal(0);
27+
const [key, setKey] = createSignal(0);
28+
const gates: Array<() => void> = [];
29+
let out = "";
30+
const dispose = createRoot(dispose => {
31+
const m1 = createMemo(async () => {
32+
const v = s();
33+
await new Promise<void>(r => gates.push(r));
34+
if (v === 1) throw new Error("boom");
35+
return v;
36+
});
37+
const view = createErrorBoundary(
38+
() =>
39+
createLoadingBoundary(
40+
() => {
41+
createRenderEffect(
42+
() => m1(),
43+
() => {}
44+
);
45+
return "content";
46+
},
47+
() => "[L]",
48+
{ on: () => key() }
49+
),
50+
(e: () => any) => `[E ${e()?.message}]`
51+
);
52+
createRenderEffect(
53+
() => {
54+
const v = view();
55+
return typeof v === "function" ? (v as () => unknown)() : v;
56+
},
57+
v => void (out = String(v))
58+
);
59+
return dispose;
60+
});
61+
flush();
62+
expect(out).toBe("[L]");
63+
gates.shift()!(); // m1 resolves to 0
64+
await tick();
65+
expect(out).toBe("content");
66+
setS(1); // refetch in flight: the Loading has shown content, so it holds
67+
flush();
68+
expect(out).toBe("content");
69+
gates.shift()!(); // m1 rejects
70+
await tick();
71+
expect(out).toBe("[E boom]");
72+
setS(2); // refetch, still gated...
73+
setKey(1); // ...and the Loading re-arms in the same flush
74+
flush();
75+
expect(out).toBe("[E boom]"); // PR head 0104feff: "[L]"
76+
await tick();
77+
expect(out).toBe("[E boom]");
78+
gates.shift()!(); // m1 resolves to 2
79+
await tick();
80+
expect(out).toBe("content");
81+
dispose();
82+
});

‎scripts/size/scenarios.js‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2660,9 +2660,9 @@ module.exports = [
26602660
// A projection unchained from a store proxy tells its readers (#4361, 2026-10-28, over next @ 6b7e34a, after #4337): cap 31.80 KB unchanged, recorded minified 96,944 -> 96,958 B (+14 B minified over next); measured over next @ ffe0c1c5 at +1 B brotli. A keyed projection whose derive returned another store's proxy, then a plain array, reconciled the array against the live proxy, which already read the source's next frame, so no leaf or container heard the change and the frame stalled; a live chained base now writes every node (node equality judges each) and its container. Correctness. Recorded minified = measured; CI re-bases.
26612661
// Derived-store leaf served its staging while the derive has never committed (#4355, 2026-10-28, over next @ 5f60713a, after #4361): cap 31.80 KB unchanged, recorded minified 96,958 -> 96,977 B (+19 B), measured locally (linux) at 31,743 B brotli, under the cap. A verdict reader (a memo over a derive that reads `latest()`) was served a never-landed derived store's seed for one pass; the store's `nodeValue` now serves the leaf's staging while the family's derive is uninitialized (+19 B minified, store engine only). Correctness.
26622662
// A verdict memo leaving its lane on an outside write wakes its reader (#4367, 2026-10-28, over next @ 6b792a95, after #4355): cap 31.80 KB unchanged, recorded minified 96,977 -> 96,978 B (+1 B minified over next), measured locally (linux) at 31,736 B brotli. A pass outside any transaction's flush that leaves a shown lane wakes its readers at the seam even while the lane's frame is held; the guess-take read moved behind `guessed` pays for it in the bundles without optimism (-2 B minified there).
2663-
// An Errored heals when the last reader that caught its error is disposed (#4373, 2026-10-28, over next @ 6b792a95, after #4355; re-recorded over next @ b68942ca): cap 31.80 KB unchanged, recorded minified 96,978 -> 97,013 B (+35 B minified over next's record, measured locally on linux; every boundary-carrying scenario pays the same +38–52 B, inside its recorded minified except this one, which sat at its cap). A boundary's readers become a reader -> source map, so an error boundary waits on what threw only while a reader that caught it is alive. Correctness (Ryan's ruling on #4373). Recorded minified = measured.
2663+
// An Errored heals when the last reader that caught its error is disposed (#4373, 2026-10-28, over next @ 6b792a95, after #4355; re-recorded over next @ b68942ca): cap 31.80 KB unchanged, recorded minified 96,978 -> 97,023 B (+45 B minified over next's record, measured locally on linux; every boundary-carrying scenario pays the same +38–52 B, inside its recorded minified except this one, which sat at its cap). A boundary's readers become a reader -> source map, so an error boundary waits on what threw only while a reader that caught it is alive. Correctness (Ryan's ruling on #4373). Recorded minified = measured.
26642664
limit: "31.80 KB",
2665-
capMinified: 97013,
2665+
capMinified: 97023,
26662666
alias
26672667
},
26682668
{
@@ -5739,9 +5739,9 @@ module.exports = [
57395739
// Bug-fix batch (2026-10-26, over next @ 95dd480f): 41.47 KB -> 41.56 KB, recorded minified 123,120 -> 123,192 B (+72 B), measured in CI at 41,547 B brotli. Same growth as the live floor: the 2026-10-26 bug-fix batch: #4279 hydrated Errored runs its content in the hydration pass (+82 B minified), #4281 latest()-first throw (+51), #4280 derived store follows a memo's pending/errors (+15), #4277 outer boundary recovers after an inner rethrow (+11), #4278 per-key isPending (+11), net of #4261 moveBefore (-39) and layout. Accepted by the maintainer (2026-10-26). Cap at measured + 10 B rounded up to 0.01 KB; recorded minified = measured.
57405740
// Off-screen fallback disposed in the pass that picks content (#4282 / #4268, 2026-10-26, over next @ fbd375d1): cap 41.56 KB unchanged, recorded minified 123,192 -> 123,216 B (+24 B; +24 B over next), measured in CI at 41,531 B brotli. A re-armed Loading disposes a fallback its committed output does not show in that pass, so the fallback's pending render effects stop holding the frame. Size-Exception accepted by the maintainer (2026-10-26). Cap at measured + 10 B rounded up to 0.01 KB, never lowered; recorded minified = measured.
57415741
// An isPending() probe wakes a dormant memo outside its window (#4366, 2026-10-28, over next @ 5f60713a): cap 41.56 KB unchanged, recorded minified 123,216 -> 123,182 B (+6 B minified over next), measured locally (linux) at 41,831 B brotli. A lazy or dormant memo (an unowned memo left with no reader) woken by a read inside `isPending`/`latest` recomputed inside the probe's window, so it derived from its sources' committed values; the wake now runs outside it, as a pull does (A31). Correctness. Recorded minified = measured; CI re-bases.
5742-
// An Errored heals when the last reader that caught its error is disposed (#4373, 2026-10-28, re-recorded over next @ b68942ca): cap 41.56 KB unchanged, recorded minified 123,182 -> 123,218 B (+36 B minified over next's record), measured locally (linux) at 41,866 B brotli. A boundary's readers become a reader -> source map, so an error boundary waits on what threw only while a reader that caught it is alive. Correctness (Ryan's ruling on #4373). Recorded minified = measured; CI re-bases.
5742+
// An Errored heals when the last reader that caught its error is disposed (#4373, 2026-10-28, re-recorded over next @ b68942ca): cap 41.56 KB unchanged, recorded minified 123,182 -> 123,228 B (+46 B minified over next's record), measured locally (linux) at 41,856 B brotli. A boundary's readers become a reader -> source map, so an error boundary waits on what threw only while a reader that caught it is alive. Correctness (Ryan's ruling on #4373). Recorded minified = measured; CI re-bases.
57435743
limit: "41.56 KB",
5744-
capMinified: 123218,
5744+
capMinified: 123228,
57455745
alias: pageAlias
57465746
},
57475747
{
@@ -6121,9 +6121,9 @@ module.exports = [
61216121
// Bug-fix batch (2026-10-26, over next @ 95dd480f): 47.01 KB -> 47.11 KB, recorded minified 140,402 -> 140,456 B (+54 B), measured in CI at 47,099 B brotli. Same growth as the live floor: the 2026-10-26 bug-fix batch: #4279 hydrated Errored runs its content in the hydration pass (+82 B minified), #4281 latest()-first throw (+51), #4280 derived store follows a memo's pending/errors (+15), #4277 outer boundary recovers after an inner rethrow (+11), #4278 per-key isPending (+11), net of #4261 moveBefore (-39) and layout. Accepted by the maintainer (2026-10-26). Cap at measured + 10 B rounded up to 0.01 KB; recorded minified = measured.
61226122
// Off-screen fallback disposed in the pass that picks content (#4282 / #4268, 2026-10-26, over next @ fbd375d1): 47.11 KB -> 47.16 KB, recorded minified 140,456 -> 140,480 B (+24 B; +24 B over next), measured in CI at 47,148 B brotli. A re-armed Loading disposes a fallback its committed output does not show in that pass, so the fallback's pending render effects stop holding the frame. Size-Exception accepted by the maintainer (2026-10-26). Cap at measured + 10 B rounded up to 0.01 KB, never lowered; recorded minified = measured.
61236123
// An isPending() probe wakes a dormant memo outside its window (#4366, 2026-10-28, over next @ 5f60713a): cap 47.16 KB unchanged, recorded minified 140,480 -> 140,442 B (+24 B minified over next), measured locally (linux) at 47,465 B brotli. A lazy or dormant memo (an unowned memo left with no reader) woken by a read inside `isPending`/`latest` recomputed inside the probe's window, so it derived from its sources' committed values; the wake now runs outside it, as a pull does (A31). Correctness. Recorded minified = measured; CI re-bases.
6124-
// An Errored heals when the last reader that caught its error is disposed (#4373, 2026-10-28, re-recorded over next @ b68942ca): cap 47.16 KB unchanged, recorded minified 140,442 -> 140,475 B (+33 B minified over next's record), measured locally (linux) at 47,480 B brotli. A boundary's readers become a reader -> source map, so an error boundary waits on what threw only while a reader that caught it is alive. Correctness (Ryan's ruling on #4373). Recorded minified = measured; CI re-bases.
6124+
// An Errored heals when the last reader that caught its error is disposed (#4373, 2026-10-28, re-recorded over next @ b68942ca): cap 47.16 KB unchanged, recorded minified 140,442 -> 140,485 B (+43 B minified over next's record), measured locally (linux) at 47,463 B brotli. A boundary's readers become a reader -> source map, so an error boundary waits on what threw only while a reader that caught it is alive. Correctness (Ryan's ruling on #4373). Recorded minified = measured; CI re-bases.
61256125
limit: "47.16 KB",
6126-
capMinified: 140475,
6126+
capMinified: 140485,
61276127
alias: pageAlias,
61286128
conditions: solidConditions,
61296129
compile: { hydratable: true }

0 commit comments

Comments
 (0)