Skip to content

Conversation

@lmac-1
Copy link
Collaborator

@lmac-1 lmac-1 commented Jan 23, 2026

Description

This PR fixes a bug where converging edges would swap positions when selected on the diagram.

The issue was caused by sortOrderForSvg reordering edges based on selection state, which affected Dagre's layout decisions. The fix preserves stable edge order regardless of selection.

Before:
image

After:
image

See the bug in action: https://www.loom.com/share/302055f6f3b748f1a4523ef7ccef67af

Closes #4328

Validation steps

  1. Open workflow with multiple branching points
  2. Make sure your diagram is on auto layout mode
  3. Click edges from different parent nodes
  4. Click edges that lead to converging paths
  5. Expected: All paths maintain their positions

Additional notes for the reviewer

  1. If you have bigger workflows - perhaps click around on the paths and make sure that everything behaves as expected
  2. I suspected that this sorting algorithm was to ensure that the edges stayed on top in terms of z-index. I've verified both with and without the fix that the behaviour remains the same when there are edges that are on top of each other.

AI Usage

Please disclose whether you've used AI anywhere in this PR (it's cool, we just
want to know!):

  • I have used Claude Code
  • I have used another model
  • I have not used AI

You can read more details in our
Responsible AI Policy

Pre-submission checklist

  • I have performed an AI review of my code (we recommend using /review
    with Claude Code)
  • I have implemented and tested all related authorization policies.
    (e.g., :owner, :admin, :editor, :viewer)
  • I have updated the changelog.
  • I have ticked a box in "AI usage" in this PR

Fixes #4328

When clicking different edges in auto-layout mode, paths would swap
positions because sortOrderForSvg was reordering edges based on
selection state. Dagre's layout algorithm uses edge order to determine
positioning when disableOptimalOrderHeuristic is enabled.

Fix by removing selection-based sorting and preserving stable edge order.
Only disabled/enabled status affects sort order now.
@github-project-automation github-project-automation bot moved this to New Issues in v2 Jan 23, 2026
@codecov
Copy link

codecov bot commented Jan 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.33%. Comparing base (549de66) to head (b398d4e).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4348      +/-   ##
==========================================
+ Coverage   89.29%   89.33%   +0.04%     
==========================================
  Files         425      425              
  Lines       19994    19994              
==========================================
+ Hits        17854    17862       +8     
+ Misses       2140     2132       -8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 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
Contributor

@doc-han doc-han left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works perfectly 🎉
Can we remove the comments with the PR number in them?

Also, I'm yet to understand why the sort function was initially made to work in that manner(pushing the selected edge to the bottom).

return -1;
}

return a.selected - b.selected;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice fix.
I'm trying to understand why this code existed in the first place. Seems to have zero value and I can't understand why it was like this.

Copy link
Contributor

@doc-han doc-han left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove the comments with PR numbers? Thanks.

@github-project-automation github-project-automation bot moved this from New Issues to In review in v2 Jan 26, 2026
@lmac-1
Copy link
Collaborator Author

lmac-1 commented Jan 26, 2026

@doc-han thanks for the review. I've fixed the comments referring to the PR. Can you check it again?

Also re the sorting function, I asked my good friend Claude and it seems to think that it "ensures disabled edges render behind enabled edges in the SVG." So I think it's best if we keep it in!

@lmac-1 lmac-1 requested a review from doc-han January 26, 2026 21:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

Shifty Path and Step Behavior on Auto-Layout Mode

3 participants