Skip to content

fix: Fix nested block duplication bumping parent stack - #10682

Merged
lizschwab merged 3 commits into
RaspberryPiFoundation:mainfrom
matthewalberto:fix/paste-nested-block-bumps-stack
Nov 17, 2026
Merged

lizschwab merged 3 commits into
RaspberryPiFoundation:mainfrom
matthewalberto:fix/paste-nested-block-bumps-stack

Conversation

@matthewalberto

@matthewalberto matthewalberto commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

The basics

The details

Resolves

Fixes #10675.

Proposed Changes

Prevent duplicate blocks from triggering unintended stack adjustments during their initial render.

Defer bumping other blocks until after the duplicate has been positioned.

Preserve the initial render step so Blockly can calculate the duplicate's connection positions correctly.

Add regression tests covering duplication of nested blocks with children.

Reason for Changes

When duplicating a block nested inside another block, the duplicate initially appears directly on top of the original. Blockly is expected to move the duplicate down and to the right.

Previously, Blockly performed bumping during the initial render, before repositioning the duplicate. Because the duplicate's edges aligned with the original block's interior, the original stack was bumped instead, leaving the duplicate in its initial position.

Deferring bumping until after repositioning ensures that the correct blocks are moved.

Test Coverage

Full test suite: Added 4 regression tests. The original implementation fails 3 of the 4 new tests and passes 4044 tests overall. With this fix, all 4047 tests pass.

Mutation testing: All 7 deliberate breakages were caught. An additional test was added after one breakage escaped the initial run.

Lint and formatting: Clean on all 3 changed files. The only failure in the wider lint run is caused by Windows line endings in unrelated files; CI runs on Linux.

Not tested: Real-browser behavior, Linux locally, and alternative renderers.

Documentation

No documentation changes are needed.

Additional Information

Claude Code (Claude Opus 5.5) was used collaboratively throughout the process, including reproducing the bug, implementing the fix, writing the four regression tests, and performing validation checks. All PR description text was written independently by the human contributor.

@matthewalberto
matthewalberto requested a review from a team as a code owner November 13, 2026 03:17
@github-actions github-actions Bot added the PR: fix Fixes a bug label Nov 13, 2026

@github-actions github-actions Bot 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.

Welcome! It looks like this is your first pull request in Blockly, so here are a couple of tips:

  • You can find tips about contributing to Blockly and how to validate your changes on our developer site.
  • We use conventional commits to make versioning the package easier. Make sure your commit message is in the proper format or learn how to fix it.
  • If any of the other checks on this PR fail, you can click on them to learn why. It might be that your change caused a test failure, or that you need to double-check the style guide.
    Thank you for opening this PR! A member of the Blockly team will review it soon.

@github-actions github-actions Bot added PR: fix Fixes a bug and removed PR: fix Fixes a bug labels Nov 13, 2026

@lizschwab lizschwab 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 taking this on! I took a look at your PR and had a few small changes I'd like to see applied. There are four comments that start with "Nit"; these are nit-picks and can be applied if you like but I would not hold back an approval on them. The rest should be addressed.

I pulled down the changes and tested them locally using the repro steps in the bug ticket. They do resolve the issue (see screen recording below).

Screen.Recording.2026-11-13.at.3.28.39.PM.mov

As a side note, the PR comments read a bit like an LLM either drafted them or polished them. In the future, it would help us out if these comments be written in your own words. If you need to use an LLM for translation or spelling/grammar check, that's fine, but for writing your pull request summary we'd prefer more natural language. Please see our AI policy for more details.

workspace.connectionDBList.forEach((db) => db?.endBulkUpdates());
}
for (const block of blocks) {
for (const block of bumpNeighbours ? blocks : []) {

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 is a little difficult to read. I would prefer something more like
if (bumpNeigbours) { for (const block of blocks) {...} }

// After appending the block to the workspace, it will be bumped from its neighbors
// However, the algorithm for deciding where to paste a block depends on
// the starting position of the copied block, so we'll pass those coordinates along
// The algorithm for deciding where to paste a block depends on the starting

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.

I don't see a need to change this comment with these changes.

let block;
try {
block = append(copyData.blockState, workspace) as BlockSvg;
// Finish any renders queued before the paste, so that the render below

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.

I don't think this comment is needed.

this.workspace,
coordinate,
);
this.clock.runAll();

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.

Nit: Same as above.

this.workspace,
coordinate,
);
this.clock.runAll();

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.

Nit: same as above

// After appending the block to the workspace, it will be bumped from its neighbors
// However, the algorithm for deciding where to paste a block depends on
// the starting position of the copied block, so we'll pass those coordinates along
// The algorithm for deciding where to paste a block depends on the starting

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.

I don't see a need to change this comment with these changes.

let block;
try {
block = append(copyData.blockState, workspace) as BlockSvg;
// Finish any renders queued before the paste, so that the render below

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 comment is not needed.

Use an if around the bump loop, restore the original paste comment,
drop the extra comment and the clock.runAll() calls the tests do not need.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@matthewalberto

Copy link
Copy Markdown
Contributor Author

I pushed the changes, cheers.

@lizschwab lizschwab 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.

This looks good to me. I pulled down the latest changes and tested again.

@lizschwab lizschwab 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 addressing my feedback so far. There's an additional change we would like to see before merging in.

let block;
try {
block = append(copyData.blockState, workspace) as BlockSvg;
renderManagement.triggerQueuedRenders();

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.

I checked in with @gonfunko, who is more familiar with this code, and we feel that this call to triggerQueuedRenders() and the one on line 55 are both hack fixes for a different issue. Please remove these and update the tests. It's fine if you need to add a clock tick to get any tests working; I asked for them to be removed when they weren't doing anything to change the outcome of the tests, but you may need them to get the tests passing. There's one test that appears to be addressing an edge case that these calls are meant to fix which you may need to simply remove.

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.

I removed both calls, then reverted render_management.ts back to main. I also removed the connection-positions test, but kept the other 3 tests with ticks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@lizschwab lizschwab 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 the quick turnaround on that feedback!

Edited to add: I pulled down these changes and tested them locally. They resolve the original issue.

@lizschwab
lizschwab merged commit 01955b3 into RaspberryPiFoundation:main Nov 17, 2026
6 checks passed
matthewalberto added a commit to matthewalberto/matthewalberto that referenced this pull request Nov 18, 2026
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.

Duplicating a nested block that has children bumps the parent stack

2 participants