Skip to content

Don't call mount/3 of LiveView when the instruction of returns of hooks on mount is :halt - #1599

Closed
nallwhy wants to merge 1 commit into
phoenixframework:masterfrom
nallwhy:master
Closed

nallwhy wants to merge 1 commit into
phoenixframework:masterfrom
nallwhy:master

Conversation

@nallwhy

@nallwhy nallwhy commented Sep 3, 2021 •

Copy link
Copy Markdown
Contributor

It fixes #1598.

If you agree with this approach, I will keep work on it.

TODO

  • Add tests

@nallwhy nallwhy changed the title Don't call mount of LiveView when the instruction of mounted hooks is :halt Don't call mount/3 of LiveView when the instruction of mounted hooks is :halt Sep 3, 2021
@nallwhy nallwhy changed the title Don't call mount/3 of LiveView when the instruction of mounted hooks is :halt Don't call mount/3 of LiveView when the returned instruction of hooks on mount is :halt Sep 3, 2021
@nallwhy nallwhy changed the title Don't call mount/3 of LiveView when the returned instruction of hooks on mount is :halt Don't call mount/3 of LiveView when the instruction of returns of hooks on mount is :halt Sep 3, 2021
@mcrumm

mcrumm commented Sep 3, 2021

Copy link
Copy Markdown
Member

@nallwhy Looks good! There is already a test for redirect on mount, but we can update it to ensure the mount callback is not invoked on the LiveView.

In the test support lifecycle module, look for RedirectMount and add the following mount callback:

# Phoenix.LiveViewTest.HooksLive.RedirectMount

  def mount(_, _, socket) do
    case socket.assigns.live_action do
      :halt -> raise "mount should not have been called"
      _ -> {:ok, socket}
    end
  end

then once the tests are passing we can :shipit:

@mcrumm

mcrumm commented Sep 3, 2021

Copy link
Copy Markdown
Member

I am working on another fix too, so I went ahead and merged this with the test changes, thanks so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LiveView callback is invoked when a hook mounted by on_mount/1 returns {:halt, socket}

2 participants