Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
2 tasks done
enzocomics opened this issue Apr 18, 2024 · 7 comments
Closed
2 tasks done
Labels
bug Something isn't working released

Comments

@enzocomics
Copy link

enzocomics commented Apr 18, 2024

  • 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
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

  • Specifying a code block language that isn't defined in codeBlockLanguages shouldn't throw an app-breaking error
  • Maybe it shouldn't even attempt to create a code block if the language is not specified

Desktop (please complete the following information):

  • OS: Windows 11
  • Browser: Firefox 125.0.1, Chrome 124.0.6367.61

Additional context

Thank you for your help!

@enzocomics enzocomics added the bug Something isn't working label Apr 18, 2024
@petyosi
Copy link
Contributor

petyosi commented Apr 18, 2024

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
Copy link

ajboni commented Apr 18, 2024

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
Copy link

Melvynx commented Apr 18, 2024

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

@enzocomics
Copy link
Author

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
Copy link
Contributor

petyosi commented Apr 19, 2024

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.

Copy link

🎉 This issue has been resolved in version 2.20.7 🎉

The release is available on:

Your semantic-release bot 📦🚀

@enzocomics
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released
Projects
None yet
Development

No branches or pull requests

4 participants