flume icon indicating copy to clipboard operation
flume copied to clipboard

NodeEditor ignores changes to `nodes` parameter after initial render

Open NicWickman opened this issue 3 years ago • 9 comments

Unfortunately this seems to be by design, but it complicates what should be the basic function of loading in a graph.

NodeEditor provides a way to retrieve the nodes and I am saving them out to localStorage, but I'm unable to actually populate the graph with any nodes by manually changing the nodes object after the editor has been rendered.

NicWickman avatar Oct 23 '21 01:10 NicWickman

I just realized this was closed, but might actually be my problem. Did you ever find a work-around for this?

Dante83 avatar Jan 20 '22 04:01 Dante83

I found a work around here. You can assign the key prop of the NodeEditor component and tap into which ever event is modifying the nodes and change the key as well.

for eg: if this.props.nodes is what's changing.

  componentDidUpdate(prevProps) {
    if (this.props.nodes !== prevProps.nodes) {
      this.ukey = (new Date()).toISOString(); //not a good idea to use date, but works for testing
    }
  }

and render like

  render() {
    return (
        <NodeEditor
          ref={this.nodeEditor}
          portTypes={this.flconfig.portTypes}
          nodeTypes={this.flconfig.nodeTypes}
          nodes={this.props.nodes}
          context={this.props.context}
          onChange={this.handleChange}
          key={this.ukey}
        />
    );
  }

idling-mind avatar Jan 20 '22 12:01 idling-mind

@idling-mind That was helpful in keeping the nodes, but the connections don't seem to re-render for some reason.

State3

As you can see, it seems from the console.logged node that the connection is still there, but they're just not rendering after <NodeEditor> goes away, or is replaced (say I switch to one of the tabs on the top or switch out one key'd node editor for another by selecting it on the right.

(Initial State - the connections are drawn) State1

(Final State - I swapped views and came back, the nodes are there, the connection data is in tact from above, but the connections are now missing and no longer work). State2

Not sure where they're going, and I'm still a bit of a react noob, so maybe I'm overlooking some newbie mistake with react or redux, but of course, if the connection system breaks then I didn't do a good job of saving the state and the app is broken from then on. I would try digging into the source, but I'm not sure how to do that with an NPM JS project verses a traditional JS script.

Dante83 avatar Jan 21 '22 20:01 Dante83

I'm also not sure why the connection should disappear. May be try different versions of the libraries?

idling-mind avatar Jan 24 '22 06:01 idling-mind

I'm running into this problem in 0.8.0, which does not appear to still support the key property. Any suggestions on how to manually set the nodes in the editor?

wallw-teal avatar May 09 '22 20:05 wallw-teal

This is a consistent pain point from an original design decision that makes updating the nodes dynamically difficult for performance. I'm going to get this fixed so it wi work like you'd expect a controlled react component to work. I'm in the process of converting the whole library to typescript and then this feature is up next.

chrisjpatty avatar May 10 '22 01:05 chrisjpatty

Is there any update on this? I'm building a web app that uses this, and unfortunately I'm a react noob

minecraft2048 avatar Nov 02 '22 23:11 minecraft2048

Maybe creating a new imperative method to load the new nodes should work?

If we can't update the state directly for performance reasons, having a chance to update via a method can be good enough for most of the cases.

i`ve made a PR to propose a solution, hope you like it. (link)

danlobo avatar Nov 24 '22 13:11 danlobo

Any way to break into it would be awesome.

Dante83 avatar Nov 24 '22 16:11 Dante83