Skip to content

fix: clear parent when block is removed from input with shadow#525

Merged
cwillisf merged 1 commit into
developfrom
fix-scratch-blocks-3541
Apr 14, 2026
Merged

fix: clear parent when block is removed from input with shadow#525
cwillisf merged 1 commit into
developfrom
fix-scratch-blocks-3541

Conversation

@cwillisf
Copy link
Copy Markdown
Contributor

Resolves

Proposed Changes

When a block was removed from an input that had a shadow block, the shadow was correctly restored, but the moved block's parent reference was not cleared. This change clears that parent reference in this case.

Reason for Changes

The previous behavior caused getTopLevelScript to follow the stale parent pointer back to the old stack, so clicking the detached reporter would run the old stack instead of reporting its value.

Test Coverage

Added a regression test for scratchfoundation/scratch-blocks#3541

When a block was removed from an input that had a shadow block, the
shadow was correctly restored but the moved block's parent reference
was not cleared. This caused getTopLevelScript to follow the stale
parent pointer back to the old stack, so clicking the detached
reporter would run the old stack instead of reporting its value.

Fixes scratchfoundation/scratch-blocks#3541
@cwillisf cwillisf requested a review from Copilot April 14, 2026 15:25
@cwillisf cwillisf requested a review from a team as a code owner April 14, 2026 15:25
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a Blocks.moveBlock edge case where removing a non-shadow block from an input which has a shadow restores the shadow correctly but leaves the moved block’s parent pointer stale, causing getTopLevelScript (and thus stack-click behavior) to resolve to the wrong script.

Changes:

  • Clear the moved block’s parent when disconnecting from an input where a shadow is being restored.
  • Add a regression unit test covering “move out of input with shadow clears parent” behavior.

Reviewed changes

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

File Description
packages/scratch-vm/src/engine/blocks.js Clears parent on disconnect when restoring a shadow into an input, preventing stale ancestry.
packages/scratch-vm/test/unit/engine_blocks.js Adds a regression test reproducing the stale-parent / wrong-top-level-script scenario.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 14, 2026

Test Results

    4 files    956 suites   12m 59s ⏱️
2 323 tests 2 315 ✅  8 💤 0 ❌
5 650 runs  5 612 ✅ 38 💤 0 ❌

Results for commit 25588f0.

♻️ This comment has been updated with latest results.

@cwillisf cwillisf merged commit 1074d9e into develop Apr 14, 2026
17 checks passed
@cwillisf cwillisf deleted the fix-scratch-blocks-3541 branch April 14, 2026 15:59
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 14, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

clicking on a reporter removed from a stack can run that stack

2 participants