Repository navigation
Commit 658eecd
fix(signals): keep a chained optimistic write back to the base's previous value (#3674)
* fix(signals): chained optimistic write to base value is kept (#3672)
A chained optimistic store (`createOptimisticStore(base)` over a
`createStore`) serves the base's live value; its own nodes are links whose
`_value` is never served and never updated when the base commits. The
engine's no-op check in optimisticWrite compared the draft's write against
that stale `_value`, so once a first action had been confirmed in the base,
a second action writing the key back to its earlier value (position 1 then
0), re-adding a key the base had deleted, or popping a row the base had
appended emitted no override while the action's other writes showed.
notifyOptimisticWrites now syncs a chained node that carries no active
override to the visible committed value right before the engine write, on
the value, presence and length emits alike. Non-chained families are
untouched; the optimistic module is tree-shakeable, and every size scenario
stays under its cap.
* fix: address review findings
The optimistic add and delete branches sync a chained node's `_value` to
the unwrapped raw of the inner store's child, not its proxy, so the
settle-time revert compare against the override's raw no longer notifies
readers of a row that was deleted and re-added in one action.
The add and delete branches read `old[key]` once per key instead of
running a chained backing's get trap twice.
The rules index lists optimistic.ts among §7b's citations, which the
`emit` comment's citation had left stale.
* fix(signals): chained optimistic revert compares against the base's live value (#3672)
The write side (previous commits) handed optimisticWrite's no-op check the
visible committed value. The revert consulted the same link `_value`:
resolveOptimisticNodes decides whether to notify by comparing the override
against `_value`, and a chained node's `_value` is never served, so it only
ever held the seed or the last write-time refresh. When the base committed
WHILE an override was active (a server confirm arriving mid-action) and the
action then wrote the key back to its pre-write value, the compare matched
and notified nobody — a `createMemo` over the view stayed at the guess while
the base and untracked reads showed the truth. A render effect off the lane
was rescued by readsHeldCommitted's replay, which is why the shape hid.
Chain `GlobalQueue._resolveOptimistic` in installNextBlockedHalf (the
`_transitionBlocked` pattern): for every chained host in the reverting
batch, refresh its armed value/length nodes to `unwrapValue(base[key])` and
its armed presence nodes to `key in base`, untracked, then delegate. The
compare is exact — readers re-derive iff truth differs from the guess, and
a confirmed guess settles without re-running them. Stays in the
tree-shakeable optimistic module; core floor 0 B.
Size: "hydrating + every store primitive family" 31.80 -> 31.87 KB
(measured 31,862 B against next's 31,786: -12 B write side, +88 B revert
side). Not a frozen floor cap; floor-caps.json unchanged.
Co-authored-by: Claude via Cursor <[email protected]>
Co-authored-by: Cursor <[email protected]>
---------
Co-authored-by: Ryan Carniato <[email protected]>
Co-authored-by: Claude via Cursor <[email protected]>
Co-authored-by: Cursor <[email protected]>1 parent 55e2022 commit 658eecd
6 files changed
Lines changed: 602 additions & 9 deletions
File tree
- .changeset
- packages/signals
- docs
- src/store/next
- tests/store
- scripts/size
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
| 36 | + | |
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| |||
390 | 390 | | |
391 | 391 | | |
392 | 392 | | |
393 | | - | |
| 393 | + | |
394 | 394 | | |
395 | 395 | | |
396 | 396 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
| |||
137 | 138 | | |
138 | 139 | | |
139 | 140 | | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
140 | 176 | | |
141 | 177 | | |
142 | 178 | | |
| |||
584 | 620 | | |
585 | 621 | | |
586 | 622 | | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
587 | 631 | | |
588 | 632 | | |
589 | 633 | | |
590 | 634 | | |
591 | 635 | | |
592 | 636 | | |
593 | 637 | | |
594 | | - | |
595 | | - | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
596 | 641 | | |
597 | 642 | | |
598 | 643 | | |
599 | 644 | | |
600 | | - | |
| 645 | + | |
601 | 646 | | |
602 | 647 | | |
603 | 648 | | |
| |||
606 | 651 | | |
607 | 652 | | |
608 | 653 | | |
609 | | - | |
610 | | - | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
611 | 657 | | |
612 | 658 | | |
613 | 659 | | |
614 | 660 | | |
615 | 661 | | |
616 | | - | |
| 662 | + | |
617 | 663 | | |
618 | 664 | | |
619 | 665 | | |
| |||
0 commit comments