How to stop calling domToMutation indefinitely on dragging connected block

61 views
Skip to first unread message

Harsh Chaturvedi

unread,
Feb 7, 2023, 3:31:43 AM2/7/23
to Blockly
Hi,

I have a block with mutation, in my domToMutation handler I'm calling an API to load new field values, this works as expected. The same handler (domToMutation) is called once when the block is dragged on the canvass.

ref - SetValue_Drag_DomToMutation SetValue_Drag_DomToMutation.png

However, if two of the same blocks are attached together, the domToMutation is called indefinitely on the drag action for both the blocks.

SetValue_Drag_Indefinite.png


How can I ensure that the domToMutation handler is called only once during the drag action (or that the domToMutation is only called once the drag ends).

TIA,
Harsh

Neil Fraser

unread,
Feb 10, 2023, 3:37:41 PM2/10/23
to Blockly
Really good catch.  That's definitely a bug on our end.  Filed here: https://github.com/google/blockly/issues/6839

Neil Fraser

unread,
Feb 10, 2023, 3:50:00 PM2/10/23
to Blockly
Of course us simply acknowledging that it's our bug doesn't help you in the mean time.  Sorry about that.

All you need to do to resolve the issue on your end is to add this line to the top of your domToMutation function:
  if (this.isInsertionMarker()) return;

Harsh Chaturvedi

unread,
Feb 16, 2023, 2:31:06 AM2/16/23
to Blockly
Thanks Neil.
I tried the work around and it works.

Reply all
Reply to author
Forward
0 new messages