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/3] 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/3] 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)); } } From 4b6148a4abf9e0bb8ff847ac333b60ebf562be34 Mon Sep 17 00:00:00 2001 From: redeck <466959@niuitmo.ru> Date: Wed, 11 Feb 2026 20:16:44 +0300 Subject: [PATCH 3/3] add more specified comments --- src/application/services/useNote.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/application/services/useNote.ts b/src/application/services/useNote.ts index 80b77443..70bf0de0 100644 --- a/src/application/services/useNote.ts +++ b/src/application/services/useNote.ts @@ -202,7 +202,8 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt const response = await noteService.getNoteById(id); /** - * Id changed, loaded another note + * If route already points to another note, + * ignore this outdated response */ if (currentId.value !== id) { return; @@ -215,6 +216,10 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt noteParents.value = response.parents; void getNoteHierarchy(id); } catch (error) { + /** + * If user already switched to another note, + * do not handle errors from the previous request + */ if (currentId.value !== id) { return; } @@ -266,7 +271,7 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt const specifiedNoteTools = resolveToolsByContent(content); /** - * Id may be changed + * Remember current note id to detect route changes during save */ const savedNoteId = currentId.value; @@ -409,7 +414,7 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt watch(noteTitle, (currentNoteTitle) => { if (route.name == 'note' && currentId.value !== null) { /** - * URL may have changed, use note id + * Build tab URL from current note id to avoid using outdated route.path */ const noteUrl = `/note/${currentId.value}`;