Page MenuHomePhabricator

Warning: Use of navigate is deprecated. use navigateTo instead
Open, LowPublic

Description

When in the mobile Special:Homepage we use OO.Router.navigate method which has been deprecated for a long time and this warning is being thrown to the JS console. The deprecation was in the context of T189173: Router.prototype.navigate only works with hash fragments and doesn't support replace state

Use of "navigate" is deprecated. use navigateTo instead
...
$summaryModulesContainer.on( 'click', summaryModulesSelector, function ( e ) {
   e.preventDefault();
   // See BaseModule->getModuleRoute()
   if ( $( this ).data( 'module-route' ) ) {
      router.navigate( $( this ).data( 'module-route' ) );
   }
} );

I tried to use the suggested replacement method OO.Router.navigateTo by changing the calls from something like navigate("#/homepage/impact") to navigateTo(document.title, { path: "#/homepage/impact" }) but it didn't work as expected.

In our code we listen to the route event ie router.on('route', handleRouteChanges ) but with the new call this event is not triggered. I think the reason is the old navigate method used the code window.location.hash = path which would trigger popstate and hashchange events but with the call to pushState none of this is called as per MDN docs:

Calling history.pushState() or history.replaceState() won't trigger a popstate event. The popstate event is only triggered by performing a browser action, such as clicking on the back button (or calling history.back() in JavaScript), when navigating between two history entries for the same document.

hashchange

I'm not sure if this is something we need to re-work on our side or a possible defect in OO router. This change is the reproduce-able scenario. I tried to find other extensions doing similar things but the variety of setups makes it hard (I will come back to it). In any case this should be marked as very low priority.

Event Timeline

Sgs triaged this task as Low priority.Dec 16 2021, 11:51 AM
Sgs moved this task from Inbox to Triaged on the Growth-Team board.