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

mermaid.render() returns 'undefined' for svgCode in Blazor. #6264

Open
sby-a-izumi opened this issue Feb 10, 2025 · 0 comments
Open

mermaid.render() returns 'undefined' for svgCode in Blazor. #6264

sby-a-izumi opened this issue Feb 10, 2025 · 0 comments
Labels
Status: Triage Needs to be verified, categorized, etc Type: Bug / Error Something isn't working or is incorrect

Comments

@sby-a-izumi
Copy link

sby-a-izumi commented Feb 10, 2025

Description

I expected return svgCode with 'await mermaid.render('Id', mermaidText)' but returns 'undefined'.

My code is bellow.

const { svgCode, bindFunctions } = await mermaid.render('hogehoge', graph TB\na-->b');
console.log(svgCode); // undefined

Steps to reproduce and Code Sample

  1. Edit App.razor for initialize mermaid.
<script type="module">
  import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.esm.min.mjs';
  window.mermaid = mermaid;
</script>
  1. Create razor file for page.
<div id="hogehoge"></div>
  1. Create razor.cs file for page.
protected override async Task OnParametersSetAsync()
{
  // Initialize mermaid.
  await JSRuntime.InvokeVoidAsync("initializeMermaid");

  // Render mermaid.
  var testMermaidText = "graph TB\na-->b");
  var svg = await JSRuntime.InvokeAsync<string>("renderMermaidToSVG", testMermaidText);
}
  1. Create javaScript file.
window.initializeMermaid = async () => {
  await mermaid.initialize({ startOnLoad: false });
};

window.renderMermaidToSVG = async (mermaidText) => {
  try {
    const div = document.getElementById('hogehoge');
    if (!div) {
      throw new Error('Div not found.');
      console.log("error occured.");
    }
    // Logging document.
    console.log("document");
    console.log(document);

    // Logging div.
    console.log("div");
    console.log(div); 

    // Ensure mermaid is initialized befor rendering
    if (typeof mermaid === 'undefined' || !mermaid) {
      throw new Error('Mermaid is not initialized');
    }

    // Logging mermaid.
    console.log("mermaid");
    console.log(mermaid);

    // Logging mermaid text.
    console.log("text");
    console.log(mermaidText);

    const { svgCode, bindFunctions } = await mermaid.render('hogehoge', mermaidText );
    // Logging svgCode.
    console.log("svgCode");
    console.log(svgCode);

    return svgCode;
  } catch (error) {
    throw error;
  }
};

Screenshots

Image

The browser's developer tools show that “undefined” is returned for svgCode.

Setup

  • Mermaid version:
  • Browser and Version: [Chrome, Edge, Firefox]

Suggested Solutions

No response

Additional Context

No response

@sby-a-izumi sby-a-izumi added Status: Triage Needs to be verified, categorized, etc Type: Bug / Error Something isn't working or is incorrect labels Feb 10, 2025
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: Bug / Error Something isn't working or is incorrect
Projects
None yet
Development

No branches or pull requests

1 participant