Repository navigation
fix(editor): retry the dimension backfill and give it time on long takes #1618
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -89,6 +89,13 @@ import { useSequentialTimelineOps } from "./useSequentialTimelineOps"; | |
| // these 2 s, which is what all five add* used to hardcode. | ||
| const DEFAULT_NEW_REGION_SEC = 2; | ||
|
|
||
| // The on-load dimension backfill runs in the background, so it can wait far longer than an | ||
| // insert's 5 s probe. It has to: the Linux recorder writes fragmented MP4 with no index, and | ||
| // Chromium walks every fragment before `loadedmetadata`, which takes well past 5 s on a long | ||
| // take (#1610). A failure is retried on a later document change, a bounded number of times. | ||
| const DIMS_PROBE_TIMEOUT_MS = 60_000; | ||
| const DIMS_PROBE_ATTEMPTS = 3; | ||
|
|
||
| // NaN-guarded floors. Timeline inputs arrive from drag deltas and persisted | ||
| // documents, both of which can carry NaN; every action needs the same guard. | ||
| const finiteSec = (n: number) => (Number.isFinite(n) ? Math.max(0, n) : 0); | ||
|
|
@@ -257,10 +264,11 @@ export function useTimeline() { | |
| // cropped clip could show under ORIGINAL while an un-probed 16:9 sibling was missing entirely. | ||
| // Probe once on load and persist via saveDocument with `history: false` (a write the user | ||
| // never made must not be what the next Ctrl+Z reverses), so the fix sticks and every consumer | ||
| // agrees without each re-probing on its own (what the export dialog used to do). Attempt each | ||
| // asset at most once per session, even on failure, so a file that can't be probed doesn't | ||
| // spin the effect on every document change. | ||
| // agrees without each re-probing on its own (what the export dialog used to do). A failed | ||
| // probe is tried again on a later document change, up to DIMS_PROBE_ATTEMPTS per session, so | ||
| // one slow open is not final (#1610) and an unreadable file still doesn't spin the effect. | ||
| const probedAssetIdsRef = useRef<Set<string>>(new Set()); | ||
| const dimsProbeAttemptsRef = useRef<Map<string, number>>(new Map()); | ||
| useEffect(() => { | ||
| if (!document) return; | ||
| const usedAssetIds = new Set(document.timeline.clips.map((c) => c.assetId)); | ||
|
|
@@ -278,7 +286,8 @@ export function useTimeline() { | |
| (a) => | ||
| usedAssetIds.has(a.id) && | ||
| (needsScreen(a) || needsCamera(a)) && | ||
| !probedAssetIdsRef.current.has(a.id), | ||
| !probedAssetIdsRef.current.has(a.id) && | ||
| (dimsProbeAttemptsRef.current.get(a.id) ?? 0) < DIMS_PROBE_ATTEMPTS, | ||
| ); | ||
| if (missing.length === 0) return; | ||
| // No cleanup cancels this. The effect re-runs on EVERY document change, and a fresh | ||
|
|
@@ -293,18 +302,27 @@ export function useTimeline() { | |
| const probed: Record<string, { video?: Dims; camera?: Dims }> = {}; | ||
| for (const a of missing) { | ||
| probedAssetIdsRef.current.add(a.id); | ||
| dimsProbeAttemptsRef.current.set(a.id, (dimsProbeAttemptsRef.current.get(a.id) ?? 0) + 1); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Recheck retry eligibility when each queued asset starts. If the first run captures Reserve all batch candidates before the first
|
||
| const entry: { video?: Dims; camera?: Dims } = {}; | ||
| let failed = false; | ||
| if (needsScreen(a)) { | ||
| const dims = await probeVideoDimensions(toFileUrl(a.originalPath)); | ||
| const dims = await probeVideoDimensions(toFileUrl(a.originalPath), DIMS_PROBE_TIMEOUT_MS); | ||
| if (dims) entry.video = dims; | ||
| else failed = true; | ||
| } | ||
| // Probed independently of the screen: one file being unreadable must not cost | ||
| // the other its dimensions, and a camera-less asset simply skips this. | ||
| if (a.cameraTrack && needsCamera(a)) { | ||
| const dims = await probeVideoDimensions(toFileUrl(a.cameraTrack.sourcePath)); | ||
| const dims = await probeVideoDimensions( | ||
| toFileUrl(a.cameraTrack.sourcePath), | ||
| DIMS_PROBE_TIMEOUT_MS, | ||
| ); | ||
| if (dims) entry.camera = dims; | ||
| else failed = true; | ||
| } | ||
| if (entry.video || entry.camera) probed[a.id] = entry; | ||
| // Unmarked so a later document change retries what is still missing. | ||
| if (failed) probedAssetIdsRef.current.delete(a.id); | ||
| } | ||
| if (Object.keys(probed).length === 0) return; | ||
| // The store only takes a document once its save returns, so a write still in flight | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep deferred persistence eligible for recovery.
If
waitForDocumentSaves()times out after a successful probe, Line 333 clears the completion marker but leaves the attempt count unchanged. After three such deferrals, this guard permanently excludes the asset for this hook instance. Later document changes cannot save its dimensions, even when the save queue becomes idle.Previously, clearing the marker allowed another run. Retain successful dimensions for a later persistence attempt, or restore retry eligibility when persistence is deferred. Keep the limit for actual probe failures.