Detecting a LiveView reconnect in mount

I have a LiveView where on mount, I stream a large amount of data to a Javascript grid (AG Grid). When a LiveView reconnects (like from a deploy and restarting the server), I don’t want to resend all that data again; the only state that I need to rehydrate on the server side comes from forms.

Is there anything like a reconnected?/1 function that I can use to detect when a reconnection happens on mount that way I can forgo streaming the grid data again?

I know I can engineer a solution using JS hooks and having the LV ask the hook if it’s already “mounted” before sending the data, but would be nice if there was a built in way.

Thanks for the help!

2 Likes

We send up a _mounts connect param
https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.html#get_connect_params/1-reserved-params

3 Likes

Awesome, thank you!!