mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-01-18 22:36:14 +08:00
fix: fix React Node View render problem in React 18 (#2985)
This commit is contained in:
parent
de1253a8b0
commit
f32293b0d5
@ -1,5 +1,6 @@
|
|||||||
import { Editor } from '@tiptap/core'
|
import { Editor } from '@tiptap/core'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
import { flushSync } from 'react-dom'
|
||||||
|
|
||||||
import { Editor as ExtendedEditor } from './Editor'
|
import { Editor as ExtendedEditor } from './Editor'
|
||||||
|
|
||||||
@ -77,14 +78,16 @@ export class ReactRenderer<R = unknown, P = unknown> {
|
|||||||
|
|
||||||
this.reactElement = <Component {...props } />
|
this.reactElement = <Component {...props } />
|
||||||
|
|
||||||
if (this.editor?.contentComponent) {
|
flushSync(() => {
|
||||||
this.editor.contentComponent.setState({
|
if (this.editor?.contentComponent) {
|
||||||
renderers: this.editor.contentComponent.state.renderers.set(
|
this.editor.contentComponent.setState({
|
||||||
this.id,
|
renderers: this.editor.contentComponent.state.renderers.set(
|
||||||
this,
|
this.id,
|
||||||
),
|
this,
|
||||||
})
|
),
|
||||||
}
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
updateProps(props: Record<string, any> = {}): void {
|
updateProps(props: Record<string, any> = {}): void {
|
||||||
@ -97,14 +100,16 @@ export class ReactRenderer<R = unknown, P = unknown> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
destroy(): void {
|
destroy(): void {
|
||||||
if (this.editor?.contentComponent) {
|
flushSync(() => {
|
||||||
const { renderers } = this.editor.contentComponent.state
|
if (this.editor?.contentComponent) {
|
||||||
|
const { renderers } = this.editor.contentComponent.state
|
||||||
|
|
||||||
renderers.delete(this.id)
|
renderers.delete(this.id)
|
||||||
|
|
||||||
this.editor.contentComponent.setState({
|
this.editor.contentComponent.setState({
|
||||||
renderers,
|
renderers,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user