uiwjs / react-md-editor

A simple markdown editor with preview, implemented with React.js and TypeScript.
https://uiwjs.github.io/react-md-editor
MIT License
2.19k stars 160 forks source link

TypeError when running MDEditor in NextJS #465

Open ZacMelendez opened 1 year ago

ZacMelendez commented 1 year ago

I am running v3.20.1 of react-md-editor, in NextJS v13.0.7, trying to use the MDEditor with react-hook-forms under a controlled input. It works well, except for the fact that every other page load or so, I get this error:

Unhandled Runtime Error
TypeError: Cannot read properties of undefined (reading 'source')

Call Stack
source
node_modules/rehype-prism-plus/node_modules/refractor/lang/js-templates.js (12:56)
Prism
node_modules/rehype-prism-plus/node_modules/refractor/lang/js-templates.js (375:5)
syntax
node_modules/rehype-prism-plus/node_modules/refractor/lib/core.js (125:4)
refractor
node_modules/rehype-prism-plus/node_modules/refractor/lib/all.js (454:0)
./node_modules/rehype-prism-plus/node_modules/refractor/lib/all.js
file:///Users/zachm/Desktop/dev/zachoverflow/.next/static/chunks/node_modules_uiw_react-md-editor_esm_index_js.js (5338:1)
options.factory
/_next/static/chunks/webpack.js (713:31)
__webpack_require__
file:///Users/zachm/Desktop/dev/zachoverflow/.next/static/chunks/webpack.js (37:33)
fn
/_next/static/chunks/webpack.js (368:21)
eval
webpack-internal:///./node_modules/rehype-prism-plus/dist/rehype-prism-plus.es.js (12:78)
./node_modules/rehype-prism-plus/dist/rehype-prism-plus.es.js
file:///Users/zachm/Desktop/dev/zachoverflow/.next/static/chunks/node_modules_uiw_react-md-editor_esm_index_js.js (1978:1)
options.factory
/_next/static/chunks/webpack.js (713:31)
__webpack_require__
file:///Users/zachm/Desktop/dev/zachoverflow/.next/static/chunks/webpack.js (37:33)
fn
/_next/static/chunks/webpack.js (368:21)
eval
webpack-internal:///./node_modules/@uiw/react-markdown-preview/esm/index.js (13:75)
./node_modules/@uiw/react-markdown-preview/esm/index.js
file:///Users/zachm/Desktop/dev/zachoverflow/.next/static/chunks/node_modules_uiw_react-md-editor_esm_index_js.js (28:1)
options.factory
/_next/static/chunks/webpack.js (713:31)
__webpack_require__
file:///Users/zachm/Desktop/dev/zachoverflow/.next/static/chunks/webpack.js (37:33)
fn
/_next/static/chunks/webpack.js (368:21)
eval
webpack-internal:///./node_modules/@uiw/react-md-editor/esm/Editor.js (6:85)
./node_modules/@uiw/react-md-editor/esm/Editor.js
file:///Users/zachm/Desktop/dev/zachoverflow/.next/static/chunks/node_modules_uiw_react-md-editor_esm_index_js.js (94:1)
options.factory
/_next/static/chunks/webpack.js (713:31)
__webpack_require__
file:///Users/zachm/Desktop/dev/zachoverflow/.next/static/chunks/webpack.js (37:33)
fn
/_next/static/chunks/webpack.js (368:21)
eval
webpack-internal:///./node_modules/@uiw/react-md-editor/esm/index.js (6:65)
./node_modules/@uiw/react-md-editor/esm/index.js
file:///Users/zachm/Desktop/dev/zachoverflow/.next/static/chunks/node_modules_uiw_react-md-editor_esm_index_js.js (435:1)
options.factory
/_next/static/chunks/webpack.js (713:31)
__webpack_require__
file:///Users/zachm/Desktop/dev/zachoverflow/.next/static/chunks/webpack.js (37:33)
Function.fn
/_next/static/chunks/webpack.js (368:21)

I am fine with ignoring it, as it is not every single time, but I am not sure why the error is happening. Can anyone assist?

jaywcjlove commented 1 year ago

@ZacMelendez https://codesandbox.io/embed/nextjs-example-react-md-editor-uiwjs-react-md-editor-issues-465-jy6r6h?fontsize=14&hidenavigation=1&theme=dark