Fix race condition in customOutDir validation on unmount

Co-authored-by: mifi <402547+mifi@users.noreply.github.com>
pull/2724/head
copilot-swe-agent[bot] 8 months ago
parent 5a527ab19b
commit 6abbaa6fc1

@ -60,8 +60,9 @@ export default function useUserSettingsRoot() {
// Validate customOutDir on mount - reset if it's not a valid directory // Validate customOutDir on mount - reset if it's not a valid directory
// This prevents issues where customOutDir was set to a file path instead of a directory // This prevents issues where customOutDir was set to a file path instead of a directory
// https://github.com/mifi/lossless-cut/issues/XXXX
useEffect(() => { useEffect(() => {
let mounted = true;
async function validateCustomOutDir() { async function validateCustomOutDir() {
if (customOutDir == null) return; if (customOutDir == null) return;
@ -69,16 +70,20 @@ export default function useUserSettingsRoot() {
const stat = await lstat(customOutDir); const stat = await lstat(customOutDir);
if (!stat.isDirectory()) { if (!stat.isDirectory()) {
console.warn('customOutDir is not a directory, resetting:', customOutDir); console.warn('customOutDir is not a directory, resetting:', customOutDir);
setCustomOutDir(undefined); if (mounted) setCustomOutDir(undefined);
} }
} catch (err) { } catch (err) {
// If we can't stat the path (doesn't exist, permission denied, etc.), reset it // If we can't stat the path (doesn't exist, permission denied, etc.), reset it
console.warn('customOutDir is invalid, resetting:', customOutDir, err); console.warn('customOutDir is invalid, resetting:', customOutDir, err);
setCustomOutDir(undefined); if (mounted) setCustomOutDir(undefined);
} }
} }
validateCustomOutDir(); validateCustomOutDir();
return () => {
mounted = false;
};
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, []); // Only run on mount }, []); // Only run on mount

Loading…
Cancel
Save