File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -599,14 +599,22 @@ class Client {
599599 if ( ! this . gameStop ( ) ) {
600600 console . info ( "Player is active, ask before leaving game" ) ;
601601
602- // Rollback navigator history (here so the confirm dialog also works on mobile)
603- history . pushState ( null , "" , this . currentUrl ) ;
602+ // Rollback navigator history to stay in game on cancel
603+ // Before calling confirm so dialog also shows on mobile
604+ history . replaceState ( null , "" , this . currentUrl ) ;
604605
605606 const isConfirmed = confirm (
606607 translateText ( "help_modal.exit_confirmation" ) ,
607608 ) ;
608609
609610 if ( ! isConfirmed ) {
611+ // Rebuild stack:
612+ // - prevent being put back homepage when clicking back button again after cancelling
613+ // - replaceState instead of 2x pushState for cleaner history
614+ // Can't prevent browser blocking popState on clicking back button again without in-game click first
615+ // - preventable by only having pushState this.currentUrl here, which breaks confirm on mobile
616+ history . replaceState ( null , "" , window . location . origin + "#refresh" ) ;
617+ history . pushState ( null , "" , this . currentUrl ) ;
610618 return ;
611619 }
612620 }
You can’t perform that action at this time.
0 commit comments