Cannot gracefully handle parser error with onError option or try-catch
See original GitHub issueFirst off; thank you for the great library! It’s been a pleasure to work with so far.
This issue pertains to the React component using the React presets. I am experiencing a runtime error when specific (not all) improper BBCode is passed to the parser, and am unable to gracefully handle the error using onError or try-catch block. I’ve created a sandbox to illustrate the issue.
Sandbox: https://codesandbox.io/s/purple-cloud-k8fjl?file=/src/index.js
In this sandbox, I’m using BBCode component in React to render the BBCode [b]Testing[/b][hr]
.
Expected behavior: It should process the [b]Testing[/b]
and leave the problematic [hr]
unprocessed. So I expect it to render the following: Testing[hr]
It should also either trigger an onError()
call, or the code in the catch
block of the try-catch. Ideally we want it handled in onError()
, but I included the try-catch in this sandbox because it’s weird that the try-catch does not catch it. Maybe that can indicate something about the cause of the problem.
Actual behavior: Neither the onError()
function nor the catch
block are called. The application crashes with a runtime error. The specific error depends on what specifically broke the parser. In my example I use "[hr]"
and it throws:
Invariant Violation
hr is a void element tag and must neither have `children` nor use `dangerouslySetInnerHTML`.
in hr (created by Component)
in span (created by Component)
in Component (at src/index.js:10)
in App (at src/index.js:25)
[hr]
is not the only tag that causes this; it also breaks on [br]
and [col]
, so it seems to be a special case and there may be other cases. It does not break on all improper BBCode but I am not sure what the conditions are that trigger this.
It is possible this is not an issue with bbob but an error in my own code; if so I would be grateful for any help with what I did wrong, and how to properly handle it to get the behavior I want 😃
Thank you again!
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (3 by maintainers)
Top GitHub Comments
Now all works https://codesandbox.io/s/jolly-lewin-zu2z9?file=/src/index.js
Yes, you right. Error occurs in React JSX. So it can be fixed in bbob-react package. (escape invalid chars, trim tag names, etc)