Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(relation_map): save the open note before its pane closes
Elian Dorana310f4dec1a8
diff --git a/apps/client/src/widgets/type_widgets/relation_map/NotePane.spec.tsx b/apps/client/src/widgets/type_widgets/relation_map/NotePane.spec.tsxindex 49da948ea8..95dff2344f 100644--- a/apps/client/src/widgets/type_widgets/relation_map/NotePane.spec.tsx+++ b/apps/client/src/widgets/type_widgets/relation_map/NotePane.spec.tsx@@ -148,14 +148,16 @@ describe("relation map NotePane", () => {expect(pane()).toBeNull();});- it("stays closed for a note that is not on the map, and closes once its note leaves it", async () => {+ it("stays closed for a note that is not on the map, and closes once its note leaves it after asking the editor to save", async () => {await mount({ noteIdsOnMap: [ "second" ] });expect(pane()).toBeNull();await mount({ selection: { noteId: "second" } });expect(title()).toBe("Second");+ editorAskedToSave.mockClear();await update({ noteIdsOnMap: [ "first" ] });+ expect(editorAskedToSave).toHaveBeenCalledTimes(1);expect(pane()).toBeNull();});diff --git a/apps/client/src/widgets/type_widgets/relation_map/NotePane.tsx b/apps/client/src/widgets/type_widgets/relation_map/NotePane.tsxindex 62800cbc5f..0f77253fe5 100644--- a/apps/client/src/widgets/type_widgets/relation_map/NotePane.tsx+++ b/apps/client/src/widgets/type_widgets/relation_map/NotePane.tsx@@ -1,7 +1,7 @@import "./NotePane.css";import { RefObject } from "preact";-import { useCallback, useEffect, useImperativeHandle, useState } from "preact/hooks";+import { useCallback, useEffect, useImperativeHandle, useLayoutEffect, useState } from "preact/hooks";import { t } from "../../../services/i18n";import { isMobile } from "../../../services/utils";@@ -62,9 +62,10 @@ export default function NotePane({ paneRef, noteIdsOnMap, mapApiRef, isReadOnly,if (!selection) setMaximized(false);}, [ selection ]);- // Closes the pane when its note is removed from the map or deleted.+ // Closes the pane when its note is removed from the map or deleted. A layout effect, so that+ // the editor is still mounted, and saves, when `closePane()` asks it to.const isOnMap = !!selection && noteIdsOnMap.includes(selection.noteId);- useEffect(() => {+ useLayoutEffect(() => {if (selection && (!isOnMap || note === null)) {closePane();}@@ -82,7 +83,7 @@ export default function NotePane({ paneRef, noteIdsOnMap, mapApiRef, isReadOnly,return () => window.removeEventListener("keydown", onKeyDown, true);}, [ selection?.noteId, closePane ]);- if (!note || !isOnMap) return null;+ if (!note) return null;return (<EmbeddedNoteScope component={paneComponent} noteContext={noteContext}>