Skip to content

Commit 178605c

Browse files
ryansolidclaude
andauthored
fix(signals): derived-store E3 twin — a landing wakes a reader parked on its error; a first landing is loading, not pending (#4388)
* fix(signals): a derived store's landing wakes a reader parked on its error A render effect reading a derived store whose derive had errored, then recovered through `latest()` into a new flight, never re-ran when that flight landed. Its `Errored` went back to content with the value missing, or its `Loading` stayed on the fallback. A render effect reading the memo the store copies committed the value. Cause: the reader met the error in the derive's pull (`pullFamily`) before any leaf existed, so it observes the derive only. The recovery re-ran the derive into NotReady (the family's wake). The upstream memo's landing then cleared the derive's status, so the landing pass began from status 0 and its commit took it for a settled derive's pass (`wake` 0): no `insertSubs`. The leaves carry nothing to a reader that never read one. Fix: `settleFamily` (a landing after the family's wake) also notifies the derive's own subscribers. Only a landing that follows a wake reaches it, so a settled derive's passes still wake nobody (#4342). Found by the async-gen campaign (seed 3289, E3 store twin): minimized cases 1, 5 and 25 of research/2026-10-28-async-gen-campaign-1.md. Tests: packages/signals/tests/derived-store-recovery-wake.test.ts (action and plain write, memo vs store parity) and packages/web/test/derived-store-recovery-wake.spec.tsx (attribute and text hole). Store engine only: +5 to +6 B minified on the four store scenarios, ledger lines added. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2 * fix(signals): a derived store's first landing is loading, not pending `isPending` of a derived store's key read `true` for one pass at the store's first landing, where the memo the store copies reads `false`. A `<Show when={isPending(...)}>` over the key opened for that pass, and its child met a sibling's error, which reached the root `Errored`. Cause: a sibling derive reading `latest()` gives the landing flush a transaction. The leaf born staged from the never-committed derive's landing is unheld, and core's verdict calls an unheld staging pending under a transaction (`provisionalVerdict`, not final). For a memo born staged core knows it has no committed value, so its first answer is loading, not pending (A19 exc. 1, F-9, D-30); a store leaf carries no status, so the check missed it. #4355 made the same moment serve the staging instead of the seed; this is its verdict half. Fix: in `nodeValue`, a pass reading such a leaf while the family's derive has never committed links it and is served the staging with no verdict (a handler read keeps the staging, as before). The get trap's absent-key path no longer reads the node before `nodeValue` does, which ran the verdict first. Found by the async-gen campaign (seed 3289, E3 store twin): minimized case 34 of research/2026-10-28-async-gen-campaign-1.md. Tests: packages/signals/tests/derived-store-first-landing-verdict.test.ts (the verdict, and a reader gated on it) and packages/web/test/derived-store-first-landing-verdict.spec.tsx (the Show). Store engine only: +19 to +22 B minified on the store scenarios over the wake commit, +17 B on four page scenarios (two of them frozen floors, under their recorded minified; floor-caps.json untouched). Ledger lines added; RULES-INDEX regenerated. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2 * fix(signals): keep read()'s dev diagnostics on a store's first-landing read nodeValue serves a never-committed family's staging without core read(), which also skipped read()'s dev-only side effects for that read: the devtools onRead hook, the foreign-read check and the post-await untracked-read check. Factor them into a dev-only devRead(el) that read() and nodeValue's staged branch both call under __DEV__. Prod output is byte-identical (every size scenario, minified and brotli). 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 cbc0eeb commit 178605c

11 files changed

Lines changed: 436 additions & 10 deletions
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@solidjs/signals": patch
3+
"solid-js": patch
4+
---
5+
6+
`isPending` of a derived store's key no longer reads `true` for one pass at the store's first landing. A first answer is loading, not pending, as it is for the memo the store copies. Before, a `<Show when={isPending(...)}>` over such a key could open for that pass and mount content that was never meant to show.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@solidjs/signals": patch
3+
"solid-js": patch
4+
---
5+
6+
A render effect reading a derived store that errored, then recovered through `latest()` into a new flight, now re-runs when that flight lands. Before, it never re-ran: an `Errored` around it went back to its content with the value missing, or a `Loading` around it stayed on its fallback.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Status legend: **live** stated and standing · **ruled** carries an explicit rul
6363
| A16 | amended | `docs/SPEC-ASYNC-SEMANTICS.md:221` | scheduler.ts×1 | spec-async-semantics.test.ts×1 strict-read-pending-store.test.ts×2 uninitialized-visibility.test.ts×1 visibility-oracle-store.states.ts×2 visibility-oracle.states.ts×2 visibility-oracle.test.ts×1 | [ruled, amended in place 2026-07-06 (promoted from B5)] `isPending` never throws in untracked contexts — (was B5) `isPending` never throws in untracked contexts — thunks that throw real errors or read… |
6464
| A17 | amended | `docs/SPEC-ASYNC-SEMANTICS.md:71` | async.ts×3 constants.ts×1 lanes.ts×7 scheduler.ts×2 verdict.ts×1 map.ts×1 optimistic.ts×1 store.ts×3 | create-deferred-3710.test.ts×1 fuzz-findings-l2.test.ts×6 lane-uninitialized-landing-3648.test.ts×5 optimistic-over-held-row-3796.test.ts×1 optimistic-read-lane-not-transaction-3698.test.ts×2 optimistic-undefined-override.test.ts×1 posture-store-parity.test.ts×1 refresh-await.test.ts×1 reveal-gating-contract.test.ts×3 spec-async-semantics.test.ts×10 createOptimisticStore.test.ts×2 kanban-a17-fixture.test.ts×3 optimistic-list-mutation-matrix.test.ts×1 optimistic-maparray-index-frame-f1.test.ts×1 optimistic-untracked-reads-f3-f5.test.ts×1 signal-store-twins-qd.test.ts×1 treeshake.test.ts×1 until.test.ts×1 visibility-oracle-store.states.ts×24 visibility-oracle-store.test.ts×1 visibility-oracle.states.ts×20 visibility-oracle.test.ts×1 | [ruled, amended in place 2026-07-06 (promoted from C4)] An active override is the displayed value until its transaction commits, and the graph's value until its own source answers — **Statement (curre… |
6565
| A18 | amended | `docs/SPEC-ASYNC-SEMANTICS.md:81` | action.ts×1 async.ts×2 core.ts×3 lanes.ts×8 scheduler.ts×2 types.ts×1 verdict.ts×1 map.ts×1 optimistic.ts×1 projection.ts×1 | body-end-supersession-visibility.test.ts×4 createOptimistic.test.ts×3 l2-fuzz-existing-rules.test.ts×2 lane-contract.test.ts×1 lane-frame-deferred-run-3662.test.ts×1 lane-outside-view.test.ts×1 lane-uninitialized-landing-3648.test.ts×5 optimistic-move-duplicate-3548.test.ts×2 optimistic-read-lane-not-transaction-3698.test.ts×4 posture-store-parity.test.ts×5 spec-async-semantics.test.ts×5 flight-owned-transaction.test.ts×1 lane-authority-twins.test.ts×1 optimistic-list-mutation-matrix.test.ts×1 optimistic-untracked-reads-f3-f5.test.ts×1 signal-store-twins-qd.test.ts×1 unchanged-presence-no-hold-3743.test.ts×2 superseded-before-first-commit.test.ts×4 visibility-oracle-store.states.ts×8 visibility-oracle-store.test.ts×1 visibility-oracle.states.ts×19 visibility-oracle.test.ts×1 | [ruled, amended in place 2026-07-07 (promoted from B4)] An override lives exactly as long as its own transaction; a newer truth from the source supersedes it in the graph immediately, on screen at com… |
66-
| A19 | amended | `docs/SPEC-ASYNC-SEMANTICS.md:149` | async.ts×1 constants.ts×1 core.ts×6 scheduler.ts×2 types.ts×1 verdict.ts×4 store.ts×1 | create-deferred-3710.test.ts×2 fuzz-findings-l2.test.ts×4 lane-uninitialized-landing-3648.test.ts×2 mount-over-foreign-hold-3761.test.ts×2 spec-async-semantics.test.ts×3 derived-presence-async-3726.test.ts×2 superseded-before-first-commit.test.ts×3 uninitialized-visibility.test.ts×1 visibility-oracle-store.states.ts×8 visibility-oracle-store.test.ts×1 visibility-oracle.states.ts×14 visibility-oracle.test.ts×1 write-proposals-3494.test.ts×1 | [ruled, amended in place 2026-07-07 (promoted from C1)] `isPending(x)` ≡ the observable value is not final (three causes) — (was C1 — **partially reverses an earlier decision**) **Definition: `isPendi… |
66+
| A19 | amended | `docs/SPEC-ASYNC-SEMANTICS.md:149` | async.ts×1 constants.ts×1 core.ts×6 scheduler.ts×2 types.ts×1 verdict.ts×4 store.ts×2 | create-deferred-3710.test.ts×2 derived-store-first-landing-verdict.test.ts×1 fuzz-findings-l2.test.ts×4 lane-uninitialized-landing-3648.test.ts×2 mount-over-foreign-hold-3761.test.ts×2 spec-async-semantics.test.ts×3 derived-presence-async-3726.test.ts×2 superseded-before-first-commit.test.ts×3 uninitialized-visibility.test.ts×1 visibility-oracle-store.states.ts×8 visibility-oracle-store.test.ts×1 visibility-oracle.states.ts×14 visibility-oracle.test.ts×1 write-proposals-3494.test.ts×1 | [ruled, amended in place 2026-07-07 (promoted from C1)] `isPending(x)` ≡ the observable value is not final (three causes) — (was C1 — **partially reverses an earlier decision**) **Definition: `isPendi… |
6767
| A20 | superseded | `docs/SPEC-ASYNC-SEMANTICS.md:408` | — | question-scoped-pending.test.ts×2 spec-async-semantics.test.ts×3 createOptimisticStore.test.ts×1 | [superseded 2026-07-13 by A24] (superseded) Optimistic writes announce a store-wide pending — (**SUPERSEDED 2026-07-13 by A24** — the mask is deleted; optimistic writes are verdict-inert. Kept for the… |
6868
| A21 | superseded | `docs/SPEC-ASYNC-SEMANTICS.md:415` | — | question-scoped-pending.test.ts×3 spec-async-semantics.test.ts×3 | [superseded 2026-07-13 by A24] (superseded) The store-wide mask — (**SUPERSEDED 2026-07-13 by A24** — the store-wide mask is deleted with the mask model; nothing silences a new question. The effective… |
6969
| A22 | amended | `docs/SPEC-ASYNC-SEMANTICS.md:229` | store.ts×1 | createProjection.draft-lifetime-3585.test.ts×1 spec-async-semantics.test.ts×1 visibility-oracle-store.states.ts×1 | [ruled, amended in place 2026-07-08] Pending is per-node; store-wide only for the firewall's own work — **Pending is per-node: store-wide verdicts exist only as the firewall's own in-flight work (A9) … |

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1832,10 +1832,16 @@ export function pullComputed(owner: Computed<any>, c: Computed<any>): void {
18321832
if (height >= c._height && owner._parent !== c) c._height = height + 1;
18331833
}
18341834

1835-
export function read<T>(el: Signal<T> | Computed<T>): T {
1836-
if (__DEV__) DEV.hooks.onRead?.(el);
1837-
if (__DEV__ && !tracking) checkForeignRead();
1838-
if (__DEV__ && asyncTailFlights !== 0 && !tracking && untrackDepth === 0)
1835+
/**
1836+
* Dev only: a read's diagnostics — the devtools read hook, the foreign-read
1837+
* check and the post-await untracked-read check. Every caller guards with
1838+
* `__DEV__`: `read` here, and a store leaf's read that is served without
1839+
* `read` (`nodeValue`'s first landing), so no read goes unseen in dev.
1840+
*/
1841+
export function devRead(el: Signal<any> | Computed<any>): void {
1842+
DEV.hooks.onRead?.(el);
1843+
if (!tracking) checkForeignRead();
1844+
if (asyncTailFlights !== 0 && !tracking && untrackDepth === 0)
18391845
checkPostAwaitRead(
18401846
el,
18411847
el,
@@ -1844,6 +1850,10 @@ export function read<T>(el: Signal<T> | Computed<T>): T {
18441850
((el as any)._statusFlags & (STATUS_PENDING | STATUS_UNINITIALIZED)) ===
18451851
(STATUS_PENDING | STATUS_UNINITIALIZED)
18461852
);
1853+
}
1854+
1855+
export function read<T>(el: Signal<T> | Computed<T>): T {
1856+
if (__DEV__) devRead(el);
18471857

18481858
let c = context;
18491859
if ((c as Root)?._root) c = (c as Root)._parentComputed;

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,10 @@ function settleFamily(fam: StoreFamily): void {
191191
forEachFamilyNode(fam, n => {
192192
if (n._subs !== null) settlePendingSource(n as unknown as Computed<any>, fw);
193193
});
194+
// The landing is the derive's change for a reader parked on the derive
195+
// itself, whatever status the landing pass began from (an errored derive
196+
// re-asked: a reader that met the error has no leaf to learn it from).
197+
insertSubs(fw);
194198
}
195199

196200
/** A source's status reached the derive by propagation (core

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import {
5050
import {
5151
captureWriteSnapshot,
5252
context,
53+
devRead,
5354
disposalDepth,
5455
isEqual,
5556
notePromotedWrite,
@@ -64,6 +65,7 @@ import {
6465
stagedScreen,
6566
strictRead,
6667
strictReadActive,
68+
tracking,
6769
untrack,
6870
untrackDepth,
6971
verdict
@@ -78,7 +80,7 @@ import {
7880
warnStrictReadUntracked
7981
} from "../core/dev.js";
8082
import { signalHook } from "../core/identities.js";
81-
import { setSlotUnobserved } from "../core/graph.js";
83+
import { link, setSlotUnobserved } from "../core/graph.js";
8284
import { getObserver, getOwner } from "../core/owner.js";
8385
import { checkForeignRead } from "../core/copies.js";
8486
import { insertIntoHeap } from "../core/heap.js";
@@ -1749,14 +1751,21 @@ function changedBetween(
17491751
* verdict reader, #4355) is served the staging, as for a memo born staged
17501752
* (core `serve`). */
17511753
function nodeValue(node: Signal<any>, backing: any, target: StoreTarget): any {
1752-
let v = readNode(node);
1754+
let v;
17531755
if (
17541756
node._pendingValue !== NOT_PENDING &&
17551757
!(node._config & CONFIG_HELD) &&
17561758
target.fam !== null &&
17571759
(context === null || target.fam.node?._statusFlags! & STATUS_UNINITIALIZED)
1758-
)
1760+
) {
1761+
// A pass over a derive that has never committed: the staging is its
1762+
// first answer, not a change — linked and served with no verdict (a
1763+
// first landing is loading, not pending: A19 exc. 1, F-9, as for a memo
1764+
// born staged; core's verdict would call the leaf's staging pending).
1765+
if (__DEV__) devRead(node); // read()'s dev diagnostics, which this read skips
1766+
if (context !== null && tracking) link(node, context as Computed<any>);
17591767
v = node._pendingValue;
1768+
} else v = readNode(node);
17601769
return v === (FORCE as any) ? backing : v;
17611770
}
17621771

@@ -2145,7 +2154,8 @@ const traps: ProxyHandler<StoreTarget> = {
21452154
// Reading a currently-absent own key subscribes to it (R12) — for any
21462155
// target OUTSIDE its own draft scope, even mid-setter (#3037, above).
21472156
if (v === undefined && !inDraft(target)) {
2148-
if (getObserver() !== null) readNode(getNode(target, key, accProbe));
2157+
// (`nodeValue` reads — and links — the node it creates.)
2158+
if (getObserver() !== null) getNode(target, key, accProbe);
21492159
const node = target.n?.[key];
21502160
if (node) {
21512161
const nv = nodeValue(node, undefined, target);
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
import { afterEach, describe, expect, it } from "vitest";
2+
import { NOT_PENDING } from "../src/core/constants.js";
3+
import { $TARGET } from "../src/store/store.js";
4+
import {
5+
DEV,
6+
createErrorBoundary,
7+
createLoadingBoundary,
8+
createMemo,
9+
createRenderEffect,
10+
createRoot,
11+
createSignal,
12+
createStore,
13+
flush,
14+
isPending,
15+
latest
16+
} from "../src/index.js";
17+
18+
// async-gen campaign 1 (seed 3289), E3 store twin, minimized case 34:
19+
// [s0=0 m0=async(s0+s0) m1=memo(latest(m0)+s0 !%4=1)]
20+
// <Show when=isPending(m0) fb><span split[m1()]></span></Show> :: s0=1
21+
// A derived store's first landing is its first answer: loading before it,
22+
// final at it — never pending (F-9, D-30, A19 exc. 1), exactly as for the
23+
// memo it copies. A sibling derive reading `latest(m0)` gives the landing
24+
// flush a transaction; the leaf born staged from the landing then answered
25+
// `isPending` true for one pass, which opened the gate onto a reader of the
26+
// poisoned `m1`, whose error reached the root boundary.
27+
describe("a derived store's first landing is not pending", () => {
28+
const settle = async () => {
29+
for (let i = 0; i < 4; i++) {
30+
for (let j = 0; j < 6; j++) await Promise.resolve();
31+
flush();
32+
await new Promise(r => setTimeout(r, 0));
33+
}
34+
flush();
35+
};
36+
37+
afterEach(() => {
38+
DEV!.hooks.onRead = undefined;
39+
});
40+
41+
// `stagedLeafReads` (dev): counts devtools reads of store 0's leaf `v`
42+
// while it holds a staging — the first landing's reads, which `nodeValue`
43+
// serves without core `read`.
44+
async function run(via: "memo" | "store", gated: boolean, stagedLeafReads?: { n: number }) {
45+
const log: string[] = [];
46+
const flights: (() => void)[] = [];
47+
let set!: (v: number) => void;
48+
let dispose!: () => void;
49+
createRoot(d => {
50+
dispose = d;
51+
const [s, setS] = createSignal(0);
52+
set = setS;
53+
const m0 = createMemo(() => {
54+
const v = 1 + 2 * s();
55+
return new Promise<number>(r => flights.push(() => r(v)));
56+
});
57+
const m1 = createMemo(() => {
58+
const v = 1 + latest(m0) + s();
59+
if (v % 4 === 1) throw new Error("m1:" + v);
60+
return v;
61+
});
62+
let view0: () => any = m0;
63+
let view1: () => any = m1;
64+
if (via === "store") {
65+
const [st0] = createStore<{ v?: number }>(draft => {
66+
draft.v = m0();
67+
}, {});
68+
const [st1] = createStore<{ v?: number }>(draft => {
69+
draft.v = m1();
70+
}, {});
71+
view0 = () => st0.v;
72+
view1 = () => st1.v;
73+
if (stagedLeafReads)
74+
DEV!.hooks.onRead = n => {
75+
const leaf = (st0 as any)[$TARGET].n?.v;
76+
if (n === leaf && leaf._pendingValue !== NOT_PENDING) stagedLeafReads.n++;
77+
};
78+
}
79+
const out = createErrorBoundary(
80+
() =>
81+
createLoadingBoundary(
82+
() => {
83+
const when = createMemo(() => isPending(view0));
84+
createRenderEffect(when, v => {
85+
log.push(`pending:${v}`);
86+
});
87+
if (gated)
88+
createRenderEffect(
89+
() => (when() ? view1() : "-"),
90+
v => {
91+
log.push(`child:${v}`);
92+
}
93+
);
94+
return "content";
95+
},
96+
() => "loading"
97+
),
98+
() => "error"
99+
);
100+
createRenderEffect(out, v => {
101+
log.push(String(v));
102+
});
103+
});
104+
flush();
105+
set(1);
106+
await settle();
107+
while (flights.length) {
108+
flights.splice(0, 1).forEach(f => f());
109+
await settle();
110+
}
111+
dispose();
112+
return log;
113+
}
114+
115+
it("isPending of the leaf never reads true at the first landing", async () => {
116+
const memo = await run("memo", false);
117+
expect(memo).toEqual(["loading", "pending:false", "content"]);
118+
expect(await run("store", false)).toEqual(memo);
119+
});
120+
121+
it("a reader gated on that verdict never opens onto the sibling's error", async () => {
122+
const memo = await run("memo", true);
123+
expect(memo).toEqual(["loading", "pending:false", "child:-", "content"]);
124+
expect(await run("store", true)).toEqual(memo);
125+
});
126+
127+
it("dev: a staged first-landing read of the leaf still reaches the read hook", async () => {
128+
const stagedLeafReads = { n: 0 };
129+
expect(await run("store", true, stagedLeafReads)).toEqual([
130+
"loading",
131+
"pending:false",
132+
"child:-",
133+
"content"
134+
]);
135+
expect(stagedLeafReads.n).toBeGreaterThan(0);
136+
});
137+
});
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import { describe, expect, it } from "vitest";
2+
import {
3+
action,
4+
createErrorBoundary,
5+
createLoadingBoundary,
6+
createMemo,
7+
createRenderEffect,
8+
createRoot,
9+
createSignal,
10+
createStore,
11+
flush,
12+
latest
13+
} from "../src/index.js";
14+
15+
// async-gen campaign 1 (seed 3289), E3 store twin, minimized case 1:
16+
// [s0=0 m0=memo(s0 !%4=1) m1=async(latest(m0) !%4=3)] <span fx[m1()]></span> :: A(s0=3)
17+
// A derived store over an async memo that reads an errored memo through
18+
// `latest()`. The render effect reading the store met the error in the
19+
// derive's pull, before any leaf existed, so it observes the derive only.
20+
// The recovery re-runs the derive into NotReady (the family's wake), and
21+
// the derive's status is cleared before its landing pass. The landing is
22+
// still the derive's change for that reader (memo parity, F-12/D-39: a new
23+
// answer replaces the error): the reader re-runs and commits the value.
24+
describe("a derived store's landing wakes a reader parked on its error", () => {
25+
const settle = async () => {
26+
for (let i = 0; i < 4; i++) {
27+
for (let j = 0; j < 6; j++) await Promise.resolve();
28+
flush();
29+
await new Promise(r => setTimeout(r, 0));
30+
}
31+
flush();
32+
};
33+
34+
async function run(via: "memo" | "store", how: "action" | "write") {
35+
const log: string[] = [];
36+
const flights: (() => void)[] = [];
37+
let write!: (v: number) => void;
38+
let dispose!: () => void;
39+
createRoot(d => {
40+
dispose = d;
41+
const [s, setS] = createSignal(0);
42+
const m0 = createMemo(() => {
43+
const v = 1 + s();
44+
if (v % 4 === 1) throw new Error("m0:" + v);
45+
return v;
46+
});
47+
const m1 = createMemo(() => {
48+
const v = 1 + latest(m0);
49+
return new Promise<number>(r => flights.push(() => r(v)));
50+
});
51+
let view: () => any = m1;
52+
if (via === "store") {
53+
const [state] = createStore<{ v?: number }>(draft => {
54+
draft.v = m1();
55+
}, {});
56+
view = () => state.v;
57+
}
58+
const act = action(function* (v: number) {
59+
setS(v);
60+
yield new Promise<void>(r => flights.push(r));
61+
});
62+
write = how === "action" ? v => act(v) : setS;
63+
const out = createErrorBoundary(
64+
() =>
65+
createLoadingBoundary(
66+
() => {
67+
createRenderEffect(view, v => {
68+
log.push(`v:${v}`);
69+
});
70+
return "content";
71+
},
72+
() => "loading"
73+
),
74+
() => "error"
75+
);
76+
createRenderEffect(out, v => {
77+
log.push(String(v));
78+
});
79+
});
80+
flush();
81+
write(3);
82+
await settle();
83+
while (flights.length) {
84+
flights.splice(0).forEach(f => f());
85+
await settle();
86+
}
87+
dispose();
88+
return log;
89+
}
90+
91+
for (const how of ["action", "write"] as const) {
92+
it(`${how}: the store's reader commits the recovered value, as the memo's does`, async () => {
93+
const memo = await run("memo", how);
94+
expect(memo).toEqual(["error", "content", "v:5"]);
95+
expect(await run("store", how)).toEqual(memo);
96+
});
97+
}
98+
});

0 commit comments

Comments
 (0)