uber / react-digraph

A library for creating directed graph editors
MIT License
2.63k stars 268 forks source link

centerNodeOnMove not working right when it is False #324

Open AhmadYoussef opened 3 years ago

AhmadYoussef commented 3 years ago

Thank lots for all the hard work. It really is a great library.

I would like to report a bug here:

After I updated the library to version 7.1.0, I got the bug that when I set centerNodeOnMove= false, the node does not move as it should.

So I switched back to V 7.0.0 to solve the problem ... but now when I select a node and click backspace while writing in input, the selected node is directly deleted ... so is there any way to turn off this event in version 7.0.0 using ref?

Otherwise, it would be nice if someone could solve the problem.

Hint: I have tried all versions after 7.0.0 and I get the same error that the node is moved incorrectly when centerNodeOnMove= false

AhmadYoussef commented 3 years ago

I did today a debug to the code and I found out that this line is rendering while the node is moving https://github.com/uber/react-digraph/blob/1ab55aa99fbbadb18737a7f380d2ebdec3db116a/src/components/node.js#L117

so it will rewrite the pointerOffset. so I decided to remove the assigned value and move it to useRef in this line

https://github.com/uber/react-digraph/blob/1ab55aa99fbbadb18737a7f380d2ebdec3db116a/src/components/node.js#L112

and I made it like this :

  const position = useRef({
    x: data.x || 0,
    y: data.y || 0,
    pointerOffset: null,
  });

but I am not sure if this will not work correctly with another function ... but I test it and it looks fine.

I hope you will fix the problem in the next version.