#v12 - Repetitive calling onNodeChanges after add

1 messages · Page 1 of 1 (latest)

tiny cipher
#

After migrating to v12,
Programmatically (onDrop) adding of nodes causing reactflow to repetitively call onNodeChanges despite custom node having fix width & height.

onNodeChanges is using the provided applyNodeChanges function (uncommited)

tiny cipher
dusky grove
#

Where can we find the flow?

white grove
#

Not exactly sure why you create your own "change" in here

    onDrop: e => {
      e.preventDefault();
      const { rfInstance, selNode, onNodesChange, onSelectionChange } = get();
      const type = e.dataTransfer.getData('application/reactflow') as NodeTypeKeys;
      if (!type || !rfInstance) {
        return;
      }
      const position = rfInstance.screenToFlowPosition({ x: e.clientX, y: e.clientY });
      const node = { id: nanoid(), type, position, selected: true, data: {} };
      const changes: NodeChange[] = [{ type: 'add', item: node }];
      if (selNode) {
        changes.push({ type: 'select', id: selNode.id, selected: false });
      }
      onNodesChange(changes);
      onSelectionChange({ nodes: [node], edges: [] });
    },

instead of using the built-in addNodes or setNodes function 🤔

Is there a specific reason for that?

tiny cipher
tiny cipher
tiny cipher
#

I will try to debug it more tomorrow / weekend.

This repetitive behavior isn't present in v11.
Changes made doesn't seem to introduce the bug either, but i might be wrong bcaGuiltySweat.

dusky grove
#

the issue is that you are not applying the dimensions correctly

#

this

if (dimensions) {
  node.width = dimensions.width;
  node.height = dimensions.height;
}

should be

if (dimensions) {
  node.computed = node.computed ?? {};
  node.computed.width = dimensions.width;
  node.computed.height = dimensions.height;
}
tiny cipher
tiny cipher
#

I tried using the provided applyNodeChanges and it's still re-calling the function multiple times.

dusky grove
#

which changes are coming in?

#

do your nodes change size after getting initialized?

tiny cipher
tiny cipher
dusky grove
#

you say that you get changes of type "add" ?