LiveView: Feature to "cancel" second render

Yes, but if the page actually uses any live features, you shouldn’t use auto_connect: false.

This came across my mind as well. Maybe what people actually want is a

defmodule MyAppWeb.DeadView do
  use Phoenix.DeadView

  def mount(params, session, conn) do
    conn
    |> assign(...)
    |> then(&{:ok, &1})
  end

  def render(assigns) do
    ~H"""
    ...
    """
  end
end

although mount might not be the correct terminology here. Then, to switch to a LiveView you “just” switch out the conn for a socket and replace use Phoenix.DeadView with use Phoenix.LiveView.

One drawback compared to auto_connect is that if you navigate to this page from a LiveView, the existing connection cannot be used and a regular request is performed instead.

1 Like