Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wants to merge 1 commit into from

Conversation

nallwhy
Copy link
Contributor

@nallwhy nallwhy commented Sep 3, 2021

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
Copy link
Member

mcrumm commented Sep 3, 2021

@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
Copy link
Member

mcrumm commented Sep 3, 2021

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