fix(react): the editor passed into EditorContent can be null

This commit is contained in:
Nick the Sick 2024-08-13 18:17:45 +02:00
parent 6d1621c513
commit d4d99e8ad3
No known key found for this signature in database
GPG Key ID: F575992F156E5BCC
3 changed files with 9 additions and 4 deletions

View File

@ -0,0 +1,5 @@
---
"@tiptap/react": patch
---
When changing the types, a bug was introduced where null could no longer be a valid value

View File

@ -3,7 +3,7 @@ import { ReactPortal } from 'react'
import { ReactRenderer } from './ReactRenderer.js'
export type EditorWithContentComponent = Editor & { contentComponent: ContentComponent | null }
export type EditorWithContentComponent = Editor & { contentComponent?: ContentComponent | null }
export type ContentComponent = {
setRenderer(id: string, renderer: ReactRenderer): void;
removeRenderer(id: string): void;

View File

@ -108,7 +108,7 @@ export class PureEditorContent extends React.Component<
this.initialized = false
this.state = {
hasContentComponentInitialized: Boolean((props.editor as EditorWithContentComponent).contentComponent),
hasContentComponentInitialized: Boolean((props.editor as EditorWithContentComponent | null)?.contentComponent),
}
}
@ -121,7 +121,7 @@ export class PureEditorContent extends React.Component<
}
init() {
const editor = this.props.editor as EditorWithContentComponent
const editor = this.props.editor as EditorWithContentComponent | null
if (editor && !editor.isDestroyed && editor.options.element) {
if (editor.contentComponent) {
@ -165,7 +165,7 @@ export class PureEditorContent extends React.Component<
}
componentWillUnmount() {
const editor = this.props.editor as EditorWithContentComponent
const editor = this.props.editor as EditorWithContentComponent | null
if (!editor) {
return