From 7105a060f8f49ffe512998b19eb1768a405db4e6 Mon Sep 17 00:00:00 2001 From: Caio Pizzol Date: Thu, 9 Oct 2025 16:31:40 -0300 Subject: [PATCH] fix: improve cleanup logic This commit refines the cleanup process in the SuperDocTemplateBuilder component by ensuring that the instance is properly referenced before calling the destroy method. It also resets additional references to prevent memory leaks. --- src/index.tsx | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/index.tsx b/src/index.tsx index 197da12..002fde3 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -472,12 +472,16 @@ const SuperDocTemplateBuilder = forwardRef< initSuperDoc(); return () => { - if (superdocRef.current) { - if (typeof superdocRef.current.destroy === "function") { - superdocRef.current.destroy(); - } - superdocRef.current = null; + triggerCleanupRef.current = null; + menuTriggerFromRef.current = null; + + const instance = superdocRef.current; + + if (instance && typeof instance.destroy === "function") { + instance.destroy(); } + + superdocRef.current = null; }; }, [ document?.source,