projectstorm / react-diagrams

a super simple, no-nonsense diagramming library written in react that just works
https://projectstorm.cloud/react-diagrams
MIT License
8.6k stars 1.17k forks source link

Unable to update custom node dimensions more then once. #753

Closed smashboy closed 3 years ago

smashboy commented 3 years ago

I'm trying to build dynamic nodes, but I'm not able to call updateDimensions multiple times. Width and height won't update on second call.

image

renato-bohler commented 3 years ago

Maybe you need to call this.editorEngine.repaintCanvas() inside the setTimeout callback?

smashboy commented 3 years ago

@renato-bohler I was trying that too, I can't undedstand how it works at all. I wrote handler in my custom Widget that should repaint canvas each time I'm trying to update dimensions, but it still doesn't work properly. TableNodeView is a RFC and I'm calling updateDimensions in useEffect on first mount to adjust size to content that is inside node. It is updating dimensions only when I click on table.

image

image

smashboy commented 3 years ago

Also I was trying to pass this.props.node.isSelected and this.props.node.updateDimensions directly to my RFC component and when they are called I'm getting errors, because of this issue also have to wrap or call functions directly in TableNodeWidget. UpdateDimensions throws Cannot read property 'width' of undefined, when width is hardcoded to function call.

image

smashboy commented 3 years ago

Also I don't think that calling repaintCanvas() is even doing something with dimensions. With or without calling repaintCanvas() it works the same.

smashboy commented 3 years ago

Looks like node is getting updated if I console.log dimensions after updating them in my updateDimenions method, but they are not getting passed to render function.

ilyaborodin commented 3 years ago

@smashboy did you find solution?

smashboy commented 3 years ago

@ilyaborodin Yes, it is a weird one. My NodeWidget component is wrapped in mobx observer and because of that new props were not passed to NodeWidget. So I've had to make observable part as a separate component in order to get new props. Btw not only dimensions were not getting updated, other props were not getting updated too. image