Skip to content

Commit ecf3011

Browse files
ryansolidclaude
andauthored
fix(signals): four optimistic store bugs (#4480, #4489, #4482, #4484) (#4511)
* fix(signals): an error boundary a held pass mounts over a staged error settles (#4480) boundarySeam's fold-back (D-16, U-9: a fallback staged into the hold its readers landed in is content-ready at that hold's commit) ran for error boundaries too. What an error boundary still waits on after `prune` is an error staged into the hold (D-41), not a landing: clearing its readers redrew the output, which met the staged error again, set the error signal and produced a new output — and the held effect that owns the boundary re-ran on it, mounting a fresh one, forever ("Potential Infinite Loop Detected ... last staged node: effect"). The fold-back is now a loading boundary's only. The error is an answer staged with the frame (D-41, F-12): the held frame keeps what it showed and the error fallback reveals with the hold (F-1, F-2). Not optimistic-specific: any held pass (an effect re-run under a transition's hold) that mounts createErrorBoundary over a memo whose rejection is staged in that hold hung. The #4480 shape reaches it through the D-34 hold of a filter change behind a pending guess. Pins: packages/signals/tests/errored-held-mount-staged-error-4480.test.ts (the general shape), packages/web/test/optimistic-reask-error-effect-boundary-4480.spec.tsx (the issue's repro). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2 * fix(signals): a derived store's held rejection is staged with its frame (#4489) handleAsync published any rejection of a node with a setter (only a projection's derive passes one) at once, skipping D-41's staging. The store's effect and the screen still waited (their held passes), but an untracked read of a leaf pulled the errored derive and threw the new error while the screen still showed the rows: a click handler on a held row crashed (#4489, with an optimistic removal guess holding a filter change, D-34). A held derive's rejection now stages like a memo's (`stageError`): readers in the hold derive from the staging and stage their own error with the frame; a reader served the screen, an untracked read included, reads the committed leaves (with the guesses over them, F-11) until the frame reveals, when the error shows to the screen, the error arm and reads alike (D-41, D-29, D-34; F-1 "what it does not say"). The change is the deletion of the projection exception: core gets 3 B smaller. Closes D-41's open derived-store deviation: its `it.fails` pin in tests/error-is-an-answer.test.ts passes, now as `it`; RULES-DERIVED.md's "Deviation today" note for it is updated. Pin: packages/signals/tests/optimistic-held-error-untracked-read-4489.test.ts Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2 * fix(signals): a removal guess re-based over a new question shows only its answer's rows (#4482) An older question's truth landing beneath a keyed arrangement guess is re-based by row key (D-35, `_laneRebase`): rows from the truth, the guess's order, the rows it removed left out. It also kept every guessed row the truth lacked ("the guess's own landing judges them") — meant for rows the guess added, but it kept the rows the guess had only carried over from the truth it was written on too. After a filter switch held behind the guess (D-34), an assign's refresh answering the new question re-based the close guess into the open list's #1 and #4 beside the closed list's #2: rows of two questions on one screen (F-1). The guess's `removed` set now holds every key of the view the setter saw that is not the guess's own row: the rows it removed (as before) and the rows it carried over unchanged from the committed truth (the committed row object itself). The re-base takes those from the new truth; rows the guess added, or carried from another action's pending guess (#4336's layered filter), stay. The screen at the assign's acceptance is the close guess composed over the closed answer, `[#2 eve]` (the issue's second acceptable frame). The re-base also loses its null check on the set. Pin: packages/web/test/optimistic-removal-rebase-new-question-4482.spec.tsx Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2 * fix(signals): a derive's post-await writes no longer leak into the next setter (#4484) The store traps notify a write-override write (a derive's continuation after an `await`, which runs with no setter open) at once, but `touch` had also listed its target in `pendingNotify`, and nothing took it off. The next outermost `storeSetter` — on any store — drained the list at its exit and notified that target with `userWrite` set: on an optimistic family the derive's staged landing (the truth held beneath a pending guess) went through `optHooks.writes` as the user's edit and became guesses. A guess on the detail store thus put the list's truth over the close action's removal guess: #3 came back while the close was out. An outermost setter now clears the stale entries on entry (every entry there was notified already). The guess holds until its own refresh answers it (F-11, D-33, D-35); a guess on another store does not touch it. With the fetch in a memo the derive writes inside its pass and never hit this. Pin: packages/web/test/optimistic-removal-survives-other-store-guess-4484.spec.tsx Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2 * test(web): import the #4480 pin's createErrorBoundary from solid-js/internal The boundary primitive is exported from `solid-js` at runtime but typed for renderers through `solid-js/internal`; the web spec type check (`test-types`) failed on the `solid-js` import. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2 * perf(signals): the #4484 setter-entry clear runs only when the list is not empty Clearing an empty Set allocates a new table: the outermost-setter clear cost every setter one allocation (store write floor, steady state: +4.3% instructions under callgrind with CodSpeed's flags; CodSpeed -7.6%). The list is empty at an outermost setter's entry but for write-override targets, so the clear now follows a size read: +1.4% for +8 B minified. (A flag set in touch measured +0.27% but cost +34 B.) Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2 --------- Co-authored-by: Claude <[email protected]>
1 parent e6c2f3b commit ecf3011

16 files changed

Lines changed: 676 additions & 28 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+
A derived store's held rejection is staged like a memo's (D-41, #4489). While a hold is open — an action holding a filter change behind a pending guess, or any transition — an untracked read of the store (a click handler on a row the screen still shows) reads the screen instead of throwing the new error; the effect's error arm, `<Errored>` and the read all see the error together at the reveal. Closes D-41's derived-store deviation (the `it.fails` pin in `error-is-an-answer.test.ts` now passes as `it`).
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+
An error boundary that a held pass mounts over a source whose error is staged in that hold (D-41) no longer loops the flush for good (#4480). The seam's fold-back of a fallback staged into the hold its readers landed in (D-16, U-9) is a loading boundary's: it also cleared an error boundary's readers, so the output re-derived into the staged error every round and the effect owning the boundary re-ran on each new output. The error now waits with the hold and its fallback reveals with the frame (D-41, F-12). Seen with a derived optimistic store whose re-ask failed while a guess was pending, read by an effect through `createErrorBoundary`.
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 keyed optimistic store's removal guess re-based over a new question's answer no longer shows the old list's rows beside the new ones (#4482). The re-base (D-35) kept every guessed row the new truth lacked, including the rows the guess had only carried over from the truth it was written on; it now composes the guess's own edit — the rows it added or carried from another action's guess, minus the rows it removed — over the new truth, and takes the rest from that truth (F-1).
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 derived store's writes after an `await` no longer leak into the next user setter (#4484). A write-override write (the derive's continuation) notifies its target at once but left it listed for notification, so the next outermost store setter — on any store — notified the derive's staged landing as its own write; on an optimistic family that made the landing a guess over a pending one, and a pending removal guess showed its row again when another action guessed on a different store. An outermost setter now starts with no stale targets (F-11, D-33).

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ A first load that rejects has no previous content to keep: born held (D-2), it s
358358

359359
**Built 2026-10-15.** An error a held node's flight or pass finds is staged in `_pendingValue` (CONFIG_STAGED_ERROR) and committed with the frame, which publishes it through the ordinary error path; a held recovery keeps the shown error (`_shownError`) until its own commit, and a recovery equal to the last good value is a change of answer, held or not. `watch` (`resolve`, `until`, `refresh`) rejects at the landing. The duplicated immediate-publish path is gone. Pins: `tests/error-is-an-answer.test.ts`, `tests/watch-error-outcomes.test.ts` (GabbeV, #3886).
360360

361-
**Deviation today.** An untracked read of a derived store's property (`createStore(fn)`, projections) throws a held rejection before its frame; the store's effect and the screen do wait. Pinned `it.fails` in `tests/error-is-an-answer.test.ts`. The standalone cases from #3886's audit (a write to a failed writable memo, error-wrapper formatting, comparator release, snapshot capture) are not this rule. **Status:** standing.
361+
**Derived stores (closed 2026-10-30, #4489).** A derived store's (`createStore(fn)`, projections, optimistic stores) held rejection is staged like a memo's: an untracked read of its property reads the screen until the frame reveals. Pinned in `tests/error-is-an-answer.test.ts` and `tests/optimistic-held-error-untracked-read-4489.test.ts`. The standalone cases from #3886's audit (a write to a failed writable memo, error-wrapper formatting, comparator release, snapshot capture) are not this rule. **Status:** standing.
362362

363363
### D-42. A reactive read is not an `await`: `try/catch` around it is not a channel
364364

‎packages/signals/src/boundaries.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,13 @@ function boundarySeam(): void {
406406
// (D-16, U-9): the content is ready when that hold commits (D-15). Not
407407
// only at the re-arm's own seam: readers pending then land, held, a
408408
// flush later (#4379 — the staged fallback otherwise commits with the
409-
// hold, and a quiet refresh then caught keeps it up, F-9).
409+
// hold, and a quiet refresh then caught keeps it up, F-9). A loading
410+
// fallback only: what an error boundary still waits on after `prune` is
411+
// an error, staged into that hold (D-41) — the fallback is the hold's
412+
// content and reveals with it; folding back re-derived the output into
413+
// the error again every round (#4480).
410414
if (
415+
b._type & STATUS_PENDING &&
411416
!b._initialized &&
412417
o._config & CONFIG_HELD &&
413418
[...b._readers].every(

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -563,10 +563,10 @@ export function handleAsync<T>(
563563
el._time = clock;
564564
return;
565565
}
566-
// D-41: a held node's error is staged (`stageError`). A derived store's
567-
// readers learn its error through the family, not the derive's
568-
// dependents: it publishes now.
569-
if (stillPending || setter || !stageError(el, error)) {
566+
// D-41: a held node's error is staged (`stageError`) — a derived
567+
// store's derive's too: its family publishes it at the commit
568+
// (store/projection.ts `errorFamily`, #4489).
569+
if (stillPending || !stageError(el, error)) {
570570
notifyStatus(el, stillPending ? STATUS_PENDING : STATUS_ERROR, error);
571571
// The error is this pass's answer, published now: it replaces the shown
572572
// frame as a value's commit would (`commitPendingNode`), so the frame

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

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -164,22 +164,27 @@ export function notifyOptimisticWrites(
164164
}
165165
if (structural) {
166166
const rows = isArr ? (pb as any[]).map(unwrapValue) : shallowKeys(pb);
167-
// The rows the setter removed from the view it saw, by key: a later
168-
// re-base over another action's truth must not bring them back. A set
169-
// (empty or not) marks a keyed arrangement guess (`fold`).
167+
// The keys of the view the setter saw that are not the guess's own
168+
// rows, which a re-base over another truth takes from that truth
169+
// (`_laneRebase`): the rows the setter removed, which it never brings
170+
// back, and the rows it only carried over from the truth beneath (the
171+
// committed row itself), which the new truth decides. Rows it added, or carried from another action's guess,
172+
// are the guesses' own: their landings judge them. A set (empty or not)
173+
// marks a keyed arrangement guess (`fold`).
170174
let removed: Set<unknown> | null = null;
171175
const keyFn = t.fam!.key;
172176
if (isArr && keyFn !== null && keyFn !== undefined) {
173177
removed = new Set();
174178
const kept = new Set<unknown>();
179+
const truth = new Set(base as any[]);
175180
for (let i = 0; i < rows.length; i++) {
176181
const k = isWrappable(rows[i]) ? keyFn(rows[i]) : undefined;
177182
if (k !== undefined) kept.add(k);
178183
}
179184
for (let i = 0; i < (old as any[]).length; i++) {
180185
const r = unwrapValue((old as any[])[i]);
181186
const k = isWrappable(r) ? keyFn(r) : undefined;
182-
if (k !== undefined && !kept.has(k)) removed.add(k);
187+
if (k !== undefined && (!kept.has(k) || truth.has(r))) removed.add(k);
183188
}
184189
}
185190
optimisticWrite(getContainerNode(t), new LaneView(rows, base, removed) as any);
@@ -344,11 +349,15 @@ GlobalQueue._slotTake = (n, back) => {
344349
};
345350
/** Q-D (plan sec. 39): an OLDER question's truth landed beneath an arrangement
346351
* guess (`laneWrite` held it — another action's landing is not this guess's
347-
* answer). The guess is re-based over it: order from the guess, rows from
348-
* the truth by key (a guessed row the truth has is the truth's object — the
349-
* row target adopted it, its proxy survives), guessed rows the truth lacks
350-
* kept (the guess's own landing judges them), truth rows the guess lacks
351-
* appended. The composed arrangement becomes the lane's value on every
352+
* answer). The guess's edit is re-based over it: order from the guess, rows
353+
* from the truth by key (a guessed row the truth has is the truth's object —
354+
* the row target adopted it, its proxy survives), rows the guess added — or
355+
* carried from another action's guess — kept (their landings judge them),
356+
* truth rows the guess lacks appended unless it removed them. A row the
357+
* guess only carried over from the truth it was written on is that truth's,
358+
* not the guess's: the new truth decides it, so after a new question the
359+
* old list's rows never show beside the new one's (F-1, D-35, #4482;
360+
* `removed`). The composed arrangement becomes the lane's value on every
352361
* index whose row the committed backing does not already show — compared
353362
* BY KEY, never by raw identity: the same key's new object is the same row
354363
* (its target adopted it) and the slot stays the committed backing's — (a
@@ -375,6 +384,7 @@ GlobalQueue._laneRebase = (el: Signal<any>, truth: unknown, older: boolean) => {
375384
if (k !== undefined && !byKey.has(k)) byKey.set(k, r);
376385
}
377386
const used = new Set<unknown>();
387+
const removed = view.removed!;
378388
const rows: any[] = [];
379389
// From the guess as written, not an earlier re-base's composition: a
380390
// derive's landing writes key by key, and a truth row one partial write
@@ -387,13 +397,12 @@ GlobalQueue._laneRebase = (el: Signal<any>, truth: unknown, older: boolean) => {
387397
if (tr !== undefined) {
388398
rows.push(tr);
389399
used.add(k);
390-
} else rows.push(g);
400+
} else if (!removed.has(k)) rows.push(g);
391401
}
392-
const removed = view.removed;
393402
for (let i = 0; i < truth.length; i++) {
394403
const r = truth[i];
395404
const k = isWrappable(r) ? keyFn(r) : undefined;
396-
if (k !== undefined && !used.has(k) && (removed === null || !removed.has(k))) rows.push(r);
405+
if (k !== undefined && !used.has(k) && !removed.has(k)) rows.push(r);
397406
}
398407
view.rows = rows;
399408
view.base = rows;

‎packages/signals/src/store/projection.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,11 @@ export function runProjectionComputed<T extends object>(
332332
// rejection): the wake, as for the pass. Errored: every live
333333
// reader re-derives and meets the error at its pull (memo parity,
334334
// #2897) — and the flush that runs them advances the clock, so a
335-
// later tracked re-read may retry (core `read`).
335+
// later tracked re-read may retry (core `read`). A held derive's
336+
// error is staged (D-41, #4489): a reader in the hold derives from
337+
// the staging and stages its own error with the frame; one served
338+
// the screen (an untracked read included) reads the committed
339+
// leaves until the frame reveals.
336340
if (first && owner._statusFlags & STATUS_UNINITIALIZED) return;
337341
if (pending) wakeFamily(fam);
338342
else errorFamily(fam, error);

‎packages/signals/src/store/store.ts‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,10 @@ export class LaneView {
294294
/** The backing the guess is shown over: the committed one at the
295295
* guess, the composed arrangement after a re-base (optimistic.ts). */
296296
public base: Record<PropertyKey, any>,
297-
/** Keys the setter REMOVED from the view it saw (a deliberate delete,
298-
* not a row the truth has yet to show): a re-base does not restore
299-
* them. `null` when none. */
297+
/** A keyed list's guess: the keys of the view the setter saw that are
298+
* not the guess's own rows — removed by it, or only carried over from
299+
* the truth beneath. A re-base takes them from the new truth
300+
* (optimistic.ts). `null` when not keyed. */
300301
public removed: Set<unknown> | null = null
301302
) {}
302303
}
@@ -2466,6 +2467,15 @@ export function storeSetter<T>(proxy: T, fn: (draft: T) => T | void, guard = tru
24662467
writeScopes.add(scopeKey(target));
24672468
const prevUser = userWrite;
24682469
userWrite = guard;
2470+
// An outermost setter's exit notifies the targets it wrote. A
2471+
// write-override write (a derive's continuation after an `await`, no
2472+
// setter open) is notified at once by its trap but stays listed (its keys
2473+
// share one written set while the continuation writes): dropped here, or
2474+
// this setter's exit would notify the derive's staging as its own — a
2475+
// user's, on an optimistic family, as guesses (#4484). Read before the
2476+
// clear: the list is empty here but for those, and clearing an empty set
2477+
// allocates.
2478+
if (writing === 0 && pendingNotify.size) pendingNotify.clear();
24692479
writing++;
24702480
let result: any;
24712481
try {

0 commit comments

Comments
 (0)