@@ -3117,6 +3117,11 @@ function normalizeNavigateOptions(
31173117 } ;
31183118 }
31193119
3120+ let getInvalidBodyError = ( ) => ( {
3121+ path,
3122+ error : getInternalRouterError ( 400 , { type : "invalid-body" } ) ,
3123+ } ) ;
3124+
31203125 // Create a Submission on non-GET navigations
31213126 let rawFormMethod = opts . formMethod || "get" ;
31223127 let formMethod = normalizeFormMethod
@@ -3126,6 +3131,11 @@ function normalizeNavigateOptions(
31263131
31273132 if ( opts . body ) {
31283133 if ( opts . formEncType === "text/plain" ) {
3134+ // text only support POST/PUT/PATCH/DELETE submissions
3135+ if ( ! isMutationMethod ( formMethod ) ) {
3136+ return getInvalidBodyError ( ) ;
3137+ }
3138+
31293139 let text =
31303140 typeof opts . body === "string"
31313141 ? opts . body
@@ -3150,6 +3160,11 @@ function normalizeNavigateOptions(
31503160 } ,
31513161 } ;
31523162 } else if ( opts . formEncType === "application/json" ) {
3163+ // json only supports POST/PUT/PATCH/DELETE submissions
3164+ if ( ! isMutationMethod ( formMethod ) ) {
3165+ return getInvalidBodyError ( ) ;
3166+ }
3167+
31533168 try {
31543169 let json =
31553170 typeof opts . body === "string" ? JSON . parse ( opts . body ) : opts . body ;
@@ -3166,10 +3181,7 @@ function normalizeNavigateOptions(
31663181 } ,
31673182 } ;
31683183 } catch ( e ) {
3169- return {
3170- path,
3171- error : getInternalRouterError ( 400 , { type : "invalid-body" } ) ,
3172- } ;
3184+ return getInvalidBodyError ( ) ;
31733185 }
31743186 }
31753187 }
@@ -3199,10 +3211,7 @@ function normalizeNavigateOptions(
31993211 searchParams = new URLSearchParams ( opts . body ) ;
32003212 formData = convertSearchParamsToFormData ( searchParams ) ;
32013213 } catch ( e ) {
3202- return {
3203- path,
3204- error : getInternalRouterError ( 400 , { type : "invalid-body" } ) ,
3205- } ;
3214+ return getInvalidBodyError ( ) ;
32063215 }
32073216 }
32083217
0 commit comments