Why does liveview auth use phx-update="ignore"?

The new phx.gen.auth in Phoenix 1.7 uses phx-update="ignore" on the form. I’ve read the docs on that attribute, and don’t understand why it’s relevant in this scenario. Why is phx.gen.auth going out of its way to prevent an update on this form?

The docs:

A container can be marked with phx-update, allowing the DOM patch operations to avoid updating or removing portions of the LiveView, or to append or prepend the updates rather than replacing the existing contents. This is useful for client-side interop with existing libraries that do their own DOM operations.

The code:

  <.simple_form
    :let={f}
    id="login_form"
    for={:user}
    action={~p"/users/log_in"}
    as={:user}
    phx-update="ignore"
  >
    <.input field={{f, :email}} type="email" label="Email" required />
    <.input field={{f, :password}} type="password" label="Password" required />

    <:actions :let={f}>
      <.input field={{f, :remember_me}} type="checkbox" label="Keep me logged in" />
      <.link href={~p"/users/reset_password"} class="text-sm font-semibold">
        Forgot your password?
      </.link>
    </:actions>
    <:actions>
      <.button phx-disable-with="Signing in..." class="w-full">
        Sign in <span aria-hidden="true">→</span>
      </.button>
    </:actions>
  </.simple_form>

Thanks!

2 Likes

I would guess that’s because that liveview (UserLoginLive) which contains the form does not actually do anything with it, and the form itself points and does POST request to the UserSessionController which does the authentication logic, updates session etc. In a way this liveview is just a simple static form, with “live” part taken from it. :smile:

(these controller/liveview names assume you generated project with mix phx.gen.auth Accounts User users )


Now that I think of it - reply above does not exactly answers the question why?
My another guess would be - to be me explicit. There is no phx-change nor phx-submit on it, so it’s going to behave like a normal form (which is also indicated by specifying action on that form)

Aah, great point. I think the fact that it’s not connected with a changeset and submit is exactly it- it’s just a dummy page. Thanks a lot! The generators are a good source to know how to use Phoenix and this had me stumped.

1 Like