Skip to content

Commit 0847122

Browse files
ryansolidclaude
andauthored
fix(signals): mounts under one boundary keep their own holds across flushes (#4302)
* fix(signals): keep separate-flush mounts under one boundary in independent holds A boundary's tree and output are structure between the content and the render effect that shows it, not a user derivation of the content (D-3). They now carry CONFIG_FRAME, the bit render effects get at creation, and read a hold they are not part of as committed (re-derived at its landing); a re-pass outside its hold's flush publishes mainline instead of re-joining that hold. Two <Show>s under one <Errored>/<Loading>, mounted in separate flushes over independent holds, no longer merge them (S-5 rows 1'-3', D-4). An `on` boundary's output keeps joining (D-13). Fixes #4283 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2 * fix(signals): no floor cost for the boundary frame bit; keep `on` boundaries independent Render effects carry CONFIG_FRAME from creation (`type << 23`), so the three frame checks in core test one bit instead of `_type` plus a bit: the floors get 6 B smaller minified and pay nothing for boundaries. A frame re-pass published mainline clears CONFIG_HELD whichever frame reader it is (render effect, boundary structure, verdict memo): its readers read the value it publishes. A boundary's output is structure except while a re-arm's swap is the change's work: `arm` clears the bit, and the output's pass sets it again once it is neither armed nor held. `<Loading on>` around two mounts made in separate flushes now keeps their holds independent too (D-13 re-arm tests unchanged). The regression test covers both landing orders and an `on` boundary that was re-armed earlier. Refs #4283 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 88ea86c commit 0847122

5 files changed

Lines changed: 164 additions & 6 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+
Two mounts under one boundary, made in separate flushes, keep their holds independent (S-5 rows 1′–3′, D-4, #4283). A boundary's tree and output are structure, not a user derivation of its content: like the render effect that flattens the same children without a boundary, they read a hold they are not part of as committed and are re-derived at its landing, and a re-pass of one outside its hold's flush publishes mainline instead of re-joining that hold and merging it with the next flush's. `<Errored>` and `<Loading>` (with or without `on`) around two `<Show>`s, each over its own hold, now reveal each branch at its own hold's landing. A re-arm's swap is still the change's work: while it is, the output joins the change (D-13).

‎packages/signals/src/boundaries.ts‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import {
4343
CAUGHT_REARMED,
4444
CONFIG_REDERIVE,
45+
CONFIG_FRAME,
4546
CONFIG_HELD,
4647
CONFIG_OVERRIDE,
4748
CONFIG_VERDICT,
@@ -472,6 +473,8 @@ function arm(b: Boundary): void {
472473
return;
473474
}
474475
b._armed = true;
476+
// The swap is the change's work: the output joins it (D-13, #3540).
477+
b._output!._config &= ~CONFIG_FRAME;
475478
// A verdict read in `on` (`isPending`, or a memo of one — #3528's
476479
// `createMemo(() => isPending(m2))`: the mark carries, core.ts `read`)
477480
// whose frame has no transaction yet: the swap is still display-ahead — the frame gets one now (it lands
@@ -605,6 +608,13 @@ function createBoundary<T>(
605608
if (revealHooks && controller) revealHooks._register(controller, b);
606609
const output = computed<T>(
607610
(): T => {
611+
// Structure, not a derivation of its content (CONFIG_FRAME, #4283): it
612+
// reads a hold it is not part of as the screen, as the render effect
613+
// flattening the same children without a boundary would. Not while a
614+
// re-arm's swap is the change's work (`arm`), until that swap commits
615+
// (D-13, #3540).
616+
const self = getOwner() as Computed<any>;
617+
if (!b._armed && !(self._config & CONFIG_HELD)) self._config |= CONFIG_FRAME;
608618
// Reveal order (reveal.ts): a gated slot shows its fallback — or, in a
609619
// collapsed tail, nothing — whatever its content's state; the
610620
// controller is told the pass ran (its readiness may have changed) and
@@ -615,7 +625,7 @@ function createBoundary<T>(
615625
// It may release this very slot (the frontier whose content just
616626
// settled): the pass goes on to show it — the redraw it asks for is
617627
// refused mid-pass and not needed.
618-
link(tree, getOwner() as Computed<any>);
628+
link(tree, self);
619629
if (revealHooks && b._reveal !== null) revealHooks._changed(b._reveal);
620630
if (b._gated) {
621631
if (b._collapsed) {
@@ -634,7 +644,7 @@ function createBoundary<T>(
634644
// once clean.
635645
const status = tree._statusFlags & (STATUS_PENDING | STATUS_ERROR);
636646
if (status !== 0) {
637-
link(tree, getOwner() as Computed<any>);
647+
link(tree, self);
638648
if (status & type) {
639649
if (isCollecting(b)) {
640650
caught(b, tree, undefined);
@@ -660,7 +670,6 @@ function createBoundary<T>(
660670
// enters: the outside sees its committed value until the landing,
661671
// which reveals the content — a fallback staged earlier is replaced
662672
// ahead of the commit and never shown.
663-
const self = getOwner() as Computed<any>;
664673
if (
665674
b._readers.size !== 0 &&
666675
self._statusFlags & STATUS_UNINITIALIZED &&
@@ -734,6 +743,8 @@ function createBoundary<T>(
734743
__OBSERVE__ ? { name: "value", _noSnapshot: true } : { _noSnapshot: true }
735744
);
736745
output._config |= CONFIG_REDERIVE;
746+
// The tree is structure too (the output's pass marks the output).
747+
tree._config |= CONFIG_FRAME;
737748
b._output = output;
738749
return accessor<T>(output);
739750
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,15 @@ export const CONFIG_SUPERSEDES = 1 << 27;
207207
* (`{...(on() ? { a } : {})}`), and the advice (`equals`) cannot be applied
208208
* (#4256). Set through `_extraConfig` by observe builds only. */
209209
export const CONFIG_KEY_BAG = 1 << 28;
210+
/** The frame (rule 3, D-3): a render effect (set at creation, as
211+
* `EFFECT_RENDER << 23` — keep the two in step), and a boundary's tree and
212+
* output (boundaries.ts) — structure between the content and the render
213+
* effect that shows it, not a user derivation of the content. Outside a
214+
* hold's own flush it reads that hold's values as committed and is
215+
* re-derived at its landing, and a re-pass of it publishes mainline: it
216+
* joins nothing, so two mounts under one boundary made in separate flushes
217+
* keep their holds apart (D-4, S-5 rows 1′–3′, #4283). */
218+
export const CONFIG_FRAME = 1 << 23;
210219

211220
export const STATUS_NONE = 0;
212221
export const STATUS_PENDING = 1 << 0;

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,8 @@ export function recompute(el: Computed<any>, create: boolean = false): void {
376376
// A29, or mounted by a pass of it still awaiting its commit, #4010) keeps
377377
// staging: live writes keep it current, it effects at the swap (ruling
378378
// A).
379+
// A boundary's structure (CONFIG_FRAME) is the frame like a render
380+
// effect: it publishes mainline outside its transaction's flush (#4283).
379381
// A pending flight is the transition's own work (#3884). A probe on an
380382
// earlier pass left CONFIG_VERDICT, and a frame read here would serve the
381383
// committed screen, settle the flight and drop the hold — a superseding
@@ -389,8 +391,10 @@ export function recompute(el: Computed<any>, create: boolean = false): void {
389391
// world (`read`), and has left it otherwise.
390392
// An answered deferred node's re-pass is a lagging question (D-40):
391393
// it joins nothing, so the write that reached it commits mainline.
394+
// `EFFECT_RENDER << 23` is CONFIG_FRAME (a render effect, a boundary's
395+
// tree and output), spelled from the effect type as at creation.
392396
if (tx._lane || el._config & CONFIG_LAGS) {
393-
} else if (isEffect !== EFFECT_RENDER && !(el._config & CONFIG_VERDICT))
397+
} else if (!(el._config & (CONFIG_VERDICT | (EFFECT_RENDER << 23))))
394398
joinPassTx(tx, freshHook?.(el, el._statusFlags & STATUS_UNINITIALIZED));
395399
else if (
396400
tx !== flushTransaction &&
@@ -402,8 +406,10 @@ export function recompute(el: Computed<any>, create: boolean = false): void {
402406
// after the new frame's first runs, and the held pass's own
403407
// children die below (`disposeChildren`). The landing re-derives a
404408
// fresh held frame for the reveal (`_reruns`).
409+
// Not held any more, whichever frame reader it is: its readers read
410+
// the value this pass publishes.
405411
el._pendingValue = NOT_PENDING;
406-
if (isEffect === EFFECT_RENDER) el._config &= ~CONFIG_HELD;
412+
el._config &= ~CONFIG_HELD;
407413
}
408414
}
409415
// The previous pass's frame. If that pass is still awaiting its commit
@@ -1149,6 +1155,10 @@ function frameRead(c: Computed<any>, el: Signal<any> | Computed<any>): boolean {
11491155
// read the screen. Lane work with no committed value yet reads a flight
11501156
// as a mount's memo does: it enters, and the boundary it mounts catches
11511157
// the pending (#3540).
1158+
// A boundary's tree and output (CONFIG_FRAME) read as a render effect
1159+
// does: structure, not a derivation of what it shows (#4283). A mount
1160+
// under a hold still enters it: the content memo it reads is born held,
1161+
// with no committed value to serve.
11521162
// (Verdict readers and lanes exist only with their engines installed.)
11531163
const verdict = observeFlightHook && c._config & CONFIG_VERDICT;
11541164
const lane = laneStageHook && passLane !== null;
@@ -1157,7 +1167,8 @@ function frameRead(c: Computed<any>, el: Signal<any> | Computed<any>): boolean {
11571167
(c._statusFlags & STATUS_UNINITIALIZED &&
11581168
(el as Computed<any>)._statusFlags & STATUS_PENDING)) &&
11591169
!verdict &&
1160-
((c as any)._type !== EFFECT_RENDER || el._config & CONFIG_INPUTS_PUBLISHED)
1170+
// CONFIG_FRAME, spelled as at the effect's creation.
1171+
(!(c._config & (EFFECT_RENDER << 23)) || el._config & CONFIG_INPUTS_PUBLISHED)
11611172
)
11621173
return false;
11631174
const t = txOf(el);
@@ -1227,6 +1238,9 @@ export function createEffectNode<T>(
12271238
? ({
12281239
id: inheritId(options, transparent, context),
12291240
_config:
1241+
// CONFIG_FRAME for a render effect (EFFECT_RENDER = 1; a user
1242+
// effect's 1 << 24 is unused).
1243+
(type << 23) |
12301244
(transparent ? CONFIG_TRANSPARENT : 0) |
12311245
(options?.ownedWrite ? CONFIG_OWNED_WRITE : 0) |
12321246
(options?.sync ? CONFIG_SYNC : 0) |
@@ -1270,6 +1284,9 @@ export function createEffectNode<T>(
12701284
: ({
12711285
id: inheritId(options, transparent, context),
12721286
_config:
1287+
// CONFIG_FRAME for a render effect (EFFECT_RENDER = 1; a user
1288+
// effect's 1 << 24 is unused).
1289+
(type << 23) |
12731290
(transparent ? CONFIG_TRANSPARENT : 0) |
12741291
(options?.ownedWrite ? CONFIG_OWNED_WRITE : 0) |
12751292
(options?.sync ? CONFIG_SYNC : 0) |
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
// #4283 (S-5 rows 1′–3′, D-4, D-3): two mounts made in separate flushes,
2+
// each reading a value held by its own hold, settle independently — with or
3+
// without a boundary around them. The boundary's tree and output are
4+
// structure, not a user derivation of both mounts: they read the screen like
5+
// the render effect that would flatten the same children without one.
6+
import {
7+
createErrorBoundary,
8+
createLoadingBoundary,
9+
createMemo,
10+
createRenderEffect,
11+
createRoot,
12+
createSignal,
13+
flush,
14+
untrack
15+
} from "../src/index.js";
16+
17+
const tick = async () => {
18+
for (let i = 0; i < 3; i++) {
19+
await new Promise(r => setTimeout(r, 0));
20+
flush();
21+
}
22+
};
23+
24+
it.each(
25+
["error", "loading", "loading-on", "none"].flatMap(boundary =>
26+
["A", "B"].map(first => [boundary, first])
27+
)
28+
)(
29+
"two mounts made in separate flushes keep independent holds (boundary: %s, %s lands first)",
30+
async (boundary, first) => {
31+
const [a, setA] = createSignal(0);
32+
const [b, setB] = createSignal(0);
33+
const [showA, setShowA] = createSignal(false);
34+
const [showB, setShowB] = createSignal(false);
35+
const [k, setK] = createSignal(0);
36+
const res = new Map<string, (v: string) => void>();
37+
const fetchKey = (k: string) => new Promise<string>(r => res.set(k, r));
38+
const screen: Record<string, string> = {};
39+
createRoot(() => {
40+
const slowA = createMemo(() => fetchKey("A:" + a()));
41+
const slowB = createMemo(() => fetchKey("B:" + b()));
42+
// `<p>{slowA()}/{slowB()}</p>` and two `<Show>`s, each mounting
43+
// `<p>{createMemo(() => x())()}</p>`.
44+
const branches = () => {
45+
createRenderEffect(
46+
() => `${slowA()}/${slowB()}`,
47+
v => void (screen.p = v)
48+
);
49+
const show = (when: () => boolean, key: string, x: () => number) =>
50+
createMemo(() => {
51+
if (!when()) return null;
52+
const m = createMemo(() => x());
53+
createRenderEffect(
54+
() => `${key} ${m()}`,
55+
v => void (screen[key] = v)
56+
);
57+
return key;
58+
});
59+
return [show(showA, "pA", a), show(showB, "pB", b)];
60+
};
61+
if (boundary === "none") for (const m of untrack(branches)) createRenderEffect(m, () => {});
62+
else
63+
createRenderEffect(
64+
boundary === "error"
65+
? createErrorBoundary(
66+
() => untrack(branches),
67+
() => "fallback"
68+
)
69+
: createLoadingBoundary(
70+
() => untrack(branches),
71+
() => "fallback",
72+
boundary === "loading-on" ? { on: k } : undefined
73+
),
74+
v => void (screen.out = String(v))
75+
);
76+
});
77+
const out = (v: string) => (boundary === "none" ? {} : { out: v });
78+
flush();
79+
res.get("A:0")!("x");
80+
res.get("B:0")!("y");
81+
await tick();
82+
// A re-arm with nothing pending under it: the swap resolves at its seam,
83+
// and the output is structure again afterwards.
84+
setK(1);
85+
flush();
86+
await tick();
87+
setA(1);
88+
flush();
89+
await tick();
90+
setB(1);
91+
flush();
92+
await tick();
93+
// Two mounts, two flushes: each joins only the hold its own flush read.
94+
setShowA(true);
95+
flush();
96+
await tick();
97+
setShowB(true);
98+
flush();
99+
await tick();
100+
expect(screen).toEqual({ p: "x/y", ...out(",") });
101+
102+
if (first === "A") {
103+
res.get("A:1")!("x1");
104+
await tick();
105+
expect(screen).toEqual({ p: "x1/y", pA: "pA 1", ...out("pA,") });
106+
res.get("B:1")!("y1");
107+
} else {
108+
res.get("B:1")!("y1");
109+
await tick();
110+
expect(screen).toEqual({ p: "x/y1", pB: "pB 1", ...out(",pB") });
111+
res.get("A:1")!("x1");
112+
}
113+
await tick();
114+
expect(screen).toEqual({ p: "x1/y1", pA: "pA 1", pB: "pB 1", ...out("pA,pB") });
115+
}
116+
);

0 commit comments

Comments
 (0)