From 15f21792746a90336e1d4dab2b7f3fcbc3af0087 Mon Sep 17 00:00:00 2001 From: Isaac Sanchez-Hawkins <266845420+isanchez404@users.noreply.github.com> Date: Fri, 8 May 2026 16:37:27 -0400 Subject: [PATCH] fix(files): guard pending navigation (#1172) * fix(files): guard pending navigation * fix(files): avoid pending navigation re-entry --------- Co-authored-by: Isaac Sanchez --- .../ui/src/components/views/FilesView.tsx | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/packages/ui/src/components/views/FilesView.tsx b/packages/ui/src/components/views/FilesView.tsx index b3ccff6f..2ce512e9 100644 --- a/packages/ui/src/components/views/FilesView.tsx +++ b/packages/ui/src/components/views/FilesView.tsx @@ -2138,9 +2138,10 @@ export const FilesView: React.FC = ({ mode = 'full' }) => { } if (selectedFile?.path !== targetPath) { - if (selectedPath !== targetPath) { - setSelectedPath(root, targetPath); + if (confirmDiscardOpen) { + return; } + void handleSelectFile(toFileNode(targetPath)); return; } @@ -2213,19 +2214,20 @@ export const FilesView: React.FC = ({ mode = 'full' }) => { pendingNavigationCycleRef.current = { key: '', attempts: 0 }; }, [ canEdit, + confirmDiscardOpen, draftContent, editorViewReadyNonce, fileError, fileLoading, isSelectedImage, loadedFilePath, + handleSelectFile, pendingFileNavigation, root, selectedFile?.path, - selectedPath, setPendingFileNavigation, - setSelectedPath, textViewMode, + toFileNode, ]); React.useEffect(() => { @@ -2240,9 +2242,10 @@ export const FilesView: React.FC = ({ mode = 'full' }) => { } if (selectedFile?.path !== targetPath) { - if (selectedPath !== targetPath) { - setSelectedPath(root, targetPath); + if (confirmDiscardOpen) { + return; } + void handleSelectFile(toFileNode(targetPath)); return; } @@ -2261,17 +2264,18 @@ export const FilesView: React.FC = ({ mode = 'full' }) => { setPendingFileFocusPath(null); }, [ canEdit, + confirmDiscardOpen, fileError, fileLoading, + handleSelectFile, isSelectedImage, loadedFilePath, pendingFileFocusPath, root, selectedFile?.path, - selectedPath, setPendingFileFocusPath, - setSelectedPath, textViewMode, + toFileNode, ]); const nudgeEditorSelectionAboveKeyboard = React.useCallback((view: EditorView | null) => {