Error "Cannot read properties of null (reading 'matchesNode')" on hot-reload in @tiptap/react
See original GitHub issueWhat’s the bug you are facing?
I have the case that I want to update the content of the editor when the content
prop changes. It looks somewhat like this:
function Editor({ content }) {
const editor = useEditor({
extensions: [StarterKit],
content
})
useEffect(() => {
editor?.commands.setContent(content)
}, [editor, content])
return <EditorContent editor={editor} />
}
When I use that setup during development, Tiptap throws an error right after hot-reloading, crashing the app:
Uncaught TypeError: Cannot read properties of null (reading 'matchesNode')
at EditorView.updateStateInner (index.es.js:4984:1)
at EditorView.updateState (index.es.js:4955:1)
at Editor.dispatchTransaction (tiptap-core.esm.js:3368:1)
at EditorView.dispatch (index.es.js:5240:30)
at Object.method [as setContent] (tiptap-core.esm.js:1926:1)
at Editor.tsx:8:25
at invokePassiveEffectCreate (react-dom.development.js:23487:1)
at HTMLUnknownElement.callCallback (react-dom.development.js:3945:1)
at Object.invokeGuardedCallbackDev (react-dom.development.js:3994:1)
at invokeGuardedCallback (react-dom.development.js:4056:1)
I’m wondering whether setContent()
must not be used like that or whether this is a bug within Tiptap. 🤔
How can we reproduce the bug on our side?
- Go to https://codesandbox.io/s/tiptap-react-reload-bug-7iqpc?file=/src/App.js
- Wait until app renders
- Change comment on line 11 to trigger a hot-reload
- Error should appear instead of rendered app
Can you provide a CodeSandbox?
https://codesandbox.io/s/tiptap-react-reload-bug-7iqpc?file=/src/App.js
What did you expect to happen?
No error when calling setContent()
Anything to add? (optional)
I could observe that the component gets un- and re-mounted during a hot-reload. The only difference to a normal mount is that the editor is instantiated during the mounting render already. Probably React keeps that around to not lose its state as Tiptap code wasn’t changed. Maybe swapping out the instance after mount causes the issue?
Did you update your dependencies?
- Yes, I’ve updated my dependencies to use the latest version of all packages.
Are you sponsoring us?
- Yes, I’m a sponsor. 💖
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:8 (3 by maintainers)
Any chance this can be patched internally @philippkuehn? I have a feeling others will end up on this thread and the linked issues…
Also, got this error, the solution isn’t working for me. Error seems to occur when i save resave my ‘styled.tsx’ related to this component.