In this scenario, the LiveView “goes back to mount” because it crashed and was replaced by a new LiveView, which knows nothing about the old one.
If you’re going to go through the effort of reporting the crash, you might as well just fix the error to not crash the LiveView! Within intended_effects()
just like in handle_event
you should have all possible cases accounted for (this is the standard in a functional language). If there is an error case, a changeset should be returned containing the errors and these errors displayed in the LV. It should never result in a LV crash.
Are you using Ecto to handle your data? Generally the Ecto callbacks return {:ok, struct}
on success, and {:error, changeset}
on failure. Then you can wrap them in a case statement like shown earlier:
case Accounts.update_user_password(user, password, user_params) do
{:ok, _user} ->
socket = put_flash(socket, :info, "Password updated successfully.")
{:noreply, socket}
{:error, changeset} ->
socket = assign(socket, password_changeset: changeset)
{:noreply, socket}
end
and display the errors to the user (here the example is for a password reset form)
<%= f = form_for @password_changeset, "#", phx_submit: "change_password" %>
<%= if @password_changeset.action do %>
<div class="alert alert-danger">
<p>Oops, something went wrong! Please check the errors below.</p>
</div>
<% end %>
<%= label f, :password, "New password" %>
<%= password_input f, :password %>
<%= error_tag f, :password %>
<%= label f, :current_password, "Current password" %>
<%= password_input f, :current_password %>
<%= error_tag f, :current_password %>
<%= submit "Change password" %>
</form>