React-diagrams: links deSerialize problem

Created on 11 Apr 2017  路  13Comments  路  Source: projectstorm/react-diagrams

I've faced a problem. While deserializing simple diagram with custom nodes and ports this line returns null. But if I call it in a few msec - it returns correct value.
It seems the canvas doesn't rendered yet when this code is run.

Where could be a problem?

diagramEngine.js - getNodePortElement()

var selector = this.canvas.querySelector('.port[data-name="' + port.getName() + '"][data-nodeid="' + port.getParent().getID()+'"]');
bug

Most helpful comment

Thanks for taking the time to do this, Ill jump onto this shortly and see what I can do.

All 13 comments

does this still happen in the 2.4.8?

Yes, it throws an error now "Cannot find Node Port element with nodeID:..."
It looks like just fired before the model was serialized.
I am making a request to a server and trying to serialize the model.

how code looks like

componentDidMount() {

    API.httpGet('/stage')
      .then((stageJson) => {
        let model2 = new SRD.DiagramModel();
        this.state.engine.setDiagramModel(model2);
        model2.deSerializeDiagram(stageJson, this.state.engine);
        subscribeModel(model2); //subscribe to model events
        this.setState({model:model2});
        _.each(model2.getNodes(),subscribeNode.bind(this)); //subscribe to node events
        this.forceUpdate()
      });
  }

I had the same error. I created a new LinkWidget and LinkFactory. I'm searching where can be the problem.

I a workaround that I made is reimporting 2 times, with a timeout of 100 milliseconds.

  serializationImport() {
    try {
      // Parse the JSON
      let object = JSON.parse(this.state.serializationInput);

      // Create a new Model
      let newModel = new SRD.DiagramModel();
      newModel.deSerializeDiagram(object, this.engine);

      // Render the `newModel`
      this.model = newModel;
      this.engine.setDiagramModel(newModel);
      this.forceUpdate();

      this._tempTimeout = setTimeout(() => {
        this.serializationImport();
        clearTimeout(this._tempTimeout);
      }, 100);

    } finally {
      this.toggleSerializationModal();
    }
  }

I have a similar issue. I am using default factories. When I deserialize the diagram with a new engine and empty model links don't get created with an error like

Cannot find Node Port element with nodeID: [1e0a6c3f-592b-49ab-a953-0b8eb67e1a55] and name: [sensorValue]

If I deserialize the model twice links appear. Probably something to do with deserialization order. Nodes need to be created before the links are created. I can see this in the logs as well, first links are added and then removed due to the node not found error message.

arghhh race conditions :C If you can provide me with a test case ill try fix it

Hi, Thanks for looking into this. I have created a small example. When app is running clicking save, clear, load buttons reproduces the issue.

Thanks for taking the time to do this, Ill jump onto this shortly and see what I can do.

Any update on this?

Hold on, I think I got it. I'll send a PR in a few minutes.

I think this is fixed in PR #80 , can anyone confirm?

Fixed in caadbf4a9a0b03bde4ee32c5f1b9789ee7ed34bb

Fixed in 2.5.2

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Naveenraj006 picture Naveenraj006  路  3Comments

abhijitnandy2011 picture abhijitnandy2011  路  3Comments

kmannislands picture kmannislands  路  3Comments

duvet86 picture duvet86  路  3Comments

iddan picture iddan  路  3Comments