Route every document mutation through a commit() helper#64
Merged
Conversation
kmatzen
force-pushed
the
fix-toggle-node-history
branch
from
July 25, 2026 16:38
4a8e0dd to
201b479
Compare
kmatzen
force-pushed
the
commit-helper-refactor
branch
from
July 25, 2026 16:38
22b16fb to
2967fa2
Compare
kmatzen
force-pushed
the
fix-toggle-node-history
branch
from
July 25, 2026 19:20
201b479 to
620f30e
Compare
Completes #54. #58 fixed the instance; this removes the bug class. The history ritual -- slice off redo entries, push a deep clone, advance the index -- was open-coded at seventeen sites. toggleNode simply omitted it, which is the bug #58 fixed: `tree` and `history[historyIndex]` diverged, so an undo discarded one more edit than the user asked for. Seventeen copies of the same four lines is an invitation to write a sixteenth that forgets. commit(state, tree, extra) now builds the whole state patch. `extra` carries whatever view state the action also sets (selection, expansion), so no action touches history or historyIndex directly. addNodeFromData already had a local commit() doing this plus its own expansion bookkeeping -- the duplication had been noticed once and solved in one place. Renamed to place() and delegated to the module helper, since keeping the name would have shadowed it and silently left that action on the old path. Behaviour is unchanged: all 28 store tests pass, including the 23 that predate this work and the 5 added with #58. One sharp edge worth knowing: commit spreads `extra` before the history fields, so a caller passing `tree` or `history` in `extra` has it overridden. That ordering is deliberate -- history bookkeeping should win -- and no current caller does it. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
kmatzen
force-pushed
the
commit-helper-refactor
branch
from
July 25, 2026 19:22
2967fa2 to
805fdbc
Compare
|
🚀 Preview deployed: https://commit-helper-refactor.sinter.pages.dev (updates on every push to this PR) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Completes #54. Stacked on #58 — that PR fixed the instance, this removes the bug class. Base is
fix-toggle-node-history, so as with #59 and #60 there will be no CI until #58 merges and GitHub retargets this.The problem
The history ritual — slice off redo entries, push a deep clone, advance the index — was open-coded at seventeen sites:
toggleNodesimply omitted it. That's the bug #58 fixed:treeandhistory[historyIndex]diverged, so an undo discarded one more edit than the user asked for. Seventeen copies of the same four lines is an invitation to write an eighteenth that forgets.The change
Every mutating action becomes
set(commit(get(), newTree, { ...view state })).extracarries selection and expansion, so no action toucheshistoryorhistoryIndexdirectly — which is exactly howtoggleNodecame to skip them.addNodeFromDataalready had a localcommit()doing this plus its own expansion bookkeeping — the duplication had been noticed once and solved in one place. I renamed itplace()and had it delegate to the module helper; keeping the name would have shadowed it and silently left that action on the old path.Verification
tsc --noEmitnewHistoryreferences remainingThe 23 pre-existing tests are the real check here. Behaviour should be identical, and they are what would catch drift. The refactor was applied by a script performing 25 exact-anchor replacements, each asserted present before substitution — so a missed site fails loudly rather than silently. But anchors only prove I edited what I intended, not that semantics are preserved; the tests are what establish that.
No discrimination check applies — this is a pure refactor with no behaviour change to detect.
One sharp edge
commitspreadsextrabefore the history fields, so a caller passingtreeorhistoryinsideextrawould have it silently overridden. The ordering is deliberate — history bookkeeping should win — and no current caller does it, but it is worth knowing before someone tries.🤖 Generated with Claude Code