fix: save file caption/name on every keystroke instead of on close#2575
fix: save file caption/name on every keystroke instead of on close#2575
Conversation
Previously, caption/name values were stored in local state and only saved to the block on Enter. Clicking outside the popover discarded input, and Enter didn't close the popover. Now handleChange calls editor.updateBlock directly, input reads from block props, and the popover is controlled so Enter closes it. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
📝 WalkthroughWalkthroughRefactored FileCaptionButton and FileRenameButton from local state management with useEffect to controlled popover state, binding input values directly to block properties and adding Enter-key handlers to close the popover without triggering composition. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~13 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
📝 Coding Plan
Comment Tip CodeRabbit can use Trivy to scan for security misconfigurations and secrets in Infrastructure as Code files.Add a .trivyignore file to your project to customize which findings Trivy reports. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
@virgile-dev does this behavior better match your expectations? Would you expect similar for the edit link toolbar? |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@packages/react/src/components/FormattingToolbar/DefaultButtons/FileCaptionButton.tsx`:
- Line 61: popoverOpen state is not reset when the selected file block changes,
causing the popover to persist/reopen incorrectly; add a useEffect that watches
the block identity (e.g., block or block.id) and calls setPopoverOpen(false)
whenever the block changes or becomes undefined to ensure the popover closes on
block switches; update FileCaptionButton to use this effect alongside the
existing popover state and handlers so changes at lines around the block usage
(references to popoverOpen, setPopoverOpen, and block) reliably reset the UI.
In
`@packages/react/src/components/FormattingToolbar/DefaultButtons/FileRenameButton.tsx`:
- Line 61: In FileRenameButton, ensure the popoverOpen state is reset whenever
the selected block identity changes: add a useEffect that watches the selected
block (e.g., selectedBlock or selectedBlockId prop) and calls
setPopoverOpen(false) when that value changes so the rename popover cannot
persist across different block selections; update any paths where render returns
null to rely on this reset.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 1f2d3325-79d5-41c1-8dc0-70f9e54156e6
📒 Files selected for processing (2)
packages/react/src/components/FormattingToolbar/DefaultButtons/FileCaptionButton.tsxpackages/react/src/components/FormattingToolbar/DefaultButtons/FileRenameButton.tsx
| } | ||
| setCurrentEditingCaption(block.props.caption); | ||
| }, [block]); | ||
| const [popoverOpen, setPopoverOpen] = useState(false); |
There was a problem hiding this comment.
Reset popover state when the selected block changes.
popoverOpen (Line 61) survives renders where block is undefined (Line 88), so this popover can reopen unexpectedly when a file block is selected again. Please reset popoverOpen when block identity changes.
Suggested fix
import {
ChangeEvent,
KeyboardEvent,
useCallback,
+ useEffect,
useState,
} from "react";
@@
const [popoverOpen, setPopoverOpen] = useState(false);
+
+ useEffect(() => {
+ setPopoverOpen(false);
+ }, [block?.id]);Also applies to: 88-90, 93-96
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In
`@packages/react/src/components/FormattingToolbar/DefaultButtons/FileCaptionButton.tsx`
at line 61, popoverOpen state is not reset when the selected file block changes,
causing the popover to persist/reopen incorrectly; add a useEffect that watches
the block identity (e.g., block or block.id) and calls setPopoverOpen(false)
whenever the block changes or becomes undefined to ensure the popover closes on
block switches; update FileCaptionButton to use this effect alongside the
existing popover state and handlers so changes at lines around the block usage
(references to popoverOpen, setPopoverOpen, and block) reliably reset the UI.
|
|
||
| setCurrentEditingName(block.props.name); | ||
| }, [block]); | ||
| const [popoverOpen, setPopoverOpen] = useState(false); |
There was a problem hiding this comment.
Reset popover state when the selected block changes.
Same issue here: popoverOpen can persist while render returns null (Line 88), which may auto-open the rename popover when a file block is selected later. Reset state on block identity changes.
Suggested fix
import {
ChangeEvent,
KeyboardEvent,
useCallback,
+ useEffect,
useState,
} from "react";
@@
const [popoverOpen, setPopoverOpen] = useState(false);
+
+ useEffect(() => {
+ setPopoverOpen(false);
+ }, [block?.id]);Also applies to: 88-90, 93-96
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In
`@packages/react/src/components/FormattingToolbar/DefaultButtons/FileRenameButton.tsx`
at line 61, In FileRenameButton, ensure the popoverOpen state is reset whenever
the selected block identity changes: add a useEffect that watches the selected
block (e.g., selectedBlock or selectedBlockId prop) and calls
setPopoverOpen(false) when that value changes so the rename popover cannot
persist across different block selections; update any paths where render returns
null to rely on this reset.
@blocknote/ariakit
@blocknote/code-block
@blocknote/core
@blocknote/mantine
@blocknote/react
@blocknote/server-util
@blocknote/shadcn
@blocknote/xl-ai
@blocknote/xl-docx-exporter
@blocknote/xl-email-exporter
@blocknote/xl-multi-column
@blocknote/xl-odt-exporter
@blocknote/xl-pdf-exporter
commit: |
Summary
File caption and rename inputs now save instantly on every keystroke, so changes are never lost regardless of how the popover closes.
Rationale
Previously, caption/name values were stored in local state and only saved to the block on Enter. This meant clicking outside the popover (which unmounts the formatting toolbar) would discard the input. Enter also didn't close the popover.
Changes
FileCaptionButtonandFileRenameButton: removed local editing state anduseEffectsync;handleChangenow callseditor.updateBlockdirectlyblock.props.caption/block.props.nameinstead of local stateopen/onOpenChange) so Enter can close itImpact
No API changes. All three UI packages (mantine, ariakit, shadcn) work without modification.
Testing
Manual testing: verified Enter closes popover, Escape closes popover, clicking outside preserves content.
Checklist
Additional Notes
Closes #2568
Closes #2567
Summary by CodeRabbit