-
Notifications
You must be signed in to change notification settings - Fork 3.5k
[go_router] Fixes deep-link with no path on cold start #5113
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] Fixes deep-link with no path on cold start #5113
Conversation
| final List<RouteMatch>? result = _getLocRouteRecursively( | ||
| location: uri.path, | ||
| remainingLocation: uri.path, | ||
| location: uri.path.isEmpty ? '/' : uri.path, |
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.
Instead of fixing this in the parsing, this should probably be fixed in GoRouteInformationProvider to normalize the uri when it receives deeplink from engine.
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.
Following are the three call stacks when the breakpoint is set at the above change:
-
On a normal launch
Call stack
RouteConfiguration._getLocRouteMatches (.../.pub-cache/hosted/pub.dev/go_router-11.1.3/lib/src/configuration.dart:304) RouteConfiguration.findMatch (.../.pub-cache/hosted/pub.dev/go_router-11.1.3/lib/src/configuration.dart:281) GoRouteInformationParser.parseRouteInformationWithDependencies (.../.pub-cache/hosted/pub.dev/go_router-11.1.3/lib/src/parser.dart:87) _RouterState._processRouteInformation (.../flutter/stable/packages/flutter/lib/src/widgets/router.dart:744) _RouterState.restoreState (.../flutter/stable/packages/flutter/lib/src/widgets/router.dart:622) RestorationMixin._doRestore (.../flutter/stable/packages/flutter/lib/src/widgets/restoration.dart:923) RestorationMixin.didChangeDependencies (.../flutter/stable/packages/flutter/lib/src/widgets/restoration.dart:909) _RouterState.didChangeDependencies (.../flutter/stable/packages/flutter/lib/src/widgets/router.dart:692) StatefulElement._firstBuild (.../flutter/stable/packages/flutter/lib/src/widgets/framework.dart:5448) ComponentElement.mount (.../flutter/stable/packages/flutter/lib/src/widgets/framework.dart:5273) Element.inflateWidget (.../flutter/stable/packages/flutter/lib/src/widgets/framework.dart:4182) Element.updateChild (.../flutter/stable/packages/flutter/lib/src/widgets/framework.dart:3707) ComponentElement.performRebuild (.../flutter/stable/packages/flutter/lib/src/widgets/framework.dart:5322) Element.rebuild (.../flutter/stable/packages/flutter/lib/src/widgets/framework.dart:5016) ComponentElement._firstBuild (.../flutter/stable/packages/flutter/lib/src/widgets/framework.dart:5279) ComponentElement.mount (.../flutter/stable/packages/flutter/lib/src/widgets/framework.dart:5273) Element.inflateWidget (.../flutter/stable/packages/flutter/lib/src/widgets/framework.dart:4182) Element.updateChild (.../flutter/stable/packages/flutter/lib/src/widgets/framework.dart:3707) ComponentElement.performRebuild (.../flutter/stable/packages/flutter/lib/src/widgets/framework.dart:5322) Element.rebuild (.../flutter/stable/packages/flutter/lib/src/widgets/framework.dart:5016)
-
Launching deep-link with Uri containing scheme and authority using
adb shell, when the app is closed by clicking the system back button (To mock deep-link on cold start)Call stack
RouteConfiguration._getLocRouteMatches (.../.pub-cache/hosted/pub.dev/go_router-11.1.3/lib/src/configuration.dart:304) RouteConfiguration.findMatch (.../.pub-cache/hosted/pub.dev/go_router-11.1.3/lib/src/configuration.dart:281) GoRouteInformationParser.parseRouteInformationWithDependencies (.../.pub-cache/hosted/pub.dev/go_router-11.1.3/lib/src/parser.dart:87) _RouterState._processRouteInformation (.../flutter/stable/packages/flutter/lib/src/widgets/router.dart:744) _RouterState.restoreState (.../flutter/stable/packages/flutter/lib/src/widgets/router.dart:622) RestorationMixin._doRestore (.../flutter/stable/packages/flutter/lib/src/widgets/restoration.dart:923) RestorationMixin.didChangeDependencies (.../flutter/stable/packages/flutter/lib/src/widgets/restoration.dart:909) _RouterState.didChangeDependencies (.../flutter/stable/packages/flutter/lib/src/widgets/router.dart:692) StatefulElement._firstBuild (.../flutter/stable/packages/flutter/lib/src/widgets/framework.dart:5448) ComponentElement.mount (.../flutter/stable/packages/flutter/lib/src/widgets/framework.dart:5273) Element.inflateWidget (.../flutter/stable/packages/flutter/lib/src/widgets/framework.dart:4182) Element.updateChild (.../flutter/stable/packages/flutter/lib/src/widgets/framework.dart:3707) ComponentElement.performRebuild (.../flutter/stable/packages/flutter/lib/src/widgets/framework.dart:5322) Element.rebuild (.../flutter/stable/packages/flutter/lib/src/widgets/framework.dart:5016) ComponentElement._firstBuild (.../flutter/stable/packages/flutter/lib/src/widgets/framework.dart:5279) ComponentElement.mount (.../flutter/stable/packages/flutter/lib/src/widgets/framework.dart:5273) Element.inflateWidget (.../flutter/stable/packages/flutter/lib/src/widgets/framework.dart:4182) Element.updateChild (.../flutter/stable/packages/flutter/lib/src/widgets/framework.dart:3707) ComponentElement.performRebuild (.../flutter/stable/packages/flutter/lib/src/widgets/framework.dart:5322) Element.rebuild (.../flutter/stable/packages/flutter/lib/src/widgets/framework.dart:5016)
-
Launching deep-link with Uri containing scheme and authority using
adb shell, when the app is in foreground or backgrounded by clicking the home buttonCall stack
RouteConfiguration._getLocRouteMatches (.../.pub-cache/hosted/pub.dev/go_router-11.1.3/lib/src/configuration.dart:304) RouteConfiguration.findMatch (.../.pub-cache/hosted/pub.dev/go_router-11.1.3/lib/src/configuration.dart:281) GoRouteInformationParser.parseRouteInformationWithDependencies (.../.pub-cache/hosted/pub.dev/go_router-11.1.3/lib/src/parser.dart:87) _RouterState._processRouteInformation (.../flutter/stable/packages/flutter/lib/src/widgets/router.dart:744) _RouterState._handleRouteInformationProviderNotification (.../flutter/stable/packages/flutter/lib/src/widgets/router.dart:762) ChangeNotifier.notifyListeners (.../flutter/stable/packages/flutter/lib/src/foundation/change_notifier.dart:403) GoRouteInformationProvider.notifyListeners (.../.pub-cache/hosted/pub.dev/go_router-11.1.3/lib/src/information_provider.dart:147) GoRouteInformationProvider._platformReportsNewRouteInformation (.../.pub-cache/hosted/pub.dev/go_router-11.1.3/lib/src/information_provider.dart:246) GoRouteInformationProvider.didPushRouteInformation (.../.pub-cache/hosted/pub.dev/go_router-11.1.3/lib/src/information_provider.dart:277) WidgetsBinding._handlePushRouteInformation (.../flutter/stable/packages/flutter/lib/src/widgets/binding.dart:704) <asynchronous gap> (Unknown Source:0) MethodChannel._handleAsMethodCall (.../flutter/stable/packages/flutter/lib/src/services/platform_channel.dart:547) <asynchronous gap> (Unknown Source:0) _DefaultBinaryMessenger.setMessageHandler.<anonymous closure> (.../flutter/stable/packages/flutter/lib/src/services/binding.dart:567) <asynchronous gap> (Unknown Source:0)
You can see, GoRouteInformationProvider gets involved only in the 3rd case.
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.
for 1 and 2, it would hit this line
https://github.com/flutter/flutter/blob/38f318b46547a6c96715b1d8454c36606acddd42/packages/flutter/lib/src/widgets/router.dart#L619
We should make sure the initialroute is normalized in here
| String _effectiveInitialLocation(String? initialLocation) { |
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.
Incorporated suggested changes in the 6cc2fc4 commit.
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.
| final Uri platformDefaultUri = | ||
| Uri.parse(WidgetsBinding.instance.platformDispatcher.defaultRouteName); | ||
| final String platformDefault = | ||
| WidgetsBinding.instance.platformDispatcher.defaultRouteName; |
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.
What if the deeplink is called when the app is already running? wasn't the path be missing in that case? I think you need to also modify the logic in _platformReportsNewRouteInformation
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.
For now, the change is not required because the RouteInformation.location getter in _platformReportsNewRouteInformation() handles the empty path.
Once the package maintainers decide to migrate from RouteInformation.location to RouteInformation.uri, then it would be the right time to edit.
Also, the care should be taken about where to strip the scheme and authority, either early or late in the code as mentioned in this comment.
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.
ah interesting, thanks for reminding. Can you add a todo somewhere to remind us about location to uri migration? That way we won't break the code when that happens
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.
Added.
chunhtai
left a comment
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.
Code LGTM, just we should add a todo to remind ourself once the migration happens
| final Uri platformDefaultUri = | ||
| Uri.parse(WidgetsBinding.instance.platformDispatcher.defaultRouteName); | ||
| final String platformDefault = | ||
| WidgetsBinding.instance.platformDispatcher.defaultRouteName; |
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.
ah interesting, thanks for reminding. Can you add a todo somewhere to remind us about location to uri migration? That way we won't break the code when that happens
hannah-hyj
left a comment
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@2af6954...c9fec61 2023-10-31 [email protected] [image_picker] Prevent multiple active calls on iOS (flutter/packages#5272) 2023-10-30 [email protected] [in_app_purchase_android] Add missing response code to BillingResponse enum (flutter/packages#5120) 2023-10-30 49699333+dependabot[bot]@users.noreply.github.com Bump github/codeql-action from 2.22.4 to 2.22.5 (flutter/packages#5263) 2023-10-30 [email protected] Bump play-service-maps dependency from version 18.1.0 to 18.2.0 (flutter/packages#5243) 2023-10-30 [email protected] Roll Flutter from a4ec627 to e12d1a7 (3 revisions) (flutter/packages#5267) 2023-10-30 [email protected] [camerax] Loosen restrictions of fallback strategies for choosing resolutions (flutter/packages#5239) 2023-10-30 [email protected] [pigeon] Don't wrap non-nullable primitives in Obj-C (flutter/packages#5214) 2023-10-30 [email protected] [flutter_lints] Replace "flutter pub add --dev" with "dev:" (flutter/packages#5260) 2023-10-28 [email protected] Roll Flutter from 5907c97 to a4ec627 (18 revisions) (flutter/packages#5255) 2023-10-27 [email protected] [go_router] Fixes deep-link with no path on cold start (flutter/packages#5113) 2023-10-27 [email protected] [two_dimensional_scrollables] Fix pinned row painting when one axis is reversed (flutter/packages#5187) 2023-10-27 [email protected] Roll Flutter from c555599 to 5907c97 (45 revisions) (flutter/packages#5252) 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 [email protected],[email protected] 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
flutter/packages@2af6954...c9fec61 2023-10-31 [email protected] [image_picker] Prevent multiple active calls on iOS (flutter/packages#5272) 2023-10-30 [email protected] [in_app_purchase_android] Add missing response code to BillingResponse enum (flutter/packages#5120) 2023-10-30 49699333+dependabot[bot]@users.noreply.github.com Bump github/codeql-action from 2.22.4 to 2.22.5 (flutter/packages#5263) 2023-10-30 [email protected] Bump play-service-maps dependency from version 18.1.0 to 18.2.0 (flutter/packages#5243) 2023-10-30 [email protected] Roll Flutter from a4ec627 to e12d1a7 (3 revisions) (flutter/packages#5267) 2023-10-30 [email protected] [camerax] Loosen restrictions of fallback strategies for choosing resolutions (flutter/packages#5239) 2023-10-30 [email protected] [pigeon] Don't wrap non-nullable primitives in Obj-C (flutter/packages#5214) 2023-10-30 [email protected] [flutter_lints] Replace "flutter pub add --dev" with "dev:" (flutter/packages#5260) 2023-10-28 [email protected] Roll Flutter from 5907c97 to a4ec627 (18 revisions) (flutter/packages#5255) 2023-10-27 [email protected] [go_router] Fixes deep-link with no path on cold start (flutter/packages#5113) 2023-10-27 [email protected] [two_dimensional_scrollables] Fix pinned row painting when one axis is reversed (flutter/packages#5187) 2023-10-27 [email protected] Roll Flutter from c555599 to 5907c97 (45 revisions) (flutter/packages#5252) 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 [email protected],[email protected] 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
List which issues are fixed by this PR. You must list at least one issue.
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
dart format.)[shared_preferences]pubspec.yamlwith an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.mdto add a description of the change, following repository CHANGELOG style.///).