Keep connection paths correct on every frame of a drag - #329
Merged
Conversation
Screenshots of the live symptom show the line drawn at the position the node occupied earlier in the gesture, with a gap of hundreds of pixels on a fast drag, closing as soon as movement stops. The distance is far more than one frame's worth of movement, so the geometry is not merely late: something is actively drawing the connection from records that trail the gesture. Writing the path once per pointer event, as the previous change did, is not enough on its own. React Flow re-renders the same edges from its own node records immediately afterwards, and if those records are behind the gesture, that render overwrites the correct path with a stale one. The net result on screen is unchanged, which matches the report that the previous change made no difference. The correct geometry is now the last write before every paint for the whole gesture, not just at the moment each pointer event is handled. An animation-frame loop, alive only while a drag is in progress, redraws the affected connections from the latest corrected positions. Whatever React renders in between can no longer be what the user sees. The loop is torn down when the gesture ends and if the canvas unmounts mid-gesture. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
Problem
Screenshots of the live symptom show the connection drawn at the position the node occupied earlier in the gesture - a gap of hundreds of pixels during a fast drag, closing as soon as movement stops. That distance is far more than one frame of movement, so this is not simply a late repaint: something is actively drawing the connection from records that trail the gesture.
Writing the path once per pointer event, as #328 did, is not sufficient on its own. React Flow re-renders those same edges from its own node records immediately afterwards, and if those records are behind the gesture, that render overwrites the correct path with a stale one. The result on screen is unchanged - which matches the report that #328 made no observable difference.
Change
The correct geometry is now the last write before every paint for the duration of the gesture, rather than only at the moment each pointer event is handled. An animation-frame loop, alive only while a drag is in progress, redraws the affected connections from the latest corrected positions. Whatever React renders in between can no longer be what ends up on screen.
The loop is torn down when the gesture ends, and also if the canvas unmounts mid-gesture.
Test plan