From 6d2441dff676a9d1f67f31181ff854e4b3d9ce17 Mon Sep 17 00:00:00 2001 From: "Ashley Engelund (weedySeaDragon @ github)" Date: Tue, 1 Nov 2022 12:08:59 -0700 Subject: [PATCH] only call getClasses if the diagram renderer supports it --- packages/mermaid/src/mermaidAPI.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/mermaid/src/mermaidAPI.ts b/packages/mermaid/src/mermaidAPI.ts index 805e42f1a..27cbdbd99 100644 --- a/packages/mermaid/src/mermaidAPI.ts +++ b/packages/mermaid/src/mermaidAPI.ts @@ -180,7 +180,7 @@ export const createCssStyles = ( } // classDefs defined in the diagram text - if (classDefs && Object.keys(classDefs).length > 0) { + if (!isEmpty(classDefs)) { if (CLASSDEF_DIAGRAMS.includes(graphType)) { const htmlLabels = config.htmlLabels || config.flowchart?.htmlLabels; // TODO why specifically check the Flowchart diagram config? @@ -481,11 +481,15 @@ const render = async function ( // Insert an element into svg. This is where we put the styles const svg = element.firstChild; const firstChild = svg.firstChild; + const diagramClassDefs = CLASSDEF_DIAGRAMS.includes(graphType) + ? diag.renderer.getClasses(text, diag) + : {}; + const rules = createUserStyles( config, graphType, // @ts-ignore convert renderer to TS. - diag.renderer.getClasses(text, diag), + diagramClassDefs, idSelector );