Skip to content

Commit 0479053

Browse files
ryansolidclaudecursoragent
committed
fix(signals): a fresh Loading over a held value shows its fallback in a flush (#3540, L2 regression)
L2 regressed A29's boundary exemption in two ways: - In a flush, a first pass under a loading boundary that has not shown content joined the flush to the hold it read, so the whole tick (the Show that mounted the boundary included) waited for the hold. A first pass that reads a hold now asks the boundaries up its chain (GlobalQueue._fresh); one such boundary catches it, and the pass joins pass-scoped (passTx), as a mount outside a flush does: the boundary's, not the tick's. A derivation outside the boundary in the same flush still holds the tick. A flush that set passTx clears it at its end. - A render effect born held under a fresh loading boundary (content bound in JSX: the tree never reads the held value) was not caught, so the boundary revealed empty content, in a flush and out of one. It is now collected as a reader, and the output's first pass shows the fallback whenever the boundary has collected readers. Refs #3540 Co-authored-by: Claude <[email protected]> Co-authored-by: Cursor <[email protected]>
1 parent 2317623 commit 0479053

8 files changed

Lines changed: 445 additions & 78 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 fresh `Loading` mounted over a held value shows its fallback in a flush too (#3540 under L2): a first pass a loading boundary that has not shown content catches is the boundary's, not the tick's, so the mount publishes and the content reveals at the commit. Content bound by a render effect under the boundary is collected, so the boundary no longer reveals empty content.

‎packages/signals/docs/RULES-INDEX.md‎

Lines changed: 48 additions & 48 deletions
Large diffs are not rendered by default.

‎packages/signals/docs/SPEC-ASYNC-SEMANTICS.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ The former Tier A table is these sections. Tier B/C, the fixed violations, and t
5555
- **A first load derived from a hold lands into it** (#3800): a first load born pending in a frame that read a hold lands into that hold if the hold is still live, else as its own commit; the hold commits without it. **Pending** — `fix/create-time-holds` (`91e474506`); [#3800](https://github.com/solidjs/solid/issues/3800) is open.
5656
- **A first pass under a loading boundary that has not shown content is the boundary's, not the tick's** — in a flush as outside one (A29's boundary exemption, #3540). The out-of-flush form is on `next`; the in-flush form (a fresh `Loading` over a held value shows its fallback in a flush) is **pending** — `fix/create-time-holds` (`ca71e5d9d`).
5757

58+
**The boundary scope, in a flush (2026-10-06, amendment — #3540's L2 regression; the bullet above is unchanged).** The in-flush form lands with `fix/l2-3540-fresh-loading`, standalone of `fix/create-time-holds`. A first pass (`STATUS_UNINITIALIZED`) that reads a hold asks the boundaries up its chain (`GlobalQueue._fresh`: caught as a pending status). When a loading boundary that has not shown content catches it, the pass joins pass-scoped (`passTx`), as a mount outside a flush does, instead of joining the flush: the Show that mounted the boundary publishes, and the boundary shows its fallback. A pass nothing catches joins the flush as before, so a derivation outside the boundary in the same flush still holds the tick. A render effect born held under the boundary (content bound in JSX — the tree never reads the held value) is caught the same way, so the boundary does not reveal empty content, in a flush or out of one; its output's first pass shows the fallback whenever it has collected readers. A flush that set `passTx` clears it at its end, so the boundary's hold does not merge with a later tick's. The `direction-rule-probe` pins are unchanged. **Pinned by:** `tests/loading-fallback-in-flush-3540.test.ts` (in a flush: through a memo, directly, bound, nested under a Loading that has shown content; a derivation outside the boundary still holds the tick; the boundary's hold stays its own; on a hold, from mainline: the same three content shapes); `packages/web/test/loading-fallback-in-flush-3540.spec.tsx`.
59+
5860
**Not yet one-way (recorded, not ruled).** The frame of a tick is still one transaction (the tick ruling above stands), so two shapes keep the hold waiting on first loads it never needed:
5961

6062
- **Same tick:** mounts created outside a flush in one tick — two mounts over the held value, or a mount and a sync reader — share the tick's frame. The frame joins the hold, and the hold waits on the mounts' first loads.

‎packages/signals/src/boundaries.ts‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ export function redraw(b: Boundary): void {
203203
/** GlobalQueue._catch: status from a frame reader, nearest boundary first.
204204
* A loading boundary on the way records a pending reader whether or not it
205205
* catches it (its `on` may collect it later). */
206-
function catchStatus(node: Computed<any>, flags: number, error: unknown): boolean {
206+
function catchStatus(node: Computed<any>, flags: number, error?: unknown): boolean {
207207
if (flags === 0) {
208208
// A status cleared. Judged by the node's status now, against each
209209
// boundary's own rule (`unsettled`) — the error path clears pending
@@ -596,25 +596,23 @@ function createBoundary<T>(
596596
}
597597
if (isCollecting(b)) {
598598
// A29's boundary exemption (#3540): a boundary MOUNTED over a held
599-
// value (its first pass; the tree born held) shows its fallback now
600-
// and the content at the commit — entering the transaction would
601-
// make the output itself born held, and nothing would show until
602-
// the commit. (The seam keeps a held reader until it is committed.)
603-
// A boundary with a committed value reads a held tree and enters:
604-
// the outside sees its committed value until the landing, which
605-
// reveals the content — a fallback staged earlier is replaced ahead
606-
// of the commit and never shown.
599+
// value (its first pass; a first pass under it that read a hold was
600+
// collected, `joinPass` — the tree's own, or a render effect's that
601+
// binds the content) shows its fallback now and the content at the
602+
// commit — entering the transaction would make the output itself
603+
// born held, and nothing would show until the commit. The seam
604+
// keeps a held reader until it is committed, then re-derives this
605+
// pass. A boundary with a committed value reads a held tree and
606+
// enters: the outside sees its committed value until the landing,
607+
// which reveals the content — a fallback staged earlier is replaced
608+
// ahead of the commit and never shown.
607609
const self = getOwner() as Computed<any>;
608610
if (
609-
tree._config & CONFIG_HELD &&
611+
b._readers.size !== 0 &&
610612
self._statusFlags & STATUS_UNINITIALIZED &&
611613
!(self._config & CONFIG_HELD)
612-
) {
613-
// The seam re-derives this pass once; by then the fallback is
614-
// the committed value, and the next pass enters.
615-
collecting.add(b);
614+
)
616615
return fallback(b);
617-
}
618616
// Readers under it still unready: the fallback, the tree untouched.
619617
// The seam re-derives this pass when they settle.
620618
if (prune(b, true) !== 0) return fallback(b);
@@ -776,6 +774,8 @@ export function createErrorBoundary<T, U>(
776774
// Installed at module evaluation — present exactly when something imports a
777775
// boundary. An app without one pays the three null checks and nothing else.
778776
GlobalQueue._catch = catchStatus;
777+
GlobalQueue._fresh = node =>
778+
node._statusFlags & STATUS_UNINITIALIZED && catchStatus(node, STATUS_PENDING);
779779
GlobalQueue._hidden = hidden;
780780
GlobalQueue._boundarySeam = boundarySeam;
781781
GlobalQueue._heldRun = heldRun;

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -941,10 +941,18 @@ export function ext(el: { _x: NodeExtension | null }): NodeExtension {
941941
* reader is a render effect. A render effect is the frame, not a derivation
942942
* (rule 3): in that transaction's own flush, or born into it (uninitialized,
943943
* A29), it reads the staged value and holds nothing of its own; otherwise it
944-
* reads the committed value instead (`frameRead`). */
944+
* reads the committed value instead (`frameRead`). A node born into the
945+
* future has no committed value: every reader joins it. A first pass is
946+
* something not ready under a loading boundary that has not shown content:
947+
* the boundary collects it and shows its fallback, and the pass is the
948+
* boundary's, not the tick's (A29's boundary exemption, #3540). */
945949
function joinPass(c: Computed<any>, el: Signal<any> | Computed<any>): void {
946950
c._flags |= REACTIVE_JOINED;
947-
if ((c as any)._type !== EFFECT_RENDER) joinPassTx(txOf(el));
951+
if (
952+
(el as Computed<any>)._statusFlags & STATUS_UNINITIALIZED ||
953+
(c as any)._type !== EFFECT_RENDER
954+
)
955+
joinPassTx(txOf(el), GlobalQueue._fresh?.(c));
948956
}
949957

950958
/** A15's stale reader (shared-hole and reveal corollaries): a render effect
@@ -1651,11 +1659,9 @@ export function read<T>(el: Signal<T> | Computed<T>): T {
16511659
!(el._config & CONFIG_OVERRIDE) &&
16521660
!(c._config & CONFIG_CHILDREN_FORBIDDEN)
16531661
) {
1654-
if (owner._statusFlags & STATUS_UNINITIALIZED) {
1655-
(c as Computed<any>)._flags |= REACTIVE_JOINED;
1656-
joinPassTx(txOf(el));
1657-
} else if (frameRead(c as Computed<any>, el)) committed = true;
1658-
else joinPass(c as Computed<any>, el);
1662+
if (owner._statusFlags & STATUS_UNINITIALIZED || !frameRead(c as Computed<any>, el))
1663+
joinPass(c as Computed<any>, el);
1664+
else committed = true;
16591665
}
16601666
}
16611667
// Lanes: a lane's node (after the pull — the node is current). NOT_PENDING

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

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,15 @@ export let flushTransaction: Transaction | null = null;
172172
* into it, and nothing else in the tick is — a write made after the mount
173173
* is a mainline write, a render effect mounted beside it a stale reader.
174174
* Inside a flush, or in a tick that already has its transaction (an
175-
* action's body), the frame joins instead (`flushTransaction`). Cleared by
176-
* the flush the join schedules. */
175+
* action's body), the frame joins instead (`flushTransaction`) — except a
176+
* first pass a loading boundary that has not shown content catches (`own`,
177+
* A29's boundary exemption, #3540): it is the boundary's, not the tick's,
178+
* and a flush that has joined nothing keeps it pass-scoped as outside one.
179+
* Cleared by the flush the join schedules, and at the end of a flush that
180+
* set it. */
177181
export let passTx: Transaction | null = null;
178-
export function joinPassTx(t: Transaction): void {
179-
if (globalQueue._running || flushTransaction !== null) return joinFuture(t);
182+
export function joinPassTx(t: Transaction, own?: unknown): void {
183+
if ((globalQueue._running && !own) || flushTransaction !== null) return joinFuture(t);
180184
if (passTx === null) passTx = resolveTx(t);
181185
else merge(resolveTx(t), passTx);
182186
schedule();
@@ -650,13 +654,15 @@ export class GlobalQueue implements IQueue {
650654
// Boundaries (boundaries.ts): the display consumers between an observer
651655
// and the root. `_catch` — status from a frame reader, nearest boundary
652656
// first (true: caught, the root never hears of it; a clear — flags 0 —
653-
// settles the reader there); `_hidden` — a frame reader behind a fallback
654-
// is not on screen and holds nothing; `_boundarySeam` — the seam's sweep
655-
// (readers gone or settled without a pass reveal; an `on` re-arm
656-
// resolves).
657+
// settles the reader there); `_fresh` — a pass that read a hold (true: a
658+
// first pass a loading boundary that has not shown content caught,
659+
// `joinPass`); `_hidden` — a frame reader behind a fallback is not on
660+
// screen and holds nothing; `_boundarySeam` — the seam's sweep (readers
661+
// gone or settled without a pass reveal; an `on` re-arm resolves).
657662
declare static _catch:
658663
| ((node: Computed<any>, flags: number, error: unknown) => boolean)
659664
| undefined;
665+
declare static _fresh: ((node: Computed<any>) => unknown) | undefined;
660666
declare static _hidden: ((r: Computed<any>) => boolean) | undefined;
661667
declare static _boundarySeam: (() => void) | undefined;
662668
// `_heldRun` — a queued run under a fallback-showing boundary waits for
@@ -702,6 +708,7 @@ export class GlobalQueue implements IQueue {
702708
if (__DEV__) DEV.hooks.onUpdate?.();
703709
} finally {
704710
this._running = false;
711+
passTx = null;
705712
}
706713
}
707714
/** L2 — the seam: end of the pure phase. Commit this flush's staged nodes,
Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
1+
/**
2+
* #3540 under L2 — A29's boundary exemption, in a flush and on a hold.
3+
*
4+
* A loading boundary that has not shown content mounted while a transaction
5+
* holds what it reads shows its fallback now and its content at the commit:
6+
* the first pass under it is the boundary's, not the tick's. A mount inside
7+
* a flush (a Show opening) publishes with it; a derivation outside the
8+
* boundary in the same flush still holds the tick. Content bound by a render
9+
* effect (the tree never reads the held value) is collected too, so the
10+
* boundary never reveals empty content.
11+
*/
12+
import { describe, expect, it } from "vitest";
13+
import {
14+
action,
15+
createLoadingBoundary,
16+
createMemo,
17+
createRenderEffect,
18+
createRoot,
19+
createSignal,
20+
flush,
21+
untrack
22+
} from "../src/index.js";
23+
24+
const tick = async () => {
25+
for (let i = 0; i < 6; i++) await Promise.resolve();
26+
flush();
27+
};
28+
29+
function hold(write: () => void) {
30+
let release!: () => void;
31+
action(function* () {
32+
write();
33+
yield new Promise<void>(resolve => (release = resolve));
34+
})();
35+
flush();
36+
return () => release();
37+
}
38+
39+
/** `<Loading fallback={fallback}>{fn()}</Loading>`, created untracked as
40+
* createComponent does. */
41+
const Loading = <T>(fn: () => T, fallback: string) =>
42+
untrack(() => createLoadingBoundary(fn, () => fallback));
43+
44+
type Content = "memo" | "direct" | "bound";
45+
46+
/** The boundary's content over `x`, logging into `log`. */
47+
function content(kind: Content, x: () => number, log: string[]) {
48+
return () => {
49+
if (kind === "direct") return `content ${x()}`;
50+
const m = createMemo(() => `content ${x()}`);
51+
if (kind === "memo") return m();
52+
// <p>{m()}</p>: the content's binding reads the memo, the tree does not.
53+
createRenderEffect(m, v => {
54+
log.push(`text ${v}`);
55+
});
56+
return "p";
57+
};
58+
}
59+
60+
function mount(kind: Content, x: () => number, log: string[]) {
61+
const view = Loading(content(kind, x, log), "fallback");
62+
createRenderEffect(view, v => {
63+
log.push(`view ${v}`);
64+
});
65+
}
66+
67+
const shapes = [
68+
["memo", "through a memo"],
69+
["direct", "directly"],
70+
["bound", "bound by a render effect under the boundary"]
71+
] as const;
72+
73+
/** The commit's reveal: the content's own entries, in any order. */
74+
const revealed = (kind: Content) =>
75+
kind === "bound" ? ["text content 1", "view p"] : ["view content 1"];
76+
77+
describe("#3540 in a flush: a fresh Loading mounted over a held value shows its fallback now", () => {
78+
function setup(kind: Content, nested = false) {
79+
const [x, setX] = createSignal(0);
80+
const [open, setOpen] = createSignal(false);
81+
const log: string[] = [];
82+
createRoot(() => {
83+
createRenderEffect(x, v => {
84+
log.push(`x ${v}`);
85+
});
86+
// <Show when={open()}><Loading fallback="fallback"><Content/></Loading></Show>
87+
const show = () =>
88+
createRenderEffect(
89+
() => {
90+
if (!open()) return false;
91+
mount(kind, x, log);
92+
return true;
93+
},
94+
v => {
95+
log.push(`open ${v}`);
96+
}
97+
);
98+
if (!nested) return show();
99+
// Under an outer Loading that has shown content.
100+
const outer = Loading(() => (show(), "outer"), "outer fallback");
101+
createRenderEffect(outer, v => {
102+
log.push(`outer ${v}`);
103+
});
104+
});
105+
flush();
106+
if (nested) expect(log).toContain("outer outer");
107+
const release = hold(() => setX(1));
108+
log.length = 0;
109+
return { setOpen, log, release };
110+
}
111+
112+
for (const [kind, how] of shapes)
113+
it(`content reads the held value ${how}: the mount publishes, the content reveals at the commit`, async () => {
114+
const s = setup(kind);
115+
s.setOpen(true);
116+
flush();
117+
expect(s.log).toEqual(["view fallback", "open true"]);
118+
119+
s.release();
120+
await tick();
121+
expect(s.log.slice(2).sort()).toEqual(["x 1", ...revealed(kind)].sort());
122+
});
123+
124+
it("nested under an outer Loading that has shown content: the inner fallback now, the outer keeps its content", async () => {
125+
const s = setup("memo", true);
126+
s.setOpen(true);
127+
flush();
128+
expect(s.log).toEqual(["view fallback", "open true"]);
129+
130+
s.release();
131+
await tick();
132+
expect(s.log.slice(2).sort()).toEqual(["view content 1", "x 1"]);
133+
});
134+
135+
it("a derivation outside the boundary in the same flush still holds the tick (membership is the tick's)", async () => {
136+
const [x, setX] = createSignal(0);
137+
const [open, setOpen] = createSignal(false);
138+
const log: string[] = [];
139+
createRoot(() => {
140+
createRenderEffect(
141+
() => {
142+
if (!open()) return false;
143+
const label = createMemo(() => `label ${x()}`);
144+
createRenderEffect(label, v => {
145+
log.push(v);
146+
});
147+
mount("direct", x, log);
148+
return true;
149+
},
150+
v => {
151+
log.push(`open ${v}`);
152+
}
153+
);
154+
});
155+
flush();
156+
const release = hold(() => setX(1));
157+
log.length = 0;
158+
159+
setOpen(true);
160+
flush();
161+
expect(log).not.toContain("open true");
162+
expect(log.filter(l => l.startsWith("label"))).toEqual([]);
163+
164+
release();
165+
await tick();
166+
expect(log).toContain("open true");
167+
expect(log).toContain("label 1");
168+
expect(log.at(-1)).toBe("view content 1");
169+
});
170+
171+
it("the boundary's hold stays its own: a mount over another hold after the flush reveals at that hold's release", async () => {
172+
const [x, setX] = createSignal(0);
173+
const [y, setY] = createSignal(0);
174+
const [open, setOpen] = createSignal(false);
175+
const log: string[] = [];
176+
createRoot(() => {
177+
createRenderEffect(
178+
() => {
179+
if (!open()) return false;
180+
mount("direct", x, log);
181+
return true;
182+
},
183+
v => {
184+
log.push(`open ${v}`);
185+
}
186+
);
187+
});
188+
flush();
189+
const releaseX = hold(() => setX(1));
190+
const releaseY = hold(() => setY(1));
191+
log.length = 0;
192+
193+
setOpen(true);
194+
flush();
195+
expect(log).toEqual(["view fallback", "open true"]);
196+
197+
// Mounted from mainline, outside a flush, over y's hold only.
198+
const other: string[] = [];
199+
createRoot(() => mount("direct", y, other));
200+
flush();
201+
expect(other).toEqual(["view fallback"]);
202+
203+
releaseY();
204+
await tick();
205+
expect(other).toEqual(["view fallback", "view content 1"]);
206+
expect(log).toEqual(["view fallback", "open true"]);
207+
208+
releaseX();
209+
await tick();
210+
expect(log.at(-1)).toBe("view content 1");
211+
});
212+
});
213+
214+
describe("#3540 on a hold: a fresh Loading mounted from mainline over a held value", () => {
215+
for (const [kind, how] of shapes)
216+
it(`content reads the held value ${how}: the fallback now, the content at the commit`, async () => {
217+
const [x, setX] = createSignal(0);
218+
const release = hold(() => setX(1));
219+
const log: string[] = [];
220+
createRoot(() => mount(kind, x, log));
221+
flush();
222+
expect(log).toEqual(["view fallback"]);
223+
224+
release();
225+
await tick();
226+
expect(log.slice(1).sort()).toEqual(revealed(kind).sort());
227+
});
228+
});

0 commit comments

Comments
 (0)