Skip to content

Commit 6dc7533

Browse files
committed
fix(signals): a reverted optimistic input gives back the guess it displaced; a fallback's latest() no longer pulls a held swap ahead (#4336, #4337)
#4336, the pure-revert optimistic input (the four `it.fails`, now plain tests): when an action's lane takes over another action's guess (lanes `laneStage`, a store slot's `_slotTake` — with the target's other guessed slots), the displaced guess is kept aside. If the taker's action ends without writing the truth, its world is void: the revert re-asks the old question as its own work, and when that revert lands the kept guess is re-seated (on the store slot's current node) in the same frame — `#1: ` then `#3: dana | mine (sending)`, nothing between; the store-return form's `#3: ` frame is gone. If the taker commits, what it kept is dropped. The guess's readers become stale readers of the taking lane, so split render effects wait with it instead of showing `#1:` beside the post's guess. All behind the `guessed` gate (folded without an optimistic write). #4337 (maintainer's probe): a `<Loading on>` whose fallback reads `latest()` swapped to its fallback beside a held change, because reading the fallback moved the output's pass into the verdict lane. The fallback read now keeps the output's lane seat and verdict bits: the swap lands with the change's frame (#3540). Pre-existing on next for any action-held `on` change; pinned by tests/loading-on-latest-fallback-4337.test.ts (Ryan's four on × toggle combos, no-hold controls, the action-held reduction). Docs: D-34 drops the open note, D-17 and S-20/S-44 record the fallback rule. Size: the store app 31.36 -> 31.66 KB (+845 B minified), awaiting the maintainer's Size-Exception. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2
1 parent 1d70fe4 commit 6dc7533

10 files changed

Lines changed: 481 additions & 109 deletions

File tree

‎.changeset/outside-input-change-holds-with-guess.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"@solidjs/signals": patch
33
---
44

5-
An input changed outside an optimistic guess's action no longer tears the screen (#4336). When a `createOptimistic` or `createOptimisticStore` guess made in a pending action (a post's `mine (sending)` over `sel() = 3`) is re-asked because a plain write changed its input (`setSel(1)`), the write is held with that action (D-34). The screen keeps `#3: dana | mine (sending)` until the action commits, then shows `#1: ...` with its answer as one frame, whether the reads share one render effect or are split across several. `isPending` is true while the new question is in flight or held, including through the action's own `refresh()`, and `latest()` answers the newest truth. A `refresh()` of the same question still keeps its own frame. For a store, the hold applies to a frame that still reads a guess: a keyed store's other keys (`comments[1]` while the guess is on `comments[3]`) wait only for their own answer. An input set through its own optimistic write in another action now shows in its own lane once its answer lands, without the other action's guess beside it. Also fixed: a held write read in the same flush before the action's first lane read no longer shows before the commit.
5+
An input changed outside an optimistic guess's action no longer tears the screen (#4336). When a `createOptimistic` or `createOptimisticStore` guess made in a pending action (a post's `mine (sending)` over `sel() = 3`) is re-asked because a plain write changed its input (`setSel(1)`), the write is held with that action (D-34). The screen keeps `#3: dana | mine (sending)` until the action commits, then shows `#1: ...` with its answer as one frame, whether the reads share one render effect or are split across several. `isPending` is true while the new question is in flight or held, including through the action's own `refresh()`, and `latest()` answers the newest truth. A `refresh()` of the same question still keeps its own frame. For a store, the hold applies to a frame that still reads a guess: a keyed store's other keys (`comments[1]` while the guess is on `comments[3]`) wait only for their own answer. An input set through its own optimistic write in another action now shows in its own lane once its answer lands, without the other action's guess beside it. Also fixed: a held write read in the same flush before the action's first lane read no longer shows before the commit. If that input's action ends without writing the truth, the other action's guess comes back in the revert's frame (`#1: ` then `#3: dana | mine (sending)`) and lasts until its own action settles; the split-effect form waits with the input's lane instead of showing `#1:` beside the guess. A `<Loading on>` boundary whose fallback reads `latest()` no longer swaps to its fallback ahead of a held change: the swap lands with the change's frame (#4337).

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ A header that reads `latest(id)` beside `on={id()}` shows the new id beside the
144144

145145
**From:** F-6, F-5. **Scenarios:** S-21.
146146

147-
`on` re-arms from whatever it reads, and the fallback appears when that read's frame has landed (D-15). `on={latest(id)}`, an `isPending()` or an optimistic signal reads a value whose frame has already landed, so the fallback shows now, beside the page that is still held: `[A] → [A + spinner] → [B + spinner] → [B + comments]`. The hold still owns every read of the held value. Content under the boundary stays off screen until it is ready; content under it that reads nothing held reveals as soon as it lands. No diagnostic. The `[A + spinner]` frame is the new id's loading state inside the old page, the same shape as a header showing the new id early. A memo between `isPending` and `on` behaves as the direct read does.
147+
`on` re-arms from whatever it reads, and the fallback appears when that read's frame has landed (D-15). `on={latest(id)}`, an `isPending()` or an optimistic signal reads a value whose frame has already landed, so the fallback shows now, beside the page that is still held: `[A] → [A + spinner] → [B + spinner] → [B + comments]`. The hold still owns every read of the held value. Content under the boundary stays off screen until it is ready; content under it that reads nothing held reveals as soon as it lands. No diagnostic. The `[A + spinner]` frame is the new id's loading state inside the old page, the same shape as a header showing the new id early. A memo between `isPending` and `on` behaves as the direct read does. What the _fallback_ reads is not `on`: a fallback reading `latest(id)` shows the new id once it is on screen (F-6), but the swap that `on={id()}` asks for still lands with its frame (D-15), never beside the held value (#4337).
148148

149149
**Collapses:** #3575, B-AHEAD, recovery 6.1, §27 7a (#3528), `tests/loading-on-frame-following-3540.test.ts` §4, `tests/loading-on-rearm-reveal-3540.test.ts` ("on: () => latest(dep)"). **Status:** standing, ruled 2026-10-09 as the frame rule, not a break through the hold.
150150

@@ -288,7 +288,7 @@ When an override's own source answers (its own landing, or a sync recompute from
288288

289289
A keyed store's arrangement guess (rows by key) that the screen showed is not voided by a correction: the truth folds beneath it (one the screen never showed is void, as above). Derivations outside the lane re-derive from the truth now and join the hold, `until`/`resolve` keep their postures over it (an `until` outside the lane reads the truth and joins the hold, D-31), and `latest()` shows the hold's world whole. Lane passes, untracked reads and the screen keep the guess until the commit, and at the commit rows match by key. So a row the truth returns keeps its identity, a row another tab added shows at the commit, and the first of two overlapping actions confirming does not void the second's guess (2026-10-21). A folded lane's list pass inside a frame that already has a transaction reads that frame's stagings as the screen, as a verdict reader does, so it never pairs the truth's length with the guess's rows.
290290

291-
A new question is not the guess's own source answering. When a guess's node re-asks because an input changed outside the guess's own action (a plain `setSel(1)` while a post that guessed over `sel() = 3` is out), the guess cannot stand beside the new input — that frame would show the new input over the old question's answer and the guess (F-1) — so the frame that changed the input is held with the guess's action (2026-10-28, #4336). The screen keeps the old input and the guess until that action commits, then shows the new input with its answer as one frame, however the reads are grouped into render effects (#4284). Meanwhile `isPending` reads `true` while the new question is in flight or held (F-9), `latest()` answers the newest truth (F-6), and untracked reads see the screen. A `refresh()` re-asks the same question and holds nothing new; the guess's own action changing the input is the correction above. A store's derive is one node asking one question for every key, so the hold is decided where the guess is read: a frame still reading a guess when the flush ends is held with it, and a read of a key with no guess is an ordinary pending read (F-2) — `comments[1]` waits for issue 1's answer, not for a post that guessed on `comments[3]`. An input set through its own optimistic write asks the new question in its own lane: the other action's guess does not answer it, so the lane waits for its own answer (F-6) and then shows it, with the guessed node as the lane's derivation from there (F-11). Open (one slot): a node carries one lane value, so when that input's action ends without writing the truth the post's guess does not come back — the screen shows the old question's truth until the post settles — and for a store whose derive returns the rows, the revert's re-ask shows the lane's answer for one frame under the old input.
291+
A new question is not the guess's own source answering. When a guess's node re-asks because an input changed outside the guess's own action (a plain `setSel(1)` while a post that guessed over `sel() = 3` is out), the guess cannot stand beside the new input — that frame would show the new input over the old question's answer and the guess (F-1) — so the frame that changed the input is held with the guess's action (2026-10-28, #4336). The screen keeps the old input and the guess until that action commits, then shows the new input with its answer as one frame, however the reads are grouped into render effects (#4284). Meanwhile `isPending` reads `true` while the new question is in flight or held (F-9), `latest()` answers the newest truth (F-6), and untracked reads see the screen. A `refresh()` re-asks the same question and holds nothing new; the guess's own action changing the input is the correction above. A store's derive is one node asking one question for every key, so the hold is decided where the guess is read: a frame still reading a guess when the flush ends is held with it, and a read of a key with no guess is an ordinary pending read (F-2) — `comments[1]` waits for issue 1's answer, not for a post that guessed on `comments[3]`. An input set through its own optimistic write asks the new question in its own lane: the other action's guess does not answer it, so the lane waits for its own answer (F-6) and then shows it, with the guessed node (for a store, every guessed slot of the target its derive writes) as the lane's derivation from there (F-11); the guess's readers wait with the lane, however the reads are grouped into render effects. The other action's guess was only displaced: when the input's action ends without writing the truth, its lane's world is void, the revert re-asks the old question as the revert's work, and the displaced guess comes back in the revert's frame over that answer — `#1: ` then `#3: dana | mine (sending)`, nothing between — and lives until its own action settles (D-33). If the input's action commits, the displaced guess is gone, as for any correction.
292292

293293
**Collapses:** [A18](./SPEC-ASYNC-SEMANTICS.md#a18-an-override-lives-exactly-as-long-as-its-own-transaction-a-newer-truth-from-the-source-supersedes-it-in-the-graph-immediately-on-screen-at-commit) supersession (#3331, 2026-09-09/10) and (d) before the first commit, "Correction display is what showed" (2026-10-05), lane contract 2, lane ruling 5, [A17](./SPEC-ASYNC-SEMANTICS.md#a17-an-active-override-is-the-displayed-value-until-its-transaction-commits-and-the-graphs-value-until-its-own-source-answers) (2026-09-09), OS-R39. **Status:** standing.
294294

‎packages/signals/docs/SCENARIOS.md‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -421,14 +421,15 @@ _Pinned: `loading-on-frame-following-3540.test.ts` §3. Ruled 2026-10-09._
421421

422422
### S-20. The action outlasts the data: a race the fallback lost, not reported — D-16
423423

424-
_Pinned: `loading-on-frame-following-3540.test.ts` §5._
424+
_Pinned: `loading-on-frame-following-3540.test.ts` §5; `loading-on-latest-fallback-4337.test.ts` (the fallback reads `latest`)._
425425

426-
| # | Action | Screen | Notes |
427-
| --- | ------------------------------------------------------------- | ---------------------------------------------------- | --------------------------------------------------------- |
428-
| 1 | `action(function* () { setId(2); yield longer; })(); flush()` | `A` (held) | entered: the fallback is the display, and it is not shown |
429-
| 2 | `comments(2)` lands | — (the action is still open) | |
430-
| 3 | the action ends | `B \| comments-B` — the fallback was never displayed | legitimate; nothing reported |
431-
| 1′ | the action ends _before_ `comments(2)` lands | `B \| spinner` with the commit, then `comments-B` | the race the fallback won |
426+
| # | Action | Screen | Notes |
427+
| --- | ------------------------------------------------------------- | ---------------------------------------------------- | ------------------------------------------------------------ |
428+
| 1 | `action(function* () { setId(2); yield longer; })(); flush()` | `A` (held) | entered: the fallback is the display, and it is not shown |
429+
| 2 | `comments(2)` lands | — (the action is still open) | |
430+
| 3 | the action ends | `B \| comments-B` — the fallback was never displayed | legitimate; nothing reported |
431+
| 1′ | the action ends _before_ `comments(2)` lands | `B \| spinner` with the commit, then `comments-B` | the race the fallback won |
432+
| 1″ | the fallback reads `latest(id)` | as 1–3: `A` held, then `B \| comments-B` | the fallback's `latest` does not pull the swap ahead (#4337) |
432433

433434
### S-21. A display-ahead read in `on` shows the fallback now, beside the held frame — D-17
434435

@@ -757,7 +758,7 @@ _Pinned: `tests/optimistic-lane-release.test.ts`, `tests/body-end-supersession-v
757758

758759
### S-44. An outside input change under a guess is held with the guess's action — D-34, F-1 (#4336)
759760

760-
_Pinned: `tests/optimistic-question-change-4336.test.ts`, `tests/optimistic-layered-filter-4336.test.ts`, `tests/optimistic-held-write-leak.test.ts`._
761+
_Pinned: `tests/optimistic-question-change-4336.test.ts`, `tests/optimistic-layered-filter-4336.test.ts`, `tests/optimistic-held-write-leak.test.ts`, `tests/loading-on-latest-fallback-4337.test.ts`._
761762

762763
```tsx
763764
const [sel, setSel] = createSignal(3);
@@ -781,10 +782,11 @@ const post = action(function* (text) {
781782
| 4 | issue 1's answer `["mine"]` lands | `#1: mine` — one frame | false | |
782783
| 1′ | `refresh(comments)` instead of `setSel(1)` | `#3: dana \| mine (sending)` until the post commits | `isPending(comments)` false | the same question: nothing new is held (#4329) |
783784
| 1″ | `sel` a `createOptimistic` over the saved selection; `action { setSel(1); yield; setSaved(1) }` | `#3: dana \| mine (sending)` until issue 1's answer, then `#1: ` — the input's lane waits for its own answer (F-6) | | the post's guess does not answer issue 1 |
785+
| 1⁗ | as 1″, but the action ends without `setSaved` (a pure revert) | `#1: ` until issue 3's re-ask lands, then `#3: dana \| mine (sending)` — one frame; the post lands later as usual | | the displaced guess comes back with the revert (D-33) |
784786
| 1‴ | keyed: `comments[id] = rows`, the post guessed on `comments[3]`; `setSel(1)` | `#1: ` once issue 1's answer lands, not waiting for the post; back on 3: `#3: dana \| mine (sending)` | | a key with no guess is an ordinary pending read (F-2) |
785787
| ✗ | | any `#1:` frame before 4, e.g. `#1: dana \| mine (sending)` | | the same with `#{sel()}` and the list in two render effects |
786788

787-
Layered: action A guesses `milk`, action B sets a filter optimistically over it. The filter shows at once in both settle orders, `milk` stays until A commits, and when B settles first nothing on screen changes (D-33, D-35). A held write read before the action's first lane read (`setG("b"); yield go; setOther(1)`) shows only at the commit. Open (one slot, D-34): when the optimistic input's action ends without writing the truth, the post's guess does not come back (`#3: dana` until the post settles), and a store whose derive returns rows shows `#3: ` for one frame while the revert re-asks issue 3.
789+
Layered: action A guesses `milk`, action B sets a filter optimistically over it. The filter shows at once in both settle orders, `milk` stays until A commits, and when B settles first nothing on screen changes (D-33, D-35). A held write read before the action's first lane read (`setG("b"); yield go; setOther(1)`) shows only at the commit. Boundary (#4337): a keyed list under `<Loading on={filter()}>` whose fallback reads `latest(filter)`, an action that guesses a row and refreshes, and `filter` set outside: the change is held with the action (row 3's guess is still read) and the boundary never leaves its content for it — no `loading` frame beside the held `filter`, toggled back or not; without the hold the fallback shows with the change and clears at its answer (S-20, D-17). Pinned by `tests/loading-on-latest-fallback-4337.test.ts`.
788790

789791
---
790792

‎packages/signals/src/boundaries.ts‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import {
5151
EFFECT_USER,
5252
REACTIVE_DISPOSED,
5353
REACTIVE_LANE_READ,
54+
REACTIVE_PROBED,
5455
REACTIVE_ZOMBIE,
5556
STATUS_ERROR,
5657
STATUS_PENDING,
@@ -750,12 +751,14 @@ function createBoundary<T>(
750751
}
751752

752753
function fallback<T>(b: Boundary): T {
754+
// (The output's pass.)
755+
const out = getOwner() as Computed<any>;
753756
// The swap a display-ahead re-arm asked for: this pass is the lane's — a
754757
// lane read by construction (REACTIVE_LANE_READ: `recompute`'s tail keeps
755758
// the pass in the lane).
756759
if (b._lane !== null) {
757760
setPassLane(b._lane);
758-
b._output!._flags |= REACTIVE_LANE_READ;
761+
out._flags |= REACTIVE_LANE_READ;
759762
b._lane = null;
760763
}
761764
// Observe: a loading boundary starts showing its fallback — the swap lands
@@ -783,11 +786,18 @@ function fallback<T>(b: Boundary): T {
783786
// outside the boundary, as the output is: its errors and runs are the
784787
// enclosing boundary's — with the output's id, so what it builds gets the
785788
// ids a build under the output would; disposed once content is on screen.
786-
if (b._fb === null) {
787-
const out = getOwner() as Computed<any>;
789+
if (b._fb === null)
788790
b._fb = runWithOwner(out._parent, () => computed(() => b._show(b), { id: out.id }))!;
789-
}
790-
return read(b._fb) as T;
791+
// The swap is structure (#3540): what the fallback reads ahead — a
792+
// verdict (`latest()`), a lane — is the fallback's display-ahead, not the
793+
// swap's: the output's pass stays where it was (F-6 stays inside the
794+
// fallback, #4337).
795+
const p = passLane;
796+
const f = out._flags;
797+
const v = read(b._fb) as T;
798+
setPassLane(p);
799+
out._flags ^= (out._flags ^ f) & (REACTIVE_PROBED | REACTIVE_LANE_READ);
800+
return v;
791801
}
792802

793803
const ERROR_SIGNAL = { ownedWrite: true, _noSnapshot: true } as const;

0 commit comments

Comments
 (0)