Skip to content

Commit cc34883

Browse files
committed
Merge remote-tracking branch 'origin/next' into claude/project-thread-x1ore2-4559
2 parents 0437f93 + d1d6d51 commit cc34883

28 files changed

Lines changed: 1020 additions & 210 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+
fix(signals): a deferred effect mounted by a held update keeps its first value as the next pass's `prev` (#4556)

‎.changeset/floor-shared-walks.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@solidjs/signals": patch
3+
"@solidjs/web": patch
4+
---
5+
6+
Shrink the compiled and hand-written floors: the dependent walks, dependency clearing, status writes, effect-run queueing, flatten's thunk walk and the delegated-event parent hop share their code (no behavior change).
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 memo on the observation lifecycle (unowned, or `lazy: true`) that blocked on an async source is no longer released before the retry its source's landing queued (#4474). The settle walk re-enqueues the blocked reader and, finding it unobserved, released it on the spot: the release pulled the retry back out of the heap, so the memo never computed the landing and woke later with no value — `latest()` of it returned `undefined` beside `isPending() === true`. The release now waits for that pass (`REACTIVE_RELEASE_AFTER`): the retry runs once, as the owned twin's does, and the node is released at the pass's tail if it is still unobserved and settled. #2934's contract is kept (no perpetual recompute — one pass, then the release), #3078's untouched (reads revive; a dormant memo dirtied in the same tick is still reclaimed before the heap). Laziness is never observable (D-22).
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+
fix(signals): a re-parked node drops pending sources its pass no longer reaches, so a `<Loading>` whose first answer was superseded while a sibling refetched reveals once both settle (#4541)

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

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ These are the only words the fundamentals use. Internal names (transaction, stag
9898

9999
**Immutable.** `isPending(x)` is `true` iff `x`'s value is not the final answer to a _new question_: an input changed and the new answer has not been committed, a landed answer waits in a hold, or in-flight work declared it will change the data (`affects()`). It is `false` the moment the value is final. Re-asking the same question — `refresh()`, polling, an action's confirming refetch — is quiet: the shown value still answers, `isPending` stays `false`, and the fresh value reveals silently; to make a reload read as pending, declare it (`affects(x); refresh(x)`). A node with no committed value has nothing to judge, so it has no verdict: a first load, or a memo born held over a held value (D-2). It is _loading_ — inside an owner `isPending` of it does what the read itself does: a first load's `NotReadyError` goes to a boundary or holds, and a reader of a memo born held is held with it (caught by a boundary that has not shown content, F-4, or held with the change, F-2) and runs at the commit, where the answer is final. No answer is shown before then. Unowned, `isPending` of it is `false` (D-24). `latest` of it is its pending value if it has one (a memo born held) and throws if it has none (a first load) (D-22). A declared first paint (`loadingValue`) is loading too. Optimistic values are verdict-inert: an optimistic write never makes its own slot pending and never silences anything. Pending is per node — per store key — never store-wide. For a node with a committed value, painting does not decide it: where `x`'s readers are — on screen, behind a fallback, in a branch not yet attached — does not change `isPending(x)`, and `latest(x)` is the newest value it has produced (D-22). A verdict on content that may have no committed value belongs inside the boundary that owns that content (D-23).
100100

101-
**What it does not say.** It does not say `isPending` can be `true` on creation (it cannot — hydration parity; a memo born held has no verdict until its commit). It does not say an action in progress is pending data (process affordances are co-written state, not verdicts).
101+
**What it does not say.** It does not say `isPending` can be `true` on creation (it cannot — hydration parity; a memo born held has no verdict until its commit). It does not say an action in progress is pending data (process affordances are co-written state, not verdicts). It does not say a boundary's first frame cannot show `true`: "on creation" is the node's, not the screen's — a node whose first answer lands beside the write that re-asks it (#4459), or while an upstream re-ask has it pending by propagation (#4569), is committed and pending, and content that reads only its verdict reveals with it (D-23, S-40).
102102

103103
**Collapses:** A19 (three causes, two exceptions), A24 (question-scoped; `affects`), A27 (the loading window), A7, A8 (per channel), A9, A12, A13, A14, A16, A22, A23, OL-R12, OS-R17/R40, PJ-R28–R31, recovery 6.3/6.4. **Derived:** D-22–D-26, D-30, D-36. **Scenarios:** S-14, S-25–S-29, S-36, S-37.
104104

‎packages/signals/docs/SCENARIOS.md‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,23 @@ _Ruled 2026-10-09, from the read-order brief's sibling case (416). Not D-28: thi
698698
| ✗ | | sibling `0`, slot `(empty)` | neither the fallback nor `1` — the boundary waited on `n0`, which it did not read |
699699
| ✗ | | sibling `0 \| loading` | the same wait, shown as a fallback |
700700

701+
**The verdict form (ruled 2026-10-31, #4569; D-23, #3373):** a fresh `<Loading>` whose content reads only `isPending` of a first load reveals when the verdict exists. `a0 = async(s)`, `a2 = async(await a0())`; `a0:0` lands, `a2` asks `a2:11`; `setS(1)` re-asks `a0` and marks `a2` pending by propagation while `a2:11` is up and `a2` has no value; `a2:11` lands. `a2`'s question changes only when `a2` re-runs, so the answer is current: `a2` is committed and pending on `a0`. Content that reads `a2` holds (F-2: no screen to keep) — the asymmetry is the rule.
702+
703+
```tsx
704+
<Loading fallback="loading">{isPending(() => a2()) ? "pending" : "settled"}</Loading>
705+
```
706+
707+
| # | Action | verdict-only content | control: `{a2()}` — alone or beside the probe | Notes |
708+
| --- | ---------------------------------------- | -------------------- | --------------------------------------------- | --------------------------------------------------------------------- |
709+
| 1 | mount; `a0:0` lands; `a2` asks `a2:11` | `loading` | `loading` | first load |
710+
| 2 | `setS(1)` — re-asks `a0:1` | `loading` | `loading` | `a2` pending by propagation, no value, own flight still current |
711+
| 3 | `a2:11` lands | `pending` | `loading` | `a2` initializes, committed and pending on `a0`; the plain read waits |
712+
| 4 | `a0:1` lands; `a2` re-runs, asks `a2:20` | `pending` | `loading` | |
713+
| 5 | `a2:20` lands | `settled` | `21` / `21 settled` | |
714+
| ✗ | | after 3: `loading` | | rejected: a first load kept loading by a supersession no rule has |
715+
716+
Pinned: `tests/first-load-superseded-answer-4569.test.ts` (also a 3-deep chain and the no-boundary root, which attaches at 3 with `pending`), `packages/web/test/first-load-superseded-answer-4569.spec.tsx`.
717+
701718
### S-45. A first answer landing in the same tick as an action that writes its input: `latest` shows it, the plain read waits — D-22, F-9 (async generator E9)
702719

703720
_Ruled 2026-10-28. The leaf form and the through-a-memo form show the same screen; today the leaf keeps the fallback up until the action ends — that is the ✗ row._

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

Lines changed: 83 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ import {
1616
REACTIVE_DIRTY,
1717
REACTIVE_WINDOW,
1818
REACTIVE_DISPOSED,
19+
REACTIVE_IN_HEAP,
1920
REACTIVE_RECOMPUTING_DEPS,
2021
REACTIVE_REASK,
22+
REACTIVE_RELEASE_AFTER,
2123
REACTIVE_STAGED_READ,
2224
REACTIVE_ZOMBIE,
2325
STATUS_ERROR,
@@ -77,6 +79,12 @@ export function removePendingSource(el: Computed<any>, source: Computed<any>): b
7779
return true;
7880
}
7981

82+
// Drops a node's flight reference without touching anything else: the one
83+
// form shared by the disposal and loading-window sites.
84+
export function clearInFlight(el: Computed<any>): void {
85+
if (el._x !== null) el._x._inFlight = null;
86+
}
87+
8088
function clearPendingSources(el: Computed<any>): void {
8189
// This set is node-owned and never shared; dropping the sole reference
8290
// releases the set and every entry without a redundant clear() walk.
@@ -88,7 +96,7 @@ function clearPendingSources(el: Computed<any>): void {
8896
// edge: a dep that IS the source, or one whose own pending chain carries it
8997
// (pending sources propagate the origin node, so this covers any depth).
9098
// Also guards branch-local recovery: another dependency may still need the source.
91-
function retryReaches(el: Computed<any>, source: any): boolean {
99+
export function retryReaches(el: Computed<any>, source: any): boolean {
92100
for (let d = el._deps; d; d = d._nextDep) {
93101
const dep = d._dep as Computed<any>;
94102
if (dep === source || dep._x?._pendingSources?.has(source)) return true;
@@ -118,14 +126,13 @@ export function setPendingError(el: Computed<any>, source?: Computed<any>, error
118126
if (el._x !== null) el._x._error = null;
119127
return;
120128
}
121-
if (error instanceof NotReadyError && error.source === source) {
122-
ext(el)._error = error;
123-
return;
124-
}
125-
const current = el._x?._error;
126-
if (!(current instanceof NotReadyError) || current.source !== source) {
127-
ext(el)._error = new NotReadyError(source);
128-
}
129+
// The given error when it names this source, else the current one when it
130+
// does (rewritten unchanged), else a fresh one.
131+
const current = error instanceof NotReadyError && error.source === source ? error : el._x?._error;
132+
ext(el)._error =
133+
current instanceof NotReadyError && current.source === source
134+
? current
135+
: new NotReadyError(source);
129136
}
130137

131138
export function forEachDependent(
@@ -135,6 +142,25 @@ export function forEachDependent(
135142
for (let s = el._subs; s !== null; s = s._nextSub) fn(s._sub, s);
136143
}
137144

145+
/** Each dependent reachable from `el`, depth first. `fn` sees every arrival,
146+
* `seen` when an earlier branch already walked the node (a diamond); the
147+
* node's dependents are walked once, on its first arrival unless `fn`
148+
* returns false (then it stays unmarked: a later branch may walk it). */
149+
function walkDependents(
150+
el: Computed<any>,
151+
fn: (node: Computed<any>, seen: boolean) => unknown
152+
): void {
153+
const visited = new NewSet<Computed<any>>();
154+
const visit = (node: Computed<any>) => {
155+
const seen = visited.has(node);
156+
if (fn(node, seen) !== false && !seen) {
157+
visited.add(node);
158+
forEachDependent(node, visit);
159+
}
160+
};
161+
forEachDependent(el, visit);
162+
}
163+
138164
// Queue a node to re-run on the next flush (used both when a pending source
139165
// settles and when an `isPending` observer must re-evaluate after a real error):
140166
// shared scheduling helper in heap.ts (tracked effects bypass the heap).
@@ -146,13 +172,19 @@ export function forEachDependent(
146172
// forever with zero subscribers (#2934). The node's own promise/iterator
147173
// callbacks handle their own release (settleAutodispose in handleAsync); this
148174
// covers derivatively-pending dependents, which have no callbacks of their own.
175+
// A node whose pass is already queued (the settle walk re-enqueued a
176+
// `_blocked` reader) is released at that pass's tail, not before it: the
177+
// release would pull the pass back out of the heap, and the node would wake
178+
// later with no value for the landing it missed (D-22, #4474).
149179
export function releaseIfSettledUnobserved(node: Computed<any>): void {
150-
(node as any)._fn &&
180+
if (
181+
(node as any)._fn &&
151182
node._config & CONFIG_AUTO_DISPOSE &&
152183
!node._subs &&
153184
!(node._flags & REACTIVE_ZOMBIE) &&
154-
!(node._statusFlags & STATUS_PENDING) &&
155-
unobserved(node);
185+
!(node._statusFlags & STATUS_PENDING)
186+
)
187+
node._flags & REACTIVE_IN_HEAP ? (node._flags |= REACTIVE_RELEASE_AFTER) : unobserved(node);
156188
}
157189

158190
// Error-path sweep: notifyStatus(STATUS_ERROR) clears dependents' pending
@@ -161,14 +193,9 @@ export function releaseIfSettledUnobserved(node: Computed<any>): void {
161193
// Collect-then-release so unobserved() never unlinks under the walk.
162194
export function releaseSettledDependents(el: Computed<any>): void {
163195
let candidates: Computed<any>[] | undefined;
164-
const visited = new NewSet<Computed<any>>();
165-
const visit = (node: Computed<any>) => {
166-
if (visited.has(node)) return;
167-
visited.add(node);
168-
if (!node._subs && node._config & CONFIG_AUTO_DISPOSE) (candidates ??= []).push(node);
169-
forEachDependent(node, visit);
170-
};
171-
forEachDependent(el, visit);
196+
walkDependents(el, (node, seen) => {
197+
if (!seen && !node._subs && node._config & CONFIG_AUTO_DISPOSE) (candidates ??= []).push(node);
198+
});
172199
if (candidates) for (const node of candidates) releaseIfSettledUnobserved(node);
173200
}
174201

@@ -256,17 +283,12 @@ function stageMark(node: Computed<any>, el: Computed<any>): void {
256283

257284
export function settleErroredDependents(el: Computed<any>, error: any): void {
258285
let scheduled = false;
259-
const visited = new NewSet<Computed<any>>();
260-
const visit = (node: Computed<any>) => {
261-
if (visited.has(node)) return;
262-
visited.add(node);
263-
if (node._x?._error === error) {
286+
walkDependents(el, (node, seen) => {
287+
if (!seen && node._x?._error === error) {
264288
enqueueSub(node);
265289
scheduled = true;
266290
}
267-
forEachDependent(node, visit);
268-
};
269-
forEachDependent(el, visit);
291+
});
270292
if (scheduled) schedule();
271293
}
272294

@@ -334,10 +356,12 @@ export function settlePendingSource(el: Computed<any>, source: Computed<any> = e
334356
removePendingSource(el, source);
335357
let scheduled = false;
336358
let released: Computed<any>[] | undefined;
337-
const visited = new NewSet<Computed<any>>();
338-
const settle = (node: Computed<any>) => {
359+
walkDependents(el, (node, seen) => {
339360
if (
340-
visited.has(node) ||
361+
// A node an earlier branch settled (a diamond) takes only this early
362+
// return's verdict re-run / staged-error mark, as the walk did before
363+
// it was shared.
364+
seen ||
341365
// A conditional dropped this source, but another dependency can still
342366
// carry it. Only retire pending state inherited through the recovered
343367
// branch. Deliberately NOT marked visited on this early return: the
@@ -355,11 +379,11 @@ export function settlePendingSource(el: Computed<any>, source: Computed<any> = e
355379
// D-41: a derivation of a staged error carries it (`stageMark`).
356380
return (
357381
holdWorkHook &&
358-
(node._config & CONFIG_VERDICT
359-
? enqueueSub(node)
360-
: el._config & CONFIG_STAGED_ERROR && stageMark(node, el))
382+
(node._config & CONFIG_VERDICT
383+
? enqueueSub(node)
384+
: el._config & CONFIG_STAGED_ERROR && stageMark(node, el)),
385+
false
361386
);
362-
visited.add(node);
363387
node._time = clock;
364388
const remaining = node._x?._pendingSources?.values().next().value;
365389
// STATUS_ERROR + pending sources only coexist via an errored loading
@@ -394,13 +418,12 @@ export function settlePendingSource(el: Computed<any>, source: Computed<any> = e
394418
// lists this walk is still iterating.
395419
if (!node._subs && node._config & CONFIG_AUTO_DISPOSE) (released ??= []).push(node);
396420
}
397-
forEachDependent(node, settle);
398-
};
399-
400-
forEachDependent(el, settle);
421+
});
401422

402-
// Release before the flush schedule below: unobserved() pulls the node back
403-
// out of the heap, so the enqueueSub above never recomputes a released node.
423+
// A node the enqueueSub above queued is released at that pass's tail
424+
// (`releaseIfSettledUnobserved`, REACTIVE_RELEASE_AFTER): the landing's
425+
// pass is its — released first, it woke later with no value for it
426+
// (#4474).
404427
if (released) for (const node of released) releaseIfSettledUnobserved(node);
405428

406429
if (scheduled) schedule();
@@ -565,7 +588,7 @@ export function handleAsync<T>(
565588
// serving commit #0 — same parking as recompute's catch for sync
566589
// dependency throws. The dead flight is released so the clock-gated
567590
// error-retry pull (updateIfNecessary) can also re-ask.
568-
if (el._x !== null) el._x._inFlight = null;
591+
clearInFlight(el);
569592
parkLoadingWindow(el, error);
570593
el._time = clock;
571594
return;
@@ -990,34 +1013,27 @@ export function notifyStatus(el: Computed<any>, status: number, error?: any): vo
9901013
const pendingSource = status === STATUS_PENDING && error instanceof NotReadyError && error.source;
9911014
// (CARVE 2: the lane assignment went with the engine.)
9921015

993-
if (status === STATUS_PENDING && pendingSource) {
1016+
if (pendingSource) {
9941017
// D-41: a re-ask of a shown error keeps it the display (`_shownError`).
9951018
if (el._statusFlags & STATUS_ERROR) el._x!._shownError = el._x!._error;
9961019
addPendingSource(el, pendingSource);
997-
// A re-ask of an error that answered the first read: still no value.
998-
el._statusFlags =
999-
STATUS_PENDING |
1000-
(el._statusFlags & STATUS_NO_VALUE
1020+
} else clearPendingSources(el);
1021+
// An error answering a node with no value marks it so; a re-ask of it
1022+
// (pending, from a source or not) is uninitialized again — still no
1023+
// value; a write (STATUS_NONE) gives it one.
1024+
el._statusFlags =
1025+
status |
1026+
(status === STATUS_ERROR
1027+
? el._statusFlags & (STATUS_UNINITIALIZED | STATUS_NO_VALUE)
1028+
? STATUS_NO_VALUE
1029+
: 0
1030+
: status === STATUS_PENDING && el._statusFlags & STATUS_NO_VALUE
10011031
? STATUS_UNINITIALIZED
10021032
: el._statusFlags & STATUS_UNINITIALIZED);
1003-
// Preserve the current source on this propagation so readers park on
1004-
// the distinct pending source.
1005-
setPendingError(el, pendingSource, error);
1006-
} else {
1007-
clearPendingSources(el);
1008-
// An error answering a node with no value marks it so; a re-ask of it
1009-
// (pending) is uninitialized again; a write (STATUS_NONE) gives it one.
1010-
el._statusFlags =
1011-
status |
1012-
(status === STATUS_ERROR
1013-
? el._statusFlags & (STATUS_UNINITIALIZED | STATUS_NO_VALUE)
1014-
? STATUS_NO_VALUE
1015-
: 0
1016-
: status === STATUS_PENDING && el._statusFlags & STATUS_NO_VALUE
1017-
? STATUS_UNINITIALIZED
1018-
: el._statusFlags & STATUS_UNINITIALIZED);
1019-
ext(el)._error = error;
1020-
}
1033+
// A propagated pending keeps its current source so readers park on the
1034+
// distinct pending source.
1035+
if (pendingSource) setPendingError(el, pendingSource, error);
1036+
else ext(el)._error = error;
10211037

10221038
// Lanes: a written guess is an optimistic boundary (A17 — "the optimistic
10231039
// future value until we know otherwise"). Its own source in flight is its
@@ -1098,7 +1114,7 @@ export function propagateStatus(el: Computed<any>, status: number, error: any):
10981114
// frame still passes through — its pass is the frame's (#3372, compiled
10991115
// shape: the unmount it stages makes the observer a zombie whose say is
11001116
// moot for this transaction, A15 #3463).
1101-
if (status === STATUS_PENDING && pendingSource && sub._x?._pendingSources?.has(pendingSource)) {
1117+
if (pendingSource && sub._x?._pendingSources?.has(pendingSource)) {
11021118
if (
11031119
passLane === null &&
11041120
(sub._config & (CONFIG_HELD | CONFIG_OVERRIDE)) === CONFIG_HELD &&
@@ -1109,7 +1125,7 @@ export function propagateStatus(el: Computed<any>, status: number, error: any):
11091125
return;
11101126
}
11111127
if (
1112-
(status === STATUS_PENDING && pendingSource) ||
1128+
pendingSource ||
11131129
(status !== STATUS_PENDING && (sub._x?._error !== error || sub._x?._pendingSources))
11141130
) {
11151131
// The marked subscriber is queued for the commit sweep so its status

0 commit comments

Comments
 (0)