Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

fix(editor): recover a missing primary asset when seeding the timeline

超超超超超级喜欢你的达妮娅ff9e400ab7df
diff --git a/.gitattributes b/.gitattributes
index d9dbbd32f..60897224b 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -7,6 +7,8 @@
*.rs text eol=lf
*.ts text eol=lf
*.tsx text eol=lf
+# Vite's SSR hashbang detection requires LF in imported executable modules.
+*.mjs text eol=lf
# Same drift, caught on the native helper's build file: an edit from Windows
# rewrote all 67 lines as CRLF and buried a 22-line change in a 156-line diff.
CMakeLists.txt text eol=lf
diff --git a/src/lib/ai-edition/document/probedDuration.test.ts b/src/lib/ai-edition/document/probedDuration.test.ts
index 1f7aac939..844438d4b 100644
--- a/src/lib/ai-edition/document/probedDuration.test.ts
+++ b/src/lib/ai-edition/document/probedDuration.test.ts
@@ -48,6 +48,29 @@ function legacyWithClip(): AxcutDocument {
}
describe("documentAfterProbedDuration", () => {
+ it("resolves a missing primary asset before seeding the fallback", () => {
+ const doc = emptyTimeline("deleted_asset", ["asset_1", "asset_2"]);
+ const next = documentAfterProbedDuration(doc, "asset_1", 30, PROJECT);
+ expect(next?.project.primaryAssetId).toBe("asset_1");
+ expect(next?.timeline.clips).toHaveLength(1);
+ expect(next?.timeline.clips[0]).toMatchObject({
+ assetId: "asset_1",
+ sourceStartSec: 0,
+ sourceEndSec: 30,
+ });
+ expect(next?.assets[1].durationSec).toBeUndefined();
+ expect(doc.project.primaryAssetId).toBe("deleted_asset");
+ expect(documentAfterProbedDuration(doc, "asset_2", 30, PROJECT)).toBeNull();
+ });
+
+ it("keeps a valid primary asset even when it is not first", () => {
+ const doc = emptyTimeline("asset_2", ["asset_1", "asset_2"]);
+ expect(documentAfterProbedDuration(doc, "asset_1", 30, PROJECT)).toBeNull();
+ const next = documentAfterProbedDuration(doc, "asset_2", 30, PROJECT);
+ expect(next?.project.primaryAssetId).toBe("asset_2");
+ expect(next?.timeline.clips[0].assetId).toBe("asset_2");
+ });
+
it("seeds a full-duration clip when the primary asset reports its length", () => {
const doc = emptyTimeline("asset_1", ["asset_1"]);
diff --git a/src/lib/ai-edition/document/timeline.ts b/src/lib/ai-edition/document/timeline.ts
index f997ddc18..35a8b42bb 100644
--- a/src/lib/ai-edition/document/timeline.ts
+++ b/src/lib/ai-edition/document/timeline.ts
@@ -587,7 +587,9 @@ export function documentAfterProbedDuration(
// ponytail: replaceTimeline derives clip length from asset.durationSec, which
// import never populates — without this the first auto-created clip silently
// comes out empty (normalizeIntervals clamps against a 0 duration, dropping it).
- const primaryAssetId = doc.project.primaryAssetId ?? doc.assets[0]?.id;
+ const primaryAsset =
+ doc.assets.find((asset) => asset.id === doc.project.primaryAssetId) ?? doc.assets[0];
+ const primaryAssetId = primaryAsset.id;
// Only the asset that actually fired. `replaceTimeline` pins every clip it
// builds to the primary asset, and the seed sizes that clip from `knownSec` —
// so seeding on an event from any OTHER asset writes one video's length under
@@ -595,6 +597,7 @@ export function documentAfterProbedDuration(
if (!primaryAssetId || primaryAssetId !== assetId) return null;
const docWithDuration: AxcutDocument = {
...doc,
+ project: { ...doc.project, primaryAssetId },
// Only a length that was never measured, which is `applyProbedDuration`'s rule
// above widened to cover a stored 0 — the seed exists to give `replaceTimeline` a
// duration to clamp against, and a 0 defeats that exactly as a missing one does.