File tree Expand file tree Collapse file tree 3 files changed +54
-4
lines changed Expand file tree Collapse file tree 3 files changed +54
-4
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " @remix-run/router " : patch
3
+ ---
4
+
5
+ Ensure revalidations happen when hash is present
Original file line number Diff line number Diff line change @@ -7456,6 +7456,49 @@ describe("a router", () => {
7456
7456
expect ( t . history . replace ) . not . toHaveBeenCalled ( ) ;
7457
7457
} ) ;
7458
7458
7459
+ it ( "handles revalidation when a hash is present" , async ( ) => {
7460
+ let t = setup ( {
7461
+ routes : TASK_ROUTES ,
7462
+ initialEntries : [ "/#hash" ] ,
7463
+ hydrationData : {
7464
+ loaderData : {
7465
+ root : "ROOT_DATA" ,
7466
+ index : "INDEX_DATA" ,
7467
+ } ,
7468
+ } ,
7469
+ } ) ;
7470
+
7471
+ let key = t . router . state . location . key ;
7472
+ let R = await t . revalidate ( ) ;
7473
+ expect ( t . router . state ) . toMatchObject ( {
7474
+ historyAction : "POP" ,
7475
+ location : { pathname : "/" } ,
7476
+ navigation : IDLE_NAVIGATION ,
7477
+ revalidation : "loading" ,
7478
+ loaderData : {
7479
+ root : "ROOT_DATA" ,
7480
+ index : "INDEX_DATA" ,
7481
+ } ,
7482
+ } ) ;
7483
+
7484
+ await R . loaders . root . resolve ( "ROOT_DATA*" ) ;
7485
+ await R . loaders . index . resolve ( "INDEX_DATA*" ) ;
7486
+ expect ( t . router . state ) . toMatchObject ( {
7487
+ historyAction : "POP" ,
7488
+ location : { pathname : "/" } ,
7489
+ navigation : IDLE_NAVIGATION ,
7490
+ revalidation : "idle" ,
7491
+ loaderData : {
7492
+ root : "ROOT_DATA*" ,
7493
+ index : "INDEX_DATA*" ,
7494
+ } ,
7495
+ } ) ;
7496
+ expect ( t . router . state . location . hash ) . toBe ( '#hash' ) ;
7497
+ expect ( t . router . state . location . key ) . toBe ( key ) ;
7498
+ expect ( t . history . push ) . not . toHaveBeenCalled ( ) ;
7499
+ expect ( t . history . replace ) . not . toHaveBeenCalled ( ) ;
7500
+ } ) ;
7501
+
7459
7502
it ( "handles revalidation interrupted by a <Link> navigation" , async ( ) => {
7460
7503
let t = setup ( {
7461
7504
routes : TASK_ROUTES ,
Original file line number Diff line number Diff line change @@ -1225,13 +1225,15 @@ export function createRouter(init: RouterInit): Router {
1225
1225
return ;
1226
1226
}
1227
1227
1228
- // Short circuit if it's only a hash change and not a mutation submission.
1228
+ // Short circuit if it's only a hash change and not a revalidation or
1229
+ // mutation submission.
1230
+ //
1229
1231
// Ignore on initial page loads because since the initial load will always
1230
- // be "same hash".
1231
- // For example, on /page#hash and submit a <Form method="post"> which will
1232
- // default to a navigation to /page
1232
+ // be "same hash". For example, on /page#hash and submit a <Form method="post">
1233
+ // which will default to a navigation to /page
1233
1234
if (
1234
1235
state . initialized &&
1236
+ ! isRevalidationRequired &&
1235
1237
isHashChangeOnly ( state . location , location ) &&
1236
1238
! ( opts && opts . submission && isMutationMethod ( opts . submission . formMethod ) )
1237
1239
) {
You can’t perform that action at this time.
0 commit comments