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

make errorRenderer.draw be optional #3205

Closed
ittayd opened this issue Jul 4, 2022 · 4 comments · Fixed by #4359
Closed

make errorRenderer.draw be optional #3205

ittayd opened this issue Jul 4, 2022 · 4 comments · Fixed by #4359
Labels
Status: Triage Needs to be verified, categorized, etc Type: Enhancement New feature or request

Comments

@ittayd
Copy link

ittayd commented Jul 4, 2022

Is your feature request related to a problem? Please describe.
I'm using a mermaid plugin in TiddlyWiki which is an HTML/javascript based wiki. In particular, it allows a live preview of the content. So As I create a mermaid drawing I can see how it looks like and correct mistakes. The problem is that as I type, there are errors of course. The live preview will show them, which is fine, but errorRenderer also adds them at the bottom of the HTML where they accumulate (since it's an HTML wiki the page is not reloaded)

Describe the solution you'd like
Making the rendering of errors be optional/configurable

@ittayd ittayd added Status: Triage Needs to be verified, categorized, etc Type: Enhancement New feature or request labels Jul 4, 2022
@ittayd
Copy link
Author

ittayd commented Jul 13, 2022

Further, errorRenderer creates an SVG with the same ID as the rendered node and sets a style which now affects the rendered node (in case the calling code uses it. E.g. to put the exception text in it).

@slorber
Copy link

slorber commented Sep 14, 2023

Same issue here for Docusaurus integration.

We render Mermaid diagrams on a React app and already handle thrown errors with <ErrorBoundary> components to display an error message.

We don't need the weird bomb icon + error message text being appended at the end of the DOM 😅

Other related issues:


A workaround is to remove the error as soon as it is added to the DOM, cf solution proposed by @sidharthv96 in mermaid-js/mermaid-live-editor#1288

My adapted version for Docusaurus integration (facebook/docusaurus#9305):

try {
  return await mermaid.render(id, text);
} catch (e) {
  document.querySelector(`#d${id}`)?.remove();
  throw e;
}

Of course it would be much cleaner if there was a way to make the errorRenderer optional or configurable here:

https://github.com/mermaid-js/mermaid/blob/develop/packages/mermaid/src/mermaidAPI.ts#L478

  // -------------------------------------------------------------------------------
  // Draw the diagram with the renderer
  try {
    await diag.renderer.draw(text, id, version, diag);
  } catch (e) {
    errorRenderer.draw(text, id, version);
    throw e;
  }

Is there a good reason to not add config.errorRenderer and allow it to be null?


Here's a more visual illustration of the problem, showing the Mermaid error being displayed twice (by me, and by Mermaid). I want to render Mermaid errors on my own.

CleanShot 2023-09-14 at 16 58 24

@sidharthv96
Copy link
Member

#4359 is almost there. But some minor issues.

@silverwind
Copy link
Contributor

silverwind commented Oct 2, 2023

I hide those errors with CSS. Ideally I would like to see these error rendering off by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Triage Needs to be verified, categorized, etc Type: Enhancement New feature or request
Projects
None yet
4 participants