react-editor-js: Runtime Error: this._editorJS.destroy is not a function
Environment
- @editorjs/editorjs version: 2.23.2
- react-editor-js version: 2.0.6
Describe
I currently using next.js version 12.1.4.
And the error occurs after the ClientEditorCore instance initial success as you can see below:
Also, there are two editors components mount on the page:
Editor.tsx file:
import React, { useEffect, useRef, useState } from "react";
import { EditorBlockPropsType } from "./index.type";
import { createReactEditorJS } from "react-editor-js";
import { ClientEditorCore } from "@react-editor-js/client/dist/client/src/client-editor-core";
const ReactEditorJS = createReactEditorJS();
const REACT_EDITOR_HOLDER_ID = "ssrHolder";
const EditorBlock = ({ content }: EditorBlockPropsType) => {
let editorInstance;
const [tools, setTools] = useState<any>();
const initialValue = content || {
time: 1635603431943,
blocks: [
{
id: "sheNwCUP5A",
type: "header",
data: {
text: "Editor.js",
level: 2,
},
},
],
};
useEffect(() => {
(async () => {
const importedTools = await import("./editorTools");
setTools(importedTools.EDITOR_JS_TOOLS);
})();
// console.log(EditorJS);
}, []);
if (!tools) {
return <>Loading....</>;
}
return (
<ReactEditorJS
holder={REACT_EDITOR_HOLDER_ID}
instanceRef={(instance: any) => (editorInstance = instance)}
tools={tools}
defaultValue={initialValue}
placeholder="write something here..."
onInitialize={(currentEditor: ClientEditorCore) =>
console.log(currentEditor)
}
/>
);
};
export default EditorBlock;
editorTools.ts file:
import Embed from "@editorjs/embed";
import Table from "@editorjs/table";
import List from "@editorjs/list";
import Warning from "@editorjs/warning";
import Code from "@editorjs/code";
import LinkTool from "@editorjs/link";
import Image from "@editorjs/image";
import Raw from "@editorjs/raw";
import Header from "@editorjs/header";
import Quote from "@editorjs/quote";
import Marker from "@editorjs/marker";
import CheckList from "@editorjs/checklist";
import Delimiter from "@editorjs/delimiter";
import InlineCode from "@editorjs/inline-code";
import SimpleImage from "@editorjs/simple-image";
export const EDITOR_JS_TOOLS = {
embed: Embed,
table: Table,
marker: Marker,
list: List,
warning: Warning,
code: Code,
linkTool: LinkTool,
image: Image,
raw: Raw,
header: Header,
quote: Quote,
checklist: CheckList,
delimiter: Delimiter,
inlineCode: InlineCode,
simpleImage: SimpleImage,
};
My github repo Thank for support me,
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 1
- Comments: 16 (1 by maintainers)
I’m using React 18 and Next 12, and this plugin was duplicating the editor, and throwing destroy is not a function error.
I fixed it by removing this plugin and using the default
editorjs
.If you use Next.js, you can import the component to work with SSR.
I have the same error. Please fix it.
Suspect this is caused when the react component is created and destroyed before Editor JS is fully loaded (Editor JS has a pending promise on
editorJS.isReady
that resolves once fully loaded).This means if you call
_editorJS.destroy()
before the underlying Editor JS is fully loaded, an error is thrown… https://github.com/codex-team/editor.js/issues/919#issuecomment-574332951Temporary fix is don’t create / destroy your react editor js component within ~3 seconds, suspect actual fix for
react-editor-js
isawait _editorJS.isReady
and then_editorJS.destroy()
This issue is coming because with react 18 page is rendered twice. To avoid this, turn off the strict mode in next.config.js
https://nextjs.org/docs/api-reference/next.config.js/react-strict-mode https://reactjs.org/docs/strict-mode.html#ensuring-reusable-state
To be fair, this is not the only extension that explodes when you give it react 18. One of the biggest changes, is the rendering mode. ReactDOM absolutely floods the console telling you that render is deprecated, this breaks a lot of extensions.
Pinning react and reactDOM 17 has worked great for me in the one application I use this extension.
On Sat., May 14, 2022, 3:01 a.m. StitiFatah, @.***> wrote:
We just went through this as well: two components and a destroy error.
In our case, it was only broken in React 18. Downgrading to 17 fixed it for us.
i realised its about strict mode and double invoking when its double invoked (its also means enviroment is in strict mode) its creates double instance and because of that one of them creates this error. Becase one of them is still null !!!
Incredible! This at least lets me try and develop with this.
Temporary Workaround
Result in package.json
I’m sorry for the late response. I’ll fix it.
If you want to contribute this repo, feel free to create pull request.