Skip to content

Commit a124577

Browse files
ryansolidcursoragentClaude via Cursor
authored
fix(signals): a boundary whose fallback is pending reveals landed content without waiting for the fallback's flight (#3540) (#3581)
* test(signals): pin what an on= re-arm does not license (#3540) Reveal-timing and fallback-pending pins for re-armed Loading boundaries. One pins a live defect: a re-armed boundary whose fallback is itself not ready does not reveal landed content until the fallback's read lands. Co-authored-by: Cursor <[email protected]> * test(signals): re-derive the on= reveal-timing pins under frame-following (#3540, #3575) The two reveal-timing pins were written against #3556's mainline swap. Under #3575 the swap is staged into the notifying write's transaction, and the boundary's output is that frame's from then on: - staged source: the action outlasts the data, so old content holds through the flight, `data 2` lands at the commit, the fallback is never shown, and LOADING_ON_OUTSIDE_HOLD reports once after the fact. - independent source: the content's own hold (the pending write it derives from) is joined to the action's frame when the staged output pass reads its landing — reveal at the commit, no fallback, same diagnostic. The pre-#3575 sequence is the display-ahead read's (`latest()`), pinned beside it. Co-authored-by: Claude via Cursor <[email protected]> Co-authored-by: Cursor <[email protected]> * fix(signals): judge a boundary whose fallback is pending before the verdict (#3540) A collecting Loading boundary whose FALLBACK read something not ready left its output pass pending on that read; an initialized parent held the frame on it. When the content landed, the boundary was ready — but its output pass derives from `_disabled`, not the tree, so the tree settling never re-ran it; only the boundary sweep does, and that sweep ran at the commit (finalizePureQueue), after the verdict the output's own read kept parking. The content waited for the fallback's flight. Judge that one shape before the verdict, under the transaction (`CollectionQueue._judgeHeld`, walked by `checkBoundaryChildren(this, true)` after the re-arm drain): a collecting boundary whose output is pending stages `_disabled` false with the frame and its output re-runs in the same heap, reads the tree, and drops the fallback's read through recompute's ordinary settle of a pass's outgoing pending sources — the verdict sees the release. Boundaries with a ready fallback park nothing and keep the commit sweep's reveal unchanged. The DEV after-the-fact LOADING_ON_OUTSIDE_HOLD rule (devHeldSweep) now also recognizes a swap the pre-verdict sweep cleared while still staged (`_disabled` staged false over a never-committed true) as never displayed; `_checkSources` drops `_swapUnseen` only for a swap that committed. Pins: the on= case (loading-on-rearm-reveal-3540 'content lands before the fallback') and its no-on analogue (loading-fallback-release-3540, whose second test shows the general computed case always released — the bug was boundary-specific). Core floor +63 B, documented in treeshake.test.ts. Co-authored-by: Claude via Cursor <[email protected]> Co-authored-by: Cursor <[email protected]> * chore(size): re-set four caps for the pre-verdict boundary judgment (#3540) +38..+81 B brotli per scenario, re-measured rebased over #3577 (origin/next 709c02b, same solid/web dist): the flush's pre-verdict boundary walk in core, and `_judgeHeld` / `_output` in boundaries. Re-set: isPending/latest (12.40 -> 12.45), hydrating no-stores (20.70 -> 20.75), CSR (15.75 -> 15.80, over #3577's own bump) and the CSR observe tier (17.30 -> 17.35, no observe-gated bytes; brotli layout). Each carries its measurement note. The simple-app floor (12,493 / 12.50) and observe + attribution (27,743 / 27.75) now land within `next`'s caps and keep them; the other four scenarios are within their caps too. Co-authored-by: Claude via Cursor <[email protected]> Co-authored-by: Cursor <[email protected]> --------- Co-authored-by: Cursor <[email protected]> Co-authored-by: Claude via Cursor <[email protected]>
1 parent 5e46732 commit a124577

7 files changed

Lines changed: 709 additions & 26 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 boundary whose fallback reads something not ready now reveals its content as soon as the content lands, instead of waiting for the fallback's own flight (#3540). The boundary's output pass derives from its `_disabled` switch, not its tree, so only the boundary sweep re-runs it — and that sweep ran at the commit, after the verdict the output's own pending read kept parking. Such a boundary is now judged before the verdict, under the transaction, so its output re-runs, reads the tree and drops the fallback's read ahead of the verdict. Boundaries whose fallback is ready are unaffected. The DEV `LOADING_ON_OUTSIDE_HOLD` after-the-fact rule recognizes a swap cleared this way as never displayed.

‎packages/signals/src/boundaries.ts‎

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,8 @@ export class CollectionQueue extends Queue {
364364
_collectionType: number;
365365
_sources: Set<Computed<any>> = new Set();
366366
_tree?: BoundaryComputed<any>;
367+
/** The output pass — fallback or content (createCollectionBoundary). */
368+
_output?: Computed<any>;
367369
_pending = true;
368370
_disabled: Signal<boolean> = signal(false, { ownedWrite: true, _noSnapshot: true });
369371
_error?: Signal<unknown>;
@@ -376,7 +378,8 @@ export class CollectionQueue extends Queue {
376378
* any: the fallback swap is display-ahead — shown through the lane. */
377379
_rearmLane: OptimisticLane | null = null;
378380
/** DEV: a frame-following swap is staged and not yet reported unseen
379-
* (devHeldSweep; cleared by the sweep that settles or clears it). */
381+
* (devHeldSweep; dropped by the sweep that finds it committed, or by the
382+
* report). */
380383
_swapUnseen?: boolean;
381384
constructor(type: number) {
382385
super();
@@ -576,6 +579,22 @@ export class CollectionQueue extends Queue {
576579
))
577580
);
578581
}
582+
/** The pre-verdict sweep (scheduler run(), #3540): a collecting boundary
583+
* whose OUTPUT is pending — its fallback read something not ready — is
584+
* judged here, under the transaction. That output is what an initialized
585+
* parent holds the frame on, and it derives from `_disabled`, not the
586+
* tree: the tree settling never re-runs it, only a sweep does, and the
587+
* commit sweep runs after the verdict the output's own read keeps parking
588+
* — the content waited for the fallback's flight. Judged ready here, the
589+
* boundary stages `_disabled` false with the frame and the output re-runs
590+
* in this heap: it reads the tree and drops the fallback's read (recompute
591+
* settles a pass's outgoing pending sources), so the verdict sees the
592+
* release. A boundary showing a ready fallback parks nothing and keeps the
593+
* commit sweep's reveal. */
594+
_judgeHeld(): void {
595+
if (this._initialized || !(this._output!._statusFlags & STATUS_PENDING)) return;
596+
this._checkSources();
597+
}
579598
_checkSources() {
580599
for (const source of this._sources) if (this._settled(source)) this._sources.delete(source);
581600
if (!this._sources.size) {
@@ -590,7 +609,10 @@ export class CollectionQueue extends Queue {
590609
this._pending = false;
591610
}
592611
if (!this._pending) {
593-
if (__DEV__) this._swapUnseen = false; // the swap ran its course (`_devHeldSweep`)
612+
// DEV: a swap that committed ran its course; one cleared here while
613+
// still staged was never displayed — the parked walk judges whose
614+
// hold that was (`_devHeldSweep`).
615+
if (__DEV__ && this._disabled._pendingValue !== true) this._swapUnseen = false;
594616
setSignal(this._disabled, false);
595617
if (__OBSERVE__ && attrHooks !== null && this._collectionType & STATUS_PENDING)
596618
attrHooks.boundaryFallback(this, this._tree, false);
@@ -618,20 +640,26 @@ function reportUnseen(queue: CollectionQueue, detail: string, name?: string): vo
618640
)
619641
);
620642
}
621-
/** DEV, a parked finalize (scheduler `checkBoundaryChildren` →
643+
/** DEV, a parked finalize (scheduler `devSweepBoundaryChildren` →
622644
* `_devHeldSweep`): the after-the-fact LOADING_ON_OUTSIDE_HOLD rule. The
623-
* re-arm's swap is still staged (`_disabled` holds `true` uncommitted) and
624-
* the content it was waiting on has settled — the sweep that follows the
625-
* commit will clear it before any effect phase runs, so the fallback is never
626-
* displayed. That is the design when other data holds the frame (a race the
627-
* fallback may still win: the shell landing first shows it); it is the missed
628-
* case when nothing but the write's own action (or an override it left)
629-
* parks the transaction — the action outlasts the data, and `on` never shows
630-
* a fallback. The source rule in `_rearm` cannot see this: nothing outside
631-
* the boundary reads the source. */
645+
* re-arm's swap never committed and the content it was waiting on has
646+
* settled: `_disabled` still holds the staged `true` (the sweep that follows
647+
* the commit will clear it before any effect phase runs), or the pre-verdict
648+
* sweep (`_judgeHeld`, a fallback that read something not ready) already
649+
* staged `false` over it. Either way the fallback is never displayed. That
650+
* is the design when other data holds the frame (a race the fallback may
651+
* still win: the shell landing first shows it); it is the missed case when
652+
* nothing but the write's own action (or an override it left) parks the
653+
* transaction — the action outlasts the data, and `on` never shows a
654+
* fallback. The source rule in `_rearm` cannot see this: nothing outside
655+
* the boundary reads the source. A swap the commit sweep clears was
656+
* committed, and displayed (`_checkSources` drops `_swapUnseen` for it). */
632657
function devHeldSweep(queue: CollectionQueue): void {
633-
if (!queue._swapUnseen || queue._disabled._pendingValue !== true) return;
634-
for (const source of queue._sources) if (!queue._settled(source)) return;
658+
if (!queue._swapUnseen) return;
659+
const staged = queue._disabled._pendingValue;
660+
if (staged === true) {
661+
for (const source of queue._sources) if (!queue._settled(source)) return;
662+
} else if (staged !== false) return;
635663
const t = queue._disabled._transition;
636664
if (t === null) return;
637665
for (const [source, reporters] of currentTransition(t)._asyncReporters)
@@ -697,7 +725,7 @@ function createCollectionBoundary<T>(
697725
cleanup(() => controller._unregister(queue));
698726
}
699727
return accessor<T>(
700-
computed(
728+
(queue._output = computed(
701729
(): T => {
702730
// `_disabled` selects fallback or content: set by a collecting
703731
// notification or a re-arm (`_rearm`), cleared by the sweep when the
@@ -717,7 +745,7 @@ function createCollectionBoundary<T>(
717745
// by snapshot capture. The tree no longer carries foreign status flags, so
718746
// capture can't rely on PENDING to skip this node the way it used to.
719747
{ _noSnapshot: true }
720-
)
748+
))
721749
);
722750
}
723751

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

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,17 @@ export class GlobalQueue extends Queue {
842842
runHeap(dirtyQueue, GlobalQueue._update);
843843
}
844844
if (activeTransition) {
845+
// A boundary whose fallback read something not ready is judged before
846+
// the verdict, under the transaction (boundaries.ts `_judgeHeld`,
847+
// #3540): its output is pending on that read and holds the frame,
848+
// and only a sweep re-runs it — the commit sweep, after the verdict
849+
// its own read keeps parking. Ready, it stages `_disabled` false with
850+
// the frame; the heap re-runs so the output drops the read ahead of
851+
// the verdict.
852+
if (this._children.length) {
853+
checkBoundaryChildren(this, true);
854+
if (dirtyQueue._max >= dirtyQueue._min) runHeap(dirtyQueue, GlobalQueue._update);
855+
}
845856
const isComplete = transitionComplete(activeTransition);
846857
if (!isComplete) {
847858
const stashedTransition = activeTransition!;
@@ -1345,8 +1356,10 @@ export function finalizePureQueue(
13451356
if (resolvePending) commitPendingNodes();
13461357
if (!incomplete && globalQueue._children.length) checkBoundaryChildren(globalQueue);
13471358
// A parked finalize sweeps nothing (the boundaries' staged swaps are the
1348-
// transaction's); DEV walks them read-only for the after-the-fact
1349-
// LOADING_ON_OUTSIDE_HOLD rule (boundaries.ts `_devHeldSweep`, #3540).
1359+
// transaction's; a boundary whose own output parks the verdict was judged
1360+
// under it in run(), ahead of the verdict); DEV walks them read-only for
1361+
// the after-the-fact LOADING_ON_OUTSIDE_HOLD rule (boundaries.ts
1362+
// `_devHeldSweep`, #3540).
13501363
else if (__DEV__ && incomplete && globalQueue._children.length)
13511364
devSweepBoundaryChildren(globalQueue);
13521365
// Contested effects (#3322) re-derive from the world this commit just
@@ -1440,10 +1453,13 @@ export function finalizePureQueue(
14401453
}
14411454
}
14421455

1443-
function checkBoundaryChildren(queue: Queue) {
1456+
/** The boundary sweep: the commit's (`_checkSources`), or — `held`, before
1457+
* the verdict (#3540) — the one for a collecting boundary whose output is
1458+
* pending on its fallback's read (`_judgeHeld`). */
1459+
function checkBoundaryChildren(queue: Queue, held?: boolean) {
14441460
for (const child of queue._children) {
1445-
(child as any)._checkSources?.();
1446-
checkBoundaryChildren(child as Queue);
1461+
held ? (child as any)._judgeHeld?.() : (child as any)._checkSources?.();
1462+
checkBoundaryChildren(child as Queue, held);
14471463
}
14481464
}
14491465
/** DEV twin of checkBoundaryChildren for a parked finalize (#3540): read-only. */
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
/**
2+
* #3540 — the no-`on` analogue of `loading-on-rearm-reveal-3540.test.ts`.
3+
*
4+
* A boundary whose fallback reads a pending async source makes its output
5+
* pass pending on that source; an initialized ancestor holds its last frame.
6+
* When the boundary's content lands, the boundary is ready — but its output
7+
* pass derives from `_disabled`, not the tree, so only a sweep re-runs it,
8+
* and the commit sweep runs after the verdict that the output's own pending
9+
* keeps parking: the content waited for the fallback's flight. The boundary
10+
* is judged before the verdict instead (`_judgeHeld`): the output re-runs,
11+
* reads the tree, drops the fallback's read, and the ancestor reveals the
12+
* content NOW. It has nothing to do with re-arming; the second test is the
13+
* general form — a plain computed dropping a pending source — which always
14+
* released.
15+
*/
16+
import { afterEach, beforeEach, expect, test, vi } from "vitest";
17+
import {
18+
createLoadingBoundary,
19+
createMemo,
20+
createRenderEffect,
21+
createRoot,
22+
createSignal,
23+
flush,
24+
untrack
25+
} from "../src/index.js";
26+
27+
beforeEach(() => vi.useFakeTimers());
28+
afterEach(() => vi.useRealTimers());
29+
30+
const sleep = (ms: number) => new Promise<void>(r => setTimeout(r, ms));
31+
const microtask = () => Promise.resolve();
32+
33+
test("a fresh inner boundary with a pending fallback, mounted under an initialized outer, reveals when its content lands", async () => {
34+
const [show, setShow] = createSignal(false);
35+
const [asked, setAsked] = createSignal(0);
36+
const outer = { value: undefined as unknown, log: [] as unknown[] };
37+
let dispose!: () => void;
38+
createRoot(d => {
39+
dispose = d;
40+
const data = createMemo(async () => {
41+
const v = asked();
42+
await sleep(1000);
43+
return v;
44+
});
45+
const fallbackData = createMemo(async () => {
46+
const v = asked();
47+
await sleep(3000);
48+
return `loading ${v}`;
49+
});
50+
const innerMemo = createMemo(() =>
51+
show()
52+
? createLoadingBoundary(
53+
() => `data ${data()}`,
54+
() => fallbackData()
55+
)
56+
: null
57+
);
58+
createRenderEffect(
59+
untrack(() =>
60+
createLoadingBoundary(
61+
() => {
62+
const b = innerMemo();
63+
return b ? b() : "nothing";
64+
},
65+
() => "OUTER FALLBACK"
66+
)
67+
),
68+
v => {
69+
outer.value = v;
70+
outer.log.push(v);
71+
}
72+
);
73+
});
74+
flush();
75+
await vi.advanceTimersByTimeAsync(3000);
76+
flush();
77+
expect(outer.value).toBe("nothing");
78+
79+
setAsked(1);
80+
flush();
81+
await microtask();
82+
flush();
83+
setShow(true);
84+
flush();
85+
await microtask();
86+
flush();
87+
// The inner fallback is pending; the initialized outer holds "nothing".
88+
expect(outer.value).toBe("nothing");
89+
90+
// +1000ms: `data` lands, `fallbackData` still has 2000ms to go. The inner
91+
// output pass now reads the tree — the outer must reveal it at once.
92+
await vi.advanceTimersByTimeAsync(1000);
93+
flush();
94+
expect(outer.value).toBe("data 1");
95+
expect(outer.log).toEqual(["nothing", "data 1"]);
96+
dispose();
97+
});
98+
99+
test("an initialized boundary whose content switches from a pending source to another reveals when the new one lands", async () => {
100+
const [flag, setFlag] = createSignal(true);
101+
const [asked, setAsked] = createSignal(0);
102+
const out = { value: undefined as unknown, log: [] as unknown[] };
103+
let dispose!: () => void;
104+
createRoot(d => {
105+
dispose = d;
106+
const a = createMemo(async () => {
107+
const v = asked();
108+
await sleep(1000);
109+
return `a ${v}`;
110+
});
111+
const b = createMemo(async () => {
112+
const v = asked();
113+
await sleep(3000);
114+
return `b ${v}`;
115+
});
116+
createRenderEffect(
117+
untrack(() =>
118+
createLoadingBoundary(
119+
() => (flag() ? b() : a()),
120+
() => "FALLBACK"
121+
)
122+
),
123+
v => {
124+
out.value = v;
125+
out.log.push(v);
126+
}
127+
);
128+
});
129+
flush();
130+
await vi.advanceTimersByTimeAsync(3000);
131+
flush();
132+
expect(out.value).toBe("b 0");
133+
134+
setAsked(1);
135+
flush();
136+
await microtask();
137+
flush();
138+
expect(out.value).toBe("b 0"); // held on b
139+
setFlag(false);
140+
flush();
141+
await microtask();
142+
flush();
143+
expect(out.value).toBe("b 0"); // still held, now on a
144+
145+
await vi.advanceTimersByTimeAsync(1000);
146+
flush();
147+
expect(out.value).toBe("a 1");
148+
expect(out.log).toEqual(["FALLBACK", "b 0", "a 1"]);
149+
dispose();
150+
});

0 commit comments

Comments
 (0)