Skip to content

[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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nouvist
Copy link

@nouvist nouvist commented May 28, 2025

The behavior of replace and pushReplacement 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 an ImperativeRouteMatch.

Expected issue(s) should be fixed by this:

Previous behavior:

sebelum.mp4

This PR behavior:

sesudah.mp4

Pre-Review Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Footnotes

  1. 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

@ikurek
Copy link

ikurek commented May 30, 2025

@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>(
Copy link
Contributor

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.

Copy link
Author

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.

@nouvist nouvist force-pushed the fix-hangs branch 5 times, most recently from fbe167b to f8f51c6 Compare June 3, 2025 05:16
@nouvist nouvist closed this Jun 9, 2025
@nouvist nouvist deleted the fix-hangs branch June 9, 2025 04:40
@nouvist nouvist restored the fix-hangs branch June 9, 2025 04:41
@nouvist nouvist reopened this Jun 9, 2025
@Piinks Piinks requested a review from chunhtai June 10, 2025 22:14
@nouvist nouvist force-pushed the fix-hangs branch 3 times, most recently from d8ae141 to b6ed95b Compare June 17, 2025 15:07
@reidbaker reidbaker requested a review from justinmc June 18, 2025 14:59
@Piinks Piinks requested a review from hannah-hyj June 18, 2025 19:07
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,
Copy link
Contributor

@chunhtai chunhtai Jun 23, 2025

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.

  1. resolve the result immediately in pushReplacement
  2. 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.

Copy link
Author

@nouvist nouvist Jun 23, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants