-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
[CodeHighlight] Prevent hightlight.js from throwing error when language is unknown #5099
Comments
How can we know that the language is unknown? |
We could call the |
Why do you think it is a better idea to implement it on library side rather than on your application side? |
If developers like me encountering this problem, they might be rendering CodeHighlight with content from UGC (i.e. without control). The path to the solution will probably like: looking at the source code and figuring out the error coming from the underlying
Though they are doable, neither seems ideal to me if this comes from a out-of-box UI library. Also it takes developer extra time and work to figure out and solve. But I'm acceptable if the documentation gives a solution in this case? Like clarifying that the default built-in languages are listed here, and what to do if beyond the list. |
Fallback to plaintext was added in 7.2.1. |
What package has an issue
@mantine/code-highlight
Describe the bug
We get the result from highlight.js in this line without any error handling:
https://github.com/mantinedev/mantine/blob/a8e0dae3aeac876e0f016ca0b53922423661d6d3/src/mantine-code-highlight/src/use-highlight.ts#L11C46
which may resulting in the "Unknown language" error thrown by highlight.js in this line:
https://github.com/highlightjs/highlight.js/blob/17494c81dbade12834feedddf6fb208bcc9cbcce/src/highlight.js#L556
What version of @mantine/* packages do you have in package.json? (Note that all @mantine/* packages must have the same version in order to work correctly)
v7
If possible, please include a link to a codesandbox with the reproduced problem
No response
Do you know how to fix the issue
Yes
Are you willing to participate in fixing this issue and create a pull request with the fix
Yes
Possible fix
User can sovle this by wrapping a ErrorBoundary anyway but that brings some extra work.
So I'm thinking of these solutions:
language: plaintext
if the language is unknown;languageFallback
prop if the language is unknown;renderError
prop if any error happens in the highlight and renders an alternative UI instead.What do you think?
The text was updated successfully, but these errors were encountered: