-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[go_router] fix PopScope.onPopInvokedWithResult getting called twice when popping a route if GoRouteData.onExit is not null #8896
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
Conversation
@chunhtai Even though all the test pass, including the ones I specifically added to test this case, I am not 100% certain that this is the correct approach, however, I don't see another way, as |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change lgtm, but will need to fix version
looks like the ci is not happy |
The currently published version is |
Yeah, I'm not sure why. 🫠 |
looks like some tests are failing https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket/8718793893833895121/+/u/Run_package_tests/Dart_unit_tests/stdout |
Oh, I see, the 1 test in the This basically points to a deeper problem. The The only way I see this working is by changing
typedef ExitCallback = FutureOr<bool>? Function(BuildContext context, GoRouterState state); but that opens up another can of worms where This will probably need a
to ExitCallback? get onExit => null; and any override would have to be declared as @override
ExitCallback? get onExit => (BuildContext context, GoRouterState state) {
// stuff
return true;
}; This quickly ballooned into a big task. 🫠 @chunhtai do you have any other suggestions perhaps? |
…InvokedWithResult # Conflicts: # packages/go_router/CHANGELOG.md # packages/go_router/pubspec.yaml
…le-call-onPopInvokedWithResult # Conflicts: # packages/go_router/CHANGELOG.md
Hi @chunhtai and @hannah-hyj Would you mind taking another look at this PR? The changes ended up being moderately substantial in the process of fixing the double I’m committed to getting this fix landed and will follow up with the builder changes promptly. Thank you both for your time and guidance!  |
…Result' into fix/double-call-onPopInvokedWithResult
All tests passed, yay! 🎉 @chunhtai thank you for all the tips! 🙏 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I know what is going on, the issue is that when onPopPage returns false, it still attempt to call the onPopInvokedWithResult callback. This is something that needs to be fixed in framework
I will put up an framework pr to fix this closing this one |
This pull request includes changes to the
GoRouter
package, focusing on improving the handling of route pop events and adding corresponding tests. The most important changes include modifying theGoRouterDelegate
class to invoke thedidPop
method and adding comprehensive test cases to ensure the correct behavior of thePopScope
widget.The problem
PopScope.onPopInvokedWithResult
is getting called twice when popping a route since v14.0.0 which introduced #6495.The 1st time it's called from
https://github.com/flutter/flutter/blob/bb81a93d752690bc2889a713ec448359c9867f40/packages/flutter/lib/src/widgets/navigator.dart#L5586
The 2nd time it's called from
https://github.com/flutter/flutter/blob/bb81a93d752690bc2889a713ec448359c9867f40/packages/flutter/lib/src/widgets/navigator.dart#L3305
Before v14.0.0, the 2nd call doesn't happen.
I pinned it down to
GoRouteData.onExit
packages/packages/go_router/lib/src/route_data.dart
Line 69 in 2df1c3a
true
by default (it can never benull
.Since I use go_router_builder all my routes extend from
GoRouteData
whereGoRouteData.onExit
always a callable and nevernull
packages/packages/go_router/lib/src/route_data.dart
Line 114 in 2df1c3a
packages/packages/go_router/lib/src/delegate.dart
Line 139 in 2df1c3a
GoRoute
s manually withoutonExit
defined.Fixes:
Improvements to route pop handling:
packages/go_router/lib/src/delegate.dart
: Modified theGoRouterDelegate
class to call thedidPop
method when a route is popped.Addition of test cases:
packages/go_router/test/on_exit_on_pop_invoked_with_result_test.dart
: Added new test cases to verify that theonPopInvokedWithResult
callback in thePopScope
widget is called only once when a route is popped. This includes tests for both standard routes and routes usingGoRouteData
.Pre-Review Checklist
dart format
.)[shared_preferences]
pubspec.yaml
with an appropriate new version according to the pub versioning philosophy, or I have commented below to indicate which version change exemption this PR falls under1.CHANGELOG.md
to add a description of the change, following repository CHANGELOG style, or I have commented below to indicate which CHANGELOG exemption this PR falls under1.///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.
Footnotes
Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. ↩ ↩2 ↩3