From dac7eb1a3fcb0d92c1f502b59b7e8d725e028e44 Mon Sep 17 00:00:00 2001 From: Neil <4138956+nwparker@users.noreply.github.com> Date: Sun, 31 May 2026 07:43:07 -0700 Subject: [PATCH] perf: move notebook draft cleanup to root ref (#4188) --- .../src/components/editor/IpynbViewer.tsx | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/renderer/src/components/editor/IpynbViewer.tsx b/src/renderer/src/components/editor/IpynbViewer.tsx index e1385d882..442826a4e 100644 --- a/src/renderer/src/components/editor/IpynbViewer.tsx +++ b/src/renderer/src/components/editor/IpynbViewer.tsx @@ -621,12 +621,19 @@ export default function IpynbViewer({ return registerPendingEditorFlush(fileId, flushSourceDrafts) }, [fileId, flushSourceDrafts]) - useEffect(() => { - return () => { + const setRootRef = useCallback( + (node: HTMLDivElement | null): void => { + rootRef.current = node + if (node !== null) { + return + } + // Why: pending source edits and structural mutation frames belong to the + // notebook scroll root; clear them when that DOM owner detaches. void flushSourceDrafts() cancelIpynbStructuralContentFrames(structuralContentFrameIdsRef) - } - }, [flushSourceDrafts]) + }, + [flushSourceDrafts] + ) useEffect(() => { if (!parsed.notebook || Object.keys(sourceDraftsRef.current).length === 0) { @@ -820,7 +827,7 @@ export default function IpynbViewer({ return (