From 50a118cc0cd22ccba2c02dc0f10b6327b6b14dcd Mon Sep 17 00:00:00 2001 From: redeck <466959@niuitmo.ru> Date: Wed, 7 Jan 2026 20:38:49 +0500 Subject: [PATCH 1/2] fix: When quickly switch between notes, the url and id of the note may not match. --- src/application/services/useNote.ts | 53 ++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 17 deletions(-) diff --git a/src/application/services/useNote.ts b/src/application/services/useNote.ts index 74342032..80b77443 100644 --- a/src/application/services/useNote.ts +++ b/src/application/services/useNote.ts @@ -201,6 +201,13 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt try { const response = await noteService.getNoteById(id); + /** + * Id changed, loaded another note + */ + if (currentId.value !== id) { + return; + } + note.value = response.note; canEdit.value = response.accessRights.canEdit; noteTools.value = response.tools; @@ -208,6 +215,9 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt noteParents.value = response.parents; void getNoteHierarchy(id); } catch (error) { + if (currentId.value !== id) { + return; + } deleteOpenedPageByUrl(route.path); if (error instanceof DomainError) { void router.push(`/error/${error.statusCode}`); @@ -255,9 +265,14 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt */ const specifiedNoteTools = resolveToolsByContent(content); + /** + * Id may be changed + */ + const savedNoteId = currentId.value; + isNoteSaving.value = true; - if (currentId.value === null) { + if (savedNoteId === null) { /** * @todo try-catch domain errors */ @@ -273,25 +288,26 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt }, }); - patchOpenedPageByUrl( - route.path, - { - title: noteTitle.value, - url: route.path, - }); + patchOpenedPageByUrl(route.path, { + title: noteTitle.value, + url: route.path, + }); /** * Get note Hierarchy when new Note is created */ void getNoteHierarchy(noteCreated.id); } else { - await noteService.updateNoteContentAndTools(currentId.value, content, specifiedNoteTools); + await noteService.updateNoteContentAndTools(savedNoteId, content, specifiedNoteTools); } /** * Store just saved content in memory + * If id changed, do not store content */ - lastUpdateContent.value = content; + if (currentId.value === savedNoteId) { + lastUpdateContent.value = content; + } isNoteSaving.value = false; } @@ -362,7 +378,7 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt // Recursively update child notes if (hierarchy.childNotes) { - hierarchy.childNotes.forEach(child => updateNoteHierarchyContent(child, title)); + hierarchy.childNotes.forEach((child) => updateNoteHierarchyContent(child, title)); } } @@ -391,13 +407,16 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt }); watch(noteTitle, (currentNoteTitle) => { - if (route.name == 'note') { - patchOpenedPageByUrl( - route.path, - { - title: currentNoteTitle, - url: route.path, - }); + if (route.name == 'note' && currentId.value !== null) { + /** + * URL may have changed, use note id + */ + const noteUrl = `/note/${currentId.value}`; + + patchOpenedPageByUrl(noteUrl, { + title: currentNoteTitle, + url: noteUrl, + }); } updateNoteHierarchyContent(noteHierarchy.value, currentNoteTitle); }); From fe9fb69eab4f0f3062015936815eea9502727ee2 Mon Sep 17 00:00:00 2001 From: Oreshkin Sergey <97605162+redeck1@users.noreply.github.com> Date: Tue, 13 Jan 2026 23:42:09 +0300 Subject: [PATCH 2/2] Update useNote.ts --- 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 80b77443..d2e90e29 100644 --- a/src/application/services/useNote.ts +++ b/src/application/services/useNote.ts @@ -378,7 +378,7 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt // Recursively update child notes if (hierarchy.childNotes) { - hierarchy.childNotes.forEach((child) => updateNoteHierarchyContent(child, title)); + hierarchy.childNotes.forEach(child => updateNoteHierarchyContent(child, title)); } }