-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[go_router] Fix replace routes hanging the originating completer #9332
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
base: main
Are you sure you want to change the base?
Conversation
@nouvist LGTM, thank you for submitting the fix, I was facing the same issue |
@@ -168,6 +168,18 @@ class GoRouteInformationParser extends RouteInformationParser<RouteMatchList> { | |||
return redirectedFuture; | |||
} | |||
|
|||
/// Ensures the replacement routes can resolve the originating route completer. | |||
Completer<T?>? _createInheritedCompleter<T>( |
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.
What if the type T mismatched for the new route and the old route. Instead of inherited the completer, I think it should resolve the previous route's future because it is replaced.
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.
Yeah, that's the problem, but I still think resolve the completer when the replacement pops up is my preferred, as the waiting route can hold until its screen reappears.
I propose, what if the push
(etc) had a mapReplacementResult
? But it may need to be on RouteInformationState
and ImperativeRouteMatch
, which I'm not sure if there will be breaking changes or not.
fbe167b
to
f8f51c6
Compare
d8ae141
to
b6ed95b
Compare
Both are used to resolve the current route completer when it is replaced. Both are added to `RouteInformationState` and `ImperativeRouteMatch`.
String location, { | ||
required RouteMatchList base, | ||
Object? extra, | ||
MapRouteResultCallback<T?>? mapReplacementResult, |
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.
This feels weird, If we want to separate two use cases.
- resolve the result immediately in pushReplacement
- replace the future in pushReplacement.
I think we should make two different API, maybe a pushReplacement for (1) and a pushReplaceResultFuture for (2), and in (2) we should force the type to be the same as previously pushed route.
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.
case (2) that match its originating type is guaranteed. this implementation makes the caller of the originating route is the one who's responsible for replacing future. for example, A is the one that responsible for replacing C result to match with B result type when it's pushing B. that's why mapReplacementResult
is required for each pushed new route, because the assumption is any route can be replaced.
Route A -- (pushing) --> Route B -- (replaced by) --> Route C
I do consider to make the replace
and pushReplacement
itself that responsible for replacing future. but I struggle to make it match the originating route type. I think it's similar to pop
where we have no idea what type it should be.
I didn't consider case (1) before, it is indeed necessary to implement. but then, when routes can be resolve immediately when replaced, it needs value to return, and then again, we have no idea what type it should be, like pop is.
The behavior of
replace
andpushReplacement
involves popping the last route and ignoring the completer, leaving the last route's future unresolved. This PR introduces new behavior for both methods to inherit the last route's completer if the last route is anImperativeRouteMatch
.Expected issue(s) should be fixed by this:
GoRoute.push()
is not resolving when the push page gets replaced via pushReplacement flutter#141251Previous behavior:
sebelum.mp4
This PR behavior:
sesudah.mp4
Pre-Review Checklist
[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