Skip to content

Commit 91e4745

Browse files
ryansolidclaudecursoragent
committed
fix(signals): a first load derived from a hold lands into it (#3800)
A creation pass that read a held node (or whose creator did) and went pending records the transaction it derived from on its extension (_bornIn). Its first answer, landing while that transaction is still live, is staged into it and revealed at its commit; one that lands after is commit #0. The transaction is never held open by the flight: the loading-source carve-out (plan sec. 15.2) still keeps the node off its list. Co-authored-by: Claude <[email protected]> Co-authored-by: Cursor <[email protected]>
1 parent 93ae88d commit 91e4745

7 files changed

Lines changed: 198 additions & 13 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 node created over a hold now waits for it: an async first load that read a held value and lands while that hold is still live is staged into it and revealed at its commit, instead of publishing the held value early (#3800). The hold still never waits for the new node's first load; one that lands after the hold commits is its own commit.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Status legend: **live** stated and standing · **ruled** carries an explicit rul
7373
| A26 | ruled | `docs/SPEC-ASYNC-SEMANTICS.md:89` | — | action-await-contract.test.ts×2 fuzz-findings-l2.test.ts×1 posture-store-parity.test.ts×2 visibility-oracle-store.states.ts×2 visibility-oracle.states.ts×1 visibility-oracle.test.ts×1 | [ruled 2026-07-17] An ambient transaction window is one flush; parking is flush-driven — (**ruled 2026-07-17**, #2913; **enforcement hardened 2026-08-31**, #3141 — parking is flush-driven, and a trans… |
7474
| A27 | ruled | `docs/SPEC-ASYNC-SEMANTICS.md:275` | — | loading-value.test.ts×2 visibility-oracle.states.ts×18 visibility-oracle.test.ts×1 | [ruled 2026-08-10] The commit-#0 loading window is loading-class and verdict-quiet — (**ruled 2026-08-10**) **The commit-#0 loading window is loading-class and verdict-quiet.** A node born committed v… |
7575
| A28 | ruled, mechanism landed | `docs/SPEC-ASYNC-SEMANTICS.md:73` | constants.ts×1 core.ts×12 lanes.ts×2 scheduler.ts×3 types.ts×1 verdict.ts×2 store.ts×4 | createOptimistic.test.ts×5 fuzz-findings-l2.test.ts×6 held-derivation-not-a-proposal-3612.test.ts×1 latest-held-till-flush.test.ts×1 posture-store-parity.test.ts×5 question-scoped-pending.test.ts×3 snapshot-derived-store-rows.test.ts×1 createOptimisticStore.test.ts×10 optimistic-draft-visibility-3665.test.ts×5 optimistic-list-mutation-matrix.harness.ts×1 optimistic-list-mutation-matrix.test.ts×2 shallow.test.ts×1 woken-transaction-adopts-staged-bump.test.ts×1 treeshake.test.ts×2 verdict-contract.test.ts×1 visibility-oracle-store.states.ts×8 visibility-oracle.states.ts×8 | [ruled, mechanism landed 2026-09-15] A write becomes visible at flush — to every channel — (**ruled 2026-09-08**; supersedes the #2922 mid-tick pull) **A write becomes visible at flush — to every chan… |
76-
| A29 | amended | `docs/SPEC-ASYNC-SEMANTICS.md:97` | boundaries.ts×1 action.ts×1 constants.ts×1 core.ts×10 effect.ts×1 scheduler.ts×3 signals.ts×1 store.ts×1 | adoption-unchanged-key-read-3706.test.ts×9 body-end-supersession-visibility.test.ts×1 born-held.test.ts×3 boundary-not-born-held-3540.test.ts×4 create-time-holds.test.ts×1 createProjection.draft-lifetime-3585.test.ts×1 direct-commit-readers-posture.test.ts×1 fuzz-findings-l2.test.ts×6 held-conditional-memo.test.ts×1 held-frame-dependencies.test.ts×2 held-truth-lane-only.test.ts×3 l2-contract.test.ts×1 latest-held-till-flush.test.ts×2 mount-over-foreign-hold-3761.test.ts×1 optimistic-read-lane-not-transaction-3698.test.ts×3 posture-born-held-and-observation.test.ts×1 posture-store-parity.test.ts×6 derived-presence-async-3726.test.ts×3 optimistic-untracked-reads-f3-f5.test.ts×1 store-unchanged-read-independent-write-3688.test.ts×1 tick-scoped-pass-transaction.test.ts×2 treeshake.test.ts×3 visibility-oracle-store.states.ts×5 visibility-oracle-store.test.ts×1 visibility-oracle.states.ts×9 visibility-oracle.test.ts×1 write-proposals-3494.test.ts×1 | [ruled, amended in place 2026-09-13 (#3408)] A tracked read served a live transaction's staged value enters that transaction — A tracked computation served a node's staged `_pendingValue` — a value a … |
76+
| A29 | amended | `docs/SPEC-ASYNC-SEMANTICS.md:97` | boundaries.ts×1 action.ts×1 async.ts×1 constants.ts×1 core.ts×11 effect.ts×1 scheduler.ts×3 types.ts×1 signals.ts×1 store.ts×1 | adoption-unchanged-key-read-3706.test.ts×9 body-end-supersession-visibility.test.ts×1 born-held.test.ts×3 boundary-not-born-held-3540.test.ts×4 create-time-holds.test.ts×1 createProjection.draft-lifetime-3585.test.ts×1 direct-commit-readers-posture.test.ts×1 fuzz-findings-l2.test.ts×6 held-conditional-memo.test.ts×1 held-frame-dependencies.test.ts×2 held-truth-lane-only.test.ts×3 l2-contract.test.ts×1 latest-held-till-flush.test.ts×2 mount-over-foreign-hold-3761.test.ts×1 optimistic-read-lane-not-transaction-3698.test.ts×3 posture-born-held-and-observation.test.ts×1 posture-store-parity.test.ts×6 derived-presence-async-3726.test.ts×3 optimistic-untracked-reads-f3-f5.test.ts×1 store-unchanged-read-independent-write-3688.test.ts×1 tick-scoped-pass-transaction.test.ts×2 treeshake.test.ts×3 visibility-oracle-store.states.ts×5 visibility-oracle-store.test.ts×1 visibility-oracle.states.ts×9 visibility-oracle.test.ts×1 write-proposals-3494.test.ts×1 | [ruled, amended in place 2026-09-13 (#3408)] A tracked read served a live transaction's staged value enters that transaction — A tracked computation served a node's staged `_pendingValue` — a value a … |
7777
| A30 | ruled | `docs/SPEC-ASYNC-SEMANTICS.md:231` | async.ts×3 attribution.ts×1 constants.ts×1 core.ts×1 effect.ts×1 scheduler.ts×5 | async-landing-deps-3461.test.ts×3 fuzz-findings-l2.test.ts×2 held-conditional-effect.test.ts×1 held-conditional-memo.test.ts×1 held-frame-dependencies.test.ts×2 ispending-in-boundary-on-3528.test.ts×1 lane-frame-deferred-run-3662.test.ts×1 lane-frame-held-lane-3662.test.ts×1 posture-born-held-and-observation.test.ts×1 treeshake.test.ts×2 write-proposals-3494.test.ts×2 zombie-rerun-after-commit-3546.test.ts×2 | [ruled 2026-09-13 (#3410)] A memo's dependencies are the committed frame's until the frame is replaced — A pass that _staged_ its value has not replaced the committed frame, so the committed value sti… |
7878
| A31 | live | `docs/SPEC-ASYNC-SEMANTICS.md:105` | boundaries.ts×1 core.ts×1 verdict.ts×2 | fuzz-findings-l2.test.ts×5 ispending-combined-atomic-3442.test.ts×1 | [live 2026-09-14 (#3442)] A memo computes under its own lane posture, never its puller's — A memo's value is one shared slot every reader sees, so its pass runs under the lane posture the memo itself … |
7979
| A32 | ruled | `docs/SPEC-ASYNC-SEMANTICS.md:113` | core.ts×4 lanes.ts×1 store.ts×1 | visibility-oracle-store.states.ts×8 visibility-oracle-store.test.ts×1 visibility-oracle.states.ts×9 visibility-oracle.test.ts×1 | [ruled 2026-09-14] Children-forbidden readers see the frame, not the graph — `createTrackedEffect` and `onSettled` callbacks are effect-phase code that runs after the frame is decided. They read the f… |

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ import {
2929
flush,
3030
globalQueue,
3131
GlobalQueue,
32+
holdNode,
3233
joinFuture,
34+
liveTx,
3335
MAINLINE_QUESTION,
3436
passLane,
3537
question,
@@ -464,7 +466,14 @@ export function handleAsync<T>(
464466
} else {
465467
// CARVE 2: the override-covered landing (hold + A18 supersession) and the
466468
// lane-routed landing (derived override, lane effect queue) went with
467-
// the optimistic engine; every landing is the plain setSignal.
469+
// the optimistic engine; every landing is the plain setSignal. A first
470+
// answer derived from a hold still live lands into it (A29).
471+
const t = el._x!._bornIn;
472+
if (t !== null) {
473+
el._x!._bornIn = null;
474+
const live = wasUninitialized && liveTx(t);
475+
if (live) holdNode(el, live);
476+
}
468477
try {
469478
setSignal(el, () => value);
470479
} catch (e) {

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,13 @@ export function recompute(el: Computed<any>, create: boolean = false): void {
509509
if (GlobalQueue._laneStage!(el, lane, create, errored)) setPassLane(lane);
510510
else lane = null;
511511
}
512+
// The transaction a first pass derives from (A29, creation-time form): the
513+
// flush has joined one and the pass read a held node, or a pass created it
514+
// (ruling A). Lane work is the lane's.
515+
const bornIn =
516+
create && lane === null && (joined || (creatorPass(oldcontext)?._flags ?? 0) & REACTIVE_JOINED)
517+
? (flushTransaction ?? passTx)
518+
: null;
512519

513520
if (!el._x?._error) {
514521
// Observe-tier fan-in (HUGE_FAN_IN): the validated prefix [_deps.._depsTail]
@@ -631,14 +638,7 @@ export function recompute(el: Computed<any>, create: boolean = false): void {
631638
if (isEffect && el._pendingValue === NOT_PENDING) el._value = value;
632639
else if (isEffect || lane._shown) el._pendingValue = value;
633640
else el._x!._lane = value;
634-
} else if (
635-
create
636-
? !(
637-
(flushTransaction !== null || passTx !== null) &&
638-
(joined || (creatorPass(oldcontext)?._flags ?? 0) & REACTIVE_JOINED)
639-
)
640-
: isEffect && el._pendingValue === NOT_PENDING
641-
) {
641+
} else if (create ? bornIn === null : isEffect && el._pendingValue === NOT_PENDING) {
642642
// A first pass publishes directly. So does an effect: its value slot
643643
// is private (only its own run reads it), and the staging round-trip
644644
// (queuePendingNode + commitPendingNodes) paid per effect on the
@@ -656,7 +656,7 @@ export function recompute(el: Computed<any>, create: boolean = false): void {
656656
// tick is a read of its world (the mount-during-a-hold case), not
657657
// only after the seam parks it.
658658
if (create) {
659-
holdNode(el, (flushTransaction ?? passTx)!);
659+
holdNode(el, bornIn!);
660660
// Born into the future: no committed value until the landing
661661
// (`commitPendingNode` initializes it) — every reader of it
662662
// derives from the future (`read`), an untracked one throws
@@ -697,6 +697,10 @@ export function recompute(el: Computed<any>, create: boolean = false): void {
697697
if (wasPendingSource && !(el._statusFlags & (STATUS_PENDING | STATUS_UNINITIALIZED)))
698698
settlePendingSource(el);
699699
}
700+
// A first pass born pending into a transaction is not held by it — the
701+
// hold does not wait for its first load (plan sec. 15.2) — but its answer
702+
// is that world's: the landing joins the transaction if it is still live.
703+
if (bornIn !== null && el._statusFlags & STATUS_PENDING) ext(el)._bornIn = bornIn;
700704
// Dependencies are the committed frame's until it is replaced (A30, #3410):
701705
// a pass that staged its value leaves the previous pass's tail linked for
702706
// `commitPendingNode` to trim, so a write to a dependency the committed
@@ -932,6 +936,7 @@ export function ext(el: { _x: NodeExtension | null }): NodeExtension {
932936
_pendingFirstChild: null,
933937
_pendingDisposal: null,
934938
_transaction: null,
939+
_bornIn: null,
935940
_reask: false,
936941
_flushed: NOT_PENDING,
937942
_flushedAt: -1,

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,12 @@ export function joinPassTx(t: Transaction): void {
186186
export function txOf(n: Signal<any> | Computed<any>): Transaction {
187187
return (n._x!._transaction = resolveTx(n._x!._transaction!));
188188
}
189+
/** `t` resolved through merges while it is still parked or open; null once
190+
* it has landed. */
191+
export function liveTx(t: Transaction): Transaction | null {
192+
t = resolveTx(t);
193+
return transactions.indexOf(t) !== -1 ? t : null;
194+
}
189195
export function resolveTx(t: Transaction): Transaction {
190196
while (t._into !== null) t = t._into;
191197
return t;

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ export interface NodeExtension {
8181
/** L2 — the transaction holding this node while CONFIG_HELD is set
8282
* (`holdNode`); resolved through merges by `txOf`. */
8383
_transaction: Transaction | null;
84+
/** L2 — the transaction a first pass that went pending derived from (it
85+
* read a held node, or its creator did): its first answer lands into it
86+
* while it is live, so the node waits for that hold; the hold never waits
87+
* for the node's first load (A29, 2026-10-05). Consumed at the landing. */
88+
_bornIn: Transaction | null;
8489
/** The node's current flight re-asks the same question (a `refresh()`,
8590
* A19 exc. 2 / A24): verdict-quiet — `isPending` reads false for it —
8691
* through its landing until the commit. */

‎packages/signals/tests/create-time-holds.test.ts‎

Lines changed: 157 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import { describe, expect, it } from "vitest";
1010
import {
1111
action,
12+
createLoadingBoundary,
1213
createMemo,
1314
createRenderEffect,
1415
createRoot,
@@ -17,8 +18,7 @@ import {
1718
} from "../src/index.js";
1819

1920
const tick = async () => {
20-
await Promise.resolve();
21-
await Promise.resolve();
21+
for (let i = 0; i < 6; i++) await Promise.resolve();
2222
flush();
2323
};
2424

@@ -78,3 +78,158 @@ describe("#3802: a born-held render effect re-derived by a mainline write", () =
7878
expect(log.sort()).toEqual(["div true Updated", "show child"]);
7979
});
8080
});
81+
82+
describe("#3800: a node created over a hold waits for it; the hold never waits for the node", () => {
83+
// `slow` holds count = 2 while its flight is out; `parent` shows both.
84+
function setup() {
85+
const [count, setCount] = createSignal(1);
86+
const slowGates: Array<() => void> = [];
87+
const log: string[] = [];
88+
createRoot(() => {
89+
const slow = createMemo(async () => {
90+
const c = count();
91+
await new Promise<void>(resolve => slowGates.push(resolve));
92+
return c;
93+
});
94+
createRenderEffect(
95+
() => [count(), slow()] as const,
96+
([c, s]) => {
97+
log.push(`parent ${c} ${s}`);
98+
},
99+
undefined,
100+
{ schedule: true }
101+
);
102+
});
103+
flush();
104+
return { count, setCount, slowGates, log };
105+
}
106+
107+
async function holdCount(s: ReturnType<typeof setup>) {
108+
s.slowGates.shift()!();
109+
await tick();
110+
s.setCount(2);
111+
flush();
112+
expect(s.log).toEqual(["parent 1 1"]);
113+
}
114+
115+
it("a first load that reads the held value lands into the hold (the report)", async () => {
116+
const s = setup();
117+
await holdCount(s);
118+
createRoot(() => {
119+
const child = createMemo(() => Promise.resolve(s.count()));
120+
createRenderEffect(
121+
child,
122+
v => {
123+
s.log.push(`child ${v}`);
124+
},
125+
undefined,
126+
{ schedule: true }
127+
);
128+
});
129+
flush();
130+
await tick();
131+
expect(s.log).toEqual(["parent 1 1"]);
132+
133+
s.slowGates.shift()!();
134+
await tick();
135+
expect(s.log).toEqual(["parent 1 1", "parent 2 2", "child 2"]);
136+
});
137+
138+
it("under a fresh boundary: the fallback shows until the hold commits the content", async () => {
139+
const s = setup();
140+
await holdCount(s);
141+
createRoot(() => {
142+
const child = createMemo(() => Promise.resolve(s.count()));
143+
const view = createLoadingBoundary(
144+
() => `content ${child()}`,
145+
() => "fallback"
146+
);
147+
createRenderEffect(
148+
view,
149+
v => {
150+
s.log.push(`view ${v}`);
151+
},
152+
undefined,
153+
{ schedule: true }
154+
);
155+
});
156+
flush();
157+
await tick();
158+
expect(s.log).toEqual(["parent 1 1", "view fallback"]);
159+
160+
s.slowGates.shift()!();
161+
await tick();
162+
expect(s.log).toEqual(["parent 1 1", "view fallback", "parent 2 2", "view content 2"]);
163+
});
164+
165+
it("the hold commits without a slower first load; the load lands after as its own commit", async () => {
166+
const s = setup();
167+
await holdCount(s);
168+
const childGates: Array<() => void> = [];
169+
createRoot(() => {
170+
const child = createMemo(async () => {
171+
const c = s.count();
172+
await new Promise<void>(resolve => childGates.push(resolve));
173+
return c;
174+
});
175+
createRenderEffect(
176+
child,
177+
v => {
178+
s.log.push(`child ${v}`);
179+
},
180+
undefined,
181+
{ schedule: true }
182+
);
183+
});
184+
flush();
185+
186+
s.slowGates.shift()!();
187+
await tick();
188+
expect(s.log).toEqual(["parent 1 1", "parent 2 2"]);
189+
190+
childGates.shift()!();
191+
await tick();
192+
expect(s.log).toEqual(["parent 1 1", "parent 2 2", "child 2"]);
193+
});
194+
195+
it("an action's hold: the first load waits for the action, never the reverse", async () => {
196+
const [user, setUser] = createSignal("ann");
197+
const log: string[] = [];
198+
createRoot(() => {
199+
createRenderEffect(user, u => {
200+
log.push(`header ${u}`);
201+
});
202+
});
203+
flush();
204+
const release = hold(() => setUser("bob"));
205+
206+
const pageGates: Array<() => void> = [];
207+
const mount = (name: string) =>
208+
createRoot(() => {
209+
const page = createMemo(async () => {
210+
const u = user();
211+
await new Promise<void>(resolve => pageGates.push(resolve));
212+
return `${name}-${u}`;
213+
});
214+
createRenderEffect(page, v => {
215+
log.push(`page ${v}`);
216+
});
217+
});
218+
mount("fast");
219+
flush();
220+
mount("slow");
221+
flush();
222+
223+
pageGates.shift()!();
224+
await tick();
225+
expect(log).toEqual(["header ann"]);
226+
227+
release();
228+
await tick();
229+
expect(log).toEqual(["header ann", "header bob", "page fast-bob"]);
230+
231+
pageGates.shift()!();
232+
await tick();
233+
expect(log).toEqual(["header ann", "header bob", "page fast-bob", "page slow-bob"]);
234+
});
235+
});

0 commit comments

Comments
 (0)