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