Skip to content

[go_router] Make replace use pop and push to generate a new pageKey #2747

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

Merged

Conversation

ValentinVignal
Copy link
Contributor

Refactoresreplace to use pop and push to a unique page key is used every time replace is used.

Fixes flutter/flutter#114234

If you had to change anything in the flutter/tests repo, include a link to the migration guide as per the breaking change policy.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/packages repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the package surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.
  • I updated CHANGELOG.md to add a description of the change, following repository CHANGELOG style.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

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

@ValentinVignal
Copy link
Contributor Author

The test repo_checks failed because of the analyzer in the example of the go_router package:

    error - example/lib/books/src/screens/book_details.dart:7:8 - Target of URI doesn't exist: 'package:url_launcher/link.dart'. Try creating the file referenced by the URI, or try using a URI for a file that does exist. - uri_does_not_exist
    error - example/lib/books/src/screens/book_details.dart:58:13 - The method 'Link' isn't defined for the type 'BookDetailsScreen'. Try correcting the name to the name of an existing method, or defining a method named 'Link'. - undefi[...]rt:11:37 - Avoid method calls or property accesses on a "dynamic" target. - avoid_dynamic_calls
     info - example/test/sub_routes_test.dart:7:8 - The imported package 'go_router_examples' isn't a dependency of the importing package. Try adding a dependency for 'go_router_examples' in the 'pubspec.yaml' file. - depend_on_referenced_packages
     info - example/test/sub_routes_test.dart:11:37 - Avoid method calls or property accesses on a "dynamic" target. - avoid_dynamic_calls

I don't think that is related to my changes? Do you want me to try to fix it in this PR or should I do another PR instead?

@chunhtai
Copy link
Contributor

no, it should be fixed by #2751 (comment)

Can you rebase off the latest main?

@ValentinVignal ValentinVignal force-pushed the go-router/replace-with-push-count branch from 3574eae to 9b20b5c Compare November 1, 2022 01:04
@chunhtai
Copy link
Contributor

chunhtai commented Nov 2, 2022

My current plan is to make the replace to push pageless route, in that case the pagekey would no longer matter. I think this pr will be obsolete see this conversation flutter/flutter#99112. I suggest we don't move forward with this pr. WDYT

@ValentinVignal
Copy link
Contributor Author

About flutter/flutter#99112 I'm not in favor of using pageless pages from Navigator API directly. I will comment on the issue to explain why and my use cases.

However, our app is currently facing this bug, so I would say we could still push the fix. If we don't, the bug will still remain, which is an issue in my opinion.

Copy link
Contributor

@chunhtai chunhtai left a comment

Choose a reason for hiding this comment

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

Yes, you are right, it shouldn't stop this pr from merging. I left some comments

@@ -71,17 +71,21 @@ class RouteMatchList {
}

/// Removes the last match.
void pop() {
void pop({bool asserts = true}) {
Copy link
Contributor

Choose a reason for hiding this comment

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

seems weird as an API, I think we can move the _debugAssertNotEmpty check to RouterDelegate.pop instead

Copy link
Contributor

Choose a reason for hiding this comment

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

and it should probably be wrapped in an assert

Copy link
Contributor Author

Choose a reason for hiding this comment

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

seems weird as an API,

Yes, I do agree. But I saw somewhere that someone was thinking of making some router's field private (there was an issue where this was discussed). So I didn't know whether or not pop would be not-accessible publicly at some point. In this case, it would have been fine.

But if not, yes, that's not a good idea to add this parameter.

I changed it in a50d124

…ith-push-count

# Conflicts:
#	packages/go_router/CHANGELOG.md
#	packages/go_router/pubspec.yaml
Copy link
Contributor

@chunhtai chunhtai left a comment

Choose a reason for hiding this comment

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

LGTM, %nits

/// Pop the top page off the GoRouter's page stack.
void pop() {
_matchList.pop();
_debugAssertMatchListNotEmpty();
Copy link
Contributor

Choose a reason for hiding this comment

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

you can also wrap this in an assert so that release mode will not even waste time calling into an empty function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is 8e8d187 what you mean?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes

@@ -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: 5.1.2
version: 5.1.4
Copy link
Contributor

Choose a reason for hiding this comment

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

5.1.3?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With the newly merged PRs, I'll make it 5.1.6

@chunhtai chunhtai requested a review from johnpryan November 4, 2022 15:40
…ith-push-count

# Conflicts:
#	packages/go_router/CHANGELOG.md
#	packages/go_router/pubspec.yaml
@ValentinVignal
Copy link
Contributor Author

@johnpryan is there anything you want me to do on this PR ?

@johnpryan johnpryan added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 14, 2022
@auto-submit
Copy link
Contributor

auto-submit bot commented Nov 14, 2022

auto label is removed for flutter/packages, pr: 2747, due to - The status or check suite web_benchmarks_test CHROMIUM_BUILD:950363 has failed. Please fix the issues identified (or deflake) before re-applying this label.

@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 14, 2022
@johnpryan johnpryan added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 14, 2022
@chunhtai
Copy link
Contributor

Not sure why the ci stuck @ValentinVignal can you rebase off the latest main branch and try again?

@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 15, 2022
@auto-submit
Copy link
Contributor

auto-submit bot commented Nov 15, 2022

auto label is removed for flutter/packages, pr: 2747, due to - The status or check suite macos-platform_tests CHANNEL:master has failed. Please fix the issues identified (or deflake) before re-applying this label.

…ith-push-count

# Conflicts:
#	packages/go_router/CHANGELOG.md
@ValentinVignal
Copy link
Contributor Author

@chunhtai It looks like it is fine now

@chunhtai chunhtai merged commit d1f5f87 into flutter:main Nov 16, 2022
johnpryan added a commit to johnpryan/flutter_packages that referenced this pull request Nov 16, 2022
…geKey` (flutter#2747)

* 🐛 Use pop and push in replace to generate a new pageKey

* ✅ Test that replace creates a new page key

* ⬆️ Increase the version number

* ♻️ Move the asserts to the router deleguate

* Wrap _debugAssertMatchListNotEmpty in an assert

* Update packages/go_router/lib/src/delegate.dart

Co-authored-by: John Ryan <[email protected]>
johnpryan added a commit to johnpryan/flutter_packages that referenced this pull request Nov 16, 2022
[go_router] Make `replace` use `pop` and `push` to generate a new `pageKey` (flutter#2747)

* 🐛 Use pop and push in replace to generate a new pageKey

* ✅ Test that replace creates a new page key

* ⬆️ Increase the version number

* ♻️ Move the asserts to the router deleguate

* Wrap _debugAssertMatchListNotEmpty in an assert

* Update packages/go_router/lib/src/delegate.dart

Co-authored-by: John Ryan <[email protected]>

Fix broken links in documentation

update changelog
auto-submit bot pushed a commit that referenced this pull request Nov 16, 2022
[go_router] Make `replace` use `pop` and `push` to generate a new `pageKey` (#2747)

* 🐛 Use pop and push in replace to generate a new pageKey

* ✅ Test that replace creates a new page key

* ⬆️ Increase the version number

* ♻️ Move the asserts to the router deleguate

* Wrap _debugAssertMatchListNotEmpty in an assert

* Update packages/go_router/lib/src/delegate.dart

Co-authored-by: John Ryan <[email protected]>

Fix broken links in documentation

update changelog
percula pushed a commit to percula/packages that referenced this pull request Nov 17, 2022
…geKey` (flutter#2747)

* 🐛 Use pop and push in replace to generate a new pageKey

* ✅ Test that replace creates a new page key

* ⬆️ Increase the version number

* ♻️ Move the asserts to the router deleguate

* Wrap _debugAssertMatchListNotEmpty in an assert

* Update packages/go_router/lib/src/delegate.dart

Co-authored-by: John Ryan <[email protected]>
percula pushed a commit to percula/packages that referenced this pull request Nov 17, 2022
[go_router] Make `replace` use `pop` and `push` to generate a new `pageKey` (flutter#2747)

* 🐛 Use pop and push in replace to generate a new pageKey

* ✅ Test that replace creates a new page key

* ⬆️ Increase the version number

* ♻️ Move the asserts to the router deleguate

* Wrap _debugAssertMatchListNotEmpty in an assert

* Update packages/go_router/lib/src/delegate.dart

Co-authored-by: John Ryan <[email protected]>

Fix broken links in documentation

update changelog
johnpryan added a commit to Slowhand0309/packages that referenced this pull request Nov 17, 2022
…geKey` (flutter#2747)

* 🐛 Use pop and push in replace to generate a new pageKey

* ✅ Test that replace creates a new page key

* ⬆️ Increase the version number

* ♻️ Move the asserts to the router deleguate

* Wrap _debugAssertMatchListNotEmpty in an assert

* Update packages/go_router/lib/src/delegate.dart

Co-authored-by: John Ryan <[email protected]>
johnpryan added a commit to Slowhand0309/packages that referenced this pull request Nov 17, 2022
[go_router] Make `replace` use `pop` and `push` to generate a new `pageKey` (flutter#2747)

* 🐛 Use pop and push in replace to generate a new pageKey

* ✅ Test that replace creates a new page key

* ⬆️ Increase the version number

* ♻️ Move the asserts to the router deleguate

* Wrap _debugAssertMatchListNotEmpty in an assert

* Update packages/go_router/lib/src/delegate.dart

Co-authored-by: John Ryan <[email protected]>

Fix broken links in documentation

update changelog
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.

[go_router] replace doesn't generate a new pageKey
3 participants