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 (