Handle BLOCK_CREATE events for nested blocks in snippets#413
Handle BLOCK_CREATE events for nested blocks in snippets#413tracygardner merged 3 commits intomainfrom
Conversation
When a snippet (e.g. box or character) is dropped from the toolbox, Blockly fires a single BLOCK_CREATE event where changeEvent.blockId is the root block (e.g. `start`) but changeEvent.ids includes all created block IDs including nested ones like `create_box` or `load_character`. The block handlers were only calling handleMeshLifecycleChange when changeEvent.blockId === block.id, so nested creation blocks never got their meshes created on drop. Sky/ground blocks worked because they are in the special-cased list in updateOrCreateMeshFromBlock. Fix the guards in handleBlockChange (covers all create_* shape blocks) and the individual handlers for load_character, load_multi_object, and load_model to also trigger handleMeshLifecycleChange when the block's own id is found in changeEvent.ids during a BLOCK_CREATE event. https://claude.ai/code/session_01FZ6vktw81VhbPuv9QePcJE
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughLifecycle handling extended so BLOCK_CREATE events that include the current block's ID in Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
📝 Coding Plan
Comment |
When the Snippets flyout is open, window.loadingCode is set to true, which caused handleMeshLifecycleChange to skip mesh creation for all BLOCK_CREATE events — including when the user actually drops a snippet. Sky/ground had a special bypass; box snippets live in the Physics category (loadingCode=false). Characters in the Snippets category were silently blocked. Fix: only skip when loadingCode=true AND recordUndo=false (file loading). User-initiated drops always have recordUndo=true, so they now proceed to create the mesh even while the Snippets flyout is open. https://claude.ai/code/session_01FZ6vktw81VhbPuv9QePcJE
updateOrCreateMeshFromBlock also checked window.loadingCode unconditionally, which prevented createMeshOnCanvas from being called even after the fix in handleMeshLifecycleChange. Apply the same recordUndo distinction: skip only when loading saved code (recordUndo=false), not when user drops a block. https://claude.ai/code/session_01FZ6vktw81VhbPuv9QePcJE
Summary
This PR fixes handling of lifecycle events for blocks that are created as part of a snippet creation. Previously, blocks nested inside a snippet's root block would not properly handle their creation events because the event's
blockIdfield only contains the root block's ID, not the nested blocks' IDs.Key Changes
BLOCK_CREATEevents where the current block's ID is in thechangeEvent.idsarray (indicating the block was created as part of a multi-block creation like snippet instantiation)blocks/models.jsandblocks/blocks.js) to triggerhandleMeshLifecycleChangefor both:changeEvent.blockId === block.id)changeEvent.ids)Implementation Details
The fix introduces a reusable check that validates:
Blockly.Events.BLOCK_CREATEidsarray propertyThis allows blocks to properly initialize their mesh lifecycle state when created as part of a snippet, ensuring consistent behavior whether a block is created individually or as part of a larger structure.
https://claude.ai/code/session_01FZ6vktw81VhbPuv9QePcJE
Summary by CodeRabbit