Skip to content

Commit

Permalink
fix(react): the editor passed into EditorContent can be null
Browse files Browse the repository at this point in the history
  • Loading branch information
nperez0111 committed Aug 13, 2024
1 parent 6d1621c commit d4d99e8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/gentle-ads-poke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tiptap/react": patch
---

When changing the types, a bug was introduced where null could no longer be a valid value
2 changes: 1 addition & 1 deletion packages/react/src/Editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions packages/react/src/EditorContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}

Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d4d99e8

Please sign in to comment.