-
Notifications
You must be signed in to change notification settings - Fork 3k
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 support for preloading branches of StatefulShellRoute (revised solution) #6467
[go_router] Add support for preloading branches of StatefulShellRoute (revised solution) #6467
Conversation
I know I have been slacking off at this pr. I am sorry about this. My schedule is quite tight after I came back from vacation. This is still under my radar. I will try find time review this pr within 2 weeks |
No worries @chunhtai, I completely understand, have had far too much on my plate myself the last year 😅 |
@@ -60,6 +60,9 @@ class NestedTabNavigationExampleApp extends StatelessWidget { | |||
], | |||
), | |||
], | |||
// To enable preloading of the initial locations of branches, pass | |||
// 'true' for the parameter preload. | |||
// preload: true, |
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.
I'd find it clearer if the last line was uncommented as preload: false
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.
You may be right, I'll consider this.
Any updates on this? |
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.
Overall LGTM, just some comments
@@ -1255,8 +1291,39 @@ class StatefulNavigationShellState extends State<StatefulNavigationShell> | |||
final bool locationChanged = | |||
previousBranchLocation != currentBranchLocation; | |||
if (locationChanged || !hasExistingNavigator) { | |||
_branchNavigators[branch.navigatorKey] = shellRouteContext | |||
.navigatorBuilder(branch.observers, branch.restorationScopeId); | |||
_branchNavigators[branch.navigatorKey] = |
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.
just realized somewhere in this method should probably remove entries in _branchNavigators the are no longer in the StatefulShellRoute?
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.
You're right, that is definitely necessary to do now. Will have a look at it.
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.
@chuntai, I added a fix for removing old entries, but when attempting to write a test case, I ran into issues with duplicate GlobalKeys (_shellStateKey) when updating the dynamic RoutingConfig. Or - I should be clear - at first the test case worked, but not because of the code I added, but instead because the entire StatefulShellRoute was replaced/reloaded. But when I added the possibility to set the GlobalKey<StatefulNavigationShellState> _shellStateKey
to maintain state, I started to get this error.
When trying to troubleshoot it, I started to wonder whether dynamic RoutingConfig full supports ShellRoutes, at least with state. Added some test cases to test this, and it seems simple StatefulWidgets in a simple routing scenario works, but when adding a (regular) ShellRoute with a stateful shell I also get and issue with duplicate GlobalKeys.
Not sure if I just missed something, but I anyway added a gist with the test cases here: https://gist.github.com/tolo/922fd838cdea30b17121533b0012eda4
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.
can you file an issue for it? looks like a bug
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.
is the fix in this pr already?
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.
It is now. 😊 Note though that I disabled two tests that fail due to the issue I mentioned above.
What's the status here ? It seems like you said that you have a test locally that's failing but it's unrelated to the changes here ? |
Yes, @chunhtai, have you had a chance to too look at my comment above (#6467 (comment))? The issue is however only with testing if obsolete branch navigators are removed (which is done dynamic RoutingConfig), so possibly this could be moved to a separate issue/PR. And another issue should probably be opened for fixing the support for dynamic RoutingConfig for (stateful) shell routes. What do you think @chunhtai? |
will take a look this week |
packages/go_router/example/lib/others/custom_stateful_shell_route.dart
Outdated
Show resolved
Hide resolved
@@ -1255,8 +1291,39 @@ class StatefulNavigationShellState extends State<StatefulNavigationShell> | |||
final bool locationChanged = | |||
previousBranchLocation != currentBranchLocation; | |||
if (locationChanged || !hasExistingNavigator) { | |||
_branchNavigators[branch.navigatorKey] = shellRouteContext | |||
.navigatorBuilder(branch.observers, branch.restorationScopeId); | |||
_branchNavigators[branch.navigatorKey] = |
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.
can you file an issue for it? looks like a bug
@@ -1255,8 +1291,39 @@ class StatefulNavigationShellState extends State<StatefulNavigationShell> | |||
final bool locationChanged = | |||
previousBranchLocation != currentBranchLocation; | |||
if (locationChanged || !hasExistingNavigator) { | |||
_branchNavigators[branch.navigatorKey] = shellRouteContext | |||
.navigatorBuilder(branch.observers, branch.restorationScopeId); | |||
_branchNavigators[branch.navigatorKey] = |
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.
is the fix in this pr already?
(Note: issues with dynamic route config)
Any status update? |
@chunhtai, as mentioned above, I've included the fix for cleaning obsolete branches. But I'm thinking it might be better to postpone that fix until the issues with duplicate GlobalKeys is resolved. |
|
||
final Widget navigator = widget.shellRouteContext.navigatorBuilder( | ||
branch.navigatorKey, | ||
match!, |
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.
!
can be removed on this line
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.
Oh? Maybe I'm missing something, but that gives me an error (since match is ShellRouteMatch?). Would have been nice if the assert would have that effect though.
@chunhtai can this PR get some love ? (feedback) |
FYI, for those interested in |
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.
LGTM
…ple (#7583) Updated `custom_stateful_shell_route.dart` example to better support swiping in TabView. Also added code to demonstrate use of PageView instead of TabView. Note that to be fully effective from a usability perspective, the PR #6467 (branch preloading) need also be merged. This PR addresses: * flutter/flutter#150837 * flutter/flutter#112267 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] page, which explains my responsibilities. - [x] 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`.) - [x] I signed the [CLA]. - [x] The title of the PR starts with the name of the package surrounded by square brackets, e.g. `[shared_preferences]` - [x] I [linked to at least one issue that this PR fixes] in the description above. - [x] I updated `pubspec.yaml` with an appropriate new version according to the [pub versioning philosophy], or this PR is [exempt from version changes]. - [x] I updated `CHANGELOG.md` to add a description of the change, [following repository CHANGELOG style], or this PR is [exempt from CHANGELOG changes]. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/packages/blob/main/CONTRIBUTING.md [Tree Hygiene]: https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md [relevant style guides]: https://github.com/flutter/packages/blob/main/CONTRIBUTING.md#style [CLA]: https://cla.developers.google.com/ [Discord]: https://github.com/flutter/flutter/blob/master/docs/contributing/Chat.md [linked to at least one issue that this PR fixes]: https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md#overview [pub versioning philosophy]: https://dart.dev/tools/pub/versioning [exempt from version changes]: https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#version [following repository CHANGELOG style]: https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changelog-style [exempt from CHANGELOG changes]: https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changelog [test-exempt]: https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md#tests
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.
LGTM!
Hi! |
Hi @tolo can you rebase and then we can merge? |
@chunhtai Can autosubmit be added ? as conflicts were already resolved 2 weeks ago |
auto label is removed for flutter/packages/6467, due to - The status or check suite Linux repo_checks has failed. Please fix the issues identified (or deflake) before re-applying this label. |
Looks like there is some outdated excerpt I can't fix it through gihub ui. @tolo can you try to fix it? |
…ShellRoute (revised solution) (flutter/packages#6467)
…ShellRoute (revised solution) (flutter/packages#6467)
…ShellRoute (revised solution) (flutter/packages#6467)
flutter/packages@72356fd...26e123a 2024-11-13 dasyad00@gmail.com [camera_windows] Set device media type for video preview explicitly (flutter/packages#7447) 2024-11-13 39979207+ThangVuNguyenViet@users.noreply.github.com [go_router] Add support for relative routes (flutter/packages#6825) 2024-11-13 pq@users.noreply.github.com [vector_graphics_compiler] fix a renamed method parameter lint (flutter/packages#8070) 2024-11-12 feinstein@users.noreply.github.com [in_app_purchase] Add expiration date to Transaction (flutter/packages#8030) 2024-11-12 stuartmorgan@google.com [various] Clean up contributing guides (flutter/packages#8032) 2024-11-12 ditman@gmail.com [ci] Remove web renderer option from tools. (flutter/packages#8055) 2024-11-12 stuartmorgan@google.com [url_launcher] Update Pigeon version for Linux (flutter/packages#8065) 2024-11-12 tobias@leafnode.se [go_router] Add support for preloading branches of StatefulShellRoute (revised solution) (flutter/packages#6467) 2024-11-12 stuartmorgan@google.com [pigeon] Make Linux type declarations public (flutter/packages#8040) 2024-11-11 engine-flutter-autoroll@skia.org Roll Flutter from 73546b3 to c8510f2 (30 revisions) (flutter/packages#8042) 2024-11-11 magder@google.com Use dependabot multi-directory configuration for Android package updates (flutter/packages#8048) 2024-11-11 stuartmorgan@google.com [tools] Run `pub get` before `format` (flutter/packages#8052) 2024-11-11 stuartmorgan@google.com [file_selector] Fix Linux cancel regression (flutter/packages#8051) 2024-11-09 stuartmorgan@google.com [shared_preferences] Fix confusing language in README (flutter/packages#8049) 2024-11-08 magder@google.com Use dependabot multi-directory configuration for Android example gradle updates (flutter/packages#8036) 2024-11-08 43054281+camsim99@users.noreply.github.com [animations] Remove `.flutter-plugins` reference from example app (flutter/packages#8002) 2024-11-08 magder@google.com Group dependabot github-action update PRs, delete dead docker updates (flutter/packages#8044) 2024-11-08 37028599+EArminjon@users.noreply.github.com [vector_graphics_compiler] fix-null-exception (flutter/packages#8006) 2024-11-08 stuartmorgan@google.com [tools] Format Dart per-package (flutter/packages#8043) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages-flutter-autoroll Please CC flutter-ecosystem@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Adds support for preloading branches in a
StatefulShellRoute
. This functionality was initially part of an early implementation of #2650, however it was decided to implement this in a separate PR. The current implementation is a rewrite of the original implementation to better fit the final version ofStatefulShellRoute
(and go_router in general).NOTE: this is a revised version of the initial solution (see #4251), containing a substantially simpler implementation made possible thanks to recent refactoring in go_router.
This fixes issue flutter/flutter#127804.
Pre-launch Checklist
dart format
.)[shared_preferences]
pubspec.yaml
with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.md
to add a description of the change, following repository CHANGELOG style.///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.