Skip to content

Commit 3b6f839

Browse files
ryansolidclaude
andauthored
fix(signals): a re-armed Loading's off-screen fallback no longer holds the content reveal (#4282)
* fix(signals): a render effect in a re-armed Loading fallback no longer holds the content's reveal (#4268) The fallback is built outside its boundary, so its render effects counted toward the frame's hold even after the boundary's pass chose the content. Mark the fallback's scope in context and treat a reader in a fallback that is not the display as off screen (S-22 row 3'). Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2 * fix(signals): dispose a never-shown Loading fallback at once instead of a hold-wide context check (#4268) Replace the FALLBACK context key and offScreen hook with a cheaper rule at the reveal: a fallback the output's committed value does not show (a swap staged with a held frame and replaced before it commits) is disposed in the pass, so its pending readers stop holding the frame. A committed fallback still dies at the commit (#3991). +24 B minified on Loading scenarios (was +145 B). Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2 * chore(size): raise caps for #4268's +24 B (Size-Exception) Off-screen fallback disposal adds 24 B minified to the 13 Loading and boundary scenarios. Caps move to CI's measured brotli + 10 B and recorded minified to CI's measured value for each. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2 --------- Co-authored-by: Claude <[email protected]>
1 parent fbd375d commit 3b6f839

5 files changed

Lines changed: 160 additions & 36 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 re-armed `Loading` boundary (`on`) whose fallback reads pending data through a render effect — any compiled JSX fallback, such as `<p>Meta {meta()}</p>` — no longer holds the new content's reveal when the content lands first: a fallback the screen never showed is disposed as soon as the content replaces it, so the content shows as soon as it lands and the fallback is never seen, as it already did when the fallback read the data directly (#4268).

‎packages/signals/src/boundaries.ts‎

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -697,19 +697,23 @@ function createBoundary<T>(
697697
// landing when the frame parks (the run is held with it, as the old
698698
// children of a held pass are) — not now: a held swap keeps the
699699
// fallback on screen, live, until it commits. A pass back to the
700-
// fallback before then finds it still built and keeps it.
700+
// fallback before then finds it still built and keeps it. A fallback
701+
// the screen does not show (a swap staged with a held frame, replaced
702+
// before it commits) dies now: what it reads holds nothing (S-22 row
703+
// 3′, #4268).
701704
const fb = b._fb;
705+
const drop = () => {
706+
if (!b._fallback && b._fb === fb) {
707+
// A fallback that threw (a rethrow the boundary does not
708+
// handle) is what an enclosing boundary waits on: it died, and
709+
// the seam of another round drops it there (#4270).
710+
if (fb!._statusFlags & STATUS_ERROR) schedule();
711+
dispose(fb!);
712+
b._fb = null;
713+
}
714+
};
702715
if (fb !== null)
703-
globalQueue.enqueue(EFFECT_RENDER, () => {
704-
if (!b._fallback && b._fb === fb) {
705-
// A fallback that threw (a rethrow the boundary does not
706-
// handle) is what an enclosing boundary waits on: it died, and
707-
// the seam of another round drops it there (#4270).
708-
if (fb._statusFlags & STATUS_ERROR) schedule();
709-
dispose(fb);
710-
b._fb = null;
711-
}
712-
});
716+
b._output!._value !== fb._value ? drop() : globalQueue.enqueue(EFFECT_RENDER, drop);
713717
release(b);
714718
// Shown: the slot leaves its reveal order (a later re-arm gates nobody
715719
// else; the frontier moves on).
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/**
2+
* #4268 — S-22 row 3′ (D-18) with a fallback that creates a render effect.
3+
*
4+
* A re-armed boundary whose fallback reads pending data, and whose content
5+
* lands first: the fallback is never seen, and the content reveals when it
6+
* lands. A compiled JSX fallback reads through a render effect (an element
7+
* plus an `insert`), not in the fallback function itself; that effect sits
8+
* behind content that is not shown and must hold nothing.
9+
*/
10+
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
11+
import {
12+
createLoadingBoundary,
13+
createMemo,
14+
createRenderEffect,
15+
createRoot,
16+
createSignal,
17+
flush,
18+
untrack
19+
} from "../src/index.js";
20+
21+
beforeEach(() => vi.useFakeTimers());
22+
afterEach(() => vi.useRealTimers());
23+
24+
const sleep = (ms: number) => new Promise<void>(r => setTimeout(r, ms));
25+
const microtask = () => Promise.resolve();
26+
27+
function nested(fallbackEffect: boolean) {
28+
const [count, setCount] = createSignal(1);
29+
const log: unknown[] = [];
30+
let screen: unknown;
31+
let dispose!: () => void;
32+
createRoot(d => {
33+
dispose = d;
34+
const data = createMemo(async () => {
35+
const v = count();
36+
await sleep(1000);
37+
return v;
38+
});
39+
const fallbackData = createMemo(async () => {
40+
const v = count();
41+
await sleep(3000);
42+
return v;
43+
});
44+
const fallback = fallbackEffect
45+
? () => {
46+
let t = "loading";
47+
createRenderEffect(
48+
() => fallbackData(),
49+
v => {
50+
t = `loading ${v}`;
51+
}
52+
);
53+
return t;
54+
}
55+
: () => `loading ${fallbackData()}`;
56+
const inner = untrack(() =>
57+
createLoadingBoundary(() => `data ${data()}`, fallback, { on: count })
58+
);
59+
const outer = untrack(() =>
60+
createLoadingBoundary(
61+
() => inner(),
62+
() => "OUTER FALLBACK"
63+
)
64+
);
65+
createRenderEffect(outer, v => {
66+
screen = v;
67+
log.push(v);
68+
});
69+
});
70+
flush();
71+
return { setCount, screen: () => screen, log, dispose };
72+
}
73+
74+
describe("a re-armed boundary whose fallback reads pending data through a render effect (#4268)", () => {
75+
for (const fallbackEffect of [false, true]) {
76+
test(`content lands first: the fallback is never seen (${
77+
fallbackEffect ? "effect in fallback" : "read in fallback"
78+
})`, async () => {
79+
const t = nested(fallbackEffect);
80+
await vi.advanceTimersByTimeAsync(3000);
81+
flush();
82+
expect(t.screen()).toBe("data 1");
83+
t.log.length = 0;
84+
85+
t.setCount(2);
86+
flush();
87+
await microtask();
88+
flush();
89+
expect(t.screen()).toBe("data 1");
90+
91+
await vi.advanceTimersByTimeAsync(1000);
92+
flush();
93+
expect(t.screen()).toBe("data 2");
94+
95+
await vi.advanceTimersByTimeAsync(2000);
96+
flush();
97+
expect(t.screen()).toBe("data 2");
98+
expect(t.log).toEqual(["data 2"]);
99+
t.dispose();
100+
});
101+
}
102+
});

‎scripts/size/floor-caps.json‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@
88
"minified": 27029
99
},
1010
"app: hydrating (no stores) with Show/For/Loading/Errored/lazy": {
11-
"cap": "18.38 KB",
12-
"minified": 53598
11+
"cap": "18.49 KB",
12+
"minified": 53620
1313
},
1414
"page: base server components (hydrating + dynamic + frames + sf reference)": {
15-
"cap": "33.36 KB",
16-
"minified": 101535
15+
"cap": "33.37 KB",
16+
"minified": 101559
1717
},
1818
"page: live server components (base + live/GET + action + isPending/latest)": {
19-
"cap": "37.72 KB",
20-
"minified": 115193
19+
"cap": "37.75 KB",
20+
"minified": 115217
2121
},
2222
"server: floor (getRequestEvent + isServer)": {
2323
"cap": "1.34 KB",

0 commit comments

Comments
 (0)