Skip to content

Commit 4038656

Browse files
committed
test: pin #4377 (a memo over latest(m) shows m's error as the leaf does)
Fixed on next by #4364's prune change (#4387): a staged error on an error boundary's source keeps the boundary waiting. These pins fail on next @ 40cde2c (before #4387) and pass from 2861ab8 on. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2
1 parent 9bd9c34 commit 4038656

2 files changed

Lines changed: 121 additions & 0 deletions

File tree

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/**
2+
* #4377 (D-41, F-6): a memo over `latest(m)` shows `m`'s error as a leaf
3+
* `latest(m)` does. `m` is sync; the write that makes it throw is staged with
4+
* the flush, and `latest()` throws the staged error ahead of its commit (the
5+
* verdict lane's work, shown now). The render effect reading the memo held
6+
* the error before `m` did, so `<Errored>`, which waits on what threw, let it
7+
* go as settled; at the commit the leaf re-derived and reached the boundary
8+
* again, the memo's reader did not (an equal status re-notifies nobody) and
9+
* kept `m`'s last value. With a held write the same: the leaf shows the
10+
* error at the reveal, the derivation never did. Fixed by #4364's `prune`
11+
* change (#4387): a staged error on an error boundary's source keeps the
12+
* boundary waiting, so the commit that publishes it finds the boundary still
13+
* waiting on `m`. These pin it.
14+
*/
15+
import { describe, expect, it } from "vitest";
16+
import {
17+
action,
18+
createErrorBoundary,
19+
createMemo,
20+
createRenderEffect,
21+
createRoot,
22+
createSignal,
23+
flush,
24+
latest
25+
} from "../src/index.js";
26+
27+
const tick = async () => {
28+
await new Promise(r => setTimeout(r, 0));
29+
flush();
30+
};
31+
32+
type Shape = "leaf" | "derive" | "derive2" | "plain";
33+
34+
function scene(shape: Shape) {
35+
const [a, setA] = createSignal(0);
36+
let screen: unknown;
37+
createRoot(() => {
38+
const m = createMemo(() => {
39+
if (a() === 1) throw new Error("boom");
40+
return a();
41+
});
42+
const d = createMemo(() => latest(m));
43+
const d2 = createMemo(() => d());
44+
const read = { leaf: () => latest(m), derive: d, derive2: d2, plain: m }[shape];
45+
// <Errored fallback="[ERR]"><span>{read()}</span></Errored>
46+
const out = createErrorBoundary(
47+
() => {
48+
createRenderEffect(read, v => void (screen = v));
49+
return "content";
50+
},
51+
() => "[ERR]"
52+
);
53+
createRenderEffect(out, v => void (v === "[ERR]" && (screen = v)));
54+
});
55+
flush();
56+
expect(screen).toBe(0);
57+
return { setA, screen: () => screen };
58+
}
59+
60+
describe("a memo over latest(m) shows m's sync error as the leaf does (#4377)", () => {
61+
for (const shape of ["leaf", "derive", "derive2", "plain"] as const) {
62+
it(`${shape}: a plain write`, () => {
63+
const s = scene(shape);
64+
s.setA(1);
65+
flush();
66+
expect(s.screen()).toBe("[ERR]");
67+
});
68+
69+
it(`${shape}: a held write shows the error at the reveal`, async () => {
70+
const s = scene(shape);
71+
let release!: () => void;
72+
action(function* () {
73+
s.setA(1);
74+
yield new Promise<void>(r => (release = r));
75+
})();
76+
flush();
77+
await tick();
78+
expect(s.screen()).toBe(0);
79+
release();
80+
await tick();
81+
await tick();
82+
expect(s.screen()).toBe("[ERR]");
83+
});
84+
}
85+
});
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* @jsxImportSource @solidjs/web
3+
* @vitest-environment jsdom
4+
*/
5+
// #4377 (async-app generator, pair E9): `latest(m)` read in a memo shows
6+
// `m`'s error as the same read at the leaf does. The signals-side pins are
7+
// `packages/signals/tests/latest-derived-sync-error-4377.test.ts`.
8+
import { describe, expect, test } from "vitest";
9+
import { createMemo, createSignal, Errored, flush, latest } from "solid-js";
10+
import { render } from "../src/index.js";
11+
12+
describe("a memo over latest(m) when m starts throwing (#4377)", () => {
13+
for (const shape of ["leaf", "derive"] as const)
14+
test(shape, () => {
15+
const div = document.createElement("div");
16+
const [a, setA] = createSignal(0);
17+
const dispose = render(() => {
18+
const m = createMemo(() => {
19+
if (a() === 1) throw new Error("boom");
20+
return a();
21+
});
22+
const d = createMemo(() => latest(m));
23+
return (
24+
<Errored fallback={() => "[ERR]"}>
25+
<span>{shape === "leaf" ? latest(m) : d()}</span>
26+
</Errored>
27+
);
28+
}, div);
29+
flush();
30+
expect(div.innerHTML).toBe("<span>0</span>");
31+
setA(1);
32+
flush();
33+
expect(div.innerHTML).toBe("[ERR]");
34+
dispose();
35+
});
36+
});

0 commit comments

Comments
 (0)