Apply drag position corrections inside React Flow instead of after it - #326
Merged
Merged
Conversation
The canvas adjusts every drag position before rendering it: the drag-speed factor scales the movement, smart guides snap it, and a group drag carries its members by the same delta. Those adjustments ran in onNodesChange, which is downstream of React Flow's own bookkeeping, so the library never learned about them. This file documented the consequence in its own drag-end comment: the corrections "never feed back into RF's drag state." That left two different positions for one node on every frame of every drag - the corrected one this app rendered the card at, and the raw pointer one the library still believed. Connection geometry is computed by the library from its own node records, so the card and the line attached to it were being placed from different numbers. That is the connection failing to track the node, and no amount of re-render or compositing work downstream can fix it, because the two values have different inputs. The corrections now run as a React Flow change middleware (experimental_useOnNodesChangeMiddleware), inside the library's own updateNodePositions, before anything is committed. The corrected position becomes the only position: card transform and connection endpoints are derived from one number in one commit. Group-member changes join the same batch, so a group and its members stay in lockstep inside the library's update rather than alongside it. React Flow's drag-stop change receives the identical correction, which also removes the release-time bounce the old code had to paper over by substituting the settled position. onNodesChange no longer computes positions at all - it applies the corrected batch to local state and runs the side effects a settled gesture owes the rest of the app (backend commit, guide lines, culling suspension). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2 tasks
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
The canvas adjusts every drag position before rendering it: the drag-speed factor scales the movement, smart guides snap it to alignment, and dragging a group carries its members by the same delta. Those adjustments ran in
onNodesChange, which is downstream of React Flow's own bookkeeping, so the library never learned about them. The file documented the consequence in its own drag-end comment: the corrections "never feed back into RF's drag state."That left two different positions for one node on every frame of every drag - the corrected position this app rendered the card at, and the raw pointer position the library still believed. Connection geometry is computed by the library, from its own node records. So the card and the line attached to it were being positioned from two different numbers. That is the connection failing to track the node, and it explains why the symptom survived every downstream fix attempted so far: re-render tuning, layer promotion, culling, and compositing changes all operate after the point where the two values have already diverged, and none of them can make two different numbers agree.
Change
The corrections now run as a React Flow change middleware (
experimental_useOnNodesChangeMiddleware), inside the library's own position update, before anything is committed:onNodesChangeno longer computes positions at all. It applies the corrected batch to local state and runs the side effects a settled gesture owes the rest of the app: the backend position commit, the guide lines, and the culling suspension.Test plan