From e54514243c05bd60e9b62bfedb01b7127fde5e6d Mon Sep 17 00:00:00 2001 From: Neil <4138956+nwparker@users.noreply.github.com> Date: Sun, 31 May 2026 04:42:25 -0700 Subject: [PATCH] perf: move markdown preview timer cleanup to ref (#4112) --- .../src/components/editor/MarkdownPreview.tsx | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/renderer/src/components/editor/MarkdownPreview.tsx b/src/renderer/src/components/editor/MarkdownPreview.tsx index 12f584b3a..4858fa373 100644 --- a/src/renderer/src/components/editor/MarkdownPreview.tsx +++ b/src/renderer/src/components/editor/MarkdownPreview.tsx @@ -597,16 +597,6 @@ export default function MarkdownPreview({ markdownAnnotationsEnabled && sourceWorktree && sourceRelativePath !== null ) - useEffect(() => { - return () => { - // Why: review-note reveal/copy timers are event-owned, but the final - // cancellation belongs to the preview surface unmount. - cancelMarkdownPreviewEditorRevealFrames(pendingEditorRevealFrameIdsRef) - clearMarkdownPreviewTimeout(attentionReviewCommentTimeoutRef) - clearMarkdownPreviewTimeout(reviewNotesCopiedResetTimerRef) - } - }, []) - // Why: each split pane needs its own markdown preview viewport even when the // underlying file is shared. The caller passes a pane-scoped cache key so // duplicate tabs do not overwrite each other's preview scroll state. @@ -715,15 +705,23 @@ export default function MarkdownPreview({ } }, []) + const cleanupPreviewSurfaceTimers = useCallback((): void => { + // Why: reveal/copy timers are event-owned, but the final cancellation + // belongs to the preview surface unmount. + cancelMarkdownPreviewEditorRevealFrames(pendingEditorRevealFrameIdsRef) + clearMarkdownPreviewTimeout(attentionReviewCommentTimeoutRef) + clearReviewNotesCopiedResetTimer() + }, [clearReviewNotesCopiedResetTimer]) + const setRootRef = useCallback( (node: HTMLDivElement | null) => { rootRef.current = node reviewNotesCopyMountedRef.current = node !== null if (node === null) { - clearReviewNotesCopiedResetTimer() + cleanupPreviewSurfaceTimers() } }, - [clearReviewNotesCopiedResetTimer] + [cleanupPreviewSurfaceTimers] ) const scrollToAnchor = useCallback((rawAnchor: string): boolean => {