Skip to content

Sketch Lab: fix group delete bug and add backspace option for delete#73881

Open
molly-moen wants to merge 6 commits into
stagingfrom
molly/sketch-group-bug
Open

Sketch Lab: fix group delete bug and add backspace option for delete#73881
molly-moen wants to merge 6 commits into
stagingfrom
molly/sketch-group-bug

Conversation

@molly-moen

@molly-moen molly-moen commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

This PR fixes a bug when deleting a group. Previously, if you deleted a group it would move to the top right of the canvas and the elements would become immovable. This was because we weren't deleting the children of a group, only the group itself, and the orphaned nodes became buggy.

React Flow has the option to supply a onBeforeDelete handler, which modifies which nodes/edges are being deleted. I added that here, which also works for our 'cut' action, which was doing some custom logic for groups before.

While I was here, I also added the option to use backspace for delete as well as the delete key, since mac keyboards generally don't have a delete key, and we ran into some confusion here. You can still backspace in a text element to delete text without deleting an element. Depending on which goes in first, I'll make sure to update the shortcuts menu added in #73869 to include the new option.

Before

Screen.Recording.2026-07-15.at.3.08.07.PM.mov

After

Screen.Recording.2026-07-15.at.3.09.22.PM.mov

Links

Testing story

Tested locally.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes Sketch Lab deletion semantics in the React Flow canvas so deleting/cutting a group reliably deletes its grouped children, and adds Backspace as an additional delete hotkey.

Changes:

  • Add expandGroupDeletion to expand group deletions to include children (and associated edges), wired via React Flow’s onBeforeDelete.
  • Update cut behavior to rely on the centralized pre-delete expansion rather than manually deleting group children.
  • Allow both Delete and Backspace keys to trigger deletion.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
apps/src/sketchlab/reactFlow/utils/grouping.ts Adds expandGroupDeletion to expand group deletions to include children and related edges.
apps/src/sketchlab/reactFlow/components/ReactFlowCanvas.tsx Wires onBeforeDelete to expandGroupDeletion; adds Backspace as a delete key.
apps/src/sketchlab/reactFlow/hooks/useCopyPaste.ts Simplifies cut for groups to delete only the group node and rely on onBeforeDelete.
apps/test/unit/sketchlab/reactFlow/utils/groupingTest.ts Adds unit tests for expandGroupDeletion.

Comment thread apps/src/sketchlab/reactFlow/utils/grouping.ts
Comment thread apps/test/unit/sketchlab/reactFlow/utils/groupingTest.ts
@molly-moen molly-moen marked this pull request as ready for review July 15, 2026 22:12
@molly-moen molly-moen requested a review from a team July 15, 2026 22:13

@bencodeorg bencodeorg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this!

onNodeClick: isGrabMode ? undefined : handleNodeClick,
onEdgeClick: isGrabMode ? undefined : handleEdgeClick,
deleteKeyCode: !readOnly && !isGrabMode ? 'Delete' : null,
deleteKeyCode: !readOnly && !isGrabMode ? ['Delete', 'Backspace'] : null,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙌

Comment thread apps/src/sketchlab/reactFlow/utils/grouping.ts Outdated
for (const edge of allEdges) {
if (
!finalEdgeIds.has(edge.id) &&
(finalNodeIds.has(edge.source) || finalNodeIds.has(edge.target))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would delete an edge between a group and a non-grouped node, yeah? I feel like we'd keep those but 🤷‍♂️ . But ideally still delete an edge that is only attached on one side (and it's to a grouped node)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm good question. It is consistent with our current deletion behavior, if you delete a node, any edges attached to it are deleted, even if they are attached to another node.

@bencodeorg

Copy link
Copy Markdown
Contributor

Tangentially, the docs for this really make it seem like this should just work? Are we doing something special?
https://reactflow.dev/api-reference/types/delete-elements

@molly-moen

Copy link
Copy Markdown
Contributor Author

Tangentially, the docs for this really make it seem like this should just work? Are we doing something special?
https://reactflow.dev/api-reference/types/delete-elements

We must be given the bug we've seen, or their logic is flawed 🤷‍♀️

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.

3 participants