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]: add optional completer for replaced routes #6787

Conversation

pawlowskim
Copy link

When route from the stack is replaced, its completer is lost, and causes futures in routes chain to never finish. This change add optional completer that can be passed when pushing / replacing routes that will be completed when route is replaced.

It fixes: flutter/flutter#141251
This PR is continuation of: #6451

CC @chunhtai

Pre-launch Checklist

@@ -79,8 +91,16 @@ extension GoRouterHelper on BuildContext {
/// * [replace] which replaces the top-most page of the page stack but treats
/// it as the same page. The page key will be reused. This will preserve the
/// state and not run any page animation.
void pushReplacement(String location, {Object? extra}) =>
GoRouter.of(this).pushReplacement(location, extra: extra);
void pushReplacement(
Copy link
Contributor

Choose a reason for hiding this comment

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

just took a quick glance, should we make this return future instead of passing in a completer?

Copy link

Choose a reason for hiding this comment

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

@chunhtai

If we have page A -> push -> page B -> pushReplacement -> page C,

this still won't solve the problem because although we can track when the completer from pushReplacement finishes on page B by returning a Future, the Future on page A will never complete.

In the _updateRouteMatchList function, in the case of NavigatingType.pushReplacement, the completer responsible for the future in the push method is simply removed and never completed.

Passing a completer through the push method allows us to detect when such a page has been replaced.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the this is intended? the first push will never complete since it was replaced by another page regardless whether you pass in the completer or not

@chunhtai chunhtai self-requested a review June 20, 2024 21:40
@@ -1,7 +1,7 @@
name: go_router
description: A declarative router for Flutter based on Navigation 2 supporting
deep linking, data-driven routes and more
version: 14.1.4
version: 14.1.5
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a new api should bump minor version

@@ -62,6 +63,10 @@ class RouteInformationState<T> {
/// [NavigatingType.restore].
final Completer<T?>? completer;

/// The completer that needs to be completed when route is replaced.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// The completer that needs to be completed when route is replaced.
/// The completer that will be completed when route is replaced.

@@ -62,6 +63,10 @@ class RouteInformationState<T> {
/// [NavigatingType.restore].
final Completer<T?>? completer;

/// The completer that needs to be completed when route is replaced.
/// [completer] is ignored when replacing routes.
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe add only only used when type is NavigatingType.push or NavigatingType.pushReplacement
NavigatingType.replace

@chunhtai
Copy link
Contributor

Hi @pawlowskim Are you still planning on coming back to this pr?

@chunhtai
Copy link
Contributor

chunhtai commented Sep 5, 2024

Closing the pr for now. feel free to reopen once you have time

@chunhtai chunhtai closed this Sep 5, 2024
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.

Awaiting a GoRoute.push() is not resolving when the push page gets replaced via pushReplacement
4 participants