Skip to content

fix(router): navigate after the Router handled the popstate of a native back - #186

Open
anjak03 wants to merge 1 commit into
NativeScript:mainfrom
anjak03:fix/navigate-after-native-back
Open

anjak03 wants to merge 1 commit into
NativeScript:mainfrom
anjak03:fix/navigate-after-native-back

Conversation

@anjak03

@anjak03 anjak03 commented Nov 26, 2026

Copy link
Copy Markdown

PR Checklist

What is the current behavior?

After a native back, PageRouterOutlet fires a popstate from the page's navigatedFrom handler and the Router handles it in a setTimeout. The previous page already accepts taps in that gap. A RouterExtensions.navigate() from a tap runs first, then the deferred popstate navigates away from the page that was just opened and pushes a new copy of the previous page.

What is the new behavior?

NSLocationStrategy.callPopState() keeps a promise that resolves in a setTimeout scheduled after the popstate callbacks, so after the Router's. While it is pending, RouterExtensions.navigate() and navigateByUrl() wait for it, so the back is applied before the new navigation. nsRouterLink navigates through RouterExtensions and is covered too. Without a pending popstate both call the Router right away as before.

Verified with the same change applied as a runtime patch in a production app (@nativescript/angular 18.0.1) on the iOS simulator: an automated flow that taps a list item right after going back ended on a new copy of the list in 2 of 3 runs before, and on the tapped page in 6 of 6 runs after. In 2 of those runs the tap landed before the popstate and the navigation waited for it.

Fixes #185.

@coderabbitai

coderabbitai Bot commented Nov 26, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: dbb34696-be38-42a3-a909-1cb51e132c63

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Navigating right after a native back is undone by the Router's deferred popstate

1 participant