fix: caption init race condition, auto-save, and panel auto-open

- Remove store reset from useEffect cleanup — was wiping state on dep changes
  and breaking auto-save subscription
- Move panel auto-open into useEffect instead of during render
- Add fallback 500ms poll alongside postMessage listener for initial load

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Vance Ingalls
2026-04-01 23:37:13 -07:00
co-authored by Claude Opus 4.6
parent f2718783c2
commit 614a67dfd3
+10 -7
View File
@@ -139,21 +139,24 @@ export function StudioApp() {
};
window.addEventListener("message", handleMessage);
// Also try immediately in case compositions are already loaded
// Try immediately in case compositions are already loaded
tryActivateCaptions();
// Fallback poll — runtime messages can fire before listener is attached on first load
const pollId = setInterval(tryActivateCaptions, 500);
return () => {
window.removeEventListener("message", handleMessage);
if (useCaptionStore.getState().isEditMode) useCaptionStore.getState().reset();
clearInterval(pollId);
};
}, [activeCompPath, projectId]);
// Auto-expand right panel when a caption word is selected
const prevCaptionHasSelection = useRef(false);
if (captionEditMode && captionHasSelection && !prevCaptionHasSelection.current && rightCollapsed) {
setRightCollapsed(false);
}
prevCaptionHasSelection.current = captionHasSelection;
// eslint-disable-next-line no-restricted-syntax
useEffect(() => {
if (captionEditMode && captionHasSelection) {
setRightCollapsed(false);
}
}, [captionHasSelection, captionEditMode]);
const [globalDragOver, setGlobalDragOver] = useState(false);
const [uploadToast, setUploadToast] = useState<string | null>(null);
const [timelineVisible, setTimelineVisible] = useState(false);