mirror of
https://github.com/stablyai/orca.git
synced 2026-09-21 16:02:20 +00:00
Handle blur race when file changes during rename
When switching files mid-rename, React may deliver the old input's blur event after the new file renders, causing a stale rename commit. Mark the rename as cancelled when the active file changes, and add test coverage verifying stale blur events are ignored.
This commit is contained in:
@@ -196,7 +196,8 @@ describe('EditorPanelHeaderPath inline rename', () => {
|
||||
const rerenderPath = renderPath(baseFile())
|
||||
openRenameInput()
|
||||
|
||||
fireEvent.change(getRenameInput('Rename file notes.md'), { target: { value: 'renamed.md' } })
|
||||
const input = getRenameInput('Rename file notes.md')
|
||||
fireEvent.change(input, { target: { value: 'renamed.md' } })
|
||||
rerenderPath(
|
||||
baseFile({
|
||||
id: '/repo/other.md',
|
||||
@@ -207,6 +208,9 @@ describe('EditorPanelHeaderPath inline rename', () => {
|
||||
|
||||
expect(screen.queryByLabelText('Rename file notes.md')).toBeNull()
|
||||
expect(screen.queryByLabelText('Rename file other.md')).toBeNull()
|
||||
|
||||
// React may deliver the removed input's blur after the active file render.
|
||||
fireEvent.blur(input)
|
||||
expect(renameFileOnDiskMock).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ export function useEditorHeaderFileRename(activeFile: OpenFile): EditorHeaderFil
|
||||
// Why: the header renders one unkeyed path strip for every file, so a file
|
||||
// switch mid-rename would otherwise commit the typed name against the new path.
|
||||
if (renameFilePath !== activeFile.filePath) {
|
||||
renameCancelledRef.current = true
|
||||
setRenameFilePath(activeFile.filePath)
|
||||
setIsRenaming(false)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user