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

Aperta Adatta ai principianti
#188 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
82/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
react, typescript
Ambito
frontend

Direzione di ricerca

Inizia dall’implementazione di useRemixForm e individua l’effetto che reimposta isSubmittingNetwork quando isSubmittingForm è false. Riproduci il problema con un’action rapida e un modulo fetcher usando createRoutesStub; l’issue indica la modifica proposta alle dipendenze. Il lavoro è terminato quando formState.isSubmitting viene reimpostato dopo la risposta, anche se contiene errori, e il pulsante di invio si riattiva.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
TypeScript
Stelle
454
Fork
44
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

  • Nessun Dockerfile né file Docker Compose
  • Ha un modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di code-forge-io/remix-hook-form

Tutte le issue di code-forge-io/remix-hook-form

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.