vaadin / flow

Vaadin Flow is a Java framework binding Vaadin web components to Java. This is part of Vaadin 10+.
Apache License 2.0
619 stars 167 forks source link

Binding a property to TemplateModel and changing it from client breaks StateTree. #2066

Closed pekam closed 3 years ago

pekam commented 7 years ago

I have a vaadin-grid in my Polymer-template and it updates the value of currentPatient-property when the user selects an item in the grid. I need to get the id of currentPatient so I bind it in the TemplateModel:

@Include("id")
@Convert(value = LongToStringConverter.class, path = "id")
void setCurrentPatient(Patient patient);

Patient getCurrentPatient();

Now selecting a patient in client sends a message to server as it should:

Sending xhr message to server: {
"csrfToken":"cb31a0b0-0bd8-4a1d-8235-30586cd74194",
"rpc":[{
  "type":"mSync",
  "node":4,"feature":1,
  "property":"currentPatient",
  "value":{
    "doctor":{"firstName":"Alma","lastName":"Burton","nodeId":204},
    "firstName":"Frederick",
    "lastName":"Wilson",
    "medicalRecord":"102",
    "lastVisit":"2011/07/29",
    "id":"1",
    "nodeId":205}}],
"syncId":1,
"clientId":1}

But this causes also the server to send a message back to client for some reason:

Received xhr message: for(;;);[{"syncId":2,"clientId":2,"changes":[
{"node":208,"type":"attach"},
{"node":208,"type":"put","key":"doctor","feat":1,"nodeValue":204},
{"node":208,"type":"put","key":"firstName","feat":1,"value":"Frederick"},
{"node":208,"type":"put","key":"lastName","feat":1,"value":"Wilson"},
{"node":208,"type":"put","key":"medicalRecord","feat":1,"value":"102"},
{"node":208,"type":"put","key":"lastVisit","feat":1,"value":"2011/07/29"},
{"node":208,"type":"put","key":"id","feat":1,"value":"1"}],"timings":[556,6]}]

And this causes the selected patient to become unselected immediately.

Selecting the same patient twice in a row causes:

java.lang.IllegalStateException: Unregistered node was not found based on its id. The tree is most likely corrupted.
        at com.vaadin.flow.StateTree.unregister(StateTree.java:129) ~[flow-server-0.1.14-SNAPSHOT.jar:na]
        at com.vaadin.flow.StateNode.handleOnDetach(StateNode.java:427) ~[flow-server-0.1.14-SNAPSHOT.jar:na]
        at com.vaadin.flow.StateNode.visitNodeTreeBottomUp(StateNode.java:378) ~[flow-server-0.1.14-SNAPSHOT.jar:na]
        at com.vaadin.flow.StateNode.onDetach(StateNode.java:208) ~[flow-server-0.1.14-SNAPSHOT.jar:na]
        at com.vaadin.flow.StateNode.setParent(StateNode.java:167) ~[flow-server-0.1.14-SNAPSHOT.jar:na]
        at com.vaadin.flow.nodefeature.NodeFeature.detatchPotentialChild(NodeFeature.java:94) ~[flow-server-0.1.14-SNAPSHOT.jar:na]
        at com.vaadin.flow.nodefeature.NodeMap.doPut(NodeMap.java:104) ~[flow-server-0.1.14-SNAPSHOT.jar:na]
        at com.vaadin.flow.nodefeature.NodeMap.put(NodeMap.java:91) ~[flow-server-0.1.14-SNAPSHOT.jar:na]
        at com.vaadin.flow.nodefeature.ElementPropertyMap.put(ElementPropertyMap.java:103) ~[flow-server-0.1.14-SNAPSHOT.jar:na]
        at com.vaadin.flow.nodefeature.NodeMap.updateFromClient(NodeMap.java:362) ~[flow-server-0.1.14-SNAPSHOT.jar:na]
        ...

This issue is maybe related to: https://github.com/vaadin/flow/issues/2035

pleku commented 7 years ago

@pekam can you verify whether this still reproduces ?

pekam commented 7 years ago

Yes, this still reproduces with the latest Flow-snapshot.

TatuLund commented 3 years ago

Is this fixed by https://github.com/vaadin/flow/pull/4787

At least the linked PR changes the code so that visitNodeTreeBottomUp(StateNode::handleOnDetach); has been removed from onDetach and flow presented in stacktrace is no longer possible.