From 1b471013407e3b0a4a3e8dcb1103a44aab619ad6 Mon Sep 17 00:00:00 2001 From: Julien Calixte Date: Sun, 28 Jun 2026 23:52:37 +0200 Subject: [PATCH] fix(notes): persist new SHA and dedup files by path on edit Editing a note in a stacked note saved cache without the path, so store.files never received the new SHA and lookups went stale. Pass the path through, and make addFile dedup by path as well as SHA so an edit (same path, new SHA) replaces the old entry instead of duplicating it. --- src/components/StackedNote.vue | 3 ++- src/modules/repo/store/userRepo.store.spec.ts | 12 ++++++++++++ src/modules/repo/store/userRepo.store.ts | 4 +++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/components/StackedNote.vue b/src/components/StackedNote.vue index bc8cf31..59345b6 100644 --- a/src/components/StackedNote.vue +++ b/src/components/StackedNote.vue @@ -205,7 +205,8 @@ const performSave = async (overrideSha?: string) => { } await saveCacheNote(encodeUTF8ToBase64(rawContent.value), { - editedSha: newSha + editedSha: newSha, + path: path.value }) initialRawContent.value = rawContent.value } diff --git a/src/modules/repo/store/userRepo.store.spec.ts b/src/modules/repo/store/userRepo.store.spec.ts index b5b505d..30b4b9f 100644 --- a/src/modules/repo/store/userRepo.store.spec.ts +++ b/src/modules/repo/store/userRepo.store.spec.ts @@ -105,6 +105,18 @@ describe("userRepo store — synchronous mutations", () => { expect(vi.mocked(data.update)).not.toHaveBeenCalled() }) + it("addFile replaces the entry at the same path when content (sha) changed", () => { + const store = useUserRepoStore() + store.user = "alice" + store.repo = "notes" + store.files = [{ sha: "old", path: "a.md", type: "blob" }] as never + + store.addFile({ sha: "new", path: "a.md", type: "blob" } as never) + + expect(store.files).toEqual([{ sha: "new", path: "a.md", type: "blob" }]) + expect(vi.mocked(data.update)).toHaveBeenCalled() + }) + it("setFontFamily initializes userSettings when absent and persists to localStorage", () => { const store = useUserRepoStore() store.user = "alice" diff --git a/src/modules/repo/store/userRepo.store.ts b/src/modules/repo/store/userRepo.store.ts index 7171d15..7a6e1de 100644 --- a/src/modules/repo/store/userRepo.store.ts +++ b/src/modules/repo/store/userRepo.store.ts @@ -233,7 +233,9 @@ export const useUserRepoStore = defineStore("USER_REPO_STATE", { `${this.user}-${this.repo}` ) const newFiles = [ - ...toRaw(this.files).filter((f) => f.sha !== file.sha), + ...toRaw(this.files).filter( + (f) => f.sha !== file.sha && f.path !== file.path + ), toRaw(file) ] data.update({