Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[go_router] Fix: Consistent PopScope Handling on Root Routes issue #140869 #8045

Merged
merged 7 commits into from
Nov 21, 2024

Conversation

omar-hanafy
Copy link
Contributor

@omar-hanafy omar-hanafy commented Nov 8, 2024

Description:
This PR addresses issue #140869 related to back button handling on root routes in GoRouterDelegate. The current _findCurrentNavigator() function only assigns NavigatorState when it can pop, which prevents PopScope and custom back button logic from triggering on root routes, especially on Android. Additionally, the onExit callbacks on routes requiring custom exit handling are affected.

What This PR Changes:

  1. Modification of _findCurrentNavigator():

    • Removed the conditional canPop check, setting state = navigatorKey.currentState; directly to ensure NavigatorState is always non-null, allowing consistent PopScope handling on root routes.
  2. Adjustment of popRoute() to Preserve onExit Logic:

    • Updated popRoute() to call maybePop() unconditionally to make sure PopScope can handle back button actions on root pages.
    • Added fallback to onExit logic in popRoute() if maybePop() does not handle the pop, this way, any route-specific exit callbacks are still functional.

Impact:

  • Resolves Inconsistent Back Button Handling: The fix enables PopScope and back button handling on root pages without affecting nested routes or shell routes.
  • Maintains onExit Callback Functionality: onExit is invoked when maybePop() doesn’t handle the pop, preserving custom exit behaviors.

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] page, which explains my responsibilities.
  • I read and followed the [relevant style guides] and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/packages repo does use dart format.)
  • I signed the [CLA].
  • The title of the PR starts with the name of the package surrounded by square brackets, e.g. [go_router]
  • I [linked to at least one issue that this PR fixes] in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the [pub versioning philosophy], or this PR is [exempt from version changes].
  • I updated CHANGELOG.md to add a description of the change, [following repository CHANGELOG style], or this PR is [exempt from CHANGELOG changes].
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is [test-exempt].
  • All existing and new tests are passing.

@omar-hanafy omar-hanafy requested a review from chunhtai as a code owner November 8, 2024 19:39
@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group.

@omar-hanafy omar-hanafy force-pushed the main branch 2 times, most recently from 9640161 to 0ac53c2 Compare November 11, 2024 07:11
Fixed WillPopScope/PopScope doesn't trigger with back button navigation on root screens.

Added a test for PopScope, and fixed some test failures in the delegate_test.
@omar-hanafy
Copy link
Contributor Author

Hi @chunhtai,

This PR is ready for your review. All checks have passed, and there are no issues reported. When you have a moment, could you please take a look and provide an approval if everything looks good? Your review is the last step for merging.

Thank you!

@chunhtai chunhtai requested a review from hannah-hyj November 14, 2024 22:39
@omar-hanafy
Copy link
Contributor Author

@hannah-hyj
@chunhtai

can you guys review this, so we can get this issue fixed

Copy link
Member

@hannah-hyj hannah-hyj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

excellent fix, thank you!

@omar-hanafy
Copy link
Contributor Author

You’re welcome, @hannah-hyj! I’m glad the fix meets your expectations.

@chunhtai, could you please take a moment to review this pull request? It’s passed all checks and is ready for the final review.

Copy link
Contributor

@chunhtai chunhtai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

packages/go_router/pubspec.yaml Outdated Show resolved Hide resolved
packages/go_router/CHANGELOG.md Outdated Show resolved Hide resolved
@chunhtai chunhtai added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 21, 2024
@auto-submit auto-submit bot merged commit 41c39ba into flutter:main Nov 21, 2024
77 checks passed
sinyu1012 added a commit to sinyu1012/packages that referenced this pull request Nov 22, 2024
* main: (64 commits)
  [quick_actions_plaform_interface] add localizedSubtitle (flutter#8112)
  [tools] Don't check license of generated Swift package (flutter#8137)
  Roll Flutter from 8536b96ebb3e to 93d772c5cdd8 (37 revisions) (flutter#8147)
  [go_router] Fix: Consistent PopScope Handling on Root Routes issue #140869 (flutter#8045)
  [in_app_purchase_storekit] fix price displayed with wrong precision (flutter#8127)
  [pigeon] Removes the `@protected` annotation from the InstanceManager field of the   `PigeonInternalProxyApiBaseClass` (flutter#8125)
  [google_maps_flutter] Use structured Pigeon data on iOS (flutter#8142)
  [vector_graphics] handle errors from bytes loader (flutter#8080)
  [flutter_svg] Fix SvgNetworkLoader not closing internal http client (flutter#8126)
  [video_player_avfoundation] send video load failure even when eventsink was initialized late (flutter#7194)
  [flutter_markdown] enable Wasm support (flutter#8120)
  Reverts "[url_launcher] Add Swift Package Manager integration to example app (flutter#8128)" (flutter#8136)
  [url_launcher] Add Swift Package Manager integration to example app (flutter#8128)
  [pigeon] Enable example app build in CI (flutter#8119)
  [in_app_purchase_storekit] disallow ios versions lower than supported from enabling storekit (flutter#8110)
  [interactive_media_ads]: Bump com.google.ads.interactivemedia.v3:interactivemedia from 3.35.1 to 3.36.0 in /packages/interactive_media_ads/android (flutter#8046)
  [interactive_media_ads]: Bump androidx.annotation:annotation from 1.8.2 to 1.9.1 in /packages/interactive_media_ads/android (flutter#7980)
  [webview_flutter_android] Updates plugin to use `ProxyApis`s (flutter#7794)
  [interactive_media_ads] Adds support to define parameters that control the rendering of ads (flutter#8057)
  Roll Flutter from b3818f6b5979 to 8536b96ebb3e (22 revisions) (flutter#8124)
  ...

# Conflicts:
#	packages/quick_actions/quick_actions_platform_interface/CHANGELOG.md
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 22, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 22, 2024
github-merge-queue bot pushed a commit to flutter/flutter that referenced this pull request Nov 22, 2024
flutter/packages@913b99e...9203213

2024-11-22 [email protected] Reland
"[url_launcher] Add Swift Package Manager integration to example app"
(flutter/packages#8148)
2024-11-22 [email protected] [webview_flutter_wkwebview] Webkit
webview controller multiple registration fix (flutter/packages#8078)
2024-11-22 [email protected] [quick_actions_plaform_interface] add
localizedSubtitle (flutter/packages#8112)
2024-11-22 [email protected] [tools] Don't
check license of generated Swift package (flutter/packages#8137)
2024-11-21 [email protected] Roll Flutter from
8536b96 to 93d772c (37 revisions) (flutter/packages#8147)
2024-11-21 [email protected] [go_router] Fix: Consistent PopScope
Handling on Root Routes issue #140869 (flutter/packages#8045)
2024-11-21 [email protected] [in_app_purchase_storekit] fix price
displayed with wrong precision (flutter/packages#8127)
2024-11-21 [email protected] [pigeon]
Removes the `@protected` annotation from the InstanceManager field of
the `PigeonInternalProxyApiBaseClass` (flutter/packages#8125)
2024-11-21 [email protected] [google_maps_flutter] Use structured
Pigeon data on iOS (flutter/packages#8142)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC [email protected] on the revert to ensure that a
human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App p: go_router
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants