refactor(flow): rebuild layout algorithm from scratch#430
Open
nandanmen wants to merge 6 commits intocloudflare:mainfrom
Open
refactor(flow): rebuild layout algorithm from scratch#430nandanmen wants to merge 6 commits intocloudflare:mainfrom
nandanmen wants to merge 6 commits intocloudflare:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR rebuilds Flow to use a bespoke layout algorithm instead of relying on the DOM's layout algorithm.
Problem
The existing Flow implementation relies on the DOM to layout the nodes in the diagram, which keeps things simple and allows us to position nodes using CSS.
The problem is the arrows that we draw between nodes need explicit coordinates. To get these coordinates from the DOM, we need to:
We can easily check for size changes using
ResizeObserver, but we can't do the same for position. As a result, we have to do various hacks to ensure position always stay in sync:This led to a few prevailing issues:
Solution
This PR attempts to fix the problem by capturing control of how the nodes are laid out. It implements a custom layout algorithm that takes the size of each node and returns their
xandycoordinates. These positions are based on where the node is rendered in the component tree.By manually computing positions, we can: