Mirror issues

32 views
Skip to first unread message

co...@cortscorner.net

unread,
Jun 20, 2024, 1:27:25 PM (9 days ago) Jun 20
to Blockly
Hi,

In one of my blockly app (gearsbot), I'm mirroring one workspace to another. I found a case where the mirroring isn't carried out correctly.

To replicate...

- Add an "else" to the "if" block.
- Add a "print" to the "else".
- Add an "else if" to the "if" block.

You should see that the "print" remains in the "else" within the first workspace, but in the mirrored workspace, the "print" is disconnected. Same issue on my own application, and as far as I can tell, all events are being mirrored. So maybe the first workspace is doing something that isn't generating an event?

Any ideas how I can fix or work around this?

Maribeth Moffatt

unread,
Jun 21, 2024, 2:20:46 AM (9 days ago) Jun 21
to Blockly
Hey, thanks for reporting this issue! Definitely seems like a bug somewhere in core. Unfortunately I don't have workaround ideas until someone has poked more at this issue but we will post updates on the GitHub issue you filed. Thanks!

Maribeth

Christopher Allen

unread,
Jun 28, 2024, 6:03:05 AM (yesterday) Jun 28
to blo...@googlegroups.com
Hi Cort,

On Fri, 21 Jun 2024 at 07:20, 'Maribeth Moffatt' via Blockly wrote:
Hey, thanks for reporting this issue! Definitely seems like a bug somewhere in core. Unfortunately I don't have workaround ideas until someone has poked more at this issue but we will post updates on the GitHub issue you filed. Thanks!

By now you have probably seen the root cause analysis I posted last night on the issue you opened (thanks for that, by the way!)

While we figure out the best way to properly resolve this issue, you should be able to work around it by making a copy of the CONTROLS_IF_MUTATOR_MIXIN from blocks/logic.ts into your own code then modifying the loadExtraState method as follows:

  loadExtraState: function (state) {
    this.elseifCount_ = state['elseIfCount'] || 0;
    this.elseCount_ = state['hasElse'] ? 1 : 0;
    this.rebuildShape_();
  },


Then, before calling inject, unregister the existing one and register your patched copy:

Blockly.Extensions.unregister('controls_if_mutator');
Blockly.Extensions.registerMutator(
  'controls_if_mutator',
  CONTROLS_IF_MUTATOR_MIXIN,
  null,
  ['controls_if_elseif', 'controls_if_else'],
);

This is kind of a faff but isn't technically monkey patching, so that's something…

(No promises that this workaround doesn't introduce some other problems, though—it's untested except for the specific reproduction steps you gave us.)


Best wishes,

Christopher

Reply all
Reply to author
Forward
0 new messages