Skip to content

Conversation

@cpcallen
Copy link
Collaborator

@cpcallen cpcallen commented Apr 28, 2025

The basics

The details

Resolves

Fix an incorrect assumption in setParent when handling .setParent(null) calls.

Fixes #8853.

(But see comments on that bug for detail.)

Proposed Changes

  • In BlockSvg.prototype.setParent, when setting parent to null, check to see if the top-most blocklyDragging element is in fact a direct child of the canvass before attempting to insert the new top-level block ahead of it in the canvass's contents.
  • In BlockDragStragegy.prototype.revertDrag, call connectionPreviewer.hidePreview() earlier, before attempting to reconnect the dragged block to its original parent. Not strictly necessary but makes more sense.
  • Improve documentation for related methods in BlockSvg and BlockDragStrategy.

Reason for Changes

The topmost block whose root SVG element has the blocklyDragging class may not actually be a top-level block on the workspace, but the existing implementation assumed that was true and would throw an error if it wasn't. This resulted in problems when reverting a drag if an insertion marker was displayed.

Test Coverage

Adds two new tests for setParent (one of which actually caught a bug that existed in an earlier version of the fix in this PR!)

Add tests for scenarios where block(s) unrelated to the block
being disconnected has/have been marked as as being dragged.
Due to a bug in BlockSvg.prototype.setParent, one of these
fails in the case that the dragging block is not a top
block.

Also add a check to assertNonParentAndOrphan to check that the
orphan block's SVG root's parent is the workspace's canvass
(i.e., that orphan is a top-level block in the DOM too).
Fix an incorrect assumption in setParent: the topmost block
whose root SVG element has the blocklyDragging class may not
actually be a top-level block.
@cpcallen cpcallen added the PR: fix Fixes a bug label Apr 28, 2025
@cpcallen cpcallen added this to the v12 milestone Apr 28, 2025
@cpcallen cpcallen requested a review from a team as a code owner April 28, 2025 16:33
Copy link
Collaborator

@rachel-fenichel rachel-fenichel left a comment

Choose a reason for hiding this comment

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

LGTM after minor fixes.

| SVGElement
| null
| undefined;
const canvass = this.workspace.getCanvas();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: canvass - > canvas

return;
}

this.connectionPreviewer!.hidePreview();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Switch to ?. instead of !. while you're at it.

@cpcallen cpcallen enabled auto-merge (squash) April 29, 2025 15:14
@cpcallen cpcallen merged commit b9b40f4 into RaspberryPiFoundation:rc/v12.0.0 Apr 29, 2025
7 checks passed
@cpcallen cpcallen deleted the fix/8853 branch April 29, 2025 15:26
@sappm01 sappm01 removed this from Blockly 2025 Oct 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: fix Fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants