Skip to content

Commit 0271d2f

Browse files
committed
fix(signals): an unread pending memo behind memos does not hold a verdict-mounted Loading (#4340)
#4207 (#4203) kept a nested first pass left pending from joining a verdict lane's mount through its staged read (REACTIVE_STAGED_READ), but left REACTIVE_JOINED in the mask. A settled nested memo that reads the mount's staging (`gate = createMemo(() => version())`) is born held, as #4166 needs; a pending memo that reads `gate` then joins through `joinPass` (a read of a held node), so the trailing pending-hold block held it and the boundary caught it (`freshHook`), and `<Loading>` stayed on its fallback forever though nothing reads that memo. Each further memo between them only repeats the hop. A nested first pass under a mount that is not a render effect and is left pending now joins nothing, whatever it read: no render effect reaches it yet, so it holds nothing and reaches no boundary (Reader). A render effect that reads it goes pending and is caught on its own. A settled nested memo, a render effect, and the mount's own first pass are held as before. -1 B minified on the lane-engine scenarios. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2
1 parent 56a982c commit 0271d2f

4 files changed

Lines changed: 156 additions & 3 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 `<Loading>` that a verdict reader (`<Show when={latest(x) ?? x()}>`) mounts reveals its content when a component inside it writes a signal during its mount and a memo that stays pending with no reader reads it through other memos (`gate = createMemo(() => version())`, then a memo over `gate`), at any depth: that memo holds nothing and reaches no boundary. #4203's fix covered only a memo reading the written signal directly (#4340).

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -582,11 +582,15 @@ export function recompute(el: Computed<any>, create: boolean = false): void {
582582
missedWake = (el._flags & REACTIVE_MISSED_WAKE) !== 0;
583583
// A mount's staged read joins it — except a nested derivation left
584584
// pending: no render effect reaches it yet, so it holds nothing and
585-
// reaches no boundary (Reader, #4203). A reader that does is caught.
585+
// reaches no boundary (Reader, #4203), whatever it read — a memo the
586+
// mount bore held over the staging included, at any depth (#4340). A
587+
// reader that does is caught.
586588
joined = !!(
587589
el._flags &
588-
(mount && (prevLane || isEffect || !(el._statusFlags & STATUS_PENDING))
589-
? REACTIVE_JOINED | REACTIVE_STAGED_READ
590+
(mount
591+
? prevLane || isEffect || !(el._statusFlags & STATUS_PENDING)
592+
? REACTIVE_JOINED | REACTIVE_STAGED_READ
593+
: 0
590594
: REACTIVE_JOINED)
591595
);
592596
// A verdict reader is one for as long as it probes, or reads a memo
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/**
2+
* #4340: #4203's fix kept a nested first pass left pending from joining a
3+
* verdict mount's staged read, but only when it read the staging itself. A
4+
* memo that read it through another memo (`gate`) still joined through that
5+
* memo and held the boundary forever, though nothing reads it. A pending
6+
* value no render effect reaches holds nothing and reaches no boundary
7+
* (Reader), at any depth. A render effect that does read it is still held.
8+
*/
9+
import { describe, expect, it } from "vitest";
10+
import {
11+
createLoadingBoundary,
12+
createMemo,
13+
createRenderEffect,
14+
createRoot,
15+
createSignal,
16+
flush,
17+
latest,
18+
untrack
19+
} from "../src/index.js";
20+
21+
const settle = async () => {
22+
for (let i = 0; i < 3; i++) {
23+
await new Promise(r => setTimeout(r, 0));
24+
flush();
25+
}
26+
};
27+
28+
function mount(content: () => unknown) {
29+
let slot: unknown;
30+
createRoot(() => {
31+
const value = createMemo(async () => "x");
32+
const outer = createLoadingBoundary(
33+
() => {
34+
// <Show when={latest(value) ?? value()} keyed>
35+
const when = createMemo(() => latest(value) ?? value());
36+
const children = createMemo(() =>
37+
when() ? untrack(() => createLoadingBoundary(content, () => "INNER LOADING")) : undefined
38+
);
39+
return () => {
40+
const c = children();
41+
return typeof c === "function" ? c() : c;
42+
};
43+
},
44+
() => "OUTER LOADING"
45+
);
46+
createRenderEffect(
47+
() => {
48+
let v: any = outer();
49+
while (typeof v === "function") v = v();
50+
return v;
51+
},
52+
v => {
53+
slot = v;
54+
}
55+
);
56+
});
57+
return () => slot;
58+
}
59+
60+
describe("#4340: an unread pending memo behind memos does not hold a verdict-mounted boundary", () => {
61+
for (const depth of [1, 2, 3]) {
62+
it(`reveals with ${depth} intermediate memo(s)`, async () => {
63+
const slot = mount(() => {
64+
const [version, setVersion] = createSignal(0, { ownedWrite: true });
65+
setVersion(1);
66+
let gate: () => unknown = version;
67+
for (let i = 0; i < depth; i++) {
68+
const prev = gate;
69+
gate = createMemo(() => prev());
70+
}
71+
// Never read; never settles.
72+
createMemo(() => (gate(), new Promise(() => {})));
73+
return "CHILD";
74+
});
75+
flush();
76+
await settle();
77+
expect(slot()).toBe("CHILD");
78+
});
79+
}
80+
81+
it("a render effect that reads the pending memo still holds the boundary", async () => {
82+
const slot = mount(() => {
83+
const [version, setVersion] = createSignal(0, { ownedWrite: true });
84+
setVersion(1);
85+
const gate = createMemo(() => version());
86+
const pending = createMemo(() => (gate(), new Promise(() => {})));
87+
createRenderEffect(pending, () => {});
88+
return "CHILD";
89+
});
90+
flush();
91+
await settle();
92+
expect(slot()).toBe("INNER LOADING");
93+
});
94+
});
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* @jsxImportSource @solidjs/web
3+
* @vitest-environment jsdom
4+
*
5+
* #4340: #4203 with a memo between the written signal and the pending memo.
6+
* A `<Loading>` that a keyed `<Show when={latest(value) ?? value()}>`
7+
* mounts reveals its content when a component inside it writes an
8+
* `ownedWrite` signal during its mount, derives `gate` from it, and creates
9+
* a memo over `gate` that never settles. Nothing reads that memo: a pending
10+
* value no render effect reaches holds nothing and reaches no boundary.
11+
*/
12+
import { expect, test } from "vitest";
13+
import { Loading, Show, createMemo, createSignal, flush, latest } from "solid-js";
14+
import { render } from "../src/index.js";
15+
16+
async function settle() {
17+
for (let i = 0; i < 3; i++) {
18+
await new Promise(r => setTimeout(r, 0));
19+
flush();
20+
}
21+
}
22+
23+
test("an unread pending memo behind a memo does not hold a latest()-mounted Loading (#4340)", async () => {
24+
const root = document.createElement("div");
25+
function Child() {
26+
const [version, setVersion] = createSignal(0, { ownedWrite: true });
27+
setVersion(1);
28+
const gate = createMemo(() => version());
29+
createMemo(() => (gate(), new Promise(() => {})));
30+
return <p>child</p>;
31+
}
32+
33+
const dispose = render(() => {
34+
const value = createMemo(async () => "v");
35+
return (
36+
<Loading fallback={<p>outer</p>}>
37+
<Show when={latest(value) ?? value()} keyed>
38+
{_value => (
39+
<Loading fallback={<p>inner</p>}>
40+
<Child />
41+
</Loading>
42+
)}
43+
</Show>
44+
</Loading>
45+
);
46+
}, root);
47+
await settle();
48+
expect(root.textContent).toBe("child");
49+
dispose();
50+
});

0 commit comments

Comments
 (0)