Skip to content

Commit 40241b3

Browse files
authored
tiptap: fix focus issue when editor not mounted (tldraw#7043)
tiptap: fix focus issue when editor not mounted ### Change type - [x] `bugfix` - [ ] `improvement` - [ ] `feature` - [ ] `api` - [ ] `other` ### Release notes - tiptap: fix minor focus issue if editor isn't mounted yet <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Guard Tiptap toolbar actions and active-state checks when the editor view isn't mounted to prevent focus errors. > > - **Rich Text Toolbar (`DefaultRichTextToolbarContent.tsx`)**: > - Add guard to avoid invoking Tiptap operations when `textEditor.view` is undefined. > - Compute `isActive` defensively using `textEditor.view ? ... : false` to prevent access before mount. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 299507f. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent e6ed9ae commit 40241b3

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

packages/tldraw/src/lib/ui/components/Toolbar/DefaultRichTextToolbarContent.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ export function DefaultRichTextToolbarContent({
5454
// todo: we could make this a prop
5555
const actions = useMemo(() => {
5656
function handleOp(name: string, op: string) {
57+
// Check if the editor view is available before calling operations
58+
if (!textEditor.view) return
59+
5760
trackEvent('rich-text', { operation: name as any, source })
5861
// @ts-expect-error typing this is annoying at the moment.
5962
textEditor.chain().focus()[op]().run()
@@ -109,7 +112,7 @@ export function DefaultRichTextToolbarContent({
109112
}, [textEditor, trackEvent, onEditLinkStart])
110113

111114
return actions.map(({ name, attrs, onSelect }) => {
112-
const isActive = textEditor.isActive(name, attrs)
115+
const isActive = textEditor.view ? textEditor.isActive(name, attrs) : false
113116
return (
114117
<TldrawUiToolbarButton
115118
key={name}

0 commit comments

Comments
 (0)