mdx-editor / mdx-editor/editor
[BUG] Resilience on undefined markdown
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 3.7k
- Forks
- 307
- Avg merge
- 14h 22m
- Merged PRs (30d)
- 5
Description
- I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
- I have read the documentation and cannot find an answer.
Describe the bug
If the markdown parameter on the MDXEditor tag managed to be type undefined, MDX fails un-gracefully.
Typical Stack on failure
Uncaught TypeError: Cannot read properties of undefined (reading 'trim')
at eval (/node_modules/@mdxeditor/editor/dist/plugins/core/index.js:630:81)
at $beginUpdate (/node_modules/lexical/Lexical.dev.mjs:7386:5)
at updateEditor (/node_modules/lexical/Lexical.dev.mjs:7465:5)
at LexicalEditor.update (/node_modules/lexical/Lexical.dev.mjs:8830:5)
at Object.postInit (/node_modules/@mdxeditor/editor/dist/plugins/core/index.js:628:15)
at Object.postInit (/node_modules/@mdxeditor/editor/dist/RealmWithPlugins.js:33:62)
at eval (/node_modules/@mdxeditor/editor/dist/RealmWithPlugins.js:50:55)
at tap (/node_modules/@mdxeditor/editor/dist/utils/fp.js:92:3)
at eval (/node_modules/@mdxeditor/editor/dist/RealmWithPlugins.js:44:39)
at mountMemo (/node_modules/react-dom/cjs/react-dom.development.js:17225:19)
at Object.useMemo (/node_modules/react-dom/cjs/react-dom.development.js:17670:16)
Suggest this is a low priority error, as your typing on inputs is clear. Work around is really on the caller to avoid the undefined state. It was just a curious runtime situation in my app, a content loading delay where I had the document meta data but had not yet retrieved the markdown, that brought this to my attention.
Reproduction
- Start from https://codesandbox.io/p/devbox/mdx-editor-base-forked-8qg66p
- Uncomment the
body = undefined;on row 16 - Reload the page
- See Error in Javascript console.
Expected behavior
Editor renders empty, equivalent of a markdown parameter of and empty string ''.
No error thrown, I guess there could be a warning that the developer, has done something stupid... like I did.
Screenshots
Desktop (please complete the following information):
- MDXEditor - 3.35.1
- OS: MacOS - Sequoia 15.5 (24F74)
- Browser - Chrome Version 137.0.7151.121 (Official Build) (arm64)
Additional context
Add any other context about the problem here.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the CodeSandbox reproduction and the stack-trace location in node_modules/@mdxeditor/editor/dist/plugins/core/index.js. Confirm that an undefined markdown prop no longer throws and renders an empty editor, equivalent to an empty string; the issue does not name a repository test to run.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100