Skip to content

Commit afec0a7

Browse files
committed
Merge remote-tracking branch 'origin/next' into claude/project-thread-x1ore2-lane-reask
# Conflicts: # packages/signals/docs/RULES-INDEX.md # packages/signals/src/core/core.ts
2 parents 0d6ca5a + 5f22701 commit afec0a7

15 files changed

Lines changed: 1097 additions & 96 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+
`latest(x)` read inline and the same read through a memo (`createMemo(() => latest(x))`) show the same screen. A render effect re-run by a verdict memo's change now tears beside a held optimistic lane through the memo as it does inline (`1 x1 / 5`, #4284). A plain write beside an async memo shows the screen beside the proposal (`v:0 l:1`) in either read order and either form. The committed frame's effect beside one a held pass created tears during the hold inline as through a memo. `latest()` of an async derivation's first load still in flight in a verdict lane is loading, never `undefined`, including after the lane dissolves. The same holds through an identity memo or a derived store, and `isPending()` of such a load is loading too. A plain synchronous write beside `latest()` computes once. An `<Errored>` keeps its error on screen while the async memo the error came through re-asks after the source that threw recovers, instead of revealing content whose holes are still loading.

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

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

‎packages/signals/src/boundaries.ts‎

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,9 @@ function record(b: Boundary, node: Computed<any>, source = node): void {
184184
function caught(b: Boundary, node: Computed<any>, error: unknown, source = node): void {
185185
if (b._type === STATUS_ERROR) {
186186
// An error boundary waits on what THREW (`StatusError.source`), not on
187-
// the reader that saw it: the reader recovers the moment a refetch
188-
// starts (its boundary catches the pending), while the error is settled
189-
// only when its source is neither errored nor in flight — or when the
187+
// the reader that saw it, while the error is settled only when its
188+
// source is neither errored nor in flight and the reader is not pending
189+
// on the answer that replaces it (`prune`) — or when the
190190
// reader is disposed: a source no live reader holds holds nothing
191191
// (#4373). A source that died (a memo its reader owned, kept past the
192192
// pass that disposed it) settles nothing: the reader is waited on.
@@ -199,6 +199,13 @@ function caught(b: Boundary, node: Computed<any>, error: unknown, source = node)
199199
reportClientError(caught, b._owner, source);
200200
}
201201
record(b, node, source);
202+
// A loading fallback behind an error fallback is hidden: the error stays
203+
// the display until what the fallback waits on answers (D-39) — the
204+
// error boundary waits on it too.
205+
// (`_type`: STATUS_PENDING 1 < STATUS_ERROR 2 — an error boundary above a
206+
// loading one.)
207+
for (let p: Boundary | null = b; (p = p._parent); )
208+
if (p._fallback && p._type > b._type) record(p, node);
202209
if (b._armed) flip(b);
203210
// Already showing the fallback: one more reader to wait on changes
204211
// nothing on screen. The fallback is instantiated once per show — a later
@@ -327,7 +334,11 @@ function release(b: Boundary): void {
327334
* content reveals at the commit, with its run. The tree is: the output reads
328335
* it and enters the transaction itself (its committed value shows until the
329336
* landing). The statuses that keep a reader: pending — and its error, for an
330-
* error boundary (`_type` is the status it catches). */
337+
* error boundary (`_type` is the status it catches) — on the reader or its
338+
* source. A reader pending again after the source that threw answered (it
339+
* re-asks through a memo that carried the error) has no new answer yet: the
340+
* error stays the display (D-39: a pending is not a value; async-gen 91501
341+
* #1831). */
331342
export function prune(b: Boundary, pass: boolean): number {
332343
const mask = b._type | STATUS_PENDING;
333344
for (const [r, s] of b._readers) {
@@ -336,7 +347,10 @@ export function prune(b: Boundary, pass: boolean): number {
336347
// it publishes with the commit. A reader that threw it now (a lane
337348
// pass, a reader of a node born staged) reached the boundary first
338349
// (#4364).
339-
if (s._statusFlags & mask || (mask & STATUS_ERROR && s._config & CONFIG_STAGED_ERROR))
350+
if (
351+
(r._statusFlags | s._statusFlags) & mask ||
352+
(mask & STATUS_ERROR && s._config & CONFIG_STAGED_ERROR)
353+
)
340354
continue;
341355
if (
342356
(s !== b._tree || b._armed) &&

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

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ import {
127127
passTx,
128128
joinPassTx,
129129
stagedReaders,
130+
latestOpened,
130131
staleReader,
131132
laneDirty,
132133
externalUntrackHook,
@@ -385,10 +386,16 @@ export function recompute(el: Computed<any>, create: boolean = false): void {
385386
// the committed screen, settle the flight and drop the hold — a
386387
// superseding write's verdict would depend on that probe. Cleared for
387388
// this pass, before the flight it judges by is superseded; a probe in
388-
// the body re-stamps it after the plain reads.
389+
// the body re-stamps it after the plain reads. Not an effect: it has no
390+
// flight of its own (its pending is a source's), and a verdict memo's
391+
// change may have just made it a verdict reader (`laneDirty`). Only a
392+
// build with the lane engine (`laneStageHook`; verdict.ts imports it)
393+
// ever sets CONFIG_VERDICT: without it the line folds away.
389394
if (
390-
el._statusFlags & STATUS_PENDING ||
391-
(el._config & (CONFIG_ASYNC | CONFIG_HELD)) === (CONFIG_ASYNC | CONFIG_HELD)
395+
laneStageHook &&
396+
!isEffect &&
397+
(el._statusFlags & STATUS_PENDING ||
398+
(el._config & (CONFIG_ASYNC | CONFIG_HELD)) === (CONFIG_ASYNC | CONFIG_HELD))
392399
)
393400
el._config &= ~CONFIG_VERDICT;
394401
if (el._x !== null) {
@@ -2203,6 +2210,21 @@ export function stagedRead(c: Computed<any>, el?: Signal<any> | Computed<any>):
22032210
* (`bornInto`, #4010): its branch exists only there. */
22042211
export function stagedScreen(c: Computed<any>): boolean {
22052212
if (flushTransaction === null || bornInto(c, flushTransaction)) return false;
2213+
// A transaction only a `latest()` read opened holds nothing: the staging
2214+
// is the frame's read for a pass in the frame's seat, as it is before the
2215+
// frame has one, and the seam re-derives the pass once only if the flush
2216+
// parks (D-22, F-10). Lane work sees the screen (D-37). Not a pass with no
2217+
// value yet: its first answer is nobody's hold (D-6) and would commit the
2218+
// staging whether or not the frame parks — it reads the screen, and runs
2219+
// again at the landing.
2220+
if (
2221+
observeFlightHook &&
2222+
flushTransaction === latestOpened &&
2223+
passLane === null &&
2224+
c._config & CONFIG_VERDICT &&
2225+
!(c._statusFlags & STATUS_UNINITIALIZED)
2226+
)
2227+
return !stagedReaders.push(c);
22062228
staleReader(c, flushTransaction);
22072229
return true;
22082230
}

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

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ import {
5959
STATUS_UNINITIALIZED
6060
} from "./constants.js";
6161
import { attrHooks } from "./attribution-hooks.js";
62-
import { creatorReads, ext, stagedRead, tracking } from "./core.js";
62+
import { bornInto, creatorReads, ext, stagedRead, tracking } from "./core.js";
6363
import { NotReadyError } from "./error.js";
6464
import { removePendingSource } from "./async.js";
6565
import { laneValueOf } from "./truth.js";
@@ -75,6 +75,7 @@ import {
7575
joinFuture,
7676
laneDirty,
7777
list,
78+
stagedReaders,
7879
staleReader,
7980
merge,
8081
newTransaction,
@@ -509,6 +510,8 @@ function dissolveLane(l: Transaction, into: Transaction | null, except?: Signal<
509510
l._verdict = null;
510511
if (lanes.indexOf(v) !== -1) dissolveLane(v, null);
511512
}
513+
// First loads this dissolution leaves loading (below).
514+
const loading: Computed<any>[] = [];
512515
for (let i = 0; i < l._nodes.length; i++) {
513516
const n = l._nodes[i];
514517
const x = n._x!;
@@ -544,8 +547,20 @@ function dissolveLane(l: Transaction, into: Transaction | null, except?: Signal<
544547
// lane's answer beside inputs that are the truth now: a fresh reader
545548
// of its flight observes it (#3648, #3651; #3305's commit beneath a
546549
// flight).
550+
// Not a first load the lane produced nothing for whose own flight is
551+
// up, nor one pending on such a load kept here (an identity memo of
552+
// it, a derived store's derive): committing its empty `_value` would
553+
// initialize it as `undefined`, which `latest()` would serve and
554+
// `isPending()` call pending. It stays loading until its flight
555+
// answers (D-22, A19 exc. 1; async-gen 3289 #929, 91501 #504, #156).
547556
x._transaction = null;
548-
if (!effect && !guess) n._pendingValue = latest;
557+
if (!effect && !guess)
558+
slot === NOT_PENDING &&
559+
((n as Computed<any>)._statusFlags & (STATUS_UNINITIALIZED | STATUS_PENDING)) ===
560+
(STATUS_UNINITIALIZED | STATUS_PENDING) &&
561+
(x._inFlight || loading.some(q => x._pendingSources?.has(q)))
562+
? loading.push(n as Computed<any>)
563+
: (n._pendingValue = latest);
549564
commitPendingNode(n);
550565
if (!effect) {
551566
if (
@@ -927,17 +942,22 @@ const applyGuessesAt = (parent: Transaction | null): void => {
927942
judged = lanes.length;
928943
if (pendingGuesses.length !== 0) applyGuesses(parent);
929944
};
930-
const laneSeams = (leaks: Computed<any>[] | null): void => {
945+
const laneSeams = (t: Transaction | null): void => {
931946
// Passes that read a write the parked frame holds as the screen
932947
// (`stagedReaders`: lane work, a verdict reader before the verdict): they
933948
// re-derive on the committed world next round (and register as stale
934949
// readers of the transaction there); a lane's runs wait that round — a
935950
// lane sees the screen plus its own guesses.
936951
const leaked: Transaction[] = [];
937-
if (leaks !== null)
938-
for (let i = 0; i < leaks.length; i++) {
939-
const r = leaks[i];
940-
const l = r._x?._transaction;
952+
if (t !== null)
953+
for (let i = 0; i < stagedReaders.length; i++) {
954+
const r = stagedReaders[i],
955+
// A pass no transaction holds that read the frame's staging (an
956+
// effect, a `[s(), latest(s)]` reader watched before the frame had
957+
// a transaction): judged by the frame's — it re-derives only if the
958+
// frame stays parked; landing here, what it read is the screen (one
959+
// run, D-22).
960+
l = r._x?._transaction || (r._flags & REACTIVE_STAGED_READ ? t : null);
941961
// A verdict reader a later read of the same pass routed into a verdict
942962
// lane answered for itself: it re-derives at the holder's landing, not
943963
// now (one run — #3322, #3540). Other verdict-lane work re-derives only
@@ -947,15 +967,23 @@ const laneSeams = (leaks: Computed<any>[] | null): void => {
947967
// flight, held as the frame's pending observer or its staged
948968
// derivation) has nothing to re-derive: its re-run re-enters that
949969
// transaction and parks it again, every round — it runs at the
950-
// landing (#4349).
970+
// landing (#4349). One that read a staging re-derives only if its
971+
// frame stays parked: landing at this seam, what it read is the screen
972+
// (one run, D-22). Not one born into that frame (a held pass's child,
973+
// ruling A): it has no screen, its reads are the transaction's either
974+
// way — it runs again at the landing, not now.
951975
if (
952976
r._flags & REACTIVE_DISPOSED ||
953977
(l?._lane
954978
? l._parent?._verdict === l &&
955979
(r._config & CONFIG_VERDICT
956980
? !(r._flags & REACTIVE_PROBE_UNANSWERED)
957981
: !blocked(l._parent))
958-
: l && !(r._flags & (REACTIVE_STAGED_READ | REACTIVE_PROBE_UNANSWERED)))
982+
: l &&
983+
!(
984+
r._flags & REACTIVE_PROBE_UNANSWERED ||
985+
(r._flags & REACTIVE_STAGED_READ && blocked(l) && !bornInto(r, l))
986+
))
959987
)
960988
continue;
961989
// A leaked effect re-derives seated in its lane from its first read: it
@@ -968,8 +996,12 @@ const laneSeams = (leaks: Computed<any>[] | null): void => {
968996
enqueueSub(r);
969997
if (l?._lane && leaked.indexOf(l) === -1) leaked.push(l);
970998
}
971-
for (let k = Math.min(judged, lanes.length) - 1; k >= 0; k--)
972-
laneSeam(lanes[k], leaked.indexOf(lanes[k]) !== -1);
999+
// A verdict lane born at this seam is judged with it: it exists only once
1000+
// a pass routed into it — the park seam's zombie verdict readers re-run
1001+
// as its work so that this seam reveals them (#3444).
1002+
for (let k = lanes.length - 1; k >= 0; k--)
1003+
if (k < judged || lanes[k]._parent?._verdict === lanes[k])
1004+
laneSeam(lanes[k], leaked.indexOf(lanes[k]) !== -1);
9731005
// A verdict reader that entered a lane this seam held: its run waits with
9741006
// the lane, and the verdict beside it would freeze — it re-derives next
9751007
// round from the frame's seat, a stale reader of the lane (#4284).

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

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export let laneOutcomeHook:
7676
| null = null;
7777
export let laneWriteHook: (<T>(el: Signal<T> | Computed<T>, v: T) => T) | null = null;
7878
export let applyGuessesHook: ((parent: Transaction | null) => void) | null = null;
79-
export let laneSeamsHook: ((leaks: Computed<any>[] | null) => void) | null = null;
79+
export let laneSeamsHook: ((t: Transaction | null) => void) | null = null;
8080
export let laneCorrectionsHook: (() => boolean) | null = null;
8181
export let endLanesHook: ((u: Transaction) => void) | null = null;
8282
export let lanesBlockedHook: ((t: Transaction) => boolean) | null = null;
@@ -339,6 +339,13 @@ export function setPassLane(l: Transaction | null): void {
339339
* schedules the seam that consumes it: membership is the tick's — the same
340340
* synchronous frame — and the next tick's writes are not this one's. */
341341
export let flushTransaction: Transaction | null = null;
342+
/** The flush's transaction while only a `latest()` read of a staging opened
343+
* it (verdict.ts `provisionalVerdict`): it holds nothing, and a verdict
344+
* reader's plain read of a staging in it is the frame's read (D-22). */
345+
export let latestOpened: Transaction | null = null;
346+
export function openedByLatest(): void {
347+
latestOpened = flushTransaction;
348+
}
342349
/** The transaction the passes running OUTSIDE a flush this tick derive from
343350
* (a mainline mount, a mainline re-pass): the passes' own (A29, creation-
344351
* time form — "the entry is the pass's alone"): their results are staged
@@ -930,7 +937,7 @@ export class GlobalQueue implements IQueue {
930937
// pure round — the parent's flights before the parent is judged below.
931938
if (laneCorrectionsHook?.()) runHeap(dirtyQueue, GlobalQueue._update);
932939
const joined = flushTransaction;
933-
flushTransaction = null;
940+
flushTransaction = latestOpened = null;
934941
// The frame's verdict is in: the guesses written since the last seam
935942
// open their lane under the frame's transaction (a lane's own flush
936943
// parents a nested lane to it), or are dropped — the frame commits, and
@@ -1049,7 +1056,7 @@ export class GlobalQueue implements IQueue {
10491056
// world (a lane's runs wait this round).
10501057
if (laneSeamsHook) {
10511058
this._queues = lanes;
1052-
laneSeamsHook(t !== null ? stagedReaders : null);
1059+
laneSeamsHook(t);
10531060
if (stagedReaders.length) stagedReaders.length = 0;
10541061
}
10551062
this._queues = [[], []];
@@ -1341,11 +1348,22 @@ export function insertSubs(node: Signal<any> | Computed<any>): void {
13411348
* inert for its pass (`recompute` seats a lane only from its own `_x`), it
13421349
* is a live write if the effect becomes a zombie later this flush — an
13431350
* on-screen reader whose removal an adopted write stages follows the lane
1344-
* (the lane-membership ruling, 2026-10-05; `_update`). */
1351+
* (the lane-membership ruling, 2026-10-05; `_update`).
1352+
*
1353+
* A render effect re-run by a verdict memo's change (`createMemo(() =>
1354+
* latest(x))`, CONFIG_VERDICT) is the verdict reader the same read inline
1355+
* makes it, for that pass (F-6; D-26 `[s(), L()]`, #4284): a frame reader
1356+
* of its other reads — a staging's screen, a flight's committed value. One
1357+
* an earlier propagation this flush seated in another lane leaves that
1358+
* seat: its pass starts from the frame's, as the inline effect's does, and
1359+
* `laneRead` re-derives it on the screen if that lane holds (`entered`). */
13451360
export function laneDirty(node: Signal<any> | Computed<any>, l: Transaction): void {
13461361
for (let s = node._subs; s !== null; s = s._nextSub) {
1347-
const t = s._sub._x?._transaction;
1348-
if (t?._lane ? sameLane(t, l) : (s._sub as any)._type) s._sub._flags |= REACTIVE_LANE_DIRTY;
1362+
const c = s._sub,
1363+
t = c._x?._transaction;
1364+
if ((c as any)._type === EFFECT_RENDER && node._config & CONFIG_VERDICT)
1365+
((c._config |= CONFIG_VERDICT), (c._flags &= ~REACTIVE_LANE_DIRTY));
1366+
if (t?._lane ? sameLane(t, l) : (c as any)._type) c._flags |= REACTIVE_LANE_DIRTY;
13491367
}
13501368
}
13511369
/** One lane, or two of one link group (#3335): one reveal unit. */

0 commit comments

Comments
 (0)