Skip to content

fix(merman): avoid infinite loop in side parallel transitions with equal endpoints - #48898

Open
marwanvx wants to merge 1 commit into
anomalyco:v2from
marwanvx:merman-nested-states
Open

fix(merman): avoid infinite loop in side parallel transitions with equal endpoints#48898
marwanvx wants to merge 1 commit into
anomalyco:v2from
marwanvx:merman-nested-states

Conversation

@marwanvx

Copy link
Copy Markdown

Issue for this PR

Closes #48573

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

When rendering nested Mermaid state diagrams where transitions connect states across composite boundaries that share the same horizontal row, addSideParallelTransition entered an infinite loop because startY === endY, causing unbounded cell allocation and an out-of-memory crash.

This fix:

  1. Guards the vertical rail cell and walk in addSideParallelTransition with if (startY !== endY) to prevent infinite loop loops on equal endpoints.
  2. Routes cross-composite transitions between states sharing the same vertical row via bottom-parallel rails instead of side-parallel.
  3. Requires from.centerY !== to.centerY in sideParallelTargetApproach before picking a side target approach to prevent horizontal line collisions across target states.
  4. Adds regression unit and rendering tests in packages/merman.

How did you verify your code works?

  • cd packages/merman && bun test src/state/routing.test.ts (31 pass, 0 fail)
  • cd packages/merman && bun test -t "nested composite states sharing horizontal rows" src/state/diagram.test.ts (1 pass, 0 fail)
  • cd packages/merman && bun run typecheck (0 errors)
  • Verified rendering the reproduction diagram completes in ~2ms with correct ASCII output.

Screenshots / recordings

N/A

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

…ual endpoints

When states in different composite parents share the same row, routing them through side-parallel transitions causes an infinite loop in addSideParallelTransition because startY === endY and the vertical stepping loop never reaches its termination condition.

1. Guard the vertical stepping loop in addSideParallelTransition so it is skipped when startY === endY.
2. Route cross-composite transitions between states on the same horizontal row via bottom-parallel rails instead of side-parallel.
3. Require from.centerY !== to.centerY in sideParallelTargetApproach before selecting side approach to avoid horizontal collisions.
4. Add unit and rendering regression tests in packages/merman.

Fixes anomalyco#48573
@marwanvx

Copy link
Copy Markdown
Author

Linked issue: #48573 (Closes #48573 is in the PR description).

@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant