Skip to content

Commit 20db6a2

Browse files
ryansolidGrok via Cursorcursoragent
authored
fix(signals): Loading on latest leaves fallback after the shared source settles (#3892) (#3938)
* fix(signals): Loading on latest leaves fallback after the shared source settles (#3892) A display-ahead `on: () => latest()` shows the fallback from a lane slot while the boundary's committed value stays the child. When that pass leaves the lane, the child equals the committed value, so the render effect still showing the fallback is never woken. The wake waits until the frame is no longer held, and until the seam, so a newer value published in the same flush is what gets shown and an open hold keeps the fallback. Co-authored-by: Grok via Cursor <[email protected]> Co-authored-by: Cursor <[email protected]> * fix(signals): wake a left lane slot from the lane seam (#3892) A program that never opens a lane should not carry the screen-wake queue. The seam already walks the lane's nodes. Co-authored-by: Cursor <[email protected]> * size: record the measured caps for the loading wake (#3892) CI measured the accepted wake at 9,672 B, 29,252 B, and 25,263 B brotli. Those caps match the measurement, rounded up to 0.01 KB. Co-authored-by: Cursor <[email protected]> --------- Co-authored-by: Grok via Cursor <[email protected]> Co-authored-by: Cursor <[email protected]>
1 parent 3173a14 commit 20db6a2

4 files changed

Lines changed: 121 additions & 9 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 armed by latest() leaves its fallback once the shared source settles.

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ import type { Computed, Signal } from "./types.js";
9090

9191
/** Live lanes (parented). Scanned at every seam while non-empty. */
9292
const lanes: Transaction[] = [];
93+
/** A pass left a shown slot the equality gate can no longer see (#3892). */
94+
const LEFT_SHOWN = 1 << 20;
9395
function newLane(parent: Transaction): Transaction {
9496
const l = newTransaction(true, parent);
9597
lanes.push(l);
@@ -313,9 +315,14 @@ export function laneStage(
313315
errored: boolean | Computed<any>
314316
): boolean {
315317
if (!(create || errored || el._flags & REACTIVE_LANE_READ || el._config & CONFIG_GUESS)) {
316-
if (el._x !== null) {
317-
if (el._x._transaction?._lane) el._x._transaction = null;
318-
el._x._lane = NOT_PENDING;
318+
const x = el._x;
319+
if (x !== null) {
320+
const tx = x._transaction;
321+
// Cleared before equality, so a return to the committed value notifies
322+
// nobody. The seam wakes it unless the frame is still held (#3892).
323+
if (tx?._shown && !blocked(resolveTx(tx!._parent!))) el._flags |= LEFT_SHOWN;
324+
if (tx?._lane) x._transaction = null;
325+
x._lane = NOT_PENDING;
319326
}
320327
el._config &= ~(CONFIG_OVERRIDE | CONFIG_HELD);
321328
return false;
@@ -653,6 +660,10 @@ function laneSeam(l: Transaction, leaked: boolean): void {
653660
reruns(l);
654661
for (let i = 0; i < l._nodes.length; i++) {
655662
const n = l._nodes[i] as Computed<any>;
663+
if (n._flags & LEFT_SHOWN) {
664+
n._flags ^= LEFT_SHOWN;
665+
insertSubs(n);
666+
}
656667
const x = n._x!;
657668
if (x._transaction !== l) continue;
658669
if (!(n._config & CONFIG_GUESS) && !(n as any)._type && n._pendingValue !== NOT_PENDING) {
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/**
2+
* #3892 — `<Loading on={latest(id)}>` stays on its fallback after the async
3+
* source it shares with another boundary has settled.
4+
*
5+
* Compiled `{data()}` is an insert: the read lives in a child render effect,
6+
* and the boundary's value is that child (the same value once the fallback
7+
* ends). A parent render effect inserts each boundary's result. `on:
8+
* () => latest(id)` shows the fallback now, beside the frame the other
9+
* boundary holds. When the shared source settles, that parent must apply the
10+
* child again — a fresh read of the boundary is not enough.
11+
*/
12+
import { afterEach, expect, test } from "vitest";
13+
import {
14+
createLoadingBoundary,
15+
createMemo,
16+
createRenderEffect,
17+
createRoot,
18+
createSignal,
19+
flush,
20+
latest
21+
} from "../src/index.js";
22+
23+
afterEach(() => flush());
24+
25+
async function drain() {
26+
for (let i = 0; i < 6; i++) {
27+
await Promise.resolve();
28+
flush();
29+
}
30+
}
31+
32+
test("Loading on latest leaves its fallback once the shared source settles", async () => {
33+
let finish!: (value: number) => void;
34+
const replacement = new Promise<number>(resolve => {
35+
finish = resolve;
36+
});
37+
const [id, setId] = createSignal(0);
38+
const texts: string[] = [];
39+
let appliedA: unknown;
40+
let appliedB: unknown;
41+
let dispose!: () => void;
42+
43+
createRoot(d => {
44+
dispose = d;
45+
const data = createMemo(() => (id() ? replacement : Promise.resolve(1)));
46+
const slot = (fallback: string, on?: boolean) => {
47+
const i = texts.push("") - 1;
48+
return createLoadingBoundary(
49+
() => {
50+
createRenderEffect(
51+
() => data(),
52+
v => {
53+
texts[i] = String(v);
54+
}
55+
);
56+
return i;
57+
},
58+
() => fallback,
59+
on ? { on: () => latest(id) } : undefined
60+
);
61+
};
62+
const armed = slot("fallback", true);
63+
const plain = slot("kept");
64+
createRenderEffect(armed, v => {
65+
appliedA = v;
66+
});
67+
createRenderEffect(plain, v => {
68+
appliedB = v;
69+
});
70+
});
71+
72+
const screen = () =>
73+
(typeof appliedA === "number" ? texts[appliedA] : appliedA) +
74+
(typeof appliedB === "number" ? texts[appliedB] : String(appliedB));
75+
76+
flush();
77+
await drain();
78+
expect(screen()).toBe("11");
79+
80+
setId(1);
81+
flush();
82+
await drain();
83+
// Display-ahead fallback beside the other boundary's previous content.
84+
expect(screen()).toBe("fallback1");
85+
86+
finish(2);
87+
await drain();
88+
expect(screen()).toBe("22");
89+
dispose();
90+
});

‎scripts/size/scenarios.js‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,8 +1280,10 @@ module.exports = [
12801280
// it is live (`liveTx`, `holdNode`). Cap set at measured + 10 B rounded up
12811281
// to 0.01 KB. Accepted by the maintainer 2026-10-07 on the condition hello
12821282
// world stays under 10 KB.
1283-
limit: "9.65 KB",
1284-
capMinified: 27155,
1283+
// #3892 (2026-10-08): measured at 9,672 B brotli / 27,234 B minified by CI
1284+
// (Size run 37873440136). Cap set to that brotli size, rounded up to 0.01 KB.
1285+
limit: "9.68 KB",
1286+
capMinified: 27234,
12851287
alias
12861288
},
12871289
{
@@ -2321,8 +2323,10 @@ module.exports = [
23212323
// into it while it is live (`liveTx`, `holdNode`). Cap set at measured + 10
23222324
// B rounded up to 0.01 KB. Accepted by the maintainer 2026-10-07 on the
23232325
// condition hello world stays under 10 KB.
2324-
limit: "29.19 KB",
2325-
capMinified: 92263,
2326+
// #3892 (2026-10-08): measured at 29,252 B brotli / 92,410 B minified by CI
2327+
// (Size run 37873440136). Cap set to that brotli size, rounded up to 0.01 KB.
2328+
limit: "29.26 KB",
2329+
capMinified: 92410,
23262330
alias
23272331
},
23282332
{
@@ -3389,8 +3393,10 @@ module.exports = [
33893393
// into it while it is live (`liveTx`, `holdNode`). Cap set at measured + 10
33903394
// B rounded up to 0.01 KB. Accepted by the maintainer 2026-10-07 on the
33913395
// condition hello world stays under 10 KB.
3392-
limit: "25.24 KB",
3393-
capMinified: 79085,
3396+
// #3892 (2026-10-08): measured at 25,263 B brotli / 79,149 B minified by CI
3397+
// (Size run 37873440136). Cap set to that brotli size, rounded up to 0.01 KB.
3398+
limit: "25.27 KB",
3399+
capMinified: 79149,
33943400
alias
33953401
},
33963402
{

0 commit comments

Comments
 (0)