Skip to content

Refactor block event handling and add load_model gizmo support - #467

Merged
tracygardner merged 2 commits into
mainfrom
claude/model-block-live-updates-awzHi
Mar 26, 2026
Merged

Refactor block event handling and add load_model gizmo support#467
tracygardner merged 2 commits into
mainfrom
claude/model-block-live-updates-awzHi

Conversation

@tracygardner

@tracygardnertracygardner commented Mar 24, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR improves the event handling logic in block models and extends gizmo support to include the load_model type.

Key Changes

  • Refactored block event handling in blocks/models.js:

    • Reorganized the conditional logic for processing block change events to be more explicit and maintainable
    • Moved handleMeshLifecycleChange check to execute first when the event targets this block or represents a block creation
    • Consolidated handleParentLinkedUpdate and handleFieldOrChildChange checks into a single conditional block
    • Removed the inverted logic condition that was checking this.id !== changeEvent.blockId && changeEvent.type !== Blockly.Events.BLOCK_CHANGE && !isThisBlockCreated
  • Added load_model gizmo case in ui/gizmos.js:

    • Extended the gizmo toggle switch statement to handle the load_model case alongside existing model loading cases (load_multi_object, load_object, load_character)

Implementation Details

The refactoring in blocks/models.js improves code clarity by:

  1. First handling mesh lifecycle changes for directly targeted blocks
  2. Then handling parent-linked updates and field/child changes
  3. Using positive conditions instead of negated logic, making the flow easier to follow and maintain

https://claude.ai/code/session_01CVKFvSifik74xZnSM6Fdwp

Summary by CodeRabbit

  • Bug Fixes
    • Refined the event-handling pipeline for model-loading blocks, improving lifecycle management and reliability
    • Extended gizmo functionality to fully support resize operations on model-loading blocks
    • Improved mesh identifier generation with a deterministic naming strategy for better consistency and stability across block instances

- Add load_model to scale gizmo switch case in gizmos.js so dragging
the scale gizmo creates/updates a resize block in the DO section,
consistent with load_character/load_object/load_multi_object
- Update load_model block handler to use handleParentLinkedUpdate
alongside handleFieldOrChildChange, matching the load_multi_object
pattern so BLOCK_CREATE events on value-input children (e.g.
connecting a number block to X/Y/Z/SCALE) also trigger mesh updates
https://claude.ai/code/session_01CVKFvSifik74xZnSM6Fdwp
@coderabbitai

coderabbitaiBot commented Mar 24, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 46520124-336f-44cf-90c5-b715e148208d

📥 Commits

Reviewing files that changed from the base of the PR and between e70f4a8 and 0a1f606.

📒 Files selected for processing (1)
  • ui/addmeshes.js

📝 Walkthrough

Walkthrough

Event-processing for load_model blocks was reordered to handle mesh-lifecycle events earlier and to unify parent-linked and field/child update short-circuiting. Separately, gizmo scale handling was extended for load_model, and mesh ID/mapping for load_model became deterministic using modelName__block.id.

Changes

Cohort / File(s)Summary
Event Handler Refactoring
blocks/models.js
Reordered load_model event pipeline: prioritize mesh lifecycle handling for events targeting the block or snippet-creation membership, then short-circuit when parent-linked or field/child handlers handle the event. No exported API changes.
Gizmo Scale Support
ui/gizmos.js
Added case "load_model": to the scale gizmo onDragEndObservable switch so load_model blocks run the same resize/DO-section update logic as other load_* block types.
Deterministic Mesh IDs & Mapping
ui/addmeshes.js
Changed mesh ID generation for load_model to ${modelName}__${block.id} and updated meshMap/meshBlockIdMap writes to use block.id as the key; flock.createModel now receives the deterministic model ID.

Sequence Diagram(s)

sequenceDiagram
rect rgba(200,200,255,0.5)
Actor Client
end
rect rgba(200,255,200,0.5)
Participant BlockHandler
Participant MeshLifecycleHandler
Participant ParentLinkedHandler
Participant FieldChildHandler
end
Client->>BlockHandler: emit changeEvent
BlockHandler->>MeshLifecycleHandler: check & handle lifecycle (if changeEvent.blockId === this.id or isThisBlockCreated)
alt Mesh lifecycle consumed
MeshLifecycleHandler-->>BlockHandler: handled
BlockHandler-->>Client: return (stop)
else Not consumed
BlockHandler->>ParentLinkedHandler: handleParentLinkedUpdate(this, changeEvent)
alt ParentLinkedHandler handled
ParentLinkedHandler-->>BlockHandler: handled
BlockHandler-->>Client: return (stop)
else
BlockHandler->>FieldChildHandler: handleFieldOrChildChange(this, changeEvent)
alt Field/child handled
FieldChildHandler-->>BlockHandler: handled
BlockHandler-->>Client: return (stop)
else
BlockHandler-->>Client: continue other processing
end
end
end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 I hopped through code and found the flow,

Meshs first, then parents — onward we go!
Gizmos stretched to fit my load_model friend,
IDs now follow a clear, shared end.
Hooray, the pipeline hops in tune — let's blend! 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check nameStatusExplanationResolution
Docstring Coverage⚠️ WarningDocstring coverage is 0.00% which is insufficient. The required threshold is 80.00%.Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check nameStatusExplanation
Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
Title check✅ PassedThe title accurately summarizes the two main changes in the pull request: refactoring block event handling logic and adding gizmo support for load_model blocks.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/model-block-live-updates-awzHi

Comment @coderabbitai help to get the list of available commands and usage tips.

Use `modelName__block.id` as meshId (matching load_object/load_character/
load_multi_object) so that after clearMeshMaps() is called, the meshMap
re-population via block.id matches the mesh's metadata.blockKey — allowing
the scale gizmo's onDragEndObservable to look up the block correctly.
https://claude.ai/code/session_01CVKFvSifik74xZnSM6Fdwp
@cloudflare-workers-and-pages

cloudflare-workers-and-pagesBot commented Mar 26, 2026

Copy link
Copy Markdown

Deploying flockdev with Cloudflare Pages Cloudflare Pages

Latest commit:0a1f606
Status: ✅ Deploy successful!
Preview URL:https://0a8fa149.flockdev.pages.dev
Branch Preview URL:https://claude-model-block-live-upda.flockdev.pages.dev

View logs

Sign up for freeto 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.

2 participants

@tracygardner@claude