Fix RichTextInput crash when the editor is recreated#11309
Open
quentin-decre wants to merge 1 commit into
Open
Fix RichTextInput crash when the editor is recreated#11309quentin-decre wants to merge 1 commit into
quentin-decre wants to merge 1 commit into
Conversation
Tiptap v3's Editor.destroy() sets commandManager to null and the commands getter dereferences it. When the editor is recreated (readOnly/disabled/ editorOptions/id change), the content-sync passive effect could run against the just-destroyed instance and throw "Cannot read properties of null (reading 'commands')". Skip destroyed editors in addition to null ones.
Member
|
Thanks for the contribution. If the bug is timing-dependent, would you mind adding a story allowing to reproduce the bug manually? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Under tiptap v3,
<RichTextInput>can crash with:It happens when the editor is recreated — e.g. toggling
readOnly/disabled, or changingeditorOptions/id— while a record/value change is in flight. In our app it reproduces reliably when switching between records/replies (which flipsreadOnlyand changes the content at the same time).Root cause
tiptap v3's
Editor.destroy()setsthis.commandManager = null, and thecommandsgetter returnsthis.commandManager.commands. The content-sync effect guards onlyif (!editor) return, so whenuseEditorrecreates the editor, the old (now destroyed) instance can still be referenced by this passive effect, which then callseditor.commands.setContent(...)on it → dereference of a nullcommandManager.Fix
Also bail out when the editor is destroyed:
editor.isDestroyedreturnstrueoncedestroy()has run (it readseditorView?.isDestroyed ?? true), anddestroy()nullscommandManagerin the same call, so this reliably prevents the dereference. It mirrors the existing!editorguard and is a no-op in the normal path.Notes
ra-input-rich-text@5.15.1with@tiptap/*@3(package declares@tiptap/* ^3.20.4).