Skip to content

Commit e49b0c7

Browse files
ryansolidclaude
andauthored
fix(signals): a derived store's propagated error reaches its readers once (#4463)
* fix(signals): a derived store's propagated error reaches its readers once propagateStatus handed the derive's family a status without its error, so errorFamily's same-error skip could not apply and a sync derive over a sync memo re-ran its reader's error arm twice in one flush (#4457 review). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2 * chore(size): re-measure over next @ 131ceb8; type the family status error Raise the base + router and compiled hydrating caps (brotli layout from +2 B minified) and give StoreFamily.st its error parameter. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2 --------- Co-authored-by: Claude <[email protected]>
1 parent 131ceb8 commit e49b0c7

6 files changed

Lines changed: 60 additions & 10 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 sync derived store over a failing sync memo hands each new error to its readers once per flush, not twice: the error a source propagates to the derive now reaches the family's dedupe.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1059,7 +1059,7 @@ export function propagateStatus(el: Computed<any>, status: number, error: any):
10591059
notifyStatus(sub, status, error);
10601060
// A derived store's derive (store/projection.ts): marked, not re-run —
10611061
// its leaves' readers are not its dependents, so the family walks them.
1062-
(sub as any).fam?.st(status);
1062+
(sub as any).fam?.st(status, error);
10631063
}
10641064
});
10651065
}

‎packages/signals/src/store/projection.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,11 @@ function settleFamily(fam: StoreFamily): void {
205205
/** A source's status reached the derive by propagation (core
206206
* `propagateStatus`), its pass not re-run: the family learns it as from the
207207
* pass's own throw. */
208-
function familyStatus(this: StoreFamily, status: number): void {
208+
function familyStatus(this: StoreFamily, status: number, error?: unknown): void {
209209
if (status & STATUS_PENDING) wakeFamily(this);
210-
// (No error to compare: core propagates to the derive only an error it does
211-
// not already carry, so its readers learn it here first.)
212-
else if (status & STATUS_ERROR) errorFamily(this);
210+
// The error rides along: a reader the derive's own pass already handed it
211+
// (a sync derive re-run in the same flush) is not handed it again.
212+
else if (status & STATUS_ERROR) errorFamily(this, error);
213213
}
214214

215215
function forEachFamilyNode(fam: StoreFamily, fn: (n: Signal<any>) => void): void {

‎packages/signals/src/store/target.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export interface StoreFamily {
4141
* per-leaf chain; a target leaves it with its last node. */
4242
live: Set<StoreTarget>;
4343
/** A source's status reaching the derive by propagation (`familyStatus`). */
44-
st?: (status: number) => void;
44+
st?: (status: number, error?: unknown) => void;
4545
shallow?: boolean;
4646
/** Derive run counter (proj R37): the run whose draft is live. */
4747
run?: number;

‎packages/signals/tests/derived-store-error-delivered-once.test.ts‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,46 @@ for (const kind of ["optimistic", "store"] as const)
178178
await tick();
179179
expect(log).toEqual(["v 0", "ERR undefined"]);
180180
});
181+
182+
// A sync derive over a sync memo learns a new error twice in one flush: by
183+
// propagation (core `propagateStatus` -> `familyStatus`) and by its own pass
184+
// re-run against it. The second hand-off carries the same error, so the
185+
// reader's error arm runs once per error.
186+
for (const kind of ["optimistic", "store"] as const)
187+
it(`${kind === "store" ? "a createStore(fn)" : "an optimistic store's"} sync derive over a failing sync memo delivers each error once`, async () => {
188+
const log: string[] = [];
189+
let set!: (v: number) => void;
190+
const E1 = new Error("E1");
191+
const E2 = new Error("E2");
192+
createRoot(() => {
193+
const [n, s] = createSignal(0);
194+
set = s;
195+
const m = createMemo(() => {
196+
if (n() === 1) throw E1;
197+
if (n() === 2) throw E2;
198+
return n();
199+
});
200+
const make: any = kind === "store" ? createStore : createOptimisticStore;
201+
const [st] = make(
202+
(d: any) => {
203+
d.v = m();
204+
},
205+
{ v: -1 }
206+
);
207+
createEffect(() => (st as any).v, {
208+
effect: (v: any) => {
209+
log.push(`v ${v}`);
210+
},
211+
error: (e: any) => {
212+
log.push(`ERR ${e?.message}`);
213+
}
214+
} as any);
215+
});
216+
await tick();
217+
for (const v of [1, 2, 0]) {
218+
set(v);
219+
flush();
220+
await tick();
221+
}
222+
expect(log).toEqual(["v 0", "ERR E1", "ERR E2", "v 0"]);
223+
});

‎scripts/size/scenarios.js‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4317,8 +4317,9 @@ module.exports = [
43174317
// 0.01 KB; recorded minified never raised.
43184318
// A tick whose writes net to the committed value pends no errored re-run (D-8, async-gen rerun on 5e68925c) (2026-10-30, over next @ 7135a77a): 32.43 -> 32.52 KB, recorded minified 100,748 -> 100,761 B (+13 B), measured locally (linux) at 32,508 B brotli. A signal read whose staging equals its committed value is not a read of the frame's future (`read`): +13 B minified, the rest brotli layout. Correctness. Cap at measured + 10 B rounded up to 0.01 KB; recorded minified = measured.
43194319
// Batch re-record (2026-10-30, over next @ 563b6b0): cap unchanged, recorded minified 100,761 -> 100,797 B (+36 B), measured locally (linux) at 32,473 B brotli. Growth is the 2026-10-30 merges (#4454, #4457, #4461). Recorded minified = measured.
4320-
limit: "32.52 KB",
4321-
capMinified: 100797,
4320+
// A propagated error reaches a derived store's readers once (#4463, 2026-10-30, over next @ 131ceb8c): 32.52 KB -> 32.54 KB, recorded minified 100,797 -> 100,803 B (+6 B), measured locally (linux) at 32,522 B brotli. familyStatus hands the error to errorFamily so a reader its derive's pass already handed it is skipped; the brotli move is layout from +2 B minified. Cap at measured + 10 B rounded up to 0.01 KB; recorded minified = measured.
4321+
limit: "32.54 KB",
4322+
capMinified: 100803,
43224323
alias
43234324
},
43244325
{
@@ -6140,8 +6141,9 @@ module.exports = [
61406141
// at measured + 10 B rounded up to 0.01 KB; recorded minified never raised.
61416142
// Batch re-record (2026-10-30, next @ 32163a9, size job 123956613767): 41.16 KB -> 41.23 KB, recorded minified 125,416 -> 125,435 B, measured in CI at 41,215 B brotli. Growth is the 2026-10-30 merges (#4424, #4436, #4416, #4442); #4416's truncation sweep is the +19 B minified on the hydrating scenarios. Cap at measured + 10 B rounded up to 0.01 KB where over; recorded minified = measured.
61426143
// Batch re-record (2026-10-30, over next @ 563b6b0): cap unchanged, recorded minified 125,435 -> 125,468 B (+33 B), measured locally (linux) at 41,178 B brotli. Growth is the 2026-10-30 merges (#4454, #4457, #4461). Recorded minified = measured.
6143-
limit: "41.23 KB",
6144-
capMinified: 125468,
6144+
// A propagated error reaches a derived store's readers once (#4463, 2026-10-30, over next @ 131ceb8c): 41.23 KB -> 41.25 KB, recorded minified 125,468 -> 125,470 B (+2 B), measured locally (linux) at 41,231 B brotli. familyStatus hands the error to errorFamily so a reader its derive's pass already handed it is skipped; the brotli move is layout from +2 B minified. Cap at measured + 10 B rounded up to 0.01 KB; recorded minified = measured.
6145+
limit: "41.25 KB",
6146+
capMinified: 125470,
61456147
alias: pageAlias,
61466148
conditions: solidConditions,
61476149
compile: { hydratable: true }

0 commit comments

Comments
 (0)