fix(Groups): prevent stale state from overwriting group drag position#291
Open
fix(Groups): prevent stale state from overwriting group drag position#291
Conversation
…bscribeToGroup
During group drag, handleDrag() calls setState({ rect: newPos }) which stores
the new rect in data.nextState (this.state is not updated until the render cycle).
When onDragUpdate then moves the blocks, the reactive signal fires synchronously
and subscribeToGroup calls setState({ ...this.state, ...groupWithoutRect }). Since
this.state is still stale (old rect), it overwrites data.nextState.rect back to the
original position on every frame, causing the group to appear stuck or move very slowly.
Fix: use getState() instead of this.state to spread the pending nextState, which
already contains the correct rect set by handleDrag in the same frame.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdjusts group drag state handling so that subscription updates use the pending next state instead of stale component state, preventing group drag position from being overwritten during the same frame. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In the dragging branch, consider avoiding spreading the entire result of
getState()andgroupWithoutRectintosetStateand instead explicitly set only the fields that need to change to reduce the risk of inadvertently overwriting unrelated state properties.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In the dragging branch, consider avoiding spreading the entire result of `getState()` and `groupWithoutRect` into `setState` and instead explicitly set only the fields that need to change to reduce the risk of inadvertently overwriting unrelated state properties.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Contributor
|
Preview is ready. |
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.
Summary
subscribeToGroupwas usingthis.state(stale) instead ofthis.getState()(pending) when suppressing rect updates during dragWhat changed and why
During group drag, the flow is:
handleDrag()callssetState({ rect: newPos })→ stores new rect indata.nextState(butthis.stateis NOT updated until the render cycle)onDragUpdatemoves the contained blockssubscribeToGroupisDragging=true, the handler callssetState({ ...this.state, ...groupWithoutRect })The bug:
this.state.rectis the stale original position. Sincedata.nextStatealready exists from step 1,setStatehits theelsebranch and doesassign(data.nextState, { rect: stalePos, ... }), overwriting the correct rect set byhandleDragback to the initial position. This repeats every frame, making the group appear stuck.Fix: Replace
this.statewiththis.getState()which returnsdata.nextStatewhen a pending state update exists, preserving the correct rect fromhandleDrag.Files changed
src/components/canvas/groups/Group.ts— one-line fix insubscribeToGroup🤖 Generated with Claude Code
Summary by Sourcery
Bug Fixes: