mdx-editor / editor

A rich text editor React component for markdown
https://mdxeditor.dev
MIT License
1.63k stars 131 forks source link

[BUG] Breaking error when the specified code block language is misspelled/doesn't exist #423

Closed enzocomics closed 3 months ago

enzocomics commented 3 months ago

Describe the bug When typing a code block in the editor, if the user misspells the language, or references a language that doesn't exist, an application error occurs, necessitating a complete page refresh:

Application error: a client-side exception has occurred (see the browser console for more information).

Console yields this error: Error: No CodeBlockEditor registered for language=html meta=

Reproduction I discovered it on my dev site, but the issue is reproducible on the demo site https://mdxeditor.dev/editor/demo

To Reproduce Steps to reproduce the behavior:

  1. In the editor, on a new line, type ```html, followed by spacebar

Expected behavior

Desktop (please complete the following information):

Additional context

Thank you for your help!

petyosi commented 3 months ago

You raise a fair point here. I think I can just make it use the default or plain text if the language is unrecognized. What do you think?

ajboni commented 3 months ago

You raise a fair point here. I think I can just make it use the default or plain text if the language is unrecognized. What do you think?

I think that would be the expected behavior. As a reference this is how obsidian deals with these cases:

image

Melvynx commented 3 months ago

Yes, I totally agree. I encountered many issues using this, so I added literally every language 😂 Just the syntax color is perfect.

enzocomics commented 3 months ago

Yes, I agree as well. It should definitely revert to the default language (or plain text, if the language is unspecified). Thanks for looking into it!

petyosi commented 3 months ago

Everyone, just published 3.0.0-alpha.1. It replaces the previously used sandpack wrapper with vanilla a codemirror editor. This is a breaking change, because the codemirror plugin will no longer accept a sandpack theme.

The release does a few other things:

  1. Fixes the issue here, by defaulting to the defaultLanguage, or to none
  2. Automatically loads the necessary language extension (can be disabled)
  3. Lets you pass additional code mirror extensions

Please test this and let me know if you encounter any issues.

github-actions[bot] commented 3 months ago

:tada: This issue has been resolved in version 2.20.7 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

enzocomics commented 3 months ago

Confirming that the update resolved my issue. Thank you so much @petyosi for your awesome work!