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(media): save the terms on the latest document, regenerate after the save

EtienneLescot0fee0f1cb333
diff --git a/src/components/ai-edition/v4/MediaStage.regenerate.test.tsx b/src/components/ai-edition/v4/MediaStage.regenerate.test.tsx
index b57e4d550..58bb3ac21 100644
--- a/src/components/ai-edition/v4/MediaStage.regenerate.test.tsx
+++ b/src/components/ai-edition/v4/MediaStage.regenerate.test.tsx
@@ -82,7 +82,7 @@ describe("MediaStage Regenerate button", () => {
act(() => regenerate.focus());
expect((await screen.findByRole("tooltip")).textContent).toBe("mediaStage.regenerateTip");
fireEvent.click(regenerate);
- expect(transcription.request).toHaveBeenCalledWith("asset-1", "auto");
+ await vi.waitFor(() => expect(transcription.request).toHaveBeenCalledWith("asset-1", "auto"));
});
it("stays focusable and keeps its tooltip while a transcription runs, and fires nothing", async () => {
diff --git a/src/components/ai-edition/v4/MediaStage.tsx b/src/components/ai-edition/v4/MediaStage.tsx
index d370b9ee2..3cceebcad 100644
--- a/src/components/ai-edition/v4/MediaStage.tsx
+++ b/src/components/ai-edition/v4/MediaStage.tsx
@@ -9,7 +9,7 @@ import type {
AxcutTranscript,
TranscriptLanguageCode,
} from "@/lib/ai-edition/schema";
-import { useProjectStore } from "@/lib/ai-edition/store/projectStore";
+import { useProjectStore, waitForDocumentSaves } from "@/lib/ai-edition/store/projectStore";
import {
useAssetTranscriptions,
useTranscriptionStore,
@@ -429,7 +429,10 @@ export function MediaStage({
rows={2}
spellCheck={false}
onBlur={(e) => {
- const next = document && withVocabulary(document, e.target.value);
+ // The latest document, not the render's: a save replaces the whole
+ // document, so a stale one would undo a transcript written meanwhile.
+ const latest = useProjectStore.getState().document;
+ const next = latest && withVocabulary(latest, e.target.value);
if (next) void saveDocument(next, { history: true });
}}
style={{
@@ -493,7 +496,12 @@ export function MediaStage({
onClick={
selectedBusy
? undefined
- : () => void requestTranscription(selected.id, lang)
+ : async () => {
+ // Clicking here blurs the terms field, whose save is still in
+ // flight: the run must read the terms it just saved.
+ if ((await waitForDocumentSaves()) === "timeout") return;
+ void requestTranscription(selected.id, lang);
+ }
}
style={{
width: 36,