Skip to content

Conversation

@EArminjon
Copy link
Contributor

@EArminjon EArminjon commented Oct 28, 2024

(edited 4 december) PR EDITED TO FIT LATEST COMMENTS

Developper may want to remove a route in the background while an other one is displayed.
To do so, developer can use removeRoute().

RemoveRoute() didn't resolve futures created by Navigator.push and so code which await for Navigator.push will never end.

By calling complete() inside removeRoute, futures are well resolved. In addition that also allow to pass some result through removeRoute.

Ex:

Navigator.of(context).removeRoute(route, "test");
Navigator.of(context).removeRoute(route, object);

This PR aim to fix this issue : #157505

Pre-launch Checklist

@github-actions github-actions bot added framework flutter/packages/flutter repository. See also f: labels. f: routes Navigator, Router, and related APIs. labels Oct 28, 2024
@EArminjon EArminjon force-pushed the fix-expose-did-complete branch 2 times, most recently from d6074ed to 01e9627 Compare October 28, 2024 15:29
@EArminjon EArminjon marked this pull request as ready for review October 28, 2024 17:01
Copy link
Contributor

@nate-thegrate nate-thegrate left a comment

Choose a reason for hiding this comment

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

Maybe removeRoute should call didComplete internally but i didn't know what are the potential drawbacks.

I think this is a really good point.

If letting the Future hang forever is desired behavior for some reason, it probably makes sense to leave things as-is, given the workaround shown in #157505 (comment). Otherwise, I think it makes sense to unconditionally complete the future when the route is removed.

@chunhtai chunhtai self-requested a review October 30, 2024 18:23
@Piinks
Copy link
Contributor

Piinks commented Nov 19, 2024

(PR Triage): Hey @EArminjon, thanks for sending another PR! Would you like to continue working on this change and address the feedback above? Thanks!

@EArminjon
Copy link
Contributor Author

EArminjon commented Nov 20, 2024

Sorry for delay, I can try.

@EArminjon EArminjon force-pushed the fix-expose-did-complete branch 3 times, most recently from cdf2970 to 2b2fdf9 Compare November 20, 2024 10:24
@EArminjon EArminjon changed the title fix-expose-did-complete feat: remouteRoute now call didComplete Nov 20, 2024
@EArminjon EArminjon force-pushed the fix-expose-did-complete branch 2 times, most recently from 5074b2e to 0eee47b Compare November 20, 2024 10:42
@EArminjon
Copy link
Contributor Author

@Piinks done :)

@EArminjon
Copy link
Contributor Author

EArminjon commented Nov 20, 2024

I didn't know if we must consider this as a breaking change. If someone created a logic around the fact that .push() will never be completed when using removeRoute, now it will be.

nate-thegrate

This comment was marked as resolved.

@EArminjon EArminjon force-pushed the fix-expose-did-complete branch from 0eee47b to 0094a59 Compare November 20, 2024 18:58
nate-thegrate

This comment was marked as resolved.

@EArminjon EArminjon force-pushed the fix-expose-did-complete branch from 0094a59 to 6408f86 Compare November 20, 2024 21:28
@goderbauer goderbauer changed the title feat: remouteRoute now call didComplete feat: removeRoute now call didComplete Nov 26, 2024
Comment on lines 2785 to 2787
/// [NavigatorObserver.didRemove]). The removed route is disposed without
/// being notified. The future that had been returned from pushing that routes
/// being notified. The future that had been returned from pushing that route
/// will not complete.
Copy link
Contributor

Choose a reason for hiding this comment

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

It does feel a bit weird that removeRouteBelow is no longer consistent with removeRoute. Should we change all of these methods to complete their respective futures?

Copy link
Contributor Author

@EArminjon EArminjon Dec 4, 2024

Choose a reason for hiding this comment

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

pushAndRemoveUntil, restorablePushAndRemoveUntil, restorablePushNamedAndRemoveUntil and pushAndRemoveUntil could be supported but we need to add an extra logique like a callback to let developper choose to override the value of didComplete(result). if the callback is not provided we can fallback to null.

Maybe that can take place into an future pull request because that will also touch popUntil.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

PR edited to support removeRouteBelow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can also go forward and try to support all method like replace, restorable etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Must i support them all inside this PR with the risk to delay massively it or should i create a dedicated PR later ? (New unit test will be needed, lot of changes)

Copy link
Contributor

Choose a reason for hiding this comment

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

Must I support them all inside this PR with the risk of a massive delay, or should I create a dedicated PR later?

That's a really good question.

I suppose my question would be: is it all right for removeRoute & removeRouteBelow to both complete their respective futures, but for none of the other similar methods to do this?

If we merge this pull request today and there end up being issues with migrating the similar methods, I think the API would be more inconsistent than it is now.

Copy link
Contributor

Choose a reason for hiding this comment

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

pushAndRemoveUntil, restorablePushAndRemoveUntil, restorablePushNamedAndRemoveUntil and pushAndRemoveUntil could be supported but we would need to add extra logic, like a callback, to give the developer an option to override the value of didComplete(result); if the callback is not provided we can fallback to null.

My opinion as of now is that it'd be best for each removed route to have its future completed, but we can just do didComplete(null) for now. If we want pushAndRemoveUntil to support completing with a value, that can be saved for a future PR.

Does that sound okay to you?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That could be a great roadmap : first time didComplete(null) by default, next PR logic to well handle that everywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tested quickly on my side, I can well update all these functions to support the result property, and when needed, a dedicated callback for whose related to popUntil and removeUntil. Will do that later in dedicated PR (if you and reviewer agree).

Copy link
Contributor

Choose a reason for hiding this comment

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

SGTM!

@EArminjon EArminjon force-pushed the fix-expose-did-complete branch from 062127b to 010fc5e Compare December 4, 2024 19:11
@EArminjon EArminjon force-pushed the fix-expose-did-complete branch from 010fc5e to 6f7737c Compare December 4, 2024 19:40
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 14, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 14, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 15, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 15, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 16, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 16, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 17, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 17, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 17, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 18, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 18, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 18, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 19, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 19, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 19, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 20, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 20, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 20, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 20, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 20, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 20, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c: tech-debt Technical debt, code quality, testing, etc. f: routes Navigator, Router, and related APIs. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants