fix: prevent duplicate sidebar trash confirmations by Jocs · Pull Request #5806 · marktext/marktext · GitHub
Skip to content

fix: prevent duplicate sidebar trash confirmations - #5806

Merged
Jocs merged 3 commits into
developfrom
fix/sidebar-duplicate-trash-confirmation
Oct 20, 2026
Merged

Jocs merged 3 commits into
developfrom
fix/sidebar-duplicate-trash-confirmation

Conversation

@Jocs

@Jocs Jocs commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

Related: #3148 (sidebar Delete shortcut).

Summary

After the editor page remounts, one Delete / macOS Fn+Backspace can open two trash confirmation dialogs. app.vue registered sidebar bus handlers on every mount, but never removed them. The project store and bus survive the page, so a single SIDEBAR::remove event invokes both handlers and sends two identical IPC requests.

Make sidebar listener registration idempotent, return a cleanup function, and unsubscribe when the editor page unmounts or the project store is disposed. Ignore repeated shortcut keydowns. The main-process confirmation flow remains unchanged; no concurrent-request deduplication is needed.

Type of change

  • Bug fix (non-breaking, fixes an issue)
  • New feature (non-breaking, adds functionality)
  • Breaking change (causes existing functionality to change)
  • Documentation update

Test plan

  • Reproduced on macOS in Electron E2E: remount the editor page, select a sidebar file, press Delete once. With the original unguarded main-process implementation, the regression test received 2 dialogs instead of 1. The unit regression independently received 2 IPC calls for one bus event.
  • Verified the lifecycle fix with main-process deduplication temporarily removed: the same E2E receives 1 dialog. Removed the earlier concurrent-request protection.
  • 17 unit tests passed covering registration, unmount cleanup, store disposal, shortcut eligibility, confirmation, cancel, and retry.
  • All 3 sidebar-delete Electron E2E tests passed; the remount test checks a single Delete keydown and a single dialog.
  • pnpm run lint (0 errors; existing warnings), pnpm run typecheck, and pnpm run build:unpack.
  • Screenshots/recording attached (not provided; dialogs/trash are stubbed in E2E to avoid deleting user files).

By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.

@github-actions

Copy link
Copy Markdown
Contributor

@Jocs
Jocs merged commit c11e247 into develop Oct 20, 2026
13 checks passed
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.

1 participant