@@ -1144,29 +1144,55 @@ describe("a router", () => {
11441144 it ( "reloads all routes if X-Remix-Revalidate was set in a loader redirect header" , async ( ) => {
11451145 let t = initializeTmTest ( ) ;
11461146
1147- let A = await t . navigate ( "/bar " ) ;
1147+ let A = await t . navigate ( "/foo " ) ;
11481148 expect ( t . router . state . navigation . state ) . toBe ( "loading" ) ;
1149- expect ( t . router . state . navigation . location ?. pathname ) . toBe ( "/bar " ) ;
1149+ expect ( t . router . state . navigation . location ?. pathname ) . toBe ( "/foo " ) ;
11501150 expect ( t . router . state . loaderData ) . toMatchObject ( {
11511151 root : "ROOT" ,
11521152 } ) ;
11531153
1154- let B = await A . loaders . bar . redirectReturn ( "/baz " , undefined , {
1154+ let B = await A . loaders . foo . redirectReturn ( "/bar " , undefined , {
11551155 "X-Remix-Revalidate" : "yes" ,
11561156 } ) ;
11571157 expect ( t . router . state . navigation . state ) . toBe ( "loading" ) ;
1158- expect ( t . router . state . navigation . location ?. pathname ) . toBe ( "/baz " ) ;
1158+ expect ( t . router . state . navigation . location ?. pathname ) . toBe ( "/bar " ) ;
11591159 expect ( t . router . state . loaderData ) . toMatchObject ( {
11601160 root : "ROOT" ,
11611161 } ) ;
11621162
11631163 await B . loaders . root . resolve ( "ROOT*" ) ;
1164- await B . loaders . baz . resolve ( "B " ) ;
1164+ await B . loaders . bar . resolve ( "BAR " ) ;
11651165 expect ( t . router . state . navigation . state ) . toBe ( "idle" ) ;
1166- expect ( t . router . state . location . pathname ) . toBe ( "/baz " ) ;
1166+ expect ( t . router . state . location . pathname ) . toBe ( "/bar " ) ;
11671167 expect ( t . router . state . loaderData ) . toMatchObject ( {
11681168 root : "ROOT*" ,
1169- baz : "B" ,
1169+ bar : "BAR" ,
1170+ } ) ;
1171+ } ) ;
1172+
1173+ it ( "reloads all routes if X-Remix-Revalidate was set in a loader redirect header (chained redirects)" , async ( ) => {
1174+ let t = initializeTmTest ( ) ;
1175+
1176+ let A = await t . navigate ( "/foo" ) ;
1177+ expect ( A . loaders . root . stub . mock . calls . length ) . toBe ( 0 ) ; // Reused on navigation
1178+
1179+ let B = await A . loaders . foo . redirectReturn ( "/bar" , undefined , {
1180+ "X-Remix-Revalidate" : "yes" ,
1181+ } ) ;
1182+ await B . loaders . root . resolve ( "ROOT*" ) ;
1183+ expect ( B . loaders . root . stub . mock . calls . length ) . toBe ( 1 ) ;
1184+
1185+ // No cookie on second redirect
1186+ let C = await B . loaders . bar . redirectReturn ( "/baz" ) ;
1187+ expect ( C . loaders . root . stub . mock . calls . length ) . toBe ( 1 ) ;
1188+ await C . loaders . root . resolve ( "ROOT**" ) ;
1189+ await C . loaders . baz . resolve ( "BAZ" ) ;
1190+
1191+ expect ( t . router . state . navigation . state ) . toBe ( "idle" ) ;
1192+ expect ( t . router . state . location . pathname ) . toBe ( "/baz" ) ;
1193+ expect ( t . router . state . loaderData ) . toMatchObject ( {
1194+ root : "ROOT**" ,
1195+ baz : "BAZ" ,
11701196 } ) ;
11711197 } ) ;
11721198 } ) ;
@@ -2084,6 +2110,30 @@ describe("a router", () => {
20842110 } ) ;
20852111 } ) ;
20862112
2113+ it ( "reloads all routes after action redirect (chained redirects)" , async ( ) => {
2114+ let t = initializeTmTest ( ) ;
2115+ let A = await t . navigate ( "/foo" , {
2116+ formMethod : "post" ,
2117+ formData : createFormData ( { gosh : "dang" } ) ,
2118+ } ) ;
2119+ expect ( A . loaders . root . stub . mock . calls . length ) . toBe ( 0 ) ;
2120+
2121+ let B = await A . actions . foo . redirectReturn ( "/bar" ) ;
2122+ expect ( B . loaders . root . stub . mock . calls . length ) . toBe ( 1 ) ;
2123+
2124+ await B . loaders . root . resolve ( "ROOT*" ) ;
2125+ let C = await B . loaders . bar . redirectReturn ( "/baz" ) ;
2126+ expect ( C . loaders . root . stub . mock . calls . length ) . toBe ( 1 ) ;
2127+
2128+ await C . loaders . root . resolve ( "ROOT**" ) ;
2129+ await C . loaders . baz . resolve ( "BAZ" ) ;
2130+ expect ( t . router . state . navigation . state ) . toBe ( "idle" ) ;
2131+ expect ( t . router . state . loaderData ) . toEqual ( {
2132+ baz : "BAZ" ,
2133+ root : "ROOT**" ,
2134+ } ) ;
2135+ } ) ;
2136+
20872137 it ( "removes action data at new locations" , async ( ) => {
20882138 let t = initializeTmTest ( ) ;
20892139 let A = await t . navigate ( "/foo" , {
0 commit comments