Phoenix LiveView app performs full page reloads on internal navigation instead of using LiveView's client-side navigation. This causes unnecessary re-renders and loses LiveView state.
The root cause was LiveView routes not being wrapped in a live_session block, and using <a href="..."> instead of <.link navigate={...}> for internal navigation links. Without live_session, every navigation between LiveView pages causes a full page reload, which creates a new WebSocket connection.
Fix:
- Wrap LiveView routes in
live_session:
live_session :public do
live "/", HomeLive
live "/about", AboutLive
end
- Use
<.link navigate={...}>instead of<a href="...">for internal links:
<.link navigate={~p"/about"}>About</.link>
This ensures navigation happens over the existing WebSocket connection (client-side) instead of triggering full page reloads that create new WebSocket connections.