Skip to content

Build your personal knowledge base with Trilium Notes

fix(client): run unmount cleanups that report out during the unmount

Elian Doran77059566ab47
diff --git a/apps/client/src/widgets/react/FormAutocomplete.tsx b/apps/client/src/widgets/react/FormAutocomplete.tsx
index e7cfc2de61..6faee95d40 100644
--- a/apps/client/src/widgets/react/FormAutocomplete.tsx
+++ b/apps/client/src/widgets/react/FormAutocomplete.tsx
@@ -239,7 +239,9 @@ export function useForwardedKeys<T>(
const onActiveDescendantRef = useRef(onActiveDescendant);
onActiveDescendantRef.current = onActiveDescendant;
useEffect(() => onActiveDescendantRef.current?.(activeId), [ activeId ]);
- useEffect(() => () => onActiveDescendantRef.current?.(null), []);
+ // A layout cleanup runs during the unmount itself; a passive one runs after paint, by which
+ // time `createHostedList()` has already let go of the host it would report to.
+ useLayoutEffect(() => () => onActiveDescendantRef.current?.(null), []);
useLayoutEffect(() => {
handleRef.current = {
diff --git a/apps/client/src/widgets/type_widgets/canvas/persistence.ts b/apps/client/src/widgets/type_widgets/canvas/persistence.ts
index 794b4cd727..498cde410a 100644
--- a/apps/client/src/widgets/type_widgets/canvas/persistence.ts
+++ b/apps/client/src/widgets/type_widgets/canvas/persistence.ts
@@ -3,7 +3,7 @@ import { ExcalidrawElement, NonDeletedExcalidrawElement } from "@excalidraw/exca
import { AppState, BinaryFileData, BinaryFiles, ExcalidrawImperativeAPI, ExcalidrawInitialDataState, ExcalidrawProps, LibraryItem } from "@excalidraw/excalidraw/types";
import { deferred, type DeferredPromise } from "@triliumnext/commons";
import { RefObject } from "preact";
-import { useEffect, useRef, useState } from "preact/hooks";
+import { useEffect, useLayoutEffect, useRef, useState } from "preact/hooks";
import NoteContext from "../../../components/note_context";
import type FAttachment from "../../../entities/fattachment";
@@ -379,7 +379,9 @@ export function useCanvasDrawingPersistence(
};
});
- useEffect(() => () => editor?.release(attachment.attachmentId), [ editor, attachment ]);
+ // A layout cleanup runs during the unmount, before Excalidraw's `componentWillUnmount()` empties
+ // the scene that `release()` reads; a passive one runs after paint.
+ useLayoutEffect(() => () => editor?.release(attachment.attachmentId), [ editor, attachment ]);
return {
initialData,