messense / leptos_sse

Leptos server signals synced through Server-Sent-Events (SSE)
Other
29 stars 9 forks source link

Creating Signal later in client code breaks stream #4

Open smessmer opened 1 year ago

smessmer commented 1 year ago

create_sse_signal seems to work correctly when called during server side rendering and then hydrated on the client, but if it gets called later in the client stage, for example when the client router switches pages and the new page component calls create_sse_signal, then the signal just returns None and forgets that the sse channel is already established and the server already sent a value previously. Any further updates sent from the server do trigger a signal update, but if it's an unchanged value sending an empty patch, then it just changes from None to None. If the server sends a changed value, then applying the patch fails on the client with an error.

smessmer commented 1 year ago

I think the issue might be that any events that were already sent on the sse channel before the signal is created are ignored.