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(editor): four imported-audio state leaks
Benjamin Freeman030ccb8aac70
diff --git a/src/components/ai-edition/RightPanes.tsx b/src/components/ai-edition/RightPanes.tsxindex 37bf689c0..92962b8b6 100644--- a/src/components/ai-edition/RightPanes.tsx+++ b/src/components/ai-edition/RightPanes.tsx@@ -2349,6 +2349,13 @@ export function AudioTrackPane({ tl }: { tl: TimelineApi }) {const asset = track ? tl.assets.find((a) => a.id === track.assetId) : undefined;// Live-drag value for the volume slider; null means "show the committed gain".const [liveGain, setLiveGain] = useState<number | null>(null);+ // Drop the live value when the selected track changes: a drag released outside+ // the input never fires onCommit, so without this an uncommitted -10 dB from+ // track A would show as track B's gain the moment B is selected.+ // biome-ignore lint/correctness/useExhaustiveDependencies: trackId is the trigger, not a read — the body only resets the live value.+ useEffect(() => {+ setLiveGain(null);+ }, [trackId]);if (!track) return null;const fileName = track.label || asset?.label || asset?.originalPath?.split(/[\\/]/).pop() || "";diff --git a/src/components/ai-edition/v4/V4Timeline.tsx b/src/components/ai-edition/v4/V4Timeline.tsxindex 445c0ac51..037d959ec 100644--- a/src/components/ai-edition/v4/V4Timeline.tsx+++ b/src/components/ai-edition/v4/V4Timeline.tsx@@ -875,6 +875,11 @@ export function V4Timeline({e.preventDefault();e.stopPropagation();tl.selectAudioTrack(track.id);+ // Start clean: a previous drag's commit may still be in flight (its ref is+ // cleared only when `placeAudioTrack` resolves). Without this, a plain+ // select-click that never moves would let `up` read that stale value and+ // re-commit the old drag — a redundant write and an extra undo step.+ audioDragRef.current = null;const el = canvasRef.current;if (!el) return;const r = el.getBoundingClientRect();diff --git a/src/lib/ai-edition/document/audioTracks.test.ts b/src/lib/ai-edition/document/audioTracks.test.tsindex ddec1ce05..d313eb693 100644--- a/src/lib/ai-edition/document/audioTracks.test.ts+++ b/src/lib/ai-edition/document/audioTracks.test.ts@@ -1,5 +1,5 @@import { describe, expect, it } from "vitest";-import { createAudioTrack, createEmptyDocument } from "../schema";+import { type AxcutAsset, createAudioTrack, createEmptyDocument } from "../schema";import {appendAudioTrack,removeAudioTrack,@@ -29,6 +29,32 @@ describe("audioTracks document ops (issue #350)", () => {expect(removeAudioTrack(doc, "nope").audioTracks).toEqual([track]);});+ const audioAsset: AxcutAsset = {+ id: "asset_1",+ kind: "audio",+ label: "BGM",+ originalPath: "/bgm.mp3",+ cameraTrack: null,+ };++ it("removeAudioTrack also drops the track's asset when nothing else references it", () => {+ const track = createAudioTrack({ assetId: "asset_1", durationSec: 30 });+ const doc = { ...appendAudioTrack(emptyDoc(), track), assets: [audioAsset] };+ const next = removeAudioTrack(doc, track.id);+ expect(next.audioTracks).toEqual([]);+ expect(next.assets).toEqual([]);+ });++ it("removeAudioTrack keeps the asset when another track still references it", () => {+ const t1 = createAudioTrack({ assetId: "asset_1", durationSec: 30 });+ const t2 = createAudioTrack({ assetId: "asset_1", durationSec: 30 });+ const doc = {+ ...appendAudioTrack(appendAudioTrack(emptyDoc(), t1), t2),+ assets: [audioAsset],+ };+ expect(removeAudioTrack(doc, t1.id).assets).toEqual([audioAsset]);+ });+it("setAudioTrackGain stores a finite dB and defaults NaN to 0", () => {const { doc, track } = docWithTrack();expect(setAudioTrackGain(doc, track.id, -6).audioTracks[0]?.gainDb).toBe(-6);diff --git a/src/lib/ai-edition/document/audioTracks.ts b/src/lib/ai-edition/document/audioTracks.tsindex a70042f59..89c97473d 100644--- a/src/lib/ai-edition/document/audioTracks.ts+++ b/src/lib/ai-edition/document/audioTracks.ts@@ -19,9 +19,24 @@ export function appendAudioTrack(doc: AxcutDocument, track: AxcutAudioTrack): Axreturn { ...doc, audioTracks: [...doc.audioTracks, track] };}-/** Drop a track by id. A no-op if the id isn't present. */+/**+ * Drop a track by id. A no-op if the id isn't present.+ *+ * Also drops the track's asset if nothing else references it. An imported audio+ * asset is only ever reachable through its track — audio is filtered out of the+ * clip lists, so it never becomes a clip — so a deleted track orphans it, and it+ * would otherwise linger in the document forever, invisible in every asset list+ * (issue #350).+ */export function removeAudioTrack(doc: AxcutDocument, trackId: string): AxcutDocument {- return { ...doc, audioTracks: doc.audioTracks.filter((t) => t.id !== trackId) };+ const track = doc.audioTracks.find((t) => t.id === trackId);+ const audioTracks = doc.audioTracks.filter((t) => t.id !== trackId);+ if (!track) return { ...doc, audioTracks };+ const stillReferenced =+ audioTracks.some((t) => t.assetId === track.assetId) ||+ doc.timeline.clips.some((c) => c.assetId === track.assetId);+ const assets = stillReferenced ? doc.assets : doc.assets.filter((a) => a.id !== track.assetId);+ return { ...doc, audioTracks, assets };}// Shared updater — maps the one matching track through `patch`. Keeps every opdiff --git a/src/lib/ai-edition/store/useTimeline.ts b/src/lib/ai-edition/store/useTimeline.tsindex 06d580831..2e1eeab86 100644--- a/src/lib/ai-edition/store/useTimeline.ts+++ b/src/lib/ai-edition/store/useTimeline.ts@@ -144,6 +144,17 @@ export function useTimeline() {const hasDoc = document !== null && projectId !== null;+ // Clear a stale audio-track selection. `removeAudioTrack` clears it on an explicit+ // delete, but an undo (or any document swap) can drop the selected track WITHOUT+ // going through that op — and then `selectedAudioTrackId` points at nothing while the+ // inspector stays open on an empty AudioTrackPane, recoverable only by clicking a facet.+ useEffect(() => {+ if (selectedAudioTrackId === null) return;+ if (!document?.audioTracks.some((t) => t.id === selectedAudioTrackId)) {+ setSelectedAudioTrackId(null);+ }+ }, [document, selectedAudioTrackId, setSelectedAudioTrackId]);+// Backfill missing source dimensions for any USED asset whose `video` was never probed.// `probeAndCorrectClip` only populates dims on INSERT, gated on a null duration, so an asset// saved with a duration but no dims (e.g. a project migrated from before dims were probed