vaadin / hilla

Build better business applications, faster. No more juggling REST endpoints or deciphering GraphQL queries. Hilla seamlessly connects Spring Boot and React to accelerate application development.
https://hilla.dev
Apache License 2.0
904 stars 57 forks source link

[Full-stack Signals] Add automatic resynchronization #2653

Closed platosha closed 6 days ago

platosha commented 1 month ago

A signal instance that has subscribers will automatically resynchronize with the server when the client reconnects to the server after having been disconnected. While disconnected, the signal value remains set to the value that was last seen before going losing the connection, supplemented with latency compensation for any pending operations. Pending operations that have been performed while disconnected will be sent to the server when the connection is restored (assuming the same client-side instance is still in active use).

const counter = CounterService.counter();

effect(() => console.log("Value update:", counter.value));

addEventListener("offline", () => {
  console.log("Value when going offline:", counter.value);

  // Will be logged immediately thanks to latency compensation but delivered to the server only when connectivity is restored
  counter.incrementBy(1);
});

addEventListener("online", () => {
  // Nothing to do here since any change from the server hasn't yet been retrieved but that will happen soon
});

Note that the implementation should also recover from network connectivity issues that cause the connection with the server to be broken even though the browser fires no offline and online events.

platosha commented 1 month ago

Workflow notes:

platosha commented 1 month ago

Note that every operation result is a custom thenable object.

Edit: Extracted to https://github.com/vaadin/hilla/issues/2712.

Legioth commented 3 weeks ago

Some parts of this issue have been extracted to separate tickets so that the core reliability feature can be implemented more easily:

platosha commented 3 weeks ago

Note: reusing Flux is not in the scope of this ticket. We assume here that the server has disposed the Flux instance.

platosha commented 3 weeks ago

For now, let us drop the concept of buffering the outgoing operations. At the same time, we have no guarantee yet on wether the outgoing operations were received by the server or not. We'll come back to this when we have a proper event log.

Legioth commented 3 weeks ago

Buffering operations and making sure they are delivered exactly once is now described in https://github.com/vaadin/hilla/issues/2721.