fix(recents): merge the recent-files list instead of overwriting it - #404
Closed
PathGao wants to merge 1 commit into
Closed
fix(recents): merge the recent-files list instead of overwriting it#404PathGao wants to merge 1 commit into
PathGao wants to merge 1 commit into
Conversation
Three call sites serialised the window's own copy of the list back to localStorage with no re-read and no `storage` listener, so with two windows open the last one to touch the list discarded whatever the other had recorded. #370 already solved this shape for settings, so the fix reuses it rather than inventing a second mechanism: a new `recentFiles.ts` holds the pure list transforms plus `updateStoredRecentFiles(mutate)`, which re-reads, applies, and writes through #370's `writeStoredSetting`. That write is compare-and-set, so a no-op fires no `storage` event and the propagation loop terminates after one hop - #370's argument for why an `isApplyingRemote` flag cannot work applies here unchanged. A `storage` listener in the viewer folds in what sibling windows record. No change to settings.svelte.ts was needed; `writeStoredSetting` was already exported. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Collaborator
Author
|
Reopening from an in-repo branch so the five-part chain can be a real stack — GitHub cannot use a fork branch as a base ref. Same commit, no content change. |
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.
The defect
Three call sites —
saveRecentFile,deleteRecentFile, and the rename sync — each didJSON.stringify(recentFiles)from the window's own in-memory copy. No re-read, nostoragelistener. With two windows open, the last one to touch the list silently discarded whatever the other had recorded.The fix reuses #370 rather than inventing a second mechanism
This is the same shape #370 already solved for settings, so:
src/lib/utils/recentFiles.tsholds the pure list transforms plusupdateStoredRecentFiles(mutate)— re-read, apply, write.writeStoredSetting, which is compare-and-set. A no-op write fires nostorageevent, so propagation terminates after one hop. fix(settings): persist each setting on its own key and sync across windows #370's reasoning for why anisApplyingRemoteflag cannot work applies here unchanged, and is cited rather than restated.storagelistener in the viewer folds in what sibling windows record.No change to
settings.svelte.tswas needed —writeStoredSettingwas already exported.Tests
scripts/recentFilesMultiWindow.test.ts— the concurrency tests drive two simulated windows against one shared localStorage and run the real merge, rather than asserting on source text.masterstate)Not covered
🤖 Generated with Claude Code