formState.isSubmitting stays true when the fetcher's submitting and idle states land in one render

Open Beginner friendly
#188 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
82/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
react, typescript
Domain
frontend

Research direction

Start in the useRemixForm implementation and find the effect that clears isSubmittingNetwork when isSubmittingForm is false. Reproduce the issue with a fast action and fetcher form using createRoutesStub; the issue provides the proposed dependency change. Done means formState.isSubmitting resets after the response, including when it contains errors, and the submit button re-enables.

Written by the indexing model from the issue text.

Description

useRemixForm sets isSubmittingNetwork to true in onSubmit and only clears it in an effect that depends on [isSubmittingForm]. When the action responds quickly, React Router can apply the fetcher's submitting and idle states in a single render. isSubmittingForm then stays false the whole time, the effect never re-runs, and formState.isSubmitting stays true until the component remounts. The form's submit button stays disabled after the response, including when the response has errors.

Reproduction: a route whose action returns immediately (for example () => ({ errors: { root: { message: 'Save failed' } } })) and a fetcher form whose button uses disabled={formState.isSubmitting}. Rendered with createRoutesStub in a unit test, it reproduces every time: the error shows, but the button never re-enables. In the browser it happens when the response arrives before React renders the submitting state, which we saw with a busy main thread.

Fix we're using as a patch: also reset when new data arrives:

useEffect(() => {
  if (!isSubmittingForm) {
    setIsSubmittingNetwork(false);
  }
}, [isSubmittingForm, data]);

Seen on 7.2.1. 7.3.0 and main have the same effect.

Dominant language
TypeScript
Stars
454
Forks
44
PR merge metrics
No merged PRs in 30d

Getting set up

  • No Dockerfile or Docker Compose file
  • Has a pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from code-forge-io/remix-hook-form

All issues in code-forge-io/remix-hook-form

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.