From 7e1ec0dc9ff830fd758e6512b51c8b4a4f981a60 Mon Sep 17 00:00:00 2001 From: lawvs <18554747+lawvs@users.noreply.github.com> Date: Fri, 12 Apr 2024 02:32:01 +0800 Subject: [PATCH] fix: unsubscribe ydoc update listener --- src/components/preview-panel.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/components/preview-panel.tsx b/src/components/preview-panel.tsx index 08f45c4..c64187b 100644 --- a/src/components/preview-panel.tsx +++ b/src/components/preview-panel.tsx @@ -21,10 +21,14 @@ export function PreviewPanel() { if (!yDoc) { return; } - yDoc.on("update", () => { + const callback = () => { // Force re-render setCount((count) => count + 1); - }); + }; + yDoc.on("update", callback); + return () => { + yDoc.off("update", callback); + }; }, [yDoc]); return (