Skip to content

Commit ce92b78

Browse files
committed
feat(signals): publish mainline mounts before foreign holds
1 parent a5d0e76 commit ce92b78

23 files changed

Lines changed: 886 additions & 223 deletions
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+
Allow fresh mainline computations to publish a coherent committed first frame while a foreign transaction holds their inputs. After publication, continue those inputs through the new computation under the source transaction, including any downstream async work. Preserve normal entanglement for existing computations and mounts without a committed answer.

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

Lines changed: 42 additions & 42 deletions
Large diffs are not rendered by default.

‎packages/signals/docs/SPEC-ASYNC-SEMANTICS.md‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,27 @@ Sync derivations of transition-held sources are visible through `latest()`/`isPe
7474

7575
### A29. A tracked read served a live transaction's staged value enters that transaction
7676

77+
**Experimental branch amendment (mount propagation seams):** the historical
78+
creation-time rule below is replaced for a fresh, ordinary mainline computation
79+
whose inputs have committed answers. Its first pass reads foreign held inputs
80+
from the committed/displayed frame, while keeping its own batch's staged inputs.
81+
It publishes with the mounting batch; only afterwards does the foreign
82+
transaction continue through the new computation using its staged inputs.
83+
This continuation belongs to the older transaction, including any downstream
84+
async it discovers. If the mount itself is async, the older transaction waits
85+
for that initial frame to publish before continuing; this is a directional wait,
86+
not a merger of the mounting and source transactions.
87+
88+
The change does not apply to existing computations, creation inside an active
89+
transaction, loading-value windows, optimistic computations, verdict companions,
90+
or authoritative `resolve`/`until` readers. Inputs without a committed answer
91+
still suspend and follow the born-held/boundary machinery described below.
92+
Separate new subtrees over separate transactions remain independent. A shared
93+
continuation that reads multiple held transactions still follows normal memo
94+
entanglement. This is not a general propagation boundary or a parallel-futures
95+
implementation. Pinned by `tests/mount-propagation-seam.test.ts`, updated
96+
creation-time visibility tests, and the compiled nested-Show preview test.
97+
7798
**Status:** **ruled, amended in place** 2026-09-13 (#3408) — maintainer ruling, Cluster 4 triage: a value derived from the held world is that transaction's work, whichever path first read it; amended 2026-09-14 (creation-time form — "born held"; the entry is the pass's, never the mainline block's); amended 2026-09-18 (#3540, maintainer ruling — boundaries are exempt: a pass under a loading boundary that has not revealed is born held into the transaction and the boundary shows its fallback now)
7899
**Pinned by:** `tests/held-conditional-memo.test.ts` (#3408: a memo whose branch flips mainline and starts reading a held signal reveals with it, not before); `tests/born-held.test.ts` (creation-time form: fresh memo + effect held, fresh direct effect shows committed, unrelated write after the mount stays mainline, untracked read throws until commit); `tests/visibility-oracle.test.ts` (published column, held and superseded states); `tests/boundary-not-born-held-3540.test.ts` (boundary exemption: a `Loading` mounted mainline over a held value shows its fallback and reveals at the commit; content created behind a fallback is collected, not published; the `on` key lands where its change lands)
79100
**Mechanism (index, 2026-09-14; boundary exemption 2026-09-18):** `enterStagedRead` on each of `read()`'s value selections that return `_pendingValue` (both fast paths and the slow path) → `globalQueue.initTransition(el._transition)`; no-op for the ambient batch (`_transition` null), the active transaction, and a probe read (`pendingCheckActive`). Creation-time form: outside a flush `enterStagedRead` records the transaction (`stagedEntry`) instead of entering; `recompute` stages the pass's node into it (`_transition` stamped, pushed to its `_pendingNodes`, `STATUS_UNINITIALIZED` kept), adds an effect to its `_gatedSubs` and skips the synchronous first run (`effect()`); `commitPendingNode` initializes it; `read()` holds readers of a node with a staged value and no committed one. Optimistic-posture nodes keep the entering path; verdict pulls (`GlobalQueue._verdictPull` — `latest()`/`isPending()` companions and their pulls) are observations and never enter from mainline (a `latest()` call that entered captured the caller's block, 2026-09-15). Boundary exemption (#3540): `enterStagedRead` takes the staging path inside a flush too when the pass is under a fresh loading boundary (`underFreshLoadingBoundary` — the nearest pending-collecting queue up its chain is uninitialized); `recompute` tells that boundary (`queue.notify` with a `NotReadyError` sourced at the node), which collects the node and shows its fallback; `CollectionQueue._checkSources` keeps a source collected while it is born held (staged, `STATUS_UNINITIALIZED`) and releases it at the commit that initializes it. The boundary's priming read of its tree is a `spectate` read: it records nothing on the mounting pass — no link, no entry — and a born-held tree is simply not ready to it.

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

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ import {
9999
clock,
100100
currentTransition,
101101
dirtyQueue,
102+
deferMountPropagation,
102103
findLane,
103104
globalQueue,
104105
GlobalQueue,
@@ -171,6 +172,8 @@ export let stale = false;
171172
export let pendingCheckActive = false;
172173
export let latestReadActive = false;
173174
export let context: Owner | null = null;
175+
/** Only a fresh computation's first pass may establish a new mount seam. */
176+
let mounting: Computed<any> | null = null;
174177
export let currentOptimisticLane: OptimisticLane | null = null;
175178

176179
/** Notify `node`'s subscribers on `lane`'s channel: they recompute as the
@@ -391,12 +394,28 @@ export function recompute(el: Computed<any>, create: boolean = false): void {
391394
// a pending frame to live observers of the verdict (#2990).
392395
const wasLoading = el._loading;
393396

394-
// Creation-time A29 (see enterStagedRead): a pass outside a flush that is
395-
// served a live transaction's staged value records the transaction here
396-
// and is staged INTO it below — "born held" — instead of committing.
397+
// A29 still stages computations that have no committed input to mount
398+
// from. Eligible mainline creation instead publishes a first frame, then
399+
// lets the foreign hold continue through that frame after publication.
397400
const prevStagedEntry = stagedEntry;
398401
stagedEntry = null;
399402
const oldcontext = context;
403+
const prevMounting = mounting;
404+
mounting =
405+
create &&
406+
activeTransition === null &&
407+
!el._loading &&
408+
!GlobalQueue._verdictPull &&
409+
!(
410+
el._config &
411+
(CONFIG_OPTIMISTIC |
412+
CONFIG_DERIVED_OVERRIDE |
413+
CONFIG_AUTHORITATIVE_READ |
414+
CONFIG_DIRECT_COMMIT)
415+
) &&
416+
!el._x?._parentSource
417+
? el
418+
: null;
400419
context = el;
401420
el._depsTail = null;
402421
el._depGen++;
@@ -554,6 +573,7 @@ export function recompute(el: Computed<any>, create: boolean = false): void {
554573
(el._flags & (REACTIVE_ZOMBIE | REACTIVE_DISPOSED)) |
555574
(create ? el._flags & REACTIVE_SNAPSHOT_STALE : 0);
556575
context = oldcontext;
576+
mounting = prevMounting;
557577
}
558578
// The cast re-widens: TS narrowed `stagedEntry` to `null` at the reset
559579
// above and does not invalidate that across the compute call that
@@ -837,7 +857,7 @@ export function recompute(el: Computed<any>, create: boolean = false): void {
837857
// dropped a dep" — deps past `_depsTail` (trimmed below, or kept by A30
838858
// for a staged pass), or a pass that read nothing — not "recovered from
839859
// pending": a reporter registered by the stale-reader carve-out
840-
// (heldFromStale, an INITIALIZED source refetching) displays the committed
860+
// (heldFromOutside, an INITIALIZED source refetching) displays the committed
841861
// value and is never pending (fuzzer case 79). Every parked transaction,
842862
// not the reporter's stamp: the transaction waiting on it registered it
843863
// without stamping it. One idle pass per parked transaction; done ones
@@ -1775,7 +1795,7 @@ export function installAuthoritativeRead(): void {
17751795
* served the committed value because `txn` holds what it read re-runs at
17761796
* txn's commit, when the value it was denied becomes the frame — unless its
17771797
* own last value already came from that transaction. One registration for
1778-
* the node path (heldFromStale) and the store's backing paths, which have
1798+
* the node path (heldFromOutside) and the store's backing paths, which have
17791799
* no node to carry the hold (heldFromReader, the adoption hold view). */
17801800
export function recordStaleReplay(txn: Transition, c: Computed<any>): void {
17811801
const vt: Transition | null | undefined = (c as any)._valueTransition;
@@ -1790,7 +1810,7 @@ export function recordStaleReplay(txn: Transition, c: Computed<any>): void {
17901810
* lane and a separate transaction (a lane sees what lands from its parent as
17911811
* its own; a separate transaction would wait for the parent to settle) —
17921812
* see `ownsLane` in lanes.ts, built on this. One relation for the
1793-
* stale-of-foreign clause (heldFromStale), the lane arm (readsHeldCommitted)
1813+
* stale-of-foreign clause (heldFromOutside), the lane arm (readsHeldCommitted)
17941814
* and the store's backing holds (foreignHold); `serve` has no lane arm of
17951815
* its own, the lane's extra visibility lives here.
17961816
*/
@@ -1800,7 +1820,9 @@ export function ownsHold(hold: Transition): boolean {
18001820
);
18011821
}
18021822

1803-
function heldFromStale(el: Signal<any> | Computed<any>, c: Computed<any>): boolean {
1823+
function heldFromOutside(el: Signal<any> | Computed<any>, c: Computed<any>): boolean {
1824+
if (mountSeesCommitted(el._transition, c)) return true;
1825+
if (!stale) return false;
18041826
const t = el._transition;
18051827
if (t === null || ownsHold(t)) return false;
18061828
const txn = currentTransition(t);
@@ -1812,6 +1834,15 @@ function heldFromStale(el: Signal<any> | Computed<any>, c: Computed<any>): boole
18121834
return true;
18131835
}
18141836

1837+
/** The new subtree publishes a coherent first frame before the older
1838+
* transaction propagates through it. Its own transaction's staged inputs
1839+
* remain visible; only foreign held inputs use the committed frame. */
1840+
export function mountSeesCommitted(t: Transition | null | undefined, c: Computed<any>): boolean {
1841+
if (mounting !== c || !t || ownsHold(t) || currentOptimisticLane !== null) return false;
1842+
deferMountPropagation(t, c);
1843+
return true;
1844+
}
1845+
18151846
/**
18161847
* A tracked computation about to be served a live transaction's staged value
18171848
* derives from that transaction's world, so it enters the transaction and
@@ -1911,7 +1942,7 @@ export function enterStagedRead(
19111942
* - a children-forbidden reader (createTrackedEffect / onSettled: the frame,
19121943
* never the graph — A32);
19131944
* - a stale reader (render effect) of a FOREIGN transaction's staged write —
1914-
* committed, no entanglement (heldFromStale registers the replay; a node
1945+
* committed, no entanglement (heldFromOutside registers the replay; a node
19151946
* born held has no committed frame to fall back to, `noCommitted`);
19161947
* - HELD truth (#3164, CONFIG_HELD_TRUTH) read by a LANE pass: staged
19171948
* confirming truth — fold-staged onto an armed family, or entangle-stolen
@@ -1941,7 +1972,7 @@ export function readerSeesCommitted(
19411972
(currentOptimisticLane !== null && GlobalQueue._laneReadsCommitted!(el, owner, c)) ||
19421973
el._pendingValue === NOT_PENDING ||
19431974
c._config & CONFIG_CHILDREN_FORBIDDEN ||
1944-
(stale && !noCommitted && heldFromStale(el, c)) ||
1975+
(!noCommitted && heldFromOutside(el, c)) ||
19451976
(el._config & CONFIG_HELD_TRUTH &&
19461977
currentOptimisticLane !== null &&
19471978
!latestReadActive &&
@@ -2088,7 +2119,7 @@ export function readNodeFast<T>(el: Signal<T>): T | typeof READ_SLOW {
20882119
!c ||
20892120
el._pendingValue === NOT_PENDING ||
20902121
c._config & CONFIG_CHILDREN_FORBIDDEN ||
2091-
(stale && heldFromStale(el, c as Computed<any>))
2122+
heldFromOutside(el, c as Computed<any>)
20922123
? el._value
20932124
: (enterStagedRead(el), el._pendingValue)
20942125
) as T;
@@ -2144,7 +2175,7 @@ export function read<T>(el: Signal<T> | Computed<T>): T {
21442175
!c ||
21452176
el._pendingValue === NOT_PENDING ||
21462177
c._config & CONFIG_CHILDREN_FORBIDDEN ||
2147-
(stale && heldFromStale(el, c as Computed<any>))
2178+
heldFromOutside(el, c as Computed<any>)
21482179
? el._value
21492180
: (enterStagedRead(el), el._pendingValue)
21502181
) as T;
@@ -2192,7 +2223,7 @@ export function read<T>(el: Signal<T> | Computed<T>): T {
21922223
// one carve-out: a stale (render) reader of a node pending in some OTHER
21932224
// transaction keeps showing the node's committed value, no entanglement
21942225
// (parallel transactions; the reader is recorded for that transaction's
2195-
// commit replay, `heldFromStale`). The carve-out is sound only while the
2226+
// commit replay, `heldFromOutside`). The carve-out is sound only while the
21962227
// committed value is coherent with the visible frame, i.e. while the
21972228
// flight's inputs are themselves unpublished: the stamp alone does not
21982229
// say so (it is pending-node bookkeeping), so it is refused when the
@@ -2206,11 +2237,11 @@ export function read<T>(el: Signal<T> | Computed<T>): T {
22062237
if (
22072238
c &&
22082239
!(
2209-
stale &&
2240+
(stale || mounting === c) &&
22102241
!(owner._statusFlags & STATUS_UNINITIALIZED) &&
22112242
!(owner._config & CONFIG_INPUTS_PUBLISHED) &&
22122243
!(owner._config & CONFIG_HAS_LANE && GlobalQueue._laneLive!(owner as Computed<any>)) &&
2213-
heldFromStale(owner, c as Computed<any>)
2244+
heldFromOutside(owner, c as Computed<any>)
22142245
)
22152246
) {
22162247
if (__DEV__ && c && c._config & CONFIG_CHILDREN_FORBIDDEN) {

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
CONFIG_FW_CHILDREN,
44
REACTIVE_CHECK,
55
REACTIVE_DIRTY,
6+
REACTIVE_DISPOSED,
67
REACTIVE_IN_HEAP,
78
REACTIVE_IN_HEAP_HEIGHT,
89
REACTIVE_RECOMPUTING_DEPS,
@@ -29,6 +30,12 @@ export function enqueueSub(node: Computed<any>): void {
2930
insertIntoHeap(node, queue);
3031
}
3132

33+
/** Deferred replays may outlive their reader. Ordinary propagation stays on
34+
* enqueueSub's hot path; publication queues use this liveness check. */
35+
export function replaySub(node: Computed<any>): void {
36+
if (!(node._flags & REACTIVE_DISPOSED)) enqueueSub(node);
37+
}
38+
3239
export interface Heap {
3340
_heap: (Computed<unknown> | undefined)[];
3441
_marked: boolean;

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
import {
2-
CONFIG_DERIVED_OVERRIDE,
3-
CONFIG_HAS_LANE,
4-
NOT_PENDING,
5-
REACTIVE_DISPOSED
6-
} from "./constants.js";
1+
import { CONFIG_DERIVED_OVERRIDE, CONFIG_HAS_LANE, NOT_PENDING } from "./constants.js";
72
import { currentOptimisticLane, ext, hasActiveOverride, ownsHold } from "./core.js";
83
export { hasActiveOverride };
9-
import { enqueueSub } from "./heap.js";
4+
import { replaySub } from "./heap.js";
105
import {
116
activeTransition,
127
currentTransition,
@@ -145,7 +140,7 @@ export function readsHeldCommitted(owner: Computed<any>, c: Computed<any>): bool
145140
const lane = resolveLane(owner);
146141
if (!lane || !laneHeld(lane)) return false;
147142
if (ownsLane(lane, owner)) return false;
148-
lane._effectQueues[0].push(() => c._flags & REACTIVE_DISPOSED || enqueueSub(c));
143+
lane._effectQueues[0].push(() => replaySub(c));
149144
return true;
150145
}
151146

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
currentOptimisticLane,
3636
enterStagedRead,
3737
latestReadActive,
38+
mountSeesCommitted,
3839
setSignal,
3940
stale,
4041
ext
@@ -63,9 +64,9 @@ import {
6364
insertSubs,
6465
origin,
6566
queuePendingNode,
67+
runQueue,
6668
schedule,
6769
sourceObserved,
68-
type QueueCallback,
6970
type Transition
7071
} from "./scheduler.js";
7172
import type { Computed, Link, Signal } from "./types.js";
@@ -481,6 +482,7 @@ function overrideRead(el: OptimisticNode, c: Computed<any>): unknown {
481482
// a body-ended node read the committed truth beside a display still
482483
// showing the override.
483484
const owner = resolveTransition(el);
485+
if (mountSeesCommitted(owner, c)) return unwrapOverride(el._x?._overrideValue);
484486
// A lane pass composes the frame the lane applies AHEAD of the commit, so
485487
// it reads what is on screen — for a superseded node, the override (A18
486488
// (c): the applied screen keeps it until the transaction commits). The
@@ -579,10 +581,6 @@ function landOnOverride<T>(el: Signal<T> | Computed<T>, v: T | ((prev: T) => T))
579581
return v;
580582
}
581583

582-
function runQueue(queue: QueueCallback[], type: number): void {
583-
for (let i = 0; i < queue.length; i++) queue[i](type | LANE_RUN);
584-
}
585-
586584
/**
587585
* Run effects from all lanes that are ready (no OBSERVED pending async — see
588586
* laneHeld).
@@ -594,7 +592,7 @@ function runLaneEffects(type: number): void {
594592
const effects = lane._effectQueues[type - 1];
595593
if (effects.length) {
596594
lane._effectQueues[type - 1] = [];
597-
runQueue(effects, type);
595+
runQueue(effects, type | LANE_RUN);
598596
}
599597
}
600598
// Optimistic patch applications ride the same visibility slot as lane
@@ -609,8 +607,8 @@ function cleanupCompletedLanes(completingTransition: Transition | null): void {
609607
: !lane._transition;
610608
if (!owned) continue;
611609
if (!lane._mergedInto) {
612-
if (lane._effectQueues[0].length) runQueue(lane._effectQueues[0], EFFECT_RENDER);
613-
if (lane._effectQueues[1].length) runQueue(lane._effectQueues[1], EFFECT_USER);
610+
if (lane._effectQueues[0].length) runQueue(lane._effectQueues[0], EFFECT_RENDER | LANE_RUN);
611+
if (lane._effectQueues[1].length) runQueue(lane._effectQueues[1], EFFECT_USER | LANE_RUN);
614612
}
615613
if (lane._source._x?._optimisticLane === lane)
616614
if (lane._source._x !== null) lane._source._x._optimisticLane = undefined;

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import {
3636
GlobalQueue,
3737
globalQueue,
3838
schedule,
39-
wokenTransitions,
39+
queueTransitionWake,
4040
zombieQueue
4141
} from "./scheduler.js";
4242
import type { Computed, Disposable, Link, Owner, Root } from "./types.js";
@@ -113,8 +113,7 @@ export function disposeChildren(node: Owner, self: boolean = false, zombie?: boo
113113
// it (#3372): its death is a completion event the transaction must be
114114
// re-judged for, and nothing else re-enters a parked transaction.
115115
const t = n._transition;
116-
if (t && n._statusFlags & STATUS_PENDING && !wokenTransitions.includes(t))
117-
(wokenTransitions.push(t), schedule());
116+
if (t && n._statusFlags & STATUS_PENDING && queueTransitionWake(t)) schedule();
118117
}
119118
if (self && __DEV__) clearSignals(node);
120119
if (self && (node as any)._fn && (node as Computed<unknown>)._x !== null)

0 commit comments

Comments
 (0)