-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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] Refactored RouteMatchList and imperative APIs #5497
Conversation
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie or stuartmorgan on the #hackers channel in Chat (don't just cc them here, they won't see it! Use Discord!). If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix? Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
77e95ca
to
109bdfc
Compare
|
||
/// Returns the top-level pages instead of the root navigator. Used for | ||
/// testing. | ||
List<Page<Object?>> _buildPages( |
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.
most of the recursive build pages logic is moved to _CustomNavigatorState
@@ -73,25 +79,36 @@ class GoRouterDelegate extends RouterDelegate<RouteMatchList> | |||
|
|||
/// Returns `true` if the active Navigator can pop. | |||
bool canPop() { | |||
final _NavigatorStateIterator iterator = _createNavigatorStateIterator(); |
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.
previously we need to scan the list and use parent navigator key to jump around the list. Therefore i created this iterator to abstract away the logic.
After the refactor we just need to look at the last node in the RouteMatchList and walk up the tree branch.
|
||
/// Generate a [RouteMatch] object by matching the `route` with | ||
/// `remainingLocation`. | ||
/// | ||
/// The extracted path parameters, as the result of the matching, are stored | ||
/// into `pathParameters`. | ||
static RouteMatch? match({ | ||
static List<RouteMatchBase> 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.
This is the most complex part in this pr, previously match
just produce a RouteMatch for the input route.
After this change, this match
will recursively match the subroute in route
and return the entire route matches if it finds the full match.
|
||
if (builder == null) { | ||
return null; | ||
} | ||
return buildPage(context, state, Builder(builder: (BuildContext context) { | ||
return _buildPlatformAdapterPage(context, state, | ||
Builder(builder: (BuildContext context) { | ||
return builder(context, state); | ||
})); | ||
} | ||
|
||
/// Builds a [Page] for [ShellRouteBase] |
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.
nit : ShellRouteMatch
return _buildPlatformAdapterPage(context, state, | ||
Builder(builder: (BuildContext context) { | ||
return match.route.buildWidget(context, state, shellRouteContext)!; | ||
})); |
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.
nit: comma
GoRouterState buildState( | ||
RouteConfiguration configuration, RouteMatchList matches); | ||
|
||
/// Generate a list [RouteMatchBase] objects by matching the `route` and its |
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.
nit: 'Generates a list of'
} | ||
return copyWith( | ||
matches: _createNewMatchUntilIncompatible( | ||
matches, match.matches.matches, 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.
nit: comma
/// The last leaf route. | ||
/// | ||
/// If the last RouteMatchBase from [matches] is a ShellRouteMatch, it | ||
/// cursively goes into its [ShellRouteMatch.matches] until it reach the leaf |
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.
nit: recursively
/// order is removed. | ||
static List<RouteMatchBase> _removeRouteMatchFromList( | ||
List<RouteMatchBase> matches, RouteMatchBase target) { | ||
// Remove is usually caused by pop; therefore, start searching from the end. |
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.
Remove is usually caused by pop
by usually
do you mean there are other cases?
this function looks like it assumes all removal is pop. it not only removes the target, but also remove all matches after the target.
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.
updated wording
@override | ||
final ShellRouteBase route; | ||
|
||
RouteMatch get _leafMatch { |
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 found the name leafMatch
a bit confusing cause a tree can have many leaves. Maybe lastLeaf
is more clear?
@override | ||
void didChangeDependencies() { | ||
super.didChangeDependencies(); | ||
// Return a HeroController based on the app type. |
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.
nit: returns
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.
gramma is correct here since I am describing a fact, but the return may not be a good word here. will update
} | ||
} | ||
if (subRouteMatches?.isEmpty ?? true) { | ||
// If not finding a sub route match, it is consider not matched for 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.
nit: considered
73d0cd2
to
0e058a5
Compare
configuration: configuration, | ||
errorBuilder: errorBuilder, | ||
errorPageBuilder: errorPageBuilder, | ||
)); |
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.
nit: comma
required this.navigatorRestorationId, | ||
required this.onPopPageWithRouteMatch, | ||
required this.matchList, | ||
required this.matches, |
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.
why pass both matchList and matches? Can you add some comments?
registry: _registry, | ||
child: HeroControllerScope( | ||
controller: _controller!, | ||
child: Builder( |
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.
Builder() here seems like unnecessary. context is not used.
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.
good catch
// Grabs the route matches for the scope navigator key and put it into the | ||
// matches for `null`. | ||
if (result.containsKey(scopedNavigatorKey)) { | ||
final List<RouteMatchBase> matchForScopedNavigator = |
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.
nit matchesForScopedNavigator
); | ||
} else { | ||
assert(false, 'Unexpected route type: $route'); | ||
return const <GlobalKey<NavigatorState>?, List<RouteMatchBase>>{}; |
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.
return const <GlobalKey<NavigatorState>?, List<RouteMatchBase>>{}; | |
return const _empty; |
required Uri uri, | ||
}) { | ||
final GlobalKey<NavigatorState>? parentKey = | ||
route.parentNavigatorKey == null || |
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.
same here
packages/go_router/CHANGELOG.md
Outdated
@@ -1,3 +1,10 @@ | |||
## 13.0.0 | |||
|
|||
- Refactored `RouteMatchList` and imperative APIs. |
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.
nit: Refactors
Migration guide for flutter/packages#5497
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
flutter/packages@4c3bc49...23d2d9c 2023-12-22 49699333+dependabot[bot]@users.noreply.github.com Bump lewagon/wait-on-check-action from 1.3.1 to 1.3.3 (flutter/packages#5737) 2023-12-21 54558023+keyonghan@users.noreply.github.com Disable `presubmit: false` targets for recipes CQ (flutter/packages#5735) 2023-12-21 47866232+chunhtai@users.noreply.github.com [go_router] Refactored RouteMatchList and imperative APIs (flutter/packages#5497) 2023-12-21 54558023+keyonghan@users.noreply.github.com Add env_variables in ci.yaml (flutter/packages#5730) 2023-12-21 engine-flutter-autoroll@skia.org Roll Flutter (stable) from 2e9cb0a to 78666c8 (1 revision) (flutter/packages#5734) 2023-12-21 engine-flutter-autoroll@skia.org Roll Flutter from da0cd69 to 11def8e (16 revisions) (flutter/packages#5732) 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,rmistry@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
This pr refactor RouteMatchList to be a tree structure. Added a common base class RouteMatchBase. It is extended by both RouteMatch and ShellRouteMatch. The RouteMatch is for GoRoute, and is always a leaf node The ShellRouteMatch is for ShellRouteBase, and is always and intermediate node with a list of child RouteMatchBase[s]. This pr also redo how push is processed. Will add a doc explain this shortly. This is a breaking change, will write a migration guide soon. fixes flutter/flutter#134524 fixes flutter/flutter#130406 fixes flutter/flutter#126365 fixes flutter/flutter#125752 fixes flutter/flutter#120791 fixes flutter/flutter#120665 fixes flutter/flutter#113001 fixes flutter/flutter#110512
flutter/packages@4c3bc49...23d2d9c 2023-12-22 49699333+dependabot[bot]@users.noreply.github.com Bump lewagon/wait-on-check-action from 1.3.1 to 1.3.3 (flutter/packages#5737) 2023-12-21 54558023+keyonghan@users.noreply.github.com Disable `presubmit: false` targets for recipes CQ (flutter/packages#5735) 2023-12-21 47866232+chunhtai@users.noreply.github.com [go_router] Refactored RouteMatchList and imperative APIs (flutter/packages#5497) 2023-12-21 54558023+keyonghan@users.noreply.github.com Add env_variables in ci.yaml (flutter/packages#5730) 2023-12-21 engine-flutter-autoroll@skia.org Roll Flutter (stable) from 2e9cb0a to 78666c8 (1 revision) (flutter/packages#5734) 2023-12-21 engine-flutter-autoroll@skia.org Roll Flutter from da0cd69 to 11def8e (16 revisions) (flutter/packages#5732) 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,rmistry@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
This pr refactor RouteMatchList to be a tree structure. Added a common base class RouteMatchBase. It is extended by both RouteMatch and ShellRouteMatch. The RouteMatch is for GoRoute, and is always a leaf node The ShellRouteMatch is for ShellRouteBase, and is always and intermediate node with a list of child RouteMatchBase[s]. This pr also redo how push is processed. Will add a doc explain this shortly. This is a breaking change, will write a migration guide soon. fixes flutter/flutter#134524 fixes flutter/flutter#130406 fixes flutter/flutter#126365 fixes flutter/flutter#125752 fixes flutter/flutter#120791 fixes flutter/flutter#120665 fixes flutter/flutter#113001 fixes flutter/flutter#110512
This pr refactor RouteMatchList to be a tree structure.
Added a common base class RouteMatchBase. It is extended by both RouteMatch and ShellRouteMatch.
The RouteMatch is for GoRoute, and is always a leaf node
The ShellRouteMatch is for ShellRouteBase, and is always and intermediate node with a list of child RouteMatchBase[s].
This pr also redo how push is processed. Will add a doc explain this shortly.
This is a breaking change, will write a migration guide soon.
fixes flutter/flutter#134524
fixes flutter/flutter#130406
fixes flutter/flutter#126365
fixes flutter/flutter#125752
fixes flutter/flutter#120791
fixes flutter/flutter#120665
fixes flutter/flutter#113001
fixes flutter/flutter#110512
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.