Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/components/video-editor/VideoEditor.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { describe, expect, it } from "vitest";
import { hasUnsavedProjectChanges } from "./VideoEditor";

describe("hasUnsavedProjectChanges", () => {
it("treats a new unsaved project with edits as dirty", () => {
expect(hasUnsavedProjectChanges('{"editor":{"trimRegions":[1]}}', null)).toBe(true);
});

it("treats a saved project with unchanged snapshot as clean", () => {
const snapshot = '{"editor":{"trimRegions":[1]}}';
expect(hasUnsavedProjectChanges(snapshot, snapshot)).toBe(false);
});

it("treats a saved project with changed snapshot as dirty", () => {
expect(
hasUnsavedProjectChanges(
'{"editor":{"trimRegions":[1,2]}}',
'{"editor":{"trimRegions":[1]}}',
),
).toBe(true);
});

it("treats missing current snapshot as clean", () => {
expect(hasUnsavedProjectChanges(null, null)).toBe(false);
});
});
22 changes: 16 additions & 6 deletions src/components/video-editor/VideoEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,21 @@ import {
} from "./types";
import VideoPlayback, { VideoPlaybackRef } from "./VideoPlayback";

export function hasUnsavedProjectChanges(
currentProjectSnapshot: string | null,
lastSavedSnapshot: string | null,
): boolean {
if (!currentProjectSnapshot) {
return false;
}

if (lastSavedSnapshot === null) {
return true;
}
Comment on lines +71 to +73
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid marking untouched new projects as dirty

Returning true whenever lastSavedSnapshot is null makes every newly opened recording/session look dirty immediately, even before the user edits anything. In this flow currentProjectSnapshot is populated as soon as media loads, so hasUnsavedChanges is sent to the main process as true and the close handler will always show the unsaved-changes prompt for untouched projects. This is a regression from the previous behavior and creates a persistent false-positive save prompt on close for new projects.

Useful? React with 👍 / 👎.


return currentProjectSnapshot !== lastSavedSnapshot;
}

export default function VideoEditor() {
const {
state: editorState,
Expand Down Expand Up @@ -295,12 +310,7 @@ export default function VideoEditor() {
gifSizePreset,
]);

const hasUnsavedChanges = Boolean(
currentProjectPath &&
currentProjectSnapshot &&
lastSavedSnapshot &&
currentProjectSnapshot !== lastSavedSnapshot,
);
const hasUnsavedChanges = hasUnsavedProjectChanges(currentProjectSnapshot, lastSavedSnapshot);

useEffect(() => {
async function loadInitialData() {
Expand Down
Loading