Skip to content

Commit

Permalink
Don't call mount of LiveView when the instruction of mounted hooks is…
Browse files Browse the repository at this point in the history
… :halt
  • Loading branch information
nallwhy committed Sep 3, 2021
1 parent 1b29c9b commit 18b9cb3
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/phoenix_live_view/utils.ex
Original file line number Diff line number Diff line change
Expand Up @@ -288,16 +288,18 @@ defmodule Phoenix.LiveView.Utils do
Calls the `c:Phoenix.LiveView.mount/3` callback, otherwise returns the socket as is.
"""
def maybe_call_live_view_mount!(%Socket{} = socket, view, params, session) do
{_, %Socket{} = socket} = Lifecycle.mount(params, session, socket)
{cont_or_halt, %Socket{} = socket} = Lifecycle.mount(params, session, socket)

if function_exported?(view, :mount, 3) do
:telemetry.span(
[:phoenix, :live_view, :mount],
%{socket: socket, params: params, session: session},
fn ->
socket =
params
|> view.mount(session, socket)
case cont_or_halt do
:cont -> view.mount(params, session, socket)
:halt -> socket
end
|> handle_mount_result!({:mount, 3, view})

{socket, %{socket: socket, params: params, session: session}}
Expand Down

0 comments on commit 18b9cb3

Please sign in to comment.