From a9e798c399560ddb55841413870a81f5a72ae7d6 Mon Sep 17 00:00:00 2001 From: ashishj Date: Thu, 18 Aug 2022 19:39:32 +0200 Subject: [PATCH] Making sure to addDiagrams before detectType call --- src/mermaidAPI.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/mermaidAPI.js b/src/mermaidAPI.js index ebf12dc96..6a00e80ca 100644 --- a/src/mermaidAPI.js +++ b/src/mermaidAPI.js @@ -41,7 +41,7 @@ import assignWithDepth from './assignWithDepth'; import DOMPurify from 'dompurify'; import mermaid from './mermaid'; -addDiagrams(); +let hasLoadedDiagrams = false; /** * @param text @@ -49,7 +49,12 @@ addDiagrams(); * @returns {any} */ function parse(text, dia) { + if (!hasLoadedDiagrams) { + addDiagrams(); + hasLoadedDiagrams = true; + } var parseEncounteredException = false; + try { const diag = dia ? dia : new Diagram(text); diag.db.clear(); @@ -515,6 +520,10 @@ function initialize(options) { updateRendererConfigs(config); setLogLevel(config.logLevel); + if (!hasLoadedDiagrams) { + addDiagrams(); + hasLoadedDiagrams = true; + } } const mermaidAPI = Object.freeze({