tiptap: TypeError: Cannot read property 'matchesNode' of null (TipTap for React)
Description
Same issue as in https://github.com/ueberdosis/tiptap/issues/438. TypeError that crashes my app.
Steps to reproduce the bug
Happens on occasion when navigating to a page with a TipTap editor on it.
CodeSandbox
In the CSB below, run the tests, and observe the console spits out a bunch of these type errors for the browser. I don’t know why it does this…
https://codesandbox.io/s/tiptap-prose-matchesnode-error-yhvdc

Expected behavior
No error.
Environment?
- operating system: OSX
- browser: N/A
- mobile/desktop: N/A
- tiptap version:
@tiptap/core@^2.0.0-beta.65
Additional context
I tried to keep the CSB example above as close to my current code as possible, minus other third-party libraries that would unnecessarily bloat the example.
I am able to replicate the error consistently in my tests:
Error: Uncaught [TypeError: Cannot read property 'matchesNode' of null]
at reportException (/Users/jasonhughes/sites/innovator-portal/innovator/client/node_modules/jsdom/lib/jsdom/living/helpers/runtime-script-errors.js:62:24)
at Timeout.task [as _onTimeout] (/Users/jasonhughes/sites/innovator-portal/innovator/client/node_modules/jsdom/lib/jsdom/browser/Window.js:521:9)
at listOnTimeout (internal/timers.js:549:17)
at processTimers (internal/timers.js:492:7) TypeError: Cannot read property 'matchesNode' of null
at EditorView.updateStateInner (/Users/jasonhughes/sites/innovator-portal/innovator/client/node_modules/prosemirror-view/src/index.js:141:45)
at EditorView.updateState (/Users/jasonhughes/sites/innovator-portal/innovator/client/node_modules/prosemirror-view/src/index.js:114:10)
at Editor.dispatchTransaction (/Users/jasonhughes/sites/innovator-portal/innovator/client/node_modules/@tiptap/core/src/Editor.ts:299:15)
at EditorView.dispatch (/Users/jasonhughes/sites/innovator-portal/innovator/client/node_modules/prosemirror-view/src/index.js:374:50)
at Object.method [as focus] (/Users/jasonhughes/sites/innovator-portal/innovator/client/node_modules/@tiptap/core/src/CommandManager.ts:35:18)
at /Users/jasonhughes/sites/innovator-portal/innovator/client/node_modules/@tiptap/core/src/Editor.ts:90:21
at Timeout.task [as _onTimeout] (/Users/jasonhughes/sites/innovator-portal/innovator/client/node_modules/jsdom/lib/jsdom/browser/Window.js:516:19)
at listOnTimeout (internal/timers.js:549:17)
at processTimers (internal/timers.js:492:7)
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 3
- Comments: 36 (7 by maintainers)
Commits related to this issue
- tiptap: fix https://github.com/ueberdosis/tiptap/issues/1451 — committed to fantasticit/think by fantasticit 2 years ago
- Update dependencies, seem to run into ueberdosis/tiptap#1451 still — committed to alineacms/alinea by benmerckx 2 years ago
- 에디터 모드 전환 버튼 버그 수정 1. localStorage에 postKind가 지정되어있지 않을 경우 postKind를 글 모드로 지정, 이 때 대소문자 오타가 있어 수정함 (article -> ARTICLE) 2. 글, 그림모드 전환 시 오류 발생 <img width="588" alt="image" src="https://github.com... — committed to withglyph/glyph by Seohyun-Roh 8 months ago
Hey @philippkuehn, I think I’ve found a more general solution to this that prevents the error. A little hacky but let me know what you think
We were able to hack around this by adding checks for
editor.isDestroyedin our useEffect hooks like so:Could we update editor.commands to do this check automatically, and never try to run a command when the editor itself is destroyed? That might catch a lot of issues.
However, even after adding this, hot reload still triggered an error in the Yjs sync plugin, see screenshot below. It looks like that can also be suppressed by adding
// @refresh resetat the top of the file where we load the Collaboration plugin. This is a NextJS directive, not sure if there are equivalents elsewhere.can solve this problem.
This patch should fix that error.
I am using Remix v2 and have the same problem on every hot reload. I use useEditor(). I did not see a solution/workaround for people using that hook, maybe someone solved this though?
Yeah I’m still noticing this as obezzad mentioned, even after upgrading to the patch with the fix.
I’ve just followed the official documentation for installing TipTap into NextJS and got this bug. Latest TipTip and NextJS. I just copy pasted the example code without adding anything.
I tried all fixes and nothing seems to work. (I’m not sure if I was doing correctly.) Whenever I change something in the component I see this error in the browser.
Is there any other was I could make this work?
@philippkuehn Thank you for the patch! I noticed that the same error also occurs on setContent after React’s Fast Refresh.
where do you put this line? I am getting following error .
Property 'docView' does not exist on type 'EditorView'&Property 'updateStateInner' is private and only accessible within class 'EditorView'@vaetas Assuming your issue is caused by the same root cause as the issue I submitted, it was fixed in v2.0.0-beta.220!
This error also seems to be triggered by StrictMode, because the component is immediatly unmounted and remounted.
@chasinhues I hope the following would help spotting the root cause.
This issue happens to me in editor.setContent() after hot-reload and when creating an editor dynamically, it also happens when dynamically adding multiple editors without delay. If I wait for a second after creating an editor before re-creating another one, it doesn’t occur.
It seems that successive dynamic creation error is due to setTimeout(() => editor.createNodeViews(), 0) in EditorContent. I also suspect that this error causes the setContent() one too.
I added try-catch around setContent() with 3 retries separated by a delay of 100ms. However, the createNodeViews() does not seem to be catchable from the component.
Is there any chance of a hotfix to prevent this uncaught error from propagating since the software will be shipped soon 😦 ?
Same issue on my end
Updated all my dependencies to the latests to try out, the issue still shows up.
For me it starts at
"@tiptap/react": "^2.0.0-beta.43",which introduces the dependency array for the editor.The remix app was also giving an error on every hot reload due to StrictMode, removing StrictMode worked fine. But I guess that doesn’t make sense for StrictMode, lol.
It has been almost two years and there is no solution in sight.
For me the error also came with a modal function where the editor was not visible.
I solved the problem by checking if the plugins are loaded.
I modified the code by @thatsjonsense to reuse the old updateState:
This bug was apparently fixed in y-prosemirror@1.1.0, but this same version introduced another issue: https://github.com/yjs/y-prosemirror/issues/117
So I had to downgrade to y-prosemirror@1.0.20 and this problem still exists there.