From dd2020a08473aefe20e15aff37ab64e4bd101c34 Mon Sep 17 00:00:00 2001 From: Neil <4138956+nwparker@users.noreply.github.com> Date: Fri, 29 May 2026 15:55:59 -0700 Subject: [PATCH] Move contextual copy toast cleanup to editor dispose --- .../src/components/editor/setup-contextual-copy.ts | 7 +++++++ .../src/components/editor/useContextualCopySetup.tsx | 11 +---------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/renderer/src/components/editor/setup-contextual-copy.ts b/src/renderer/src/components/editor/setup-contextual-copy.ts index ea565a9ab2d..baf34a4a8f4 100644 --- a/src/renderer/src/components/editor/setup-contextual-copy.ts +++ b/src/renderer/src/components/editor/setup-contextual-copy.ts @@ -294,6 +294,13 @@ export function setupContextualCopy({ editorDomNode.addEventListener('mouseup', updateCopyHint, true) editorDomNode.addEventListener('keyup', updateCopyHint, true) editorInstance.onDidDispose(() => { + // Why: the confirmation toast timeout belongs to the Monaco editor that + // scheduled it, so editor disposal is the earliest reliable cleanup point. + if (copyToastTimeoutRef.current !== null) { + window.clearTimeout(copyToastTimeoutRef.current) + copyToastTimeoutRef.current = null + setCopyToast(null) + } if (primarySelectionTimer !== null) { window.clearTimeout(primarySelectionTimer) primarySelectionTimer = null diff --git a/src/renderer/src/components/editor/useContextualCopySetup.tsx b/src/renderer/src/components/editor/useContextualCopySetup.tsx index c65e0783f3c..5c3f31dbbfc 100644 --- a/src/renderer/src/components/editor/useContextualCopySetup.tsx +++ b/src/renderer/src/components/editor/useContextualCopySetup.tsx @@ -1,4 +1,4 @@ -import React, { useRef, useState, useEffect, useCallback } from 'react' +import React, { useRef, useState, useCallback } from 'react' import type { editor } from 'monaco-editor' import { setupContextualCopy } from './setup-contextual-copy' @@ -6,15 +6,6 @@ export function useContextualCopySetup() { const [copyToast, setCopyToast] = useState<{ left: number; top: number } | null>(null) const copyToastTimeoutRef = useRef(null) - useEffect(() => { - const toastRef = copyToastTimeoutRef - return () => { - if (toastRef.current !== null) { - window.clearTimeout(toastRef.current) - } - } - }, []) - const setupCopy = useCallback( ( editorInstance: editor.IStandaloneCodeEditor,