Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.
TypeScript cross-platformelectronffmpegopen-sourceproduct-demorustscreen-capturescreen-recorderscreen-recordingscreen-studioscreencastspeech-to-texttypescriptvideo-editingvideo-editorwaylandwgpuwhisper
fix(preview): mount the primary asset while the timeline is empty
超超超超超级喜欢你的达妮娅e32395751024
diff --git a/src/components/ai-edition/NewEditorShell.tsx b/src/components/ai-edition/NewEditorShell.tsxindex c5ab65028..34810eea7 100644--- a/src/components/ai-edition/NewEditorShell.tsx+++ b/src/components/ai-edition/NewEditorShell.tsx@@ -1606,6 +1606,10 @@ export function NewEditorShell() {hasProject={hasProject}hasAsset={hasAsset}videoSources={videoSources}+ // While the timeline is empty the preview mounts this asset rather+ // than whichever one sorts first, so the clip `handleLoadedMetadata`+ // seeds comes from the video it is sized against.+ primaryAssetId={document?.project.primaryAssetId}// Imported audio tracks (issue #350). `videoSources` already// resolves a URL for every asset (audio included), so it doubles as// the audio source list; VirtualPreview looks each track up by assetId.diff --git a/src/components/ai-edition/Preview.test.tsx b/src/components/ai-edition/Preview.test.tsxindex db84828b8..d4810ce70 100644--- a/src/components/ai-edition/Preview.test.tsx+++ b/src/components/ai-edition/Preview.test.tsx@@ -75,6 +75,7 @@ function source(id: string): VideoSource {function previewProps(props: {videoSources: VideoSource[];clips: AxcutClip[];+ primaryAssetId?: string;hasAsset?: boolean;hasProject?: boolean;}) {@@ -84,6 +85,7 @@ function previewProps(props: {hasProject={props.hasProject ?? true}hasAsset={props.hasAsset ?? true}videoSources={props.videoSources}+ primaryAssetId={props.primaryAssetId}clips={props.clips}seekTarget={null}onTimeChange={vi.fn()}@@ -157,12 +159,48 @@ describe("Preview follows the timeline, not the asset list", () => {// The bootstrap path: `handleLoadedMetadata` mints the very first clip from// the <video>'s own metadata, so a just-imported asset has to be mounted// while nothing references it yet.- it("falls back to every asset while the timeline is empty", () => {+ it("mounts the asset while the timeline is empty", () => {renderPreview({ videoSources: [source("fresh_import")], clips: [] });expect(canvas()).toHaveAttribute("data-sources", "fresh_import");});+ // A project whose first import was audio: audio never claims the empty primary+ // slot, so `assets[0]` is the audio track and the primary is the video added+ // after it. Only one source is mounted at a time and nothing on an empty+ // timeline moves that index off 0 — so mounting the audio would hand+ // `handleLoadedMetadata` an event for an asset it refuses to seed from, and the+ // timeline would never get its first clip at all.+ it("mounts the primary asset, not the one that sorts first", () => {+ renderPreview({+ videoSources: [source("bgm"), source("screen")],+ primaryAssetId: "screen",+ clips: [],+ });++ expect(canvas()).toHaveAttribute("data-sources", "screen");+ });++ // No primary recorded (a v1.7 project that predates the field): fall back to+ // `assets[0]`, which is what the seed itself falls back to.+ it("mounts the first asset when the project has no primary", () => {+ renderPreview({ videoSources: [source("first"), source("second")], clips: [] });++ expect(canvas()).toHaveAttribute("data-sources", "first");+ });++ // A primary id pointing at an asset with no source would otherwise mount+ // nothing and collapse the stage to the empty state.+ it("keeps every asset when the primary has no source", () => {+ renderPreview({+ videoSources: [source("a"), source("b")],+ primaryAssetId: "gone",+ clips: [],+ });++ expect(canvas()).toHaveAttribute("data-sources", "a,b");+ });+// A clip landing on a healthy asset takes over the preview regardless of what// happened to the asset that was mounted before it.it("switches to the asset a new clip references", () => {diff --git a/src/components/ai-edition/Preview.tsx b/src/components/ai-edition/Preview.tsxindex 3a1db9756..666af3ae7 100644--- a/src/components/ai-edition/Preview.tsx+++ b/src/components/ai-edition/Preview.tsx@@ -23,6 +23,9 @@ interface PreviewProps {hasProject: boolean;hasAsset: boolean;videoSources: VideoSource[];+ /** `document.project.primaryAssetId`, when the project has one. Read only while+ * the timeline is empty — see `previewSources`. */+ primaryAssetId?: string;/** Imported audio tracks and the (unfiltered) asset URLs they resolve to* (issue #350). Passed straight through to VirtualPreview — unlike the video* `previewSources` below, these are NOT narrowed to clip-referenced assets,@@ -61,6 +64,7 @@ export function Preview({hasProject,hasAsset,videoSources,+ primaryAssetId,audioTracks = [],audioSources = [],clips,@@ -116,8 +120,23 @@ export function Preview({const source = videoSources.find((s) => s.id === clip.assetId);if (source) referenced.push(source);}- return referenced.length > 0 ? referenced : videoSources;- }, [clips, videoSources]);+ if (referenced.length > 0) return referenced;+ // Empty timeline: mount the asset the seed is minted FOR, not whichever asset+ // happens to sort first. `handleLoadedMetadata` sizes that first clip against+ // `primaryAssetId ?? assets[0]` and ignores an event from any other asset, and+ // only ONE source is ever mounted (`videoSources[sourceIndex]` in+ // VirtualPreview, index 0 while nothing on the timeline moves it) — so mounting+ // a non-primary asset here fires an event nothing acts on and the timeline+ // stays empty for good. A project whose first import was audio is exactly that+ // case: audio never claims the empty primary slot (document-service.addAsset),+ // so `assets[0]` is the audio and the primary is the video added after it.+ // `videoSources` mirrors `document.assets` in order, so index 0 is the same+ // `assets[0]` the seed itself falls back to.+ const primary = primaryAssetId+ ? videoSources.find((source) => source.id === primaryAssetId)+ : videoSources[0];+ return primary ? [primary] : videoSources;+ }, [clips, videoSources, primaryAssetId]);// ponytail: a media failure used to fall through to `EditorEmptyState`, and// that is issue #395: ONE `error` event on the hidden <video> — including the