Skip to content

feat(comments): confirm before discarding an unsaved comment#2861

Open
YousefED wants to merge 2 commits into
mainfrom
comments-discard-pending-confirmation
Open

feat(comments): confirm before discarding an unsaved comment#2861
YousefED wants to merge 2 commits into
mainfrom
comments-discard-pending-confirmation

Conversation

@YousefED

@YousefED YousefED commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

Summary

Show a confirmation prompt before discarding an unsaved comment in the new-comment composer, so users don't lose their text by accidentally clicking away.

Rationale

As raised in discussion #2742: when writing a new comment, clicking outside the composer (or pressing Escape) immediately discards it, silently losing any text the user typed. Full draft support was considered too complex; the agreed approach was to warn the user before discarding when text has been entered.

Changes

  • When the new-comment composer is dismissed (click-outside / Escape) and the editor is not empty, a window.confirm() prompt asks the user before discarding. Cancelling keeps the composer open with the text intact; confirming discards as before. An empty composer closes silently, unchanged.
  • Refactored ownership of the composer editor: it's now created and owned by FloatingComposerController (which owns the open/dismiss lifecycle) and passed down to FloatingComposer. This lets the dismiss handler check isEmpty directly. A fresh editor is created per pending comment, so it always starts empty.
  • Added a translatable comments.discard_pending_comment string to all 24 locales.

Impact

  • Scope is limited to the new-comment composer (the case in Comment lost if the user clicks outside of the modal #2742). Reply and edit-comment composers are unchanged.
  • FloatingComposer is a public export; its props change from {} to a required newCommentEditor. In practice it can only be used via the controller (it depends on it for the editor and positioning), so real-world impact is minimal.

Testing

  • tsc -b passes for @blocknote/core and @blocknote/react.
  • eslint passes on the changed files.
  • Manually: typing a comment then clicking outside / pressing Escape prompts before discarding; an empty composer closes without a prompt.

Checklist

  • Code follows the project's coding standards.
  • Unit tests covering the new feature have been added.
  • All existing tests pass.
  • The documentation has been updated to reflect the new feature

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added a confirmation prompt when users attempt to discard a pending comment, preventing accidental loss of drafts. The confirmation is now available in 23+ languages including English, Spanish, French, German, Chinese, Japanese, Korean, and more.

When the new-comment composer is dismissed (e.g. by clicking outside or
pressing Escape) while it contains unsaved text, show a confirmation
prompt before discarding it. Previously the comment was lost silently.

The composer editor is now created and owned by FloatingComposerController
so the dismiss handler can check whether the user has typed anything, and
a translatable `comments.discard_pending_comment` string is added to all
locales.

Addresses #2742

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@vercel

vercel Bot commented Jun 17, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
blocknote Ready Ready Preview Jun 17, 2026 11:57am
blocknote-website Error Error Jun 17, 2026 11:57am

Request Review

@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

FloatingComposerController now owns the draft comment editor (created via useCreateBlockNote with i18n placeholder and schema selection) and gates dismissal behind a localized confirmation dialog when the editor has content. FloatingComposer is refactored to accept the editor as a required prop. The new discard_pending_comment i18n key is added to 22 locale files.

Changes

Discard Pending Comment Confirmation

Layer / File(s) Summary
discard_pending_comment key added to all locales
packages/core/src/i18n/locales/ar.ts, packages/core/src/i18n/locales/de.ts, packages/core/src/i18n/locales/en.ts, packages/core/src/i18n/locales/es.ts, packages/core/src/i18n/locales/fa.ts, packages/core/src/i18n/locales/fr.ts, packages/core/src/i18n/locales/he.ts, packages/core/src/i18n/locales/hr.ts, packages/core/src/i18n/locales/is.ts, packages/core/src/i18n/locales/it.ts, packages/core/src/i18n/locales/ja.ts, packages/core/src/i18n/locales/ko.ts, packages/core/src/i18n/locales/nl.ts, packages/core/src/i18n/locales/no.ts, packages/core/src/i18n/locales/pl.ts, packages/core/src/i18n/locales/pt.ts, packages/core/src/i18n/locales/ru.ts, packages/core/src/i18n/locales/sk.ts, packages/core/src/i18n/locales/uk.ts, packages/core/src/i18n/locales/uz.ts, packages/core/src/i18n/locales/vi.ts, packages/core/src/i18n/locales/zh-tw.ts, packages/core/src/i18n/locales/zh.ts
Adds comments.discard_pending_comment confirmation string to all 22 supported locale dictionaries.
FloatingComposerController: editor ownership and discard confirmation
packages/react/src/components/Comments/FloatingComposerController.tsx
Controller creates the draft editor via useCreateBlockNote with i18n placeholder and schema; dismiss handler checks editor content and calls window.confirm with the new dictionary string before discarding; useMemo deps and composer render are updated.
FloatingComposer: prop-driven editor
packages/react/src/components/Comments/FloatingComposer.tsx
Removes internal editor construction; accepts newCommentEditor: BlockNoteEditor as a required prop and reads it directly, with imports adjusted.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • nperez0111

Poem

🐇 A comment was typed, then almost erased,
But now a prompt asks: "Are you sure? Don't haste!"
In twenty-two tongues the bunny did write,
Each locale confirmed: "Discard? Is that right?"
The controller now owns the fresh editing space,
Props flow downstream at a neat, tidy pace. 🌿

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding a confirmation prompt before discarding unsaved comments.
Description check ✅ Passed The description includes all major required sections: Summary, Rationale, Changes, Impact, Testing, and Checklist, with comprehensive details for each.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch comments-discard-pending-confirmation
⚔️ Resolve merge conflicts
  • Resolve merge conflict in branch comments-discard-pending-confirmation

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/react/src/components/Comments/FloatingComposerController.tsx (1)

83-97: ⚡ Quick win

Add regression tests for the new dismiss-confirm flow.

Please add coverage for: (1) empty draft dismisses without prompt, (2) non-empty draft + confirm accepts discard, (3) non-empty draft + confirm cancel keeps composer open with text intact.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/react/src/components/Comments/FloatingComposerController.tsx` around
lines 83 - 97, Add three regression tests for the onOpenChange handler in
FloatingComposerController to cover the dismiss-confirm flow: first test that an
empty draft (when newCommentEditor.isEmpty is true) dismisses the composer
without prompting the user, second test that when a non-empty draft exists and
the user confirms the discard prompt (window.confirm returns true), the composer
closes and stopPendingComment is called, and third test that when a non-empty
draft exists and the user cancels the discard prompt (window.confirm returns
false), the composer remains open and editor.focus is called while the draft
text is preserved.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/react/src/components/Comments/FloatingComposer.tsx`:
- Around line 29-36: The `newCommentEditor` prop on the `FloatingComposer`
component has been made required, which is a breaking change for external
consumers. Either make the prop optional by adding a `?` to the type definition
and provide fallback behavior when it is not provided, or ensure this change is
documented as a semver-major release with clear migration guidance for users
currently rendering `FloatingComposer` directly.

---

Nitpick comments:
In `@packages/react/src/components/Comments/FloatingComposerController.tsx`:
- Around line 83-97: Add three regression tests for the onOpenChange handler in
FloatingComposerController to cover the dismiss-confirm flow: first test that an
empty draft (when newCommentEditor.isEmpty is true) dismisses the composer
without prompting the user, second test that when a non-empty draft exists and
the user confirms the discard prompt (window.confirm returns true), the composer
closes and stopPendingComment is called, and third test that when a non-empty
draft exists and the user cancels the discard prompt (window.confirm returns
false), the composer remains open and editor.focus is called while the draft
text is preserved.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 154a44d5-61f2-4cd3-affc-5f97fed84022

📥 Commits

Reviewing files that changed from the base of the PR and between c9e55cd and 6b57df8.

📒 Files selected for processing (25)
  • packages/core/src/i18n/locales/ar.ts
  • packages/core/src/i18n/locales/de.ts
  • packages/core/src/i18n/locales/en.ts
  • packages/core/src/i18n/locales/es.ts
  • packages/core/src/i18n/locales/fa.ts
  • packages/core/src/i18n/locales/fr.ts
  • packages/core/src/i18n/locales/he.ts
  • packages/core/src/i18n/locales/hr.ts
  • packages/core/src/i18n/locales/is.ts
  • packages/core/src/i18n/locales/it.ts
  • packages/core/src/i18n/locales/ja.ts
  • packages/core/src/i18n/locales/ko.ts
  • packages/core/src/i18n/locales/nl.ts
  • packages/core/src/i18n/locales/no.ts
  • packages/core/src/i18n/locales/pl.ts
  • packages/core/src/i18n/locales/pt.ts
  • packages/core/src/i18n/locales/ru.ts
  • packages/core/src/i18n/locales/sk.ts
  • packages/core/src/i18n/locales/uk.ts
  • packages/core/src/i18n/locales/uz.ts
  • packages/core/src/i18n/locales/vi.ts
  • packages/core/src/i18n/locales/zh-tw.ts
  • packages/core/src/i18n/locales/zh.ts
  • packages/react/src/components/Comments/FloatingComposer.tsx
  • packages/react/src/components/Comments/FloatingComposerController.tsx

Comment on lines +29 to +36
>(props: {
/**
* The (empty) editor used to compose the new comment. Created and owned by
* the `FloatingComposerController`, so it can check for unsaved text before
* the composer is dismissed.
*/
newCommentEditor: BlockNoteEditor<any, any, any>;
}) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Public API break: newCommentEditor is now required on an exported component.

Making this prop mandatory can break existing external consumers that render FloatingComposer directly. Please either preserve backward compatibility (optional prop with fallback behavior) or explicitly ship this as a semver-major change with migration guidance.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/react/src/components/Comments/FloatingComposer.tsx` around lines 29
- 36, The `newCommentEditor` prop on the `FloatingComposer` component has been
made required, which is a breaking change for external consumers. Either make
the prop optional by adding a `?` to the type definition and provide fallback
behavior when it is not provided, or ensure this change is documented as a
semver-major release with clear migration guidance for users currently rendering
`FloatingComposer` directly.

@pkg-pr-new

pkg-pr-new Bot commented Jun 17, 2026

Copy link
Copy Markdown

Open in StackBlitz

@blocknote/ariakit

npm i https://pkg.pr.new/@blocknote/ariakit@2861

@blocknote/code-block

npm i https://pkg.pr.new/@blocknote/code-block@2861

@blocknote/core

npm i https://pkg.pr.new/@blocknote/core@2861

@blocknote/mantine

npm i https://pkg.pr.new/@blocknote/mantine@2861

@blocknote/react

npm i https://pkg.pr.new/@blocknote/react@2861

@blocknote/server-util

npm i https://pkg.pr.new/@blocknote/server-util@2861

@blocknote/shadcn

npm i https://pkg.pr.new/@blocknote/shadcn@2861

@blocknote/xl-ai

npm i https://pkg.pr.new/@blocknote/xl-ai@2861

@blocknote/xl-docx-exporter

npm i https://pkg.pr.new/@blocknote/xl-docx-exporter@2861

@blocknote/xl-email-exporter

npm i https://pkg.pr.new/@blocknote/xl-email-exporter@2861

@blocknote/xl-multi-column

npm i https://pkg.pr.new/@blocknote/xl-multi-column@2861

@blocknote/xl-odt-exporter

npm i https://pkg.pr.new/@blocknote/xl-odt-exporter@2861

@blocknote/xl-pdf-exporter

npm i https://pkg.pr.new/@blocknote/xl-pdf-exporter@2861

commit: 8e15d3d

@YousefED

Copy link
Copy Markdown
Collaborator Author

@virgile-dev See a demo here: https://blocknote-lxlgmdups-typecell.vercel.app/collaboration/comments-with-sidebar

Two UX questions:

  • We currently use the browser-native "confirm dialog". Would this suffice, or prefer a dedicated confirmation dialog?
  • Do you think the confirmation dialog should be only enabled when composing a new comment, or also when replying / editing? (I think the former)

Internal (BlockNote): decide if we want to make this behavior configurable

@github-actions

Copy link
Copy Markdown
PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://TypeCellOS.github.io/BlockNote/pr-preview/pr-2861/

Built to branch gh-pages at 2026-06-17 12:01 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

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