retejs / rete

JavaScript framework for visual programming
https://retejs.org
MIT License
10.17k stars 653 forks source link

Uncaught Error: Connection view not found #579

Closed FEskandariGM closed 1 year ago

FEskandariGM commented 2 years ago

I have defined a node with multiple outputs similar to this sample code : https://codepen.io/hatead1/pen/GaZYaq But the output connections to other nodes were not created when editing and retrieving the file through editor.fromJson . To solve this problem, I tried to manually connect the corresponding outputs to the adjacent nodes. In order to connect after creating the node and creating the corresponding control, first I created a list of non-exist connections including input_node_id, input_node_port, output_node_id and output_node_port in the json format with the name of Connection and then created the connection manually through the following code.

Connection.forEach(async function (conn) {

          let out_node = editor.nodes.find(n => n.id == conn.input_node_id);
          let inp_node = editor.nodes.find(n => n.id == conn.output_node_id);
          editor.connect(out_node.outputs.get(conn.input_node_port), inp_node.inputs.get(conn.output_node_port));   
              //this.trigger('connectioncreated', connection);
              setTimeout(() => { editor.view.updateConnections({ node: out_node }); }, 10);

              await out_node.update();
               setTimeout(() => { editor.view.updateConnections({ node: out_node }); }, 10);

              await inp_node.update();
              setTimeout(() => { editor.view.updateConnections({ node: inp_node }); }, 10);
})

Connections are created, but when in line editor.view.updateConnections , I get the following error message. Uncaught Error: Connection view not found Also, when changing the position of the connection node, it does not move along with the input and output sockets and leaves a fixed view.

When usingthis.trigger('connectioncreated', connection) by changing the location of the node, the connections are created in the new position, but the previous connections remain in place, and a crowded view of nodes and connections is created.

This problem only occurs for nodes created with this property, that is, multi-output nodes with a changeable number of outputs, and there is no problem when editing through the main editor environment. The problem only occurs when creating a connection manually. What should I do to create connections and change and move when moving and changing the size of the nodes connected to it?

rete-js[bot] commented 1 year ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 10 days.