Shared state

We know that shared state is sent from server to client when needed but ¿how it really works?

These are some questions about the matter:
¿why is needed if we have bidirectional RPCs? ¿in order to rebuild the client when the page is refreshed?
¿how big the shared info could/must it be?
¿how is synchronized, the whole object or only the changed properties?
and finally ¿what about nested objects in the shared state object?

Any ideas you have would be greatly appreciated.

  • Oscar

Things are not just black and white, but shared state is primarily for more static state information (caption of a field, …) whereas RPC is mostly for events (“X was clicked” or “here is the next batch of lazy loaded data you requested”). When e.g. the page is refreshed (with @PreserveOnRefresh), shared state is re-sent but once an RPC call has been sent it is forgotten by the sender.

Shared state should be as small or as big as makes sense from the point of view of such data that needs to be sent from the server to the client. You shouldn’t send hundreds of thousands of items over it but rather use lazy loading if you have data that big.

Normally, only the changed properties of the shared state are sent. If a collection changes, the whole collection is re-sent - there is an enhancement request to optimize that, but that is a framework internal implementation detail that should not be visible outside the framework except as a further performance improvement.

Nested objects in the shared state should work in most cases as long as the actual types match the declared types. Polymorphism is not supported for objects in the shared state.