Skip to content

Apply drag position corrections inside React Flow instead of after it - #326

Merged
dovvnloading merged 1 commit into
mainfrom
fix/drag-corrections-inside-reactflow
Aug 14, 2026
Merged

Apply drag position corrections inside React Flow instead of after it#326
dovvnloading merged 1 commit into
mainfrom
fix/drag-corrections-inside-reactflow

Conversation

@dovvnloading

Copy link
Copy Markdown
Owner

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:

  • The corrected position becomes the only position. The card's placement and the connection's endpoints are derived from one number, in one commit.
  • Group-member movements 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. This also removes the release-time bounce that the previous code had to paper over by substituting the settled position after the fact.
  • 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: the backend position commit, the guide lines, and the culling suspension.

Test plan

  • Full frontend check passes: schema, types, lint (0 errors), 1927/1927 tests, production build, bundle size
  • The drag-size-cache test now drives production's real sequence - middleware first, then the handler with its output - rather than the handler alone
  • On the affected machine: drag a connected node slowly and confirm the connection stays attached to it

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>
@dovvnloading
dovvnloading merged commit 825a007 into main Aug 14, 2026
@dovvnloading
dovvnloading deleted the fix/drag-corrections-inside-reactflow branch August 15, 2026 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant