fix: clear parent when block is removed from input with shadow#525
Merged
Conversation
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
Contributor
There was a problem hiding this comment.
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
parentwhen 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.
Contributor
Test Results 4 files 956 suites 12m 59s ⏱️ Results for commit 25588f0. ♻️ This comment has been updated with latest results. |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
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
getTopLevelScriptto 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