From 9c92534ab8313080db97187ad34bb1f6ffa02362 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 21 Oct 2026 18:45:02 +0000 Subject: [PATCH] fix(signals): an unread pending memo does not hold a verdict-mounted Loading (#4203) #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 `` 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. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2 --- .changeset/verdict-mount-unread-pending.md | 5 + packages/signals/src/core/core.ts | 10 +- .../verdict-mount-unread-pending-4203.test.ts | 122 ++++++++++++++++++ ...atest-loading-unread-pending-4203.spec.tsx | 49 +++++++ 4 files changed, 185 insertions(+), 1 deletion(-) create mode 100644 .changeset/verdict-mount-unread-pending.md create mode 100644 packages/signals/tests/verdict-mount-unread-pending-4203.test.ts create mode 100644 packages/web/test/show-latest-loading-unread-pending-4203.spec.tsx diff --git a/.changeset/verdict-mount-unread-pending.md b/.changeset/verdict-mount-unread-pending.md new file mode 100644 index 0000000000..87394bd17a --- /dev/null +++ b/.changeset/verdict-mount-unread-pending.md @@ -0,0 +1,5 @@ +--- +"@solidjs/signals": patch +--- + +A `` that a verdict reader (``) 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). diff --git a/packages/signals/src/core/core.ts b/packages/signals/src/core/core.ts index 834d6c1b76..31112bfabb 100644 --- a/packages/signals/src/core/core.ts +++ b/packages/signals/src/core/core.ts @@ -550,7 +550,15 @@ export function recompute(el: Computed, create: boolean = false): void { // (markNode(c) in read()) marks the running node as part of ordinary // bookkeeping, and those marks are correctly discarded here. missedWake = (el._flags & REACTIVE_MISSED_WAKE) !== 0; - joined = !!(el._flags & (mount ? REACTIVE_JOINED | REACTIVE_STAGED_READ : REACTIVE_JOINED)); + // A mount's staged read joins it — except a nested derivation left + // pending: no render effect reaches it yet, so it holds nothing and + // reaches no boundary (Reader, #4203). A reader that does is caught. + joined = !!( + el._flags & + (mount && (prevLane || isEffect || !(el._statusFlags & STATUS_PENDING)) + ? REACTIVE_JOINED | REACTIVE_STAGED_READ + : REACTIVE_JOINED) + ); // A verdict reader is one for as long as it probes, or reads a memo // that does (`read`): a pass that did neither (REACTIVE_PROBED, the same // bit) is an ordinary derivation again. diff --git a/packages/signals/tests/verdict-mount-unread-pending-4203.test.ts b/packages/signals/tests/verdict-mount-unread-pending-4203.test.ts new file mode 100644 index 0000000000..45a76b70a2 --- /dev/null +++ b/packages/signals/tests/verdict-mount-unread-pending-4203.test.ts @@ -0,0 +1,122 @@ +/** + * #4203: #4166 carries a verdict lane's mount through nested first passes, + * so a render effect its content creates is held like a direct read. A + * plain memo the content creates is not a render effect: one that reads a + * signal the mount wrote (a staging) and never settles, with no reader, + * holds nothing and reaches no boundary (Reader). Before, it was held, so + * `…` never revealed. A memo + * that settles is still held like #4166's render effect. + */ +import { describe, expect, it } from "vitest"; +import { + action, + createLoadingBoundary, + createMemo, + createRenderEffect, + createRoot, + createSignal, + flush, + latest, + untrack +} from "../src/index.js"; + +const settle = async () => { + for (let i = 0; i < 3; i++) { + await new Promise(r => setTimeout(r, 0)); + flush(); + } +}; + +describe("#4203: an unread pending memo does not hold a verdict-mounted boundary", () => { + it("the boundary reveals its content", async () => { + let slot: unknown; + createRoot(() => { + const content = () => { + const [version, setVersion] = createSignal(0, { ownedWrite: true }); + setVersion(1); + // Never read; never settles. + createMemo(() => { + version(); + return new Promise(() => {}); + }); + return "CHILD"; + }; + const gate = createMemo(async () => "x"); + const outer = createLoadingBoundary( + () => { + // + const when = createMemo(() => latest(gate) ?? gate()); + const condition = createMemo(() => !!when()); + const children = createMemo(() => + condition() + ? untrack(() => createLoadingBoundary(content, () => "INNER LOADING")) + : undefined + ); + return () => { + const c = children(); + return typeof c === "function" ? c() : c; + }; + }, + () => "OUTER LOADING" + ); + createRenderEffect( + () => { + let v: any = outer(); + while (typeof v === "function") v = v(); + return v; + }, + v => { + slot = v; + } + ); + }); + flush(); + await settle(); + expect(slot).toBe("CHILD"); + }); + + it("a settled memo the content creates is still held (#4166)", async () => { + const [x, setX] = createSignal(0); + let screenX: unknown; + let inner: unknown; + let slot: unknown; + createRoot(() => { + createRenderEffect(x, v => { + screenX = v; + }); + // 0}>

{double()}

+ const content = () => { + const double = createMemo(() => x() * 2); + createRenderEffect(double, v => { + inner = v; + }); + return "p"; + }; + const when = createMemo(() => latest(x) > 0); + const children = createMemo(() => + when() ? untrack(() => createLoadingBoundary(content, () => "pending")) : "closed" + ); + createRenderEffect( + () => { + const c = children(); + return typeof c === "function" ? c() : c; + }, + v => { + slot = v; + } + ); + }); + flush(); + let release!: () => void; + const done = action(function* () { + setX(1); + yield new Promise(r => (release = r)); + })(); + await settle(); + expect([screenX, slot, inner]).toEqual([0, "pending", undefined]); + release(); + await done; + await settle(); + expect([screenX, slot, inner]).toEqual([1, "p", 2]); + }); +}); diff --git a/packages/web/test/show-latest-loading-unread-pending-4203.spec.tsx b/packages/web/test/show-latest-loading-unread-pending-4203.spec.tsx new file mode 100644 index 0000000000..af07b91146 --- /dev/null +++ b/packages/web/test/show-latest-loading-unread-pending-4203.spec.tsx @@ -0,0 +1,49 @@ +/** + * @jsxImportSource @solidjs/web + * @vitest-environment jsdom + * + * #4203: a `` that `` mounts + * reveals its content when a component inside it writes an `ownedWrite` + * signal during its mount and then creates a memo that reads it and never + * settles. Nothing reads the memo: a pending value no render effect + * reaches holds nothing and reaches no boundary. + */ +import { expect, test } from "vitest"; +import { Loading, Show, createMemo, createSignal, flush, latest } from "solid-js"; +import { render } from "../src/index.js"; + +async function settle() { + for (let i = 0; i < 3; i++) { + await new Promise(r => setTimeout(r, 0)); + flush(); + } +} + +test("an unread pending memo does not hold a verdict-mounted Loading (#4203)", async () => { + const root = document.createElement("div"); + function Child() { + const [version, setVersion] = createSignal(0, { ownedWrite: true }); + setVersion(1); + createMemo(() => { + version(); + return new Promise(() => {}); + }); + return "CHILD"; + } + + const dispose = render(() => { + const gate = createMemo(async () => "x"); + return ( + + gate()) ?? gate()}> + + + + + + ); + }, root); + await settle(); + expect(root.innerHTML).toBe("CHILD"); + dispose(); +});