From 9224b1dabcb54a0b06a3144b2e5ca1cd6b87b789 Mon Sep 17 00:00:00 2001 From: 7eliassen Date: Mon, 29 Jun 2026 21:26:49 +0300 Subject: [PATCH 1/6] fix/fix the note id value --- src/application/services/useNote.ts | 9 +++++---- src/presentation/pages/Note.vue | 14 ++++++++++---- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/application/services/useNote.ts b/src/application/services/useNote.ts index 74342032..30892b39 100644 --- a/src/application/services/useNote.ts +++ b/src/application/services/useNote.ts @@ -55,7 +55,7 @@ interface UseNoteComposableState { /** * Creates/updates the note */ - save: (content: NoteContent, parentId: NoteId | undefined) => Promise; + save: (content: NoteContent, parentId: NoteId | undefined, currentNoteId: NoteId | null) => Promise; /** * Returns list of tools used in note @@ -244,8 +244,9 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt * Saves the note * @param content - Note content (Editor.js data) * @param parentId - Id of the parent note. If null, then it's a root note + * @param currentNoteId - Id of the current note */ - async function save(content: NoteContent, parentId: NoteId | undefined): Promise { + async function save(content: NoteContent, parentId: NoteId | undefined, currentNoteId: NoteId | null): Promise { if (note.value === null) { throw new Error('Note is not loaded yet'); } @@ -257,7 +258,7 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt isNoteSaving.value = true; - if (currentId.value === null) { + if (currentNoteId === null) { /** * @todo try-catch domain errors */ @@ -285,7 +286,7 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt */ void getNoteHierarchy(noteCreated.id); } else { - await noteService.updateNoteContentAndTools(currentId.value, content, specifiedNoteTools); + await noteService.updateNoteContentAndTools(currentNoteId as NoteId, content, specifiedNoteTools); } /** diff --git a/src/presentation/pages/Note.vue b/src/presentation/pages/Note.vue index ce00bc7b..2c0a4654 100644 --- a/src/presentation/pages/Note.vue +++ b/src/presentation/pages/Note.vue @@ -68,7 +68,7 @@ import { computed, ref, toRef, watch } from 'vue'; import { Button, Editor, PageBlock, VerticalMenu, type VerticalMenuItem } from '@codexteam/ui/vue'; import useNote from '@/application/services/useNote'; import { useRoute, useRouter } from 'vue-router'; -import { NoteContent } from '@/domain/entities/Note'; +import { NoteContent, type NoteId } from '@/domain/entities/Note'; import { useHead } from 'unhead'; import { useI18n } from 'vue-i18n'; import { makeElementScreenshot } from '@/infrastructure/utils/screenshot'; @@ -153,7 +153,13 @@ async function noteChanged(data: NoteContent): Promise { const editorElement = editor.value ? editor.value.element : null; if (!isEmpty) { - await save(data, props.parentId); + /** + * Capture the current note id at the time of the call + * to avoid race conditions when fast switching between notes + */ + const noteIdAtCallTime = props.id; + + await save(data, props.parentId, noteIdAtCallTime); /** * In case if we do not have note id, we can change its cover, and we need successful data for cover * We need to do it after saving in case of note creation @@ -169,8 +175,8 @@ async function noteChanged(data: NoteContent): Promise { paddingTop: '100px', }); } - if (updatedNoteCover !== null && props.id !== null) { - await updateCover(props.id, updatedNoteCover); + if (updatedNoteCover !== null && noteIdAtCallTime !== null) { + await updateCover(noteIdAtCallTime as NoteId, updatedNoteCover); } } } From a3495dfbe5cb96580d0a30ecb2a50b1463d6f775 Mon Sep 17 00:00:00 2001 From: 7eliassen Date: Mon, 27 Jul 2026 21:44:10 +0300 Subject: [PATCH 2/6] feat: asign lastUpdateContent on load --- src/application/services/useNote.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/application/services/useNote.ts b/src/application/services/useNote.ts index 30892b39..b1a8c81f 100644 --- a/src/application/services/useNote.ts +++ b/src/application/services/useNote.ts @@ -202,6 +202,7 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt const response = await noteService.getNoteById(id); note.value = response.note; + lastUpdateContent.value = response.note.content; canEdit.value = response.accessRights.canEdit; noteTools.value = response.tools; parentNote.value = response.parentNote; @@ -290,9 +291,12 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt } /** - * Store just saved content in memory + * Store just saved content in memory only if the current note hasn't changed + * This prevents race conditions when switching between notes quickly */ - lastUpdateContent.value = content; + if (currentId.value === currentNoteId) { + lastUpdateContent.value = content; + } isNoteSaving.value = false; } From 035ca0ac97378d34a5f4b9af5960a13a254795d7 Mon Sep 17 00:00:00 2001 From: 7eliassen Date: Tue, 28 Jul 2026 17:19:04 +0300 Subject: [PATCH 3/6] chore: lint --- src/application/services/useNote.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/application/services/useNote.ts b/src/application/services/useNote.ts index b1a8c81f..e442e076 100644 --- a/src/application/services/useNote.ts +++ b/src/application/services/useNote.ts @@ -287,7 +287,7 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt */ void getNoteHierarchy(noteCreated.id); } else { - await noteService.updateNoteContentAndTools(currentNoteId as NoteId, content, specifiedNoteTools); + await noteService.updateNoteContentAndTools(currentNoteId, content, specifiedNoteTools); } /** From de354cd0189b21dcd8dc55477974060ae1a79709 Mon Sep 17 00:00:00 2001 From: 7eliassen Date: Tue, 4 Aug 2026 22:30:34 +0300 Subject: [PATCH 4/6] merge from fix/note-content-overrides-when-switching-between-notes --- src/application/services/useNote.ts | 22 +--------------------- src/presentation/pages/Note.vue | 1 + 2 files changed, 2 insertions(+), 21 deletions(-) diff --git a/src/application/services/useNote.ts b/src/application/services/useNote.ts index 74342032..39bd9874 100644 --- a/src/application/services/useNote.ts +++ b/src/application/services/useNote.ts @@ -141,12 +141,6 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt const route = useRoute(); - /** - * Is there any note currently saving - * Used to prevent re-load note after draft is saved - */ - const isNoteSaving = ref(false); - /** * Note Title identifier */ @@ -255,8 +249,6 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt */ const specifiedNoteTools = resolveToolsByContent(content); - isNoteSaving.value = true; - if (currentId.value === null) { /** * @todo try-catch domain errors @@ -292,8 +284,6 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt * Store just saved content in memory */ lastUpdateContent.value = content; - - isNoteSaving.value = false; } /** @@ -366,7 +356,7 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt } } - watch(currentId, (newId, prevId) => { + watch(currentId, (newId, _prevId) => { /** * One note is open, user clicks on "+" to create another new note * Clear existing note @@ -377,16 +367,6 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt return; } - const isDraftSaving = prevId === null && isNoteSaving.value; - - /** - * Case for newly created note, - * we don't need to re-load it - */ - if (isDraftSaving) { - return; - } - void load(newId); }); diff --git a/src/presentation/pages/Note.vue b/src/presentation/pages/Note.vue index ce00bc7b..5b94de8a 100644 --- a/src/presentation/pages/Note.vue +++ b/src/presentation/pages/Note.vue @@ -54,6 +54,7 @@ From 29a5bf67d6a5609dcb0bb7e6636a2063566aaa88 Mon Sep 17 00:00:00 2001 From: 7eliassen Date: Tue, 4 Aug 2026 22:47:30 +0300 Subject: [PATCH 5/6] feat: add guard to prevent race conditional --- src/presentation/pages/Note.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/presentation/pages/Note.vue b/src/presentation/pages/Note.vue index 118eafdd..0725b5bb 100644 --- a/src/presentation/pages/Note.vue +++ b/src/presentation/pages/Note.vue @@ -176,7 +176,7 @@ async function noteChanged(data: NoteContent): Promise { paddingTop: '100px', }); } - if (updatedNoteCover !== null && noteIdAtCallTime !== null) { + if (updatedNoteCover !== null && noteIdAtCallTime !== null && noteIdAtCallTime === props.id) { await updateCover(noteIdAtCallTime as NoteId, updatedNoteCover); } } From 0700c87fac04f547852102dce7529a16f00d51ca Mon Sep 17 00:00:00 2001 From: 7eliassen Date: Wed, 5 Aug 2026 17:20:44 +0300 Subject: [PATCH 6/6] refactor: reset isEditorReady flag on note id change --- src/application/services/useNoteEditor.ts | 1 - src/presentation/pages/Note.vue | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/application/services/useNoteEditor.ts b/src/application/services/useNoteEditor.ts index 6074c91b..2ad29871 100644 --- a/src/application/services/useNoteEditor.ts +++ b/src/application/services/useNoteEditor.ts @@ -148,7 +148,6 @@ export const useNoteEditor = function useNoteEditor(options: UseNoteEditorOption const loadId = ++currentLoadId; - isEditorReady.value = false; toolsUserConfigLoaded.value = false; try { diff --git a/src/presentation/pages/Note.vue b/src/presentation/pages/Note.vue index 0725b5bb..98b377ea 100644 --- a/src/presentation/pages/Note.vue +++ b/src/presentation/pages/Note.vue @@ -217,6 +217,8 @@ const verticalMenuItems = computed(() => { watch( () => props.id, () => { + isEditorReady.value = false; + /** If new child note is created, refresh editor with empty data */ if (props.id === null) { useHead({