@@ -1033,7 +1033,7 @@ export function createRouter(init: RouterInit): Router {
10331033
10341034 // Flag to ignore the next history update, so we can revert the URL change on
10351035 // a POP navigation that was blocked by the user without touching router state
1036- let ignoreNextHistoryUpdate = false ;
1036+ let unblockBlockerHistoryUpdate : ( ( ) => void ) | undefined = undefined ;
10371037
10381038 // Initialize the router, all side effects should be kicked off from here.
10391039 // Implemented as a Fluent API for ease of:
@@ -1045,8 +1045,9 @@ export function createRouter(init: RouterInit): Router {
10451045 ( { action : historyAction , location, delta } ) => {
10461046 // Ignore this event if it was just us resetting the URL from a
10471047 // blocked POP navigation
1048- if ( ignoreNextHistoryUpdate ) {
1049- ignoreNextHistoryUpdate = false ;
1048+ if ( unblockBlockerHistoryUpdate ) {
1049+ unblockBlockerHistoryUpdate ( ) ;
1050+ unblockBlockerHistoryUpdate = undefined ;
10501051 return ;
10511052 }
10521053
@@ -1068,7 +1069,9 @@ export function createRouter(init: RouterInit): Router {
10681069
10691070 if ( blockerKey && delta != null ) {
10701071 // Restore the URL to match the current UI, but don't update router state
1071- ignoreNextHistoryUpdate = true ;
1072+ let nextHistoryUpdatePromise = new Promise < void > ( ( resolve ) => {
1073+ unblockBlockerHistoryUpdate = resolve ;
1074+ } ) ;
10721075 init . history . go ( delta * - 1 ) ;
10731076
10741077 // Put the blocker into a blocked state
@@ -1082,8 +1085,10 @@ export function createRouter(init: RouterInit): Router {
10821085 reset : undefined ,
10831086 location,
10841087 } ) ;
1085- // Re-do the same POP navigation we just blocked
1086- init . history . go ( delta ) ;
1088+ // Re-do the same POP navigation we just blocked, after the url
1089+ // restoration is also complete. See:
1090+ // https://github.com/remix-run/react-router/issues/11613
1091+ nextHistoryUpdatePromise . then ( ( ) => init . history . go ( delta ) ) ;
10871092 } ,
10881093 reset ( ) {
10891094 let blockers = new Map ( state . blockers ) ;
0 commit comments