Skip to content

Fix/shadow top level scripts#543

Merged
cwillisf merged 2 commits intohotfix/scratch-blocks-release-triagefrom
fix/shadow-topLevel-scripts
Apr 29, 2026
Merged

Fix/shadow top level scripts#543
cwillisf merged 2 commits intohotfix/scratch-blocks-release-triagefrom
fix/shadow-topLevel-scripts

Conversation

@cwillisf
Copy link
Copy Markdown
Contributor

Resolves

Proposed Changes

Add a shadow check to createBlock in blocks.js so that shadow blocks arriving with topLevel: true are not added to _scripts. moveBlock already had this guard, but createBlock did not.

Reason for Changes

When Blockly respawns a shadow block (e.g. after uncovering a duplicated input), appendInternal creates the block before connecting it, so the create event arrives with topLevel: true. Without the shadow check, createBlock adds the shadow to _scripts. A shadow in _scripts causes toXML to 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

  • Regression test in engine_blocks.js: createBlock with a shadow block that has topLevel: true does not add it to _scripts, but does add it to _blocks

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.
@cwillisf cwillisf requested a review from Copilot April 25, 2026 00:04
@cwillisf cwillisf requested a review from a team as a code owner April 25, 2026 00:04
@cwillisf cwillisf changed the base branch from develop to hotfix/scratch-blocks-release-triage April 25, 2026 00:05
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

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.createBlock to only add blocks to _scripts when topLevel is true and the block is not a shadow.
  • Add a unit regression test ensuring top-level shadow blocks are stored in _blocks but 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.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 25, 2026

Test Results

    4 files    963 suites   13m 7s ⏱️
2 357 tests 2 349 ✅  8 💤 0 ❌
5 693 runs  5 655 ✅ 38 💤 0 ❌

Results for commit 88ec448.

♻️ This comment has been updated with latest results.

@cwillisf cwillisf merged commit c743c03 into hotfix/scratch-blocks-release-triage Apr 29, 2026
17 checks passed
@cwillisf cwillisf deleted the fix/shadow-topLevel-scripts branch April 29, 2026 13:02
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 29, 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.

2 participants