Skip to content

Sign-up and forgot-password keep a stale server error on screen after a resubmit that fails client-side validation #1677

Description

@dawsontoth

Summary

SignUp and ForgotPassword put their server-failure text in react-hook-form's root error and
clear it with clearErrors('root') inside the submit handler. handleSubmit never calls that
handler when the resolver rejects, so a submission that fails client-side validation leaves the
previous server failure on screen next to the fresh field error.

Reproducing

  1. Sign-up: submit with an email that already exists → the form shows User already exists above
    the submit button (correct).
  2. Clear the email field, or make it invalid, and submit again.
  3. Please enter a valid email address. appears on the field — and User already exists is still
    there
    , describing an attempt that never left the browser.

ForgotPassword has the same shape (handleSubmit(submitForm) with the clear on the valid path
only), and now has one more root-error source since #1676's client fix routes retryable failures
there.

Why it isn't fixed alongside #1676

SignIn had the same defect and it was fixed there, by hanging the clear off handleSubmit's
second (invalid) argument — but sign-in keeps its failure in component state, not in RHF's root.
The same fix does not work for the RHF-root forms: extending
handleSubmit(submitForm, () => clearErrors('root')) to SignUp was tried and the test failed —
the root error is still rendered after a resolver-rejected resubmit. So these two need a different
mechanism (clear on field change, or move both onto component state the way SignIn now is), which
is a bigger change than that fix warranted and is why it was scoped out by the review's adjudication
rather than bundled in.

Note the repo's own comment at SignUp.tsx asserts the opposite of RHF's documented behaviour here
("handleSubmit reruns the resolver, which only rewrites field errors, so a stale root would
outlive the retry") — worth confirming which is true for the pinned RHF version as part of the fix,
since it determines whether the clear belongs on submit or on change.

Suggested direction

Unify the three auth forms on one mechanism. SignIn's component-state approach is the one with a
working clear-on-invalid story, so moving SignUp and ForgotPassword onto it also removes the
two-patterns-for-three-forms split the #1676 review flagged as an open decision
(signin-error-in-hook-state).

Impact

Cosmetic but confusing: two contradictory messages, one of them stale. No data or security
consequence. Found by the cross-model review on #1676's client fix, adjudicated as pre-existing.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    rumFrom real user monitoring where we aim to keep users happy

    Type

    Fields

    Priority

    P3

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions