From ce9d7093cb8922989041ab3da8231e3f06db8570 Mon Sep 17 00:00:00 2001 From: Neil <4138956+nwparker@users.noreply.github.com> Date: Fri, 29 May 2026 20:15:48 -0700 Subject: [PATCH] fix: cancel untitled rename focus frame (#3434) --- .../editor/UntitledFileRenameDialog.tsx | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/renderer/src/components/editor/UntitledFileRenameDialog.tsx b/src/renderer/src/components/editor/UntitledFileRenameDialog.tsx index 187b1fe7dcb..c931e97b693 100644 --- a/src/renderer/src/components/editor/UntitledFileRenameDialog.tsx +++ b/src/renderer/src/components/editor/UntitledFileRenameDialog.tsx @@ -1,4 +1,4 @@ -import React, { useCallback, useRef, useState } from 'react' +import React, { useCallback, useEffect, useRef, useState } from 'react' import { FolderOpen } from 'lucide-react' import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' @@ -36,6 +36,7 @@ export function UntitledFileRenameDialog({ const [dir, setDir] = useState(worktreePath) const [error, setError] = useState(null) const nameInputRef = useRef(null) + const focusFrameRef = useRef(null) const seededOpenStateRef = useRef({ open: false, baseName, worktreePath }) const displayError = externalError ?? error @@ -54,6 +55,15 @@ export function UntitledFileRenameDialog({ seededOpenStateRef.current = { open: false, baseName, worktreePath } } + useEffect(() => { + return () => { + if (focusFrameRef.current !== null) { + cancelAnimationFrame(focusFrameRef.current) + focusFrameRef.current = null + } + } + }, []) + const handleBrowse = useCallback(async () => { const picked = await window.api.shell.pickDirectory({ defaultPath: dir || worktreePath }) if (!picked) { @@ -98,7 +108,11 @@ export function UntitledFileRenameDialog({ className="max-w-[340px]" onOpenAutoFocus={(event) => { event.preventDefault() - requestAnimationFrame(() => { + if (focusFrameRef.current !== null) { + cancelAnimationFrame(focusFrameRef.current) + } + focusFrameRef.current = requestAnimationFrame(() => { + focusFrameRef.current = null nameInputRef.current?.focus() nameInputRef.current?.select() })