Skip to content

Direction TD Inside subgraph Causes Parsing Error #6338

Open
@nour0205

Description

@nour0205

Description

In Mermaid.js, setting direction TD inside a subgraph results in a parsing error, while other directions (LR, RL, BT) function correctly.

This is inconsistent because:

  • TD is a valid global direction.
  • direction is generally allowed inside subgraph for other layouts.

Steps to reproduce

Case 1: direction TD Fails Inside Subgraph


graph LR
  subgraph A ["Subgraph A - Top to Bottom"]
    direction TD
    X["Node X"] --> Y["Node Y"]
  end

Expected Behavior:
The subgraph should follow TD direction, positioning nodes from top to bottom.

Actual Behavior:
Mermaid.js throws a parsing error.


Case 2: TD Works Globally


graph TD
  subgraph A ["Subgraph A - Top to Bottom"]
    X["Node X"]
    Y["Node Y"]
    X --> Y
  end

Expected and Actual Behavior:
The subgraph correctly follows TD layout, confirming that TD is valid globally.


Case 3: Other Directions Work Inside Subgraphs


graph LR
  subgraph A ["Right to Left"]
    direction RL
    X["Node X"] --> Y["Node Y"]
  end

  subgraph B ["Bottom to Top"]
    direction BT
    M["Node M"] --> N["Node N"]
  end

Expected and Actual Behavior:
Both subgraphs respect their assigned directions (RL and BT).
This confirms that direction is supported inside subgraphs—except for TD.

Screenshots

Image

Image

Code Sample


Setup

  • Mermaid.js Version: v11.4.1
  • Browser and Version:Microsoft Edge v132.0.2957.115
  • OS: Windows 11

Suggested Solutions

No response

Additional Context

This issue prevents using TD inside subgraphs, making it inconsistent with how direction works for other layouts.

Since TD works globally and TB works inside subgraphs, this behavior is likely a parser inconsistency.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: TriageNeeds to be verified, categorized, etcType: Bug / ErrorSomething isn't working or is incorrect

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions