Issue with Version 10 Upgrade: Uncaught Error: Connection lists did not match in length.

36 views
Skip to first unread message

Mia

unread,
Jun 28, 2024, 4:26:23 PMJun 28
to Blockly
  After upgrading to version 10, I encountered the following error:

Uncaught Error: Connection lists did not match in length.

This error occurs when I try to detach a loop block from an objects block. Below is the code for my objects block:

Blockly.Blocks['objects'] = {
    init: function() {
      this.appendDummyInput()
          .appendField("object");
      this.setPreviousStatement(true, null);
      this.setNextStatement(true, null);
      this.setColour(230);
      this.setTooltip('');
      this.setHelpUrl('');
    },
    onchange: function(event) {
        let previousBlock = this.getPreviousBlock();
        if (previousBlock && previousBlock.type === 'loop') {
          this.setNextStatement(false);
        } else {
          this.setNextStatement(true, null);
        }
    }
};

Has anyone else encountered this issue or can provide insight on how to resolve it?

Thank you in advance for your help!

Christopher Allen

unread,
Jun 28, 2024, 5:13:59 PMJun 28
to blo...@googlegroups.com
Hi Mia,

  After upgrading to version 10, I encountered the following error:

Uncaught Error: Connection lists did not match in length.

This error occurs when I try to detach a loop block from an objects block.

This error is most commonly caused when attempting to show insertion markers for a block that can mutate but which does not properly serialise its state.

Specifically: in order to show an insertion marker, a copy of the block must be made.  This is done by serialising the block and then deserialising it, and it is necessary that the deserialised copy have the same "shape"—in particular, exactly the same inputs and connections—as the original.
 

Below is the code for my objects block:

Blockly.Blocks['objects'] = {
    init: function() {
      this.appendDummyInput()
          .appendField("object");
      this.setPreviousStatement(true, null);
      this.setNextStatement(true, null);
      this.setColour(230);
      this.setTooltip('');
      this.setHelpUrl('');
    },
    onchange: function(event) {
        let previousBlock = this.getPreviousBlock();
        if (previousBlock && previousBlock.type === 'loop') {
          this.setNextStatement(false);
        } else {
          this.setNextStatement(true, null);
        }
    }
};


So this block changes shape—by adding or removing a next statement connection—but the deserialised copy will always have the next statement connection, and so a mismatch occurs.  You will need to add saveExtraState and loadExtraState methods to record and restore the presence/absence of the next statement connection so that the copy has the same shape as the original.


Best wishes,

Christopher



Mia

unread,
Jul 1, 2024, 7:56:17 AMJul 1
to Blockly

Hi Christopher,

Thank you for your help. I have added the saveExtraState and loadExtraState methods to my objects block as you suggested.

Best regards, 

Mia


2024年6月29日土曜日 6:13:59 UTC+9 cpca...@google.com:
Reply all
Reply to author
Forward
0 new messages