Skip to content

Conversation

NourBenz
Copy link
Contributor

@NourBenz NourBenz commented Apr 22, 2025

📑 Summary

This pull request fixes an issue where sequence diagram arrows with a trailing colon but no message (e.g., B ->> A:) would fail to parse. The grammar previously required at least one character after the colon, which was unnecessarily restrictive.

Resolves #6518


📏 Design Decisions

The lexer rule for TXT was too strict, requiring one or more characters after the colon. This PR modifies the rule to allow zero or more characters (* instead of +), and adds a fallback pattern to match a standalone colon.

🔧 Lexer Fix

":"(?:(?:no)?wrap:)?[^#\n;]*                                    return 'TXT';
":"                                                             return 'TXT';

This enables syntax such as:

sequenceDiagram
A ->> B:
B ->> A: response

which now parses correctly.

No changes were needed in the parser or rendering logic since TXT is already processed safely as an optional message.

📋 Tasks

Make sure you

  • 📖 have read the contribution guidelines
  • 💻 have added necessary unit/e2e tests.
  • 📓 have added documentation. Make sure MERMAID_RELEASE_VERSION is used for all new features.
  • 🦋 If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

Copy link

changeset-bot bot commented Apr 22, 2025

🦋 Changeset detected

Latest commit: b821454

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
mermaid Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the Type: Bug / Error Something isn't working or is incorrect label Apr 22, 2025
Copy link

netlify bot commented Apr 22, 2025

Deploy Preview for mermaid-js ready!

Name Link
🔨 Latest commit b821454
🔍 Latest deploy log https://app.netlify.com/sites/mermaid-js/deploys/680bcdf468c97500081f7f96
😎 Deploy Preview https://deploy-preview-6523--mermaid-js.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

pkg-pr-new bot commented Apr 22, 2025

Open in StackBlitz

npm i https://pkg.pr.new/mermaid-js/mermaid@6523
npm i https://pkg.pr.new/mermaid-js/mermaid/@mermaid-js/layout-elk@6523
npm i https://pkg.pr.new/mermaid-js/mermaid/@mermaid-js/mermaid-zenuml@6523
npm i https://pkg.pr.new/mermaid-js/mermaid/@mermaid-js/parser@6523

commit: b821454

Copy link

codecov bot commented Apr 22, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 3.87%. Comparing base (cf8fc2a) to head (b821454).
Report is 4 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           develop   #6523      +/-   ##
==========================================
- Coverage     3.87%   3.87%   -0.01%     
==========================================
  Files          412     413       +1     
  Lines        43164   43175      +11     
  Branches       665     665              
==========================================
  Hits          1672    1672              
- Misses       41492   41503      +11     
Flag Coverage Δ
unit 3.87% <ø> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

see 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

argos-ci bot commented Apr 22, 2025

The latest updates on your projects. Learn more about Argos notifications ↗︎

Build Status Details Updated (UTC)
default (Inspect) ✅ No changes detected - Apr 25, 2025, 6:10 PM

@nour0205
Copy link
Contributor

Thanks for this fix!
The lexer rule update looks correct and the unit test covers the basic expected behavior nicely.

I have a few minor improvement suggestions:

Simplification:

Since the updated regex already allows zero or more characters after :, the fallback rule ":" return 'TXT' might now be unnecessary.

Could we check if removing it would still pass all tests? Might help keep the lexer a bit cleaner.

Extra Test Suggestion:

Maybe add a test for input likeAlice ->> Bob: ;(colon + space + semicolon) or colon followed by a comment line, to ensure parsing remains stable even with odd user input.

Versioning:

This is marked as a major bump that makes sense if we assume downstream users might depend on the stricter old behavior. (Just confirming if that was fully intended.)

Overall great work this makes sequence diagrams much more user-friendly!

@knsv
Copy link
Collaborator

knsv commented Apr 28, 2025

Thanks @NourBenz. Good update! I appreciate that you added the unit test as well.

@knsv knsv added this pull request to the merge queue Apr 28, 2025
Merged via the queue into mermaid-js:develop with commit 9080431 Apr 28, 2025
22 checks passed
Copy link

mermaid-bot bot commented Apr 28, 2025

@NourBenz, Thank you for the contribution!
You are now eligible for a year of Premium account on MermaidChart.
Sign up with your GitHub account to activate.

@github-actions github-actions bot mentioned this pull request Jun 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug / Error Something isn't working or is incorrect
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sequence diagram requires colon and whitespace : after an arrow without label
3 participants