Skip to content

Commit 62bf4c4

Browse files
ryansolidclaude
andauthored
fix(signals): a pending memo nothing reads holds no fresh Loading under a held mount (#4542) (#4554)
* fix(signals): a pending memo nothing reads holds no fresh Loading under a held mount (#4542) A first pass that reads a held node and is left pending is held with the hold (its answer is the hold's, and a render effect that reads it joins). The trailing block also offered it to `freshHook`, so a fresh <Loading> caught the memo as a reader and stayed on its fallback until it settled, forever for a memo that never does, though no render effect reads it. Only an effect is caught now. A derivation left pending is held but reaches no boundary (Reader, D-12: membership is the render effect's position), and the commit waits for it only through a render effect that reads it (`blockedBy`). The #3540 reader counts drop the memo accordingly: in flight the memo content now counts as its binding alone, as held did. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2 * test(web): import JSX from @solidjs/web in the #4542 spec solid-js does not export the JSX type, so @solidjs/web#test-types failed. 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 65da5de commit 62bf4c4

4 files changed

Lines changed: 140 additions & 21 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+
fix(signals): a pending memo nothing reads no longer holds a fresh `<Loading>` when its subtree mounts under a held update (#4542)

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -976,10 +976,14 @@ export function recompute(el: Computed<any>, create: boolean = false): void {
976976
// and it is held all the same — its answer reveals no earlier than the
977977
// hold's commit (D-12) — but the hold does not wait for it: its only
978978
// readers are behind the fallback (`_hidden`; F-4, #3540). A boundary
979-
// re-armed by `on` owns what it collects outright (D-14): not held.
979+
// re-armed by `on` owns what it collects outright (D-14): not held. Only
980+
// an effect is caught: a derivation left pending is no reader (Reader,
981+
// D-12) — held, so its answer is the hold's and a render effect reading
982+
// it joins, but it reaches no boundary, and the commit waits for it only
983+
// through such a reader (`blockedBy`, #4542).
980984
if (create && lane === null && joined && el._statusFlags & STATUS_PENDING) {
981985
const t = flushTransaction ?? passTx;
982-
if (t && !t._lane && freshHook?.(el) !== CAUGHT_REARMED) holdNode(el, t);
986+
if (t && !t._lane && (!isEffect || freshHook?.(el) !== CAUGHT_REARMED)) holdNode(el, t);
983987
}
984988
// Dependencies are the committed frame's until it is replaced (A30, #3410):
985989
// a pass that staged its value leaves the previous pass's tail linked for

‎packages/signals/tests/loading-fallback-in-flush-3540.test.ts‎

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,9 @@ describe("#3540: the catcher is whoever `catchStatus` would catch at — at any
407407
// its pending status is caught again by the normal path: one reader more
408408
// than next on each boundary passed until the commit, none after it. A
409409
// render effect born held (content bound) is recorded at its staging, as
410-
// one in flight is: held or in flight alike.
410+
// one in flight is: held or in flight alike. A memo left pending is held
411+
// but never caught (no reader of its own, D-12, #4542): in flight, as
412+
// held, the memo content counts as its binding alone.
411413
const expected: Record<string, string[]> = {
412414
// The ancestor catches, as pre-L2 (which also runs the binding behind
413415
// the fallback: `text fresh 0` — L2 holds a run behind a fallback,
@@ -426,13 +428,13 @@ describe("#3540: the catcher is whoever `catchStatus` would catch at — at any
426428
"gate gate · open p · outer outer · text fresh 1"
427429
],
428430
"unrevealed flight memo": [
429-
" | o3 i2",
431+
" | o2 i1",
430432
"holder 1 | o1 i0",
431433
" | o1 i0",
432434
"gate gate · open fresh 1 · outer outer"
433435
],
434436
"unrevealed flight bound": [
435-
" | o3 i2",
437+
" | o2 i1",
436438
"holder 1 | o1 i0",
437439
" | o1 i0",
438440
"gate gate · open p · outer outer · text fresh 1"
@@ -456,13 +458,13 @@ describe("#3540: the catcher is whoever `catchStatus` would catch at — at any
456458
""
457459
],
458460
"rearmed outer flight memo": [
459-
"outer outer fallback | o2 i2",
461+
"outer outer fallback | o1 i1",
460462
"holder 1 · open fresh 1 · outer outer | o0 i0",
461463
" | o0 i0",
462464
""
463465
],
464466
"rearmed outer flight bound": [
465-
"outer outer fallback | o2 i2",
467+
"outer outer fallback | o1 i1",
466468
"holder 1 · open p · outer outer · text fresh 1 | o0 i0",
467469
" | o0 i0",
468470
""
@@ -482,13 +484,13 @@ describe("#3540: the catcher is whoever `catchStatus` would catch at — at any
482484
""
483485
],
484486
"rearmed flight memo": [
485-
"inner inner fallback | i2",
487+
"inner inner fallback | i1",
486488
"holder 1 · inner inner · open fresh 1 | i0",
487489
" | i0",
488490
""
489491
],
490492
"rearmed flight bound": [
491-
"inner inner fallback | i2",
493+
"inner inner fallback | i1",
492494
"holder 1 · inner inner · open p · text fresh 1 | i0",
493495
" | i0",
494496
""
@@ -500,13 +502,13 @@ describe("#3540: the catcher is whoever `catchStatus` would catch at — at any
500502
// (The born-held memo the mounting flush's hold owns is not recorded:
501503
// nothing catches it, D-13.)
502504
"plain held bound": [" | i1", "open p · text fresh 1 · x 1 | i0", " | i0", ""],
503-
"plain flight memo": [" | i2", "holder 1 · open fresh 1 | i0", " | i0", ""],
504-
"plain flight bound": [" | i2", "holder 1 · open p · text fresh 1 | i0", " | i0", ""],
505+
"plain flight memo": [" | i1", "holder 1 · open fresh 1 | i0", " | i0", ""],
506+
"plain flight bound": [" | i1", "holder 1 · open p · text fresh 1 | i0", " | i0", ""],
505507
"revealed held memo": [" | o1 i1", "open fresh 1 · x 1 | o0 i0", " | o0 i0", ""],
506508
"revealed held bound": [" | o1 i1", "open p · text fresh 1 · x 1 | o0 i0", " | o0 i0", ""],
507-
"revealed flight memo": [" | o2 i2", "holder 1 · open fresh 1 | o0 i0", " | o0 i0", ""],
509+
"revealed flight memo": [" | o1 i1", "holder 1 · open fresh 1 | o0 i0", " | o0 i0", ""],
508510
"revealed flight bound": [
509-
" | o2 i2",
511+
" | o1 i1",
510512
"holder 1 · open p · text fresh 1 | o0 i0",
511513
" | o0 i0",
512514
""
@@ -676,14 +678,14 @@ describe("#3540: the catcher is whoever `catchStatus` would catch at — at any
676678
expect(out).toEqual(
677679
withInner
678680
? [
679-
"inner inner fallback · open true | o0 f2",
680-
`${x1} | o0 f2`,
681+
"inner inner fallback · open true | o0 f1",
682+
`${x1} | o0 f1`,
681683
"inner p · text fresh 1 | o0 f0",
682684
" | o0 f0"
683685
]
684686
: [
685-
" | o2 f2",
686-
" | o2 f2",
687+
" | o1 f1",
688+
" | o1 f1",
687689
[x1, "open p", "text fresh 1"].sort().join(" · ") + " | o0 f0",
688690
" | o0 f0"
689691
]
@@ -736,11 +738,11 @@ describe("#3540: the boundary scope — committed content, held mounts, no catch
736738
// committed or staged value (`content 0` in a flush, a tear under A29;
737739
// `content 1` from mainline); `next` reports the boundary pending while
738740
// it holds the mount. (Readers: the content's catch walk records it once
739-
// more than the normal path, until the commit; in flight every first pass
740-
// under the boundary — the memo, the children, the tree — is caught and
741-
// held with the hold, D-12.)
741+
// more than the normal path, until the commit; in flight the first passes
742+
// under the boundary are held with the hold, and only render effects are
743+
// caught — a pending memo is no reader of its own, D-12, #4542.)
742744
const observe = (source: Source, x1: string) => [
743-
`view fallback | readers=${source === "held" ? 2 : 3} view=false m=false latest=${source === "held" ? "content 1" : "throws NotReadyError"}`,
745+
`view fallback | readers=${source === "held" ? 2 : 1} view=false m=false latest=${source === "held" ? "content 1" : "throws NotReadyError"}`,
744746
`${[x1, "view content 1"].sort().join(" · ")} | readers=0 view=false m=false latest=content 1`,
745747
" | readers=0 view=false m=false latest=content 1"
746748
];
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/**
2+
* @jsxImportSource @solidjs/web
3+
* @vitest-environment jsdom
4+
*/
5+
// #4542: a pending async memo nothing reads holds no boundary (F-2 Reader),
6+
// also when its subtree mounts under a held update and an inner Show's
7+
// condition reads a memo.
8+
import { describe, expect, test } from "vitest";
9+
import { render, type JSX } from "@solidjs/web";
10+
import { createMemo, createSignal, Loading, Show } from "solid-js";
11+
12+
const wait = (ms: number) => new Promise(r => setTimeout(r, ms));
13+
14+
type Shape = "held + memo condition" | "not held" | "held + when={true}";
15+
16+
async function navigate(shape: Shape): Promise<string> {
17+
const [path, setPath] = createSignal("a");
18+
const matched = createMemo(() => {
19+
const p = path();
20+
return p === "a" || shape === "not held" ? p : wait(10).then(() => p);
21+
});
22+
23+
function Page() {
24+
const local = createMemo(() => 1);
25+
createMemo(() => (local(), new Promise<never>(() => {})));
26+
return <p>B</p>;
27+
}
28+
function Boundary(props: { children: JSX.Element }) {
29+
const cond = createMemo(() => undefined as boolean | undefined);
30+
return (
31+
<Loading fallback={<i>inner</i>}>
32+
<Show when={shape === "held + when={true}" ? true : (cond() ?? true)}>
33+
{props.children}
34+
</Show>
35+
</Loading>
36+
);
37+
}
38+
39+
const el = document.createElement("div");
40+
const dispose = render(
41+
() => (
42+
<Loading fallback="root">
43+
<Show when={matched() === "b"} fallback={<p>A</p>}>
44+
<Boundary>
45+
<Page />
46+
</Boundary>
47+
</Show>
48+
</Loading>
49+
),
50+
el
51+
);
52+
await wait(30);
53+
expect(el.textContent).toBe("A");
54+
setPath("b");
55+
await wait(100);
56+
const text = el.textContent ?? "";
57+
dispose();
58+
return text;
59+
}
60+
61+
// The same mount whose page reads an async memo: the read holds, the
62+
// unread one never did (frames unchanged by the fix).
63+
async function navigateRead(shape: Shape): Promise<string[]> {
64+
const [path, setPath] = createSignal("a");
65+
const matched = createMemo(() => {
66+
const p = path();
67+
return p === "a" || shape === "not held" ? p : wait(10).then(() => p);
68+
});
69+
function Page() {
70+
const local = createMemo(() => 1);
71+
const d = createMemo(() => (local(), wait(40).then(() => "D")));
72+
return <p>B{d()}</p>;
73+
}
74+
const el = document.createElement("div");
75+
const dispose = render(
76+
() => (
77+
<Loading fallback="root">
78+
<Show when={matched() === "b"} fallback={<p>A</p>}>
79+
<Page />
80+
</Show>
81+
</Loading>
82+
),
83+
el
84+
);
85+
await wait(30);
86+
setPath("b");
87+
const frames: string[] = [el.textContent!];
88+
for (let i = 0; i < 24; i++) {
89+
await wait(5);
90+
const t = el.textContent!;
91+
if (frames[frames.length - 1] !== t) frames.push(t);
92+
}
93+
dispose();
94+
return frames;
95+
}
96+
97+
describe("#4542 unread pending memo under a held mount", () => {
98+
test.each<Shape>(["not held", "held + when={true}", "held + memo condition"])(
99+
"%s: a pending memo nothing reads does not hold the page's <Loading>",
100+
async shape => {
101+
expect(await navigate(shape)).toBe("B");
102+
}
103+
);
104+
105+
test("held: a page that reads an async memo still holds the navigation until it lands", async () => {
106+
expect(await navigateRead("held + memo condition")).toEqual(["A", "BD"]);
107+
});
108+
});

0 commit comments

Comments
 (0)