fix: cancel debounced save on file path update (#11069)

Adds cancellation of the debounced save when the active file path is updated after moving a file or folder. This prevents saving to the old path and ensures lastFilePathRef is updated accordingly.
This commit is contained in:
Pleasure1234 2025-10-31 14:17:06 +00:00 committed by GitHub
parent 82ca35fc29
commit 1018ad87b8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -716,10 +716,17 @@ const NotesPage: FC = () => {
const normalizedActivePath = activeFilePath ? normalizePathValue(activeFilePath) : undefined
if (normalizedActivePath) {
if (normalizedActivePath === sourceNode.externalPath) {
// Cancel debounced save to prevent saving to old path
debouncedSaveRef.current?.cancel()
lastFilePathRef.current = destinationPath
dispatch(setActiveFilePath(destinationPath))
} else if (sourceNode.type === 'folder' && normalizedActivePath.startsWith(`${sourceNode.externalPath}/`)) {
const suffix = normalizedActivePath.slice(sourceNode.externalPath.length)
dispatch(setActiveFilePath(`${destinationPath}${suffix}`))
const newActivePath = `${destinationPath}${suffix}`
// Cancel debounced save to prevent saving to old path
debouncedSaveRef.current?.cancel()
lastFilePathRef.current = newActivePath
dispatch(setActiveFilePath(newActivePath))
}
}