@@ -990,4 +990,61 @@ describe("ReactFinalForm", () => {
990990 fireEvent . focus ( getByTestId ( "password" ) ) ;
991991 expect ( getByTestId ( "password" ) . value ) . toBe ( "f1nal-f0rm-RULEZ" ) ;
992992 } ) ;
993+
994+ it ( "should set submitting back to false when onSubmit returns Promise.resolve() immediately (#903)" , async ( ) => {
995+ // Regression test for: https://github.com/final-form/react-final-form/issues/903
996+ // When onSubmit is an async function with no awaits (returns Promise<void>),
997+ // submitting should reset to false after the promise resolves.
998+ const onSubmit = jest . fn ( async ( ) => {
999+ // async with no await — resolves in the next microtask, no real async delay
1000+ } ) ;
1001+ const recordSubmitting = jest . fn ( ) ;
1002+ const { getByText } = render (
1003+ < Form onSubmit = { onSubmit } subscription = { { submitting : true } } >
1004+ { ( { handleSubmit, submitting } ) => {
1005+ recordSubmitting ( submitting ) ;
1006+ return (
1007+ < form onSubmit = { handleSubmit } >
1008+ < Field name = "name" component = "input" />
1009+ < button type = "submit" > Submit</ button >
1010+ </ form >
1011+ ) ;
1012+ } }
1013+ </ Form > ,
1014+ ) ;
1015+
1016+ fireEvent . click ( getByText ( "Submit" ) ) ;
1017+
1018+ // Wait for the microtask Promise to resolve and React to update
1019+ await act ( async ( ) => { } ) ;
1020+
1021+ // submitting should have gone true then back to false
1022+ const calls = recordSubmitting . mock . calls . map ( ( c ) => c [ 0 ] ) ;
1023+ expect ( calls ) . toContain ( true ) ; // was submitting at some point
1024+ expect ( calls [ calls . length - 1 ] ) . toBe ( false ) ; // ends as not submitting
1025+ } ) ;
1026+
1027+ it ( "should set submitting back to false when onSubmit returns Promise.resolve() (#903)" , async ( ) => {
1028+ const onSubmit = jest . fn ( ( ) => Promise . resolve ( ) ) ;
1029+ const recordSubmitting = jest . fn ( ) ;
1030+ const { getByText } = render (
1031+ < Form onSubmit = { onSubmit } subscription = { { submitting : true } } >
1032+ { ( { handleSubmit, submitting } ) => {
1033+ recordSubmitting ( submitting ) ;
1034+ return (
1035+ < form onSubmit = { handleSubmit } >
1036+ < Field name = "name" component = "input" />
1037+ < button type = "submit" > Submit</ button >
1038+ </ form >
1039+ ) ;
1040+ } }
1041+ </ Form > ,
1042+ ) ;
1043+
1044+ fireEvent . click ( getByText ( "Submit" ) ) ;
1045+ await act ( async ( ) => { } ) ;
1046+
1047+ const calls = recordSubmitting . mock . calls . map ( ( c ) => c [ 0 ] ) ;
1048+ expect ( calls [ calls . length - 1 ] ) . toBe ( false ) ;
1049+ } ) ;
9931050} ) ;
0 commit comments