Skip to content

fix: prompt for unsaved changes in new projects#312

Open
LocNguyenSGU wants to merge 1 commit intosiddharthvaddem:mainfrom
LocNguyenSGU:fix/issue-311-new-project-unsaved-prompt
Open

fix: prompt for unsaved changes in new projects#312
LocNguyenSGU wants to merge 1 commit intosiddharthvaddem:mainfrom
LocNguyenSGU:fix/issue-311-new-project-unsaved-prompt

Conversation

@LocNguyenSGU
Copy link
Copy Markdown

@LocNguyenSGU LocNguyenSGU commented Apr 3, 2026

Summary

Fix the editor dirty-state logic so new projects that have never been saved still trigger the unsaved-changes prompt after edits.

Reproduction

A newly loaded recording/session resets both currentProjectPath and lastSavedSnapshot to null. After making edits, the previous dirty-state rule still returned false because it required currentProjectPath.

Patch Summary

  • extract dirty-state evaluation into a small helper
  • treat a current snapshot with no saved snapshot as unsaved
  • add focused unit coverage for new-project and saved-project cases

Risks

Low. The change is limited to dirty-state calculation and its test coverage.

Test Coverage

  • added src/components/video-editor/VideoEditor.test.ts
  • confirmed it fails before the fix and passes after the fix

Summary by CodeRabbit

  • Tests

    • Added comprehensive test coverage for unsaved changes detection in the video editor.
  • Refactor

    • Improved internal logic for detecting unsaved project changes, making the codebase more maintainable.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 3, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8972f3f7-c6b9-49e0-b963-46e12efdae42

📥 Commits

Reviewing files that changed from the base of the PR and between b101820 and 2b3e839.

📒 Files selected for processing (2)
  • src/components/video-editor/VideoEditor.test.ts
  • src/components/video-editor/VideoEditor.tsx

📝 Walkthrough

Walkthrough

A new hasUnsavedProjectChanges helper function is extracted from inline logic in VideoEditor and exported for reuse. Tests validate the function's behavior across different project snapshot states and edit conditions.

Changes

Cohort / File(s) Summary
Project State Helper
src/components/video-editor/VideoEditor.tsx
Extracted hasUnsavedProjectChanges function that compares current and last-saved project snapshots to determine if changes exist. Replaced inline dirty-check logic with function call.
Function Tests
src/components/video-editor/VideoEditor.test.ts
Added test suite with four cases validating function behavior: handling new unsaved projects, identical snapshots, differing snapshots, and null/missing snapshot states.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related issues

Poem

A function hopped out with a test or two,
Checking if projects are old or new,
No longer hidden in inline code's fold,
Unsaved changes are now to behold! 🐰✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: fixing the unsaved-changes prompt for new projects, which directly addresses the core objective of the PR.
Description check ✅ Passed The PR description provides a clear summary, reproduction steps, patch details, risk assessment, and test coverage. However, it deviates from the repository template structure by using custom section headings instead of the required template format.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2b3e839711

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +71 to +73
if (lastSavedSnapshot === null) {
return true;
}
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 👍 / 👎.

@siddharthvaddem
Copy link
Copy Markdown
Owner

@LocNguyenSGU Ci checks are failing. Can you take another look.

@siddharthvaddem
Copy link
Copy Markdown
Owner

Hi @LocNguyenSGU Thanks for working on this. After taking a closer look at #321 I think I am going to probably have those changes in for fixing this. It sets a baseline snapshot on load means you can distinguish "user hasn't changed anything" from "never saved" without special-casing null. I feel like this is better placed in the persistence layer than the videoeditor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants