Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .filesize-allowlist
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
packages/studio/src/player/hooks/useTimelinePlayer.ts
packages/studio/src/hooks/useManifestPersistence.ts
17 changes: 15 additions & 2 deletions packages/studio/src/hooks/useManifestPersistence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ export function useManifestPersistence({
options?: { forceFromDisk?: boolean; readFromDiskFirst?: boolean },
) => Promise<void>
>(async () => {});
const manifestBootstrappedRef = useRef(false);
const motionBootstrappedRef = useRef(false);
const studioManualEditProjectRef = useRef<string | null>(projectId);

// Keep a ref to the latest projectId so async save callbacks always read the
Expand Down Expand Up @@ -144,7 +146,13 @@ export function useManifestPersistence({
iframe: HTMLIFrameElement | null = previewIframeRef.current,
options?: { forceFromDisk?: boolean; readFromDiskFirst?: boolean },
) => {
const readFromDiskFirst = Boolean(options?.forceFromDisk || options?.readFromDiskFirst);
// Bootstrap from disk on first apply per session; explicit flag avoids
// re-reading disk after the user deletes all edits (async write race).
const needsBootstrap = !manifestBootstrappedRef.current;
if (needsBootstrap) manifestBootstrappedRef.current = true;
const readFromDiskFirst = Boolean(
options?.forceFromDisk || options?.readFromDiskFirst || needsBootstrap,
);
if (!readFromDiskFirst) {
applyCurrentStudioManualEditsToPreview(iframe);
return;
Expand Down Expand Up @@ -210,7 +218,11 @@ export function useManifestPersistence({
iframe: HTMLIFrameElement | null = previewIframeRef.current,
options?: { forceFromDisk?: boolean; readFromDiskFirst?: boolean },
) => {
const readFromDiskFirst = Boolean(options?.forceFromDisk || options?.readFromDiskFirst);
const needsBootstrap = !motionBootstrappedRef.current;
if (needsBootstrap) motionBootstrappedRef.current = true;
const readFromDiskFirst = Boolean(
options?.forceFromDisk || options?.readFromDiskFirst || needsBootstrap,
);
if (!readFromDiskFirst) {
applyCurrentStudioMotionToPreview(iframe);
return;
Expand Down Expand Up @@ -427,6 +439,7 @@ export function useManifestPersistence({
studioMotionManifestRef.current = emptyStudioMotionManifest();
studioMotionRevisionRef.current += 1;
setStudioMotionRevision((revision) => revision + 1);
manifestBootstrappedRef.current = motionBootstrappedRef.current = false;
}, [projectId]);

// ── Listen for external file changes (HMR / SSE) ──
Expand Down
Loading