diff --git a/cypress/integration/rendering/sequencediagram.spec.js b/cypress/integration/rendering/sequencediagram.spec.js index e5459637b..8ab21315f 100644 --- a/cypress/integration/rendering/sequencediagram.spec.js +++ b/cypress/integration/rendering/sequencediagram.spec.js @@ -88,6 +88,16 @@ context('Sequence diagram', () => { {} ); }); + it('should handle empty lines', () => { + imgSnapshotTest( + ` + sequenceDiagram + Alice->>John: Hello John
+ John-->>Alice: Great! + `, + {} + ); + }); it('should handle line breaks and wrap annotations', () => { imgSnapshotTest( ` diff --git a/packages/mermaid/src/utils.ts b/packages/mermaid/src/utils.ts index 6f824062d..3f70b2a7c 100644 --- a/packages/mermaid/src/utils.ts +++ b/packages/mermaid/src/utils.ts @@ -764,6 +764,9 @@ export const calculateTextDimensions: ( let cheight = 0; const dim = { width: 0, height: 0, lineHeight: 0 }; for (const line of lines) { + if (!line) { + continue; + } const textObj = getTextObj(); textObj.text = line; const textElem = drawSimpleText(g, textObj)