Skip to content

Commit

Permalink
Destroy editor in safe (#4000)
Browse files Browse the repository at this point in the history
* Destroy editor in safe

* Use class component

* Use createElement
  • Loading branch information
KentoMoriwaki authored Jul 7, 2023
1 parent babf84b commit 6984ea1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
12 changes: 11 additions & 1 deletion packages/react/src/EditorContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,14 @@ export class PureEditorContent extends React.Component<EditorContentProps, Edito
}
}

export const EditorContent = React.memo(PureEditorContent)
// EditorContent should be re-created whenever the Editor instance changes
const EditorContentWithKey = (props: EditorContentProps) => {
const key = React.useMemo(() => {
return Math.floor(Math.random() * 0xFFFFFFFF).toString()
}, [props.editor])

// Can't use JSX here because it conflicts with the type definition of Vue's JSX, so use createElement
return React.createElement(PureEditorContent, { key, ...props })
}

export const EditorContent = React.memo(EditorContentWithKey)
7 changes: 6 additions & 1 deletion packages/react/src/useEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,15 @@ export const useEditor = (options: Partial<EditorOptions> = {}, deps: Dependency
})

return () => {
instance.destroy()
isMounted = false
}
}, deps)

useEffect(() => {
return () => {
editor?.destroy()
}
}, [editor])

return editor
}

0 comments on commit 6984ea1

Please sign in to comment.