@@ -2539,7 +2539,7 @@ export function useSubmit(): SubmitFunction {
25392539 let { basename } = React . useContext ( NavigationContext ) ;
25402540 let currentRouteId = useRouteId ( ) ;
25412541
2542- return React . useCallback < SubmitFunction > (
2542+ const submit = React . useCallback < SubmitFunction > (
25432543 async ( target , options = { } ) => {
25442544 let { action, method, encType, formData, body } = getFormSubmissionInfo (
25452545 target ,
@@ -2573,6 +2573,49 @@ export function useSubmit(): SubmitFunction {
25732573 } ,
25742574 [ router , basename , currentRouteId ] ,
25752575 ) ;
2576+
2577+ return React . useCallback < SubmitFunction > (
2578+ ( target , options ) => {
2579+ const deferred = new Deferred < void > ( ) ;
2580+ // @ts -expect-error - Needs React 19 types
2581+ React . startTransition ( async ( ) => {
2582+ try {
2583+ await submit ( target , options ) ;
2584+ deferred . resolve ( ) ;
2585+ } catch ( error ) {
2586+ deferred . reject ( error ) ;
2587+ }
2588+ } ) ;
2589+ return deferred . promise ;
2590+ } ,
2591+ [ submit ] ,
2592+ ) ;
2593+ }
2594+
2595+ // TODO: Move to a shared location
2596+ class Deferred < T > {
2597+ status : "pending" | "resolved" | "rejected" = "pending" ;
2598+ promise : Promise < T > ;
2599+ // @ts -expect-error - no initializer
2600+ resolve : ( value : T ) => void ;
2601+ // @ts -expect-error - no initializer
2602+ reject : ( reason ?: unknown ) => void ;
2603+ constructor ( ) {
2604+ this . promise = new Promise ( ( resolve , reject ) => {
2605+ this . resolve = ( value ) => {
2606+ if ( this . status === "pending" ) {
2607+ this . status = "resolved" ;
2608+ resolve ( value ) ;
2609+ }
2610+ } ;
2611+ this . reject = ( reason ) => {
2612+ if ( this . status === "pending" ) {
2613+ this . status = "rejected" ;
2614+ reject ( reason ) ;
2615+ }
2616+ } ;
2617+ } ) ;
2618+ }
25762619}
25772620
25782621// v7: Eventually we should deprecate this entirely in favor of using the
0 commit comments