diff --git a/components/editor/AudioEditor.tsx b/components/editor/AudioEditor.tsx index 7045703..da076db 100644 --- a/components/editor/AudioEditor.tsx +++ b/components/editor/AudioEditor.tsx @@ -881,6 +881,12 @@ export function AudioEditor() { }, [loadProjectsList]); // Save current project + // Use ref to capture latest currentTime without triggering callback recreation + const currentTimeRef = React.useRef(currentTime); + React.useEffect(() => { + currentTimeRef.current = currentTime; + }, [currentTime]); + const handleSaveProject = React.useCallback(async () => { if (tracks.length === 0) return; @@ -904,7 +910,7 @@ export function AudioEditor() { tracks, { zoom, - currentTime, + currentTime: currentTimeRef.current, // Use ref value sampleRate: audioContext.sampleRate, } ); @@ -929,17 +935,26 @@ export function AudioEditor() { duration: 3000, }); } - }, [tracks, currentProjectId, currentProjectName, zoom, currentTime, addToast]); + }, [tracks, currentProjectId, currentProjectName, zoom, addToast]); // Removed currentTime from deps // Auto-save effect (saves on track or name changes after 3 seconds of no changes) React.useEffect(() => { if (tracks.length === 0) return; + console.log('[Auto-save] Scheduling auto-save in 3 seconds...', { + trackCount: tracks.length, + projectName: currentProjectName, + }); + const autoSaveTimer = setTimeout(() => { + console.log('[Auto-save] Triggering auto-save now'); handleSaveProject(); }, 3000); // Auto-save after 3 seconds of no changes - return () => clearTimeout(autoSaveTimer); + return () => { + console.log('[Auto-save] Clearing auto-save timer'); + clearTimeout(autoSaveTimer); + }; }, [tracks, currentProjectName, handleSaveProject]); // Create new project