From 95da2ae41bd3a2b92fb7509d1929958255ec5849 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Thu, 9 Oct 2025 19:28:06 +0000 Subject: [PATCH] Refactor: Improve SuperDoc cleanup logic Co-authored-by: caiopizzol --- 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,