@@ -624,7 +624,7 @@ function setup({
624
624
// Otherwise we should only need a loader for the leaf match
625
625
let activeLoaderMatches = [ match ] ;
626
626
// @ts -expect-error
627
- if ( opts ?. formMethod = == "post " ) {
627
+ if ( opts ?. formMethod != null && opts . formMethod . toLowerCase ( ) ! == "get " ) {
628
628
if ( currentRouter . state . navigation ?. location ) {
629
629
let matches = matchRoutes (
630
630
inFlightRoutes || currentRouter . routes ,
@@ -689,7 +689,7 @@ function setup({
689
689
invariant ( currentRouter , "No currentRouter available" ) ;
690
690
691
691
// @ts -expect-error
692
- if ( opts ?. formMethod = == "post " ) {
692
+ if ( opts ?. formMethod != null && opts . formMethod . toLowerCase ( ) ! == "get " ) {
693
693
activeActionType = "navigation" ;
694
694
activeActionNavigationId = navigationId ;
695
695
// Assume happy path and mark this navigations loaders as active. Even if
@@ -779,7 +779,7 @@ function setup({
779
779
invariant ( currentRouter , "No currentRouter available" ) ;
780
780
781
781
// @ts -expect-error
782
- if ( opts ?. formMethod = == "post " ) {
782
+ if ( opts ?. formMethod != null && opts . formMethod . toLowerCase ( ) ! == "get " ) {
783
783
activeActionType = "fetch" ;
784
784
activeActionFetchId = navigationId ;
785
785
} else {
@@ -867,10 +867,7 @@ function initializeTmTest(init?: {
867
867
}
868
868
869
869
function createRequest ( path : string , opts ?: RequestInit ) {
870
- return new Request ( `http://localhost${ path } ` , {
871
- signal : new AbortController ( ) . signal ,
872
- ...opts ,
873
- } ) ;
870
+ return new Request ( `http://localhost${ path } ` , opts ) ;
874
871
}
875
872
876
873
function createSubmitRequest ( path : string , opts ?: RequestInit ) {
@@ -5899,6 +5896,47 @@ describe("a router", () => {
5899
5896
expect ( ( await request . formData ( ) ) . get ( "query" ) ) . toBe ( "params" ) ;
5900
5897
} ) ;
5901
5898
5899
+ // https://fetch.spec.whatwg.org/#concept-method
5900
+ it ( "properly handles method=PATCH weirdness" , async ( ) => {
5901
+ let t = setup ( {
5902
+ routes : TASK_ROUTES ,
5903
+ initialEntries : [ "/" ] ,
5904
+ hydrationData : {
5905
+ loaderData : {
5906
+ root : "ROOT_DATA" ,
5907
+ } ,
5908
+ } ,
5909
+ } ) ;
5910
+
5911
+ let nav = await t . navigate ( "/tasks" , {
5912
+ formMethod : "patch" ,
5913
+ formData : createFormData ( { query : "params" } ) ,
5914
+ } ) ;
5915
+ expect ( nav . actions . tasks . stub ) . toHaveBeenCalledWith ( {
5916
+ params : { } ,
5917
+ request : expect . any ( Request ) ,
5918
+ } ) ;
5919
+
5920
+ // Assert request internals, cannot do a deep comparison above since some
5921
+ // internals aren't the same on separate creations
5922
+ let request = nav . actions . tasks . stub . mock . calls [ 0 ] [ 0 ] . request ;
5923
+ expect ( request . method ) . toBe ( "PATCH" ) ;
5924
+ expect ( request . url ) . toBe ( "http://localhost/tasks" ) ;
5925
+ expect ( request . headers . get ( "Content-Type" ) ) . toBe (
5926
+ "application/x-www-form-urlencoded;charset=UTF-8"
5927
+ ) ;
5928
+ expect ( ( await request . formData ( ) ) . get ( "query" ) ) . toBe ( "params" ) ;
5929
+
5930
+ await nav . actions . tasks . resolve ( "TASKS ACTION" ) ;
5931
+ let rootLoaderRequest = nav . loaders . root . stub . mock . calls [ 0 ] [ 0 ] . request ;
5932
+ expect ( rootLoaderRequest . method ) . toBe ( "GET" ) ;
5933
+ expect ( rootLoaderRequest . url ) . toBe ( "http://localhost/tasks" ) ;
5934
+
5935
+ let tasksLoaderRequest = nav . loaders . tasks . stub . mock . calls [ 0 ] [ 0 ] . request ;
5936
+ expect ( tasksLoaderRequest . method ) . toBe ( "GET" ) ;
5937
+ expect ( tasksLoaderRequest . url ) . toBe ( "http://localhost/tasks" ) ;
5938
+ } ) ;
5939
+
5902
5940
it ( "handles multipart/form-data submissions" , async ( ) => {
5903
5941
let t = setup ( {
5904
5942
routes : [
@@ -13437,17 +13475,12 @@ describe("a router", () => {
13437
13475
expect ( e ) . toMatchInlineSnapshot ( `[Error: query() call aborted]` ) ;
13438
13476
} ) ;
13439
13477
13440
- it ( "should require a signal on the request " , async ( ) => {
13478
+ it ( "should assign signals to requests by default (per the " , async ( ) => {
13441
13479
let { query } = createStaticHandler ( SSR_ROUTES ) ;
13442
13480
let request = createRequest ( "/" , { signal : undefined } ) ;
13443
- let e ;
13444
- try {
13445
- await query ( request ) ;
13446
- } catch ( _e ) {
13447
- e = _e ;
13448
- }
13449
- expect ( e ) . toMatchInlineSnapshot (
13450
- `[Error: query()/queryRoute() requests must contain an AbortController signal]`
13481
+ let context = await query ( request ) ;
13482
+ expect ( ( context as StaticHandlerContext ) . loaderData . index ) . toBe (
13483
+ "INDEX LOADER"
13451
13484
) ;
13452
13485
} ) ;
13453
13486
@@ -14673,18 +14706,11 @@ describe("a router", () => {
14673
14706
expect ( e ) . toMatchInlineSnapshot ( `[Error: queryRoute() call aborted]` ) ;
14674
14707
} ) ;
14675
14708
14676
- it ( "should require a signal on the request " , async ( ) => {
14709
+ it ( "should assign signals to requests by default (per the spec) " , async ( ) => {
14677
14710
let { queryRoute } = createStaticHandler ( SSR_ROUTES ) ;
14678
14711
let request = createRequest ( "/" , { signal : undefined } ) ;
14679
- let e ;
14680
- try {
14681
- await queryRoute ( request , { routeId : "index" } ) ;
14682
- } catch ( _e ) {
14683
- e = _e ;
14684
- }
14685
- expect ( e ) . toMatchInlineSnapshot (
14686
- `[Error: query()/queryRoute() requests must contain an AbortController signal]`
14687
- ) ;
14712
+ let data = await queryRoute ( request , { routeId : "index" } ) ;
14713
+ expect ( data ) . toBe ( "INDEX LOADER" ) ;
14688
14714
} ) ;
14689
14715
14690
14716
it ( "should support a requestContext passed to loaders and actions" , async ( ) => {
@@ -14890,15 +14916,15 @@ describe("a router", () => {
14890
14916
14891
14917
it ( "should handle unsupported methods with a 405 Response" , async ( ) => {
14892
14918
try {
14893
- await queryRoute ( createRequest ( "/" , { method : "TRACE " } ) , {
14919
+ await queryRoute ( createRequest ( "/" , { method : "CHICKEN " } ) , {
14894
14920
routeId : "root" ,
14895
14921
} ) ;
14896
14922
expect ( false ) . toBe ( true ) ;
14897
14923
} catch ( data ) {
14898
14924
expect ( isRouteErrorResponse ( data ) ) . toBe ( true ) ;
14899
14925
expect ( data . status ) . toBe ( 405 ) ;
14900
14926
expect ( data . error ) . toEqual (
14901
- new Error ( 'Invalid request method "TRACE "' )
14927
+ new Error ( 'Invalid request method "CHICKEN "' )
14902
14928
) ;
14903
14929
expect ( data . internal ) . toBe ( true ) ;
14904
14930
}
0 commit comments