@@ -1144,29 +1144,55 @@ describe("a router", () => {
1144
1144
it ( "reloads all routes if X-Remix-Revalidate was set in a loader redirect header" , async ( ) => {
1145
1145
let t = initializeTmTest ( ) ;
1146
1146
1147
- let A = await t . navigate ( "/bar " ) ;
1147
+ let A = await t . navigate ( "/foo " ) ;
1148
1148
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 " ) ;
1150
1150
expect ( t . router . state . loaderData ) . toMatchObject ( {
1151
1151
root : "ROOT" ,
1152
1152
} ) ;
1153
1153
1154
- let B = await A . loaders . bar . redirectReturn ( "/baz " , undefined , {
1154
+ let B = await A . loaders . foo . redirectReturn ( "/bar " , undefined , {
1155
1155
"X-Remix-Revalidate" : "yes" ,
1156
1156
} ) ;
1157
1157
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 " ) ;
1159
1159
expect ( t . router . state . loaderData ) . toMatchObject ( {
1160
1160
root : "ROOT" ,
1161
1161
} ) ;
1162
1162
1163
1163
await B . loaders . root . resolve ( "ROOT*" ) ;
1164
- await B . loaders . baz . resolve ( "B " ) ;
1164
+ await B . loaders . bar . resolve ( "BAR " ) ;
1165
1165
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 " ) ;
1167
1167
expect ( t . router . state . loaderData ) . toMatchObject ( {
1168
1168
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" ,
1170
1196
} ) ;
1171
1197
} ) ;
1172
1198
} ) ;
@@ -2084,6 +2110,30 @@ describe("a router", () => {
2084
2110
} ) ;
2085
2111
} ) ;
2086
2112
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
+
2087
2137
it ( "removes action data at new locations" , async ( ) => {
2088
2138
let t = initializeTmTest ( ) ;
2089
2139
let A = await t . navigate ( "/foo" , {
0 commit comments