tiptap: Error: flushSync was called from inside a lifecycle method in
What’s the bug you are facing?
The component import { EditorContent } from "@tiptap/react" is crashing for some reason.
I’m getting the following error in console:
Uncaught Error: flushSync was called from inside a lifecycle method. It cannot be called when React is already rendering.
at flushSync (react-dom.development.js:21917:1)
at PureEditorContent.maybeFlushSync (EditorContent.tsx:82:1)
at PureEditorContent.removeRenderer (EditorContent.tsx:100:1)
at ReactRenderer.destroy (ReactRenderer.tsx:93:1)
at ReactNodeView.destroy (ReactNodeViewRenderer.tsx:173:1)
...
More specifically here:
The above error occurred in the <PureEditorContent> component:
in PureEditorContent
in PureEditorContent (at TipTap.js:154)
in div (at TipTap.js:145)
...
Reduced code:
const TipTap = ({ editor, ...props }) => {
return (
<div className="tip-tap-editor-container text-editor">
<EditorContent className="tip-tap-editor-content mt-5" editor={editor} />
</div>
)
}
If I remove the <EditorContent> the app doesn’t crash.
Not sure if this bug is only related to our implementation. Anyway, any help, clue or information is welcome in order to fix this issue which is urgent.
Which browser was this experienced in? Are any special extensions installed?
Google Chrome Version 108.0.5359.124 (Official Build) (arm64)
macOs ventura 13.1
How can we reproduce the bug on our side?
Not sure.
Can you provide a CodeSandbox?
No response
What did you expect to happen?
Not crashing.
Anything to add? (optional)
Tip-tap package versions:
{
"@tiptap/extension-color": "^2.0.0-beta.209",
"@tiptap/extension-highlight": "^2.0.0-beta.209",
"@tiptap/extension-image": "^2.0.0-beta.209",
"@tiptap/extension-link": "^2.0.0-beta.209",
"@tiptap/extension-placeholder": "^2.0.0-beta.209",
"@tiptap/extension-text-style": "^2.0.0-beta.209",
"@tiptap/extension-underline": "^2.0.0-beta.209",
"@tiptap/react": "^2.0.0-beta.209",
"@tiptap/starter-kit": "^2.0.0-beta.209",
}
React version: 16.13.1
Node version: v14.19.1
You can find the entire log here: tiptap.log
Note: my app depends of this node version only
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. 💖
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 37 (15 by maintainers)
We are running into this as well for the same reason as @philipaarseth (imperatively updating content in a
useEffect).Since we depend on updating content within an effect like this, I found that wrapping the offending
setContentinside aqueueMicrotaskalso makes the error go away… but watching this issue for a proper fix 😄Still experiencing the error with
2.1.13or2.1.16Same here. Still not fixed in 2.30 and my console is just getting flooded in the flushSync errors.
still getting this in 2.3.0
Experienced this after updating from 2.0.0-beta.220 to 2.1.7. Seems to have been caused by using setContent inside a useEffect. Moving the initialize editor content to
useEditor({ content: contentseem to have fixed it for me.offending code inside useEffect:
In my situation, I was experiencing poor performance and lag as the number of lines in a
Paragraphnode with a NodeView increased. This significantly impacted the user experience during text input. However, when I changed themaybeFlushSync(fn: () => void)method from:to:
The lag and performance issues were resolved. I am just not sure what potential risks this change might introduce.
Ah I didn’t realize the issue was specific to
ReactNodeViewRendererrather thanuseEditor/EditorContent. We don’t useReactNodeViewRenderer, so I guess that explains never seeing it.Relink to the relevant code sandbox for convenience: https://codesandbox.io/s/github/rbruels/tiptap-3580-sandbox
That’s a lot of renders… I would consider wrapping the component that renders the editor to be memoized to be shielded from all of these renders.
useEditor wherever possible will try to re-use the editor instance, but it can be garbage collected if the editors are far enough apart. If collected, this would destroy the instance & force a remount after recreating. All that to say, I would totally expect this to happen with how many times it is rendered. React does not really give us much room here for a solution. We need it to be synchronous & it isn’t, we don’t have a way to know whether React is already rendering something else. So our hands are tied here, but again, not an actual issue.
So I think it is safe to say, if you don’t recreate the editor a bunch of times really quickly this already is solved. Tons of people already have this in prod from my understanding
This should now be resolved with 2.6.0
PureEditorContent is to do with React nodeviews: https://github.com/ueberdosis/tiptap/blob/32ed87b409207897753c65b2e7c44c1a64d3173d/packages/react/src/EditorContent.tsx#L88-L99
So not yet resolved, but will be with https://github.com/ueberdosis/tiptap/pull/5273
I can confirm it’s still present on 2.5.9 as well.
@nperez0111 still facing the same issue with 2.5.9
Should be resolved with tiptap 2.5 since we no longer have to flushSync anymore
I’m having this problem as well with 2.4.0.
I tried implementing a basic example from the TipTap docs and got the crash as well, the counter here: https://tiptap.dev/docs/editor/guide/node-views/react
Adding the queueMicrotask fix here back in as a patch fixes the issue for me: https://github.com/ueberdosis/tiptap/commit/aa4389883aead90fa16e804c672dc269b9a1292a
@Slapbox Feel free to check my code sandbox — see if you can reproduce too. Maybe you’ll have an idea why it’s happening
There is a PR addressing this issue: https://github.com/ueberdosis/tiptap/pull/3533
I’m also experiencing the same errors after an update from
2.0.0-beta.202to2.0.0-beta.209.From a real quick search, it looks like #3331 may be the only changes related to this error between the 2 versions.