Vaadin 8 and Javascript component share state

I migrate my Vaadin 7 Javascript component and fail into a behavior change in Vaadin 8. Share state are only ‘partially’ send, i.e. only diffs are sent.

Sadly, this completly breaks my JavaScript component, and I was wondering if ether is a way to change or control this behavior.

To me, this is the responsability of my component to decide whether or not diff state should be used or not.

Thanks

A late reply, but I believe you can override encodeJson() in your AbstractJavaScriptComponent, and use a simplified version of what the default implementation does (see the static method LegacyCommunicationManager.encodeState(connector, state)).

In case you need to take a look at it, I believe the client side is largely handled by JavaScriptConnectorHelper.processStateChanges() which in turn is indirectly triggered by MessageHandler.handleJSON() and the many methods in the Command implementation inside it.

Thanks, I finally end up overring JsonObject encodeState() to change the default implementation.

But this is sad there is no way to control whether you want diff state or not, depending on your javacript component. For me, this is the responsability of the component to decide on it. What I have done looks more like a hack. I would have prefer something like “useDiffState (false)” :slight_smile:

And as a side note, breaking behaviors between versions is not cool… even more when nothing is said about that.

For me, the way the data is sent over the wire is a low-level implementation detail that should be completely transparent to the component implementation. In particular, this.getState() in JavaScript should always return the full state regardless of whether the full state or only a diff has been sent.

In what way does your component depend on the way the data is sent?

As I was writing a AbstractJavaScriptComponent, what is send to the JS part is not completly transparent.

My Javascript component was completly stateless, and was expecting the complete state to be send. Wtih Vaadin 8, only a diff state of what has changed in this state was sent, so my JS object did not receive all the needed informations.

I have checked LegacyCommunicationManager.encodeState (used by AbstractClientConnector) to understand a little

so my ‘hack’ was to remove any previous state keep so to have a full state send…


@Override
public JsonObject encodeState() {
getUI().getConnectorTracker().setDiffState(this, null);
return LegacyCommunicationManager.encodeState(this, getState(false));
}

then, on the javascript part, writhing


this.onStateChange = function () {
var state = this.getState();

}

receive the whole state, not only a diff state

In your example, this.getState();
should
return the full state even without hacking encodeState(). If this is not a case, then that is a regression that we should fix. Please file a ticket with specific instructions on how to reproduce.