Persist only the checkbox selection of uncommitted changes - #15198
Open
ameyypawar wants to merge 1 commit into
Open
Persist only the checkbox selection of uncommitted changes#15198ameyypawar wants to merge 1 commit into
ameyypawar wants to merge 1 commit into
Conversation
The uncommitted slice holds tree changes and hunk assignments alongside the hunk selection, and all three were persisted. Both of the former are refetched from the worktree on startup, so the persisted copy is only ever the previous session's, rendered for the frames before the fresh query replaces it. `blacklist` keeps them out of storage, and a state reconciler drops them on the way in as well, so state written by an earlier build does not rehydrate once more after upgrading.
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.
🧠 Changes
uncommittedSliceis now persisted withtreeChangesandhunkAssignmentsblacklisted, leaving onlyhunkSelection— the checkbox state — to survive a restart.The blacklist alone would not have been enough. redux-persist applies it when writing, but
getStoredStatereads back every key on disk andautoMergeLevel1merges all of them, so anything an earlier build had already written would still rehydrate once after upgrading.persistConfigFor()pairs the blacklist with a state reconciler that drops those keys on the way in as well.☕️ Reasoning
injectPersistedSlice()persisted whole slices, and the uncommitted slice holds three things:The first two are refetched from the worktree on startup, so a persisted copy is only ever the previous session's, rendered for the frames before the fresh query replaces it. That is the flash in the report, and it fits the observation that deleting the cache directory makes it go away.
The blacklist lives next to the type it has to match, as
const satisfies readonly (keyof UncommittedState)[], so a name that drifts from the slice shape fails the type check rather than silently re-persisting a key.Three tests in
persistBlacklist.test.tsdrive the real slice through a real persist cycle under the config the app builds, with only storage swapped for a recording adapter. Two of them fail ifpersistConfigFor()is reverted to returning{ key, storage }:gone.txtis still there after rehydrateThe third asserts
hunkSelectionis not blacklisted. That one is a guard against the opposite mistake rather than a regression test, and passes either way.One consequence worth stating plainly: a partial line selection inside a hunk comes back as the whole hunk checked after a restart, because
updateLines()no longer has the previous assignment to diff against. If the file also changed while the app was closed, the reconciled assignment keeps its id but covers different lines, so a restored selection can be wider than what was originally chosen. Whole-hunk and whole-file checkboxes restore exactly.Keeping
hunkAssignmentspersisted would avoid that, at the cost of still rehydrating state this issue calls out as not being checkbox selection. I went with the narrower persistence; happy to swap to blacklisting onlytreeChangesif you would rather keep line-level precision across restarts.🎫 Affected issues
Fixes: #10892