Fix/shadow top level scripts#543
Merged
cwillisf merged 2 commits intohotfix/scratch-blocks-release-triagefrom Apr 29, 2026
Merged
Fix/shadow top level scripts#543cwillisf merged 2 commits intohotfix/scratch-blocks-release-triagefrom
cwillisf merged 2 commits intohotfix/scratch-blocks-release-triagefrom
Conversation
When Blockly respawns a shadow (e.g. after uncovering a duplicated input), the create event arrives with topLevel:true because appendInternal creates the block before connecting it. A shadow in _scripts causes "Workspace Update Error" on sprite switch because toXML serializes it as a root <shadow> element that Blockly cannot load. This test currently fails — the fix follows in the next commit.
createBlock added any block with topLevel:true to _scripts without checking the shadow flag. moveBlock already had this guard, but createBlock did not. Add the same check so that shadow blocks created via Blockly's respawnShadow_ (which fires a create event with topLevel:true before connecting the shadow) cannot pollute _scripts.
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a defense-in-depth guard in the VM’s block creation path to prevent shadow blocks (incorrectly marked topLevel: true by Blockly during respawn) from being tracked as top-level scripts, which can otherwise break serialization/loading on sprite switch.
Changes:
- Update
Blocks.createBlockto only add blocks to_scriptswhentopLevelis true and the block is not a shadow. - Add a unit regression test ensuring top-level shadow blocks are stored in
_blocksbut never added to_scripts.
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 | Prevents createBlock from adding shadow blocks to _scripts when topLevel: true. |
| packages/scratch-vm/test/unit/engine_blocks.js | Adds regression coverage for the top-level shadow create event scenario. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
Test Results 4 files 963 suites 13m 7s ⏱️ Results for commit 88ec448. ♻️ This comment has been updated with latest results. |
c743c03
into
hotfix/scratch-blocks-release-triage
17 checks passed
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
Add a shadow check to
createBlockinblocks.jsso that shadow blocks arriving withtopLevel: trueare not added to_scripts.moveBlockalready had this guard, butcreateBlockdid not.Reason for Changes
When Blockly respawns a shadow block (e.g. after uncovering a duplicated input),
appendInternalcreates the block before connecting it, so the create event arrives withtopLevel: true. Without the shadow check,createBlockadds the shadow to_scripts. A shadow in_scriptscausestoXMLto serialize it as a root<shadow>element on sprite switch, which Blockly cannot load, producing "Workspace Update Error" and preventing all subsequent scripts from rendering.The root cause (shadow state corruption in
stripIds) is fixed in scratchfoundation/scratch-blocks#3570. This change is defense-in-depth: even if a future code path creates a top-level shadow, the VM will not add it to_scripts.Test Coverage
engine_blocks.js:createBlockwith a shadow block that hastopLevel: truedoes not add it to_scripts, but does add it to_blocks