Skip to content

Update to Blockly 12 with JSON serialization support#86

Open
B-head wants to merge 3 commits intomit-cml:mainfrom
B-head:update-to-blockly-12
Open

Update to Blockly 12 with JSON serialization support#86
B-head wants to merge 3 commits intomit-cml:mainfrom
B-head:update-to-blockly-12

Conversation

@B-head
Copy link

@B-head B-head commented Mar 21, 2026

Summary

  • Update dependencies to Blockly 12 (peerDependencies: ^12.0.0, devDependencies: ^12.5.1)
  • Fix generateUniqueName call that requires a workspace argument in Blockly 12
  • Add saveExtraState/loadExtraState to all blocks with mutations, fixing a crash when opening the Functions toolbox category

Context

This PR builds on the work started in #68 by @mjgallag and incorporates the fix suggested by @TannerGabriel in their review comment.

Blockly 12's flyout system generates JSON extraState for procedure caller blocks. Without loadExtraState, the deserialization falls back to textToDom() with a JSON object, causing DOMParser was unable to parse: [object Object].

This PR adds saveExtraState/loadExtraState to all six block types with mutations, while preserving the existing mutationToDom/domToMutation for XML backward compatibility.

Note on the local_declaration_statement mutator bug

The rendering error when adding a second variable via the mutator (reported in #68) could not be reproduced with Blockly 12.0.0 or 12.5.1.

Test plan

  • All 102 unit tests pass (88 existing + 14 new for saveExtraState/loadExtraState)
  • Tested with both Blockly 12.0.0 and 12.5.1
  • Manual verification: Functions category opens without error, caller blocks display correct arguments

B-head and others added 3 commits March 21, 2026 13:24
Update blockly and @blockly/dev-tools, @blockly/dev-scripts to
Blockly 12 compatible versions. Set peerDependencies to ^12.0.0
(verified working with 12.0.0).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Blockly 12 requires a workspace argument for
Blockly.Variables.generateUniqueName(). Fall back to the main workspace
if the source block is not yet attached.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Blockly 12's flyout generates JSON extraState for procedure caller
blocks, but the plugin only had XML-based mutationToDom/domToMutation.
This caused a crash when opening the Functions toolbox category
because loadExtraState fell back to textToDom with a JSON object.

Add saveExtraState/loadExtraState to all blocks with mutations:
- procedures_callnoreturn / procedures_callreturn
- procedures_defnoreturn / procedures_defreturn
- local_declaration_statement / local_declaration_expression

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant