Stop mounting your LiveView twice

This title could be clearer and more informative.Try out Clickbait Shieldfor free (5 uses left this month).

Phoenix LiveView mounts twice on first page load — once for the static HTTP dead render and again when the WebSocket connects. The common fix of guarding data loads with `connected?/1` avoids double queries but breaks SEO, link previews, and no-JS fallback by leaving the dead render empty. This post explains why the double mount exists, what `connected?/1` actually costs, and introduces an experimental fork that parks the dead-render socket in a short-lived GenServer and redeems it on WebSocket connect — skipping the second mount entirely. The fork adds an `on_connect/1` callback for connection-only side effects (subscriptions, timers, presence) and provides migration patterns for data loads, connect params, and real-time data. The upstream Phoenix team is working on a more complete 'adoptable LiveViews' solution (issue #3551), but this fork serves as an interim stopgap.

26m read timeFrom elixirdrops.net
Post cover image
Table of contents
Why a LiveView renders twiceWhat connected?/1 actually costs youWhat the Phoenix team is building: adoptable LiveViewsThe interim: a fork that parks the dead-render socketWhat runs whenMigrating to resume: four patternsWhen to keep things in mount/3Verify it actually engaged — because it fails silently
719 Impressions