Skip to content

Switching projects with unsaved editor changes silently discards them #37

Description

@inactinique

Summary

Switching to a different ClioDeck project while the editor has unsaved changes silently discards those changes — no save prompt, no warning, no save attempt at all. This is the same class of bug already fixed once at the chapter-switch level (the fix-bascule-fichier history) but reintroduced one level up, at the project-switch level.

Found while auditing the ClioDeck wiki against the actual code (pass 16, editor & export cluster, project-switch-mid-operation angle).

Current behavior (verified against code)

  • Switching chapters or documents within a project is safe: src/renderer/src/stores/editorStore.ts's loadFile() explicitly checks isDirty and awaits saveFile() before proceeding, refusing to open the next file if the save fails.
  • Switching to a different project entirely goes through a completely separate code path: src/renderer/src/stores/projectStore.ts's loadProject() (lines 90+) calls window.electron.project.load(projectPath) immediately, with no check of isDirty and no call to saveFile() anywhere in the function.
  • All three renderer call sites of loadProject() (src/renderer/src/components/Project/ProjectPanel.tsx:94,119,318 — opening a project via dialog, opening a path directly, and opening a recent project from the list) go through this same unguarded path.
  • The main-process project:load IPC handler (src/main/ipc/handlers/project-handlers.ts:102) also has no isDirty/save-related logic.

Impact

A user with unsaved edits in the currently open document/chapter who opens a different project (including via the "recent projects" list, a common quick-switch action) loses those edits with zero warning. This is a real, user-facing data-loss bug in a very commonly used action.

Suggested fix

Apply the same guard loadFile() already uses at the chapter level to loadProject(): check useEditorStore.getState().isDirty before proceeding, and await a save (or prompt the user) before opening the new project, refusing to proceed if the save fails — mirroring the existing, working chapter-switch guard.

Evidence trail

  • src/renderer/src/stores/editorStore.tsloadFile(), the existing (correct) chapter-switch guard, for comparison.
  • src/renderer/src/stores/projectStore.ts:90-114loadProject(), no such guard.
  • src/renderer/src/components/Project/ProjectPanel.tsx:94,119,318 — all three call sites.
  • src/main/ipc/handlers/project-handlers.ts:102project:load handler, no save-related logic.
  • Wiki page corrected in the same pass: 1.16-The-Editor.md.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions