Can/Should the HTML render of a LiveView vary depending on `connected?`?

I am contributing to a project where I observe a pattern such that sometimes inside a LiveView mount/3 we check for if connected?(socket) and only when true do we do an expensive database fetch and put the list in the assigns.

I have historically assumed that there was a LiveView expectation that the rendered template from the initial non-connected render should be the same as the connected render. Partially this is to solve for the wanted benefit of a user/browser/robot who does not have Javascript and still gets a valid HTML page (not a concern for our specific app since it is not a public website) — however, the second reason I thought would have been for the change tracking innards of LiveView.

Wouldn’t LiveView need those renders to align for the change tracking to work properly?

Or am I to understand it such that once the websocket connection happens, LiveView dumps the entirety of the previous render and replaces it with the outcome of the second “connected render” and uses that as the starting point of change tracking?

Thanks for your help.


No. Everything is re-transmitted in the connected mode.


It depends™ . You are right that rendering the same content on the initial HTTP render is advantageous for crawlers, but many pages do not need SEO, and if you have otherwise expensive work, it’s helpful to offload that to the connected state. So falling back to the connected render puts you in the same camp of SPAs, which have no problem taking this approach.