Skip to content

Build your personal knowledge base with Trilium Notes

fix(layout/formatting_toolbar): memory leak for closed tabs

Elian Doran476c1620163b
diff --git a/apps/client/src/widgets/ribbon/FormattingToolbar.tsx b/apps/client/src/widgets/ribbon/FormattingToolbar.tsx
index c1e7d103ff..c8d32aab77 100644
--- a/apps/client/src/widgets/ribbon/FormattingToolbar.tsx
+++ b/apps/client/src/widgets/ribbon/FormattingToolbar.tsx
@@ -64,6 +64,13 @@ export function FixedFormattingToolbar() {
}
});
+ // Clean the cache when tabs are closed.
+ useTriliumEvent("noteContextRemoved", ({ ntxIds: eventNtxIds }) => {
+ for (const eventNtxId of eventNtxIds) {
+ toolbarCache.delete(eventNtxId);
+ }
+ });
+
// Switch between the cached toolbar when user navigates to a different note context.
useEffect(() => {
if (!ntxId) return;