fix: fix React Node View render problem in React 18 (#2985)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { Editor } from '@tiptap/core'
|
||||
import React from 'react'
|
||||
import { flushSync } from 'react-dom'
|
||||
|
||||
import { Editor as ExtendedEditor } from './Editor'
|
||||
|
||||
@@ -77,6 +78,7 @@ export class ReactRenderer<R = unknown, P = unknown> {
|
||||
|
||||
this.reactElement = <Component {...props } />
|
||||
|
||||
flushSync(() => {
|
||||
if (this.editor?.contentComponent) {
|
||||
this.editor.contentComponent.setState({
|
||||
renderers: this.editor.contentComponent.state.renderers.set(
|
||||
@@ -85,6 +87,7 @@ export class ReactRenderer<R = unknown, P = unknown> {
|
||||
),
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
updateProps(props: Record<string, any> = {}): void {
|
||||
@@ -97,6 +100,7 @@ export class ReactRenderer<R = unknown, P = unknown> {
|
||||
}
|
||||
|
||||
destroy(): void {
|
||||
flushSync(() => {
|
||||
if (this.editor?.contentComponent) {
|
||||
const { renderers } = this.editor.contentComponent.state
|
||||
|
||||
@@ -106,5 +110,6 @@ export class ReactRenderer<R = unknown, P = unknown> {
|
||||
renderers,
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user