Skip to content

Commit 0117658

Browse files
ryansolidclaude
andauthored
fix(signals): an unread pending memo does not hold a verdict-mounted Loading (#4203) (#4207)
#4171 (#4166) carried a verdict lane's mount through nested first passes (`laneRoot`) so a render effect the mounted boundary's content creates is held like a direct read. The same `joined` arm also made any nested derivation that read a staging join the hold, including one left pending: the trailing pending-hold block held it and the boundary caught it (`freshHook`). A memo that reads a signal its component wrote during the mount and never settles, with no reader, then kept `<Loading>` on its fallback forever. A nested first pass that is not a render effect and is left pending no longer joins through the mount's staged read: no render effect reaches it yet, so it holds nothing and reaches no boundary (Reader). A render effect that later reads it goes pending and is caught on its own. A settled nested memo, a render effect, and the mount's own first pass (#3851) are held as before. +18 B minified on the lane-engine scenarios. Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2 Co-authored-by: Claude <[email protected]>
1 parent 5c0d190 commit 0117658

4 files changed

Lines changed: 185 additions & 1 deletion

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 `<Loading>` that a verdict reader (`<Show when={latest(x) ?? x()}>`) mounts reveals its content again when a component inside it writes a signal during its mount and creates a memo that reads it and stays pending with no reader: that memo holds nothing and reaches no boundary (#4203, a regression from #4166's fix).

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,15 @@ export function recompute(el: Computed<any>, create: boolean = false): void {
550550
// (markNode(c) in read()) marks the running node as part of ordinary
551551
// bookkeeping, and those marks are correctly discarded here.
552552
missedWake = (el._flags & REACTIVE_MISSED_WAKE) !== 0;
553-
joined = !!(el._flags & (mount ? REACTIVE_JOINED | REACTIVE_STAGED_READ : REACTIVE_JOINED));
553+
// A mount's staged read joins it — except a nested derivation left
554+
// pending: no render effect reaches it yet, so it holds nothing and
555+
// reaches no boundary (Reader, #4203). A reader that does is caught.
556+
joined = !!(
557+
el._flags &
558+
(mount && (prevLane || isEffect || !(el._statusFlags & STATUS_PENDING))
559+
? REACTIVE_JOINED | REACTIVE_STAGED_READ
560+
: REACTIVE_JOINED)
561+
);
554562
// A verdict reader is one for as long as it probes, or reads a memo
555563
// that does (`read`): a pass that did neither (REACTIVE_PROBED, the same
556564
// bit) is an ordinary derivation again.
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/**
2+
* #4203: #4166 carries a verdict lane's mount through nested first passes,
3+
* so a render effect its content creates is held like a direct read. A
4+
* plain memo the content creates is not a render effect: one that reads a
5+
* signal the mount wrote (a staging) and never settles, with no reader,
6+
* holds nothing and reaches no boundary (Reader). Before, it was held, so
7+
* `<Show when={latest(gate) ?? gate()}><Loading>…` never revealed. A memo
8+
* that settles is still held like #4166's render effect.
9+
*/
10+
import { describe, expect, it } from "vitest";
11+
import {
12+
action,
13+
createLoadingBoundary,
14+
createMemo,
15+
createRenderEffect,
16+
createRoot,
17+
createSignal,
18+
flush,
19+
latest,
20+
untrack
21+
} from "../src/index.js";
22+
23+
const settle = async () => {
24+
for (let i = 0; i < 3; i++) {
25+
await new Promise(r => setTimeout(r, 0));
26+
flush();
27+
}
28+
};
29+
30+
describe("#4203: an unread pending memo does not hold a verdict-mounted boundary", () => {
31+
it("the boundary reveals its content", async () => {
32+
let slot: unknown;
33+
createRoot(() => {
34+
const content = () => {
35+
const [version, setVersion] = createSignal(0, { ownedWrite: true });
36+
setVersion(1);
37+
// Never read; never settles.
38+
createMemo(() => {
39+
version();
40+
return new Promise(() => {});
41+
});
42+
return "CHILD";
43+
};
44+
const gate = createMemo(async () => "x");
45+
const outer = createLoadingBoundary(
46+
() => {
47+
// <Show when={latest(gate) ?? gate()}>
48+
const when = createMemo(() => latest(gate) ?? gate());
49+
const condition = createMemo(() => !!when());
50+
const children = createMemo(() =>
51+
condition()
52+
? untrack(() => createLoadingBoundary(content, () => "INNER LOADING"))
53+
: undefined
54+
);
55+
return () => {
56+
const c = children();
57+
return typeof c === "function" ? c() : c;
58+
};
59+
},
60+
() => "OUTER LOADING"
61+
);
62+
createRenderEffect(
63+
() => {
64+
let v: any = outer();
65+
while (typeof v === "function") v = v();
66+
return v;
67+
},
68+
v => {
69+
slot = v;
70+
}
71+
);
72+
});
73+
flush();
74+
await settle();
75+
expect(slot).toBe("CHILD");
76+
});
77+
78+
it("a settled memo the content creates is still held (#4166)", async () => {
79+
const [x, setX] = createSignal(0);
80+
let screenX: unknown;
81+
let inner: unknown;
82+
let slot: unknown;
83+
createRoot(() => {
84+
createRenderEffect(x, v => {
85+
screenX = v;
86+
});
87+
// <Show when={latest(x) > 0}><Loading><p>{double()}</p></Loading></Show>
88+
const content = () => {
89+
const double = createMemo(() => x() * 2);
90+
createRenderEffect(double, v => {
91+
inner = v;
92+
});
93+
return "p";
94+
};
95+
const when = createMemo(() => latest(x) > 0);
96+
const children = createMemo(() =>
97+
when() ? untrack(() => createLoadingBoundary(content, () => "pending")) : "closed"
98+
);
99+
createRenderEffect(
100+
() => {
101+
const c = children();
102+
return typeof c === "function" ? c() : c;
103+
},
104+
v => {
105+
slot = v;
106+
}
107+
);
108+
});
109+
flush();
110+
let release!: () => void;
111+
const done = action(function* () {
112+
setX(1);
113+
yield new Promise<void>(r => (release = r));
114+
})();
115+
await settle();
116+
expect([screenX, slot, inner]).toEqual([0, "pending", undefined]);
117+
release();
118+
await done;
119+
await settle();
120+
expect([screenX, slot, inner]).toEqual([1, "p", 2]);
121+
});
122+
});
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* @jsxImportSource @solidjs/web
3+
* @vitest-environment jsdom
4+
*
5+
* #4203: a `<Loading>` that `<Show when={latest(gate) ?? gate()}>` mounts
6+
* reveals its content when a component inside it writes an `ownedWrite`
7+
* signal during its mount and then creates a memo that reads it and never
8+
* settles. Nothing reads the memo: a pending value no render effect
9+
* reaches holds nothing and reaches no boundary.
10+
*/
11+
import { expect, test } from "vitest";
12+
import { Loading, Show, createMemo, createSignal, flush, latest } from "solid-js";
13+
import { render } from "../src/index.js";
14+
15+
async function settle() {
16+
for (let i = 0; i < 3; i++) {
17+
await new Promise(r => setTimeout(r, 0));
18+
flush();
19+
}
20+
}
21+
22+
test("an unread pending memo does not hold a verdict-mounted Loading (#4203)", async () => {
23+
const root = document.createElement("div");
24+
function Child() {
25+
const [version, setVersion] = createSignal(0, { ownedWrite: true });
26+
setVersion(1);
27+
createMemo(() => {
28+
version();
29+
return new Promise(() => {});
30+
});
31+
return "CHILD";
32+
}
33+
34+
const dispose = render(() => {
35+
const gate = createMemo(async () => "x");
36+
return (
37+
<Loading fallback="OUTER LOADING">
38+
<Show when={latest(() => gate()) ?? gate()}>
39+
<Loading fallback="INNER LOADING">
40+
<Child />
41+
</Loading>
42+
</Show>
43+
</Loading>
44+
);
45+
}, root);
46+
await settle();
47+
expect(root.innerHTML).toBe("CHILD");
48+
dispose();
49+
});

0 commit comments

Comments
 (0)