-
Notifications
You must be signed in to change notification settings - Fork 3.5k
[go_router] Fixes deep links with no path #6447
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 links with no path #6447
Conversation
|
@Hangyujin @johnpryan I have noticed that the code owner who is added as a reviewer hasn't been active for some time. Could you take a look at this, or do you know who could provide some feedback? Thank you! |
|
@kforjan I will take a look |
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.
Thanks for your contribution. This looks great to me, the fix looks clean and also thank you for your detailed description and tests.
| throw GoException('Location cannot be empty.'); | ||
| } | ||
| String canon = Uri.parse(loc).toString(); | ||
| final Uri uri = Uri.parse(canon); |
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.
line128 should be after line 129
I can think of a corner test case /profile/?
| // / => / | ||
| // /login?from=/ => login?from=/ | ||
| canon = canon.endsWith('/') && canon != '/' && !canon.contains('?') | ||
| canon = uri.path.endsWith('/') && uri.path != '/' && !uri.hasQuery |
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.
add && !uri.hasFragment
| initialMatches = configuration.findMatch(newUri, extra: state.extra); | ||
| } else { | ||
| initialMatches = configuration.findMatch(routeInformation.uri.toString(), | ||
| extra: state.extra); |
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: add comma
|
@Hangyujin Thank you for the feedback! I appreciate it very much and I am really glad you find it helpful. I made all the changes you proposed and added a few more tests for |
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.
LGTM
|
So I still see an issue, also after update to new version 13.2.3 |
|
Since this is merged, please file a new issue with repro. |
|
Hello @DennisKragekjaer! I have just tried using the exact same url with a same custom scheme setup like the one in your example. It worked for me and I couldn't reproduce your problem. Please note that Note for @chunhtai: while I investigated this, I noticed an edge case that I missed in my original implementation. When using custom schemes It doesn't break the flow or affect the app launch in any way, rather it just produces this error message in the debug console. It happens only with custom schemes with no path, for example: |
|
@kforjan Thanks for looking into this. The thing is I have no idea where this "dk.kragekjaer.mille...." comes from. |
flutter/packages@6b4d8b6...17f55d3 2024-04-09 [email protected] Release compileSdk changes (flutter/packages#6491) 2024-04-08 [email protected] [camera_android] Remove `TestUtils.java` (flutter/packages#6490) 2024-04-08 [email protected] Roll Flutter from 98d23f7 to 533d04d (12 revisions) (flutter/packages#6488) 2024-04-08 [email protected] [go_router_builder] Add `restorationScopeId` to `ShellRouteData` (flutter/packages#6238) 2024-04-08 [email protected] [go_router] Fixes deep links with no path (flutter/packages#6447) 2024-04-08 [email protected] [in_app_purchase] Convert Android data objects to Pigeon (flutter/packages#6453) 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@6b4d8b6...17f55d3 2024-04-09 [email protected] Release compileSdk changes (flutter/packages#6491) 2024-04-08 [email protected] [camera_android] Remove `TestUtils.java` (flutter/packages#6490) 2024-04-08 [email protected] Roll Flutter from 98d23f7 to 533d04d (12 revisions) (flutter/packages#6488) 2024-04-08 [email protected] [go_router_builder] Add `restorationScopeId` to `ShellRouteData` (flutter/packages#6238) 2024-04-08 [email protected] [go_router] Fixes deep links with no path (flutter/packages#6447) 2024-04-08 [email protected] [in_app_purchase] Convert Android data objects to Pigeon (flutter/packages#6453) 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
This PR addresses an issue where root deep links did not correctly navigate to '/'. The problem originated from the assumption that only paths (like '/', '/details', etc.) would be passed to the `canonicalUri` method in `path_utils.dart`. However, in the case of deep links, the full URL (including the scheme and domain) would be passed, causing the trailing slash to be incorrectly removed for root URLs. The first part of the fix modifies the `canonicalUri` method to check the actual path using `uri.path`. This ensures that the trailing slash is preserved for root URLs, even when the full URL is passed to the method. Importantly, even if '/' or '/details' is passed as a URI to `canonicalUri`, `uri.path` will still return '/' or '/details', ensuring consistent behavior. The second part of the fix modifies the `parseRouteInformationWithDependencies` function in `parser.dart` to correctly handle URLs with query parameters or fragments. Previously, the trailing slash was added after the query parameters or fragments, which is incorrect. The fix ensures that the trailing slash is added immediately after the base URL, before any query parameters or fragments. Preserving the trailing slash for root URLs is crucial because the `_matchByNavigatorKey` method in `match.dart` uses `uri.path` as the `remainingLocation` parameter. (why is that method relevant? because `parseRouteInformationWithDependencies` uses `findMatch`, which calls `_getLocRouteMatches`, which calls `match` and it calls `_matchByNavigatorKey`). If the trailing slash is removed from the root deep link URL, `uri.path` will not return '/', and the URL will not match any routes in the Go router. To validate these changes, new tests have been added. In `path_utils_test.dart`, tests have been added to verify that the trailing slash is not removed from a URL that is not just the path. In `parser_test.dart`, a new test has been added to verify that a URI with an empty path is correctly parsed. This test covers the case where `routeInformation.uri.hasEmptyPath` is true, which was not previously tested. Issues fixed: - flutter/flutter#133928

This PR addresses an issue where root deep links did not correctly navigate to '/'. The problem originated from the assumption that only paths (like '/', '/details', etc.) would be passed to the
canonicalUrimethod inpath_utils.dart. However, in the case of deep links, the full URL (including the scheme and domain) would be passed, causing the trailing slash to be incorrectly removed for root URLs.The first part of the fix modifies the
canonicalUrimethod to check the actual path usinguri.path. This ensures that the trailing slash is preserved for root URLs, even when the full URL is passed to the method. Importantly, even if '/' or '/details' is passed as a URI tocanonicalUri,uri.pathwill still return '/' or '/details', ensuring consistent behavior.The second part of the fix modifies the
parseRouteInformationWithDependenciesfunction inparser.dartto correctly handle URLs with query parameters or fragments. Previously, the trailing slash was added after the query parameters or fragments, which is incorrect. The fix ensures that the trailing slash is added immediately after the base URL, before any query parameters or fragments.Preserving the trailing slash for root URLs is crucial because the
_matchByNavigatorKeymethod inmatch.dartusesuri.pathas theremainingLocationparameter. (why is that method relevant? becauseparseRouteInformationWithDependenciesusesfindMatch, which calls_getLocRouteMatches, which callsmatchand it calls_matchByNavigatorKey). If the trailing slash is removed from the root deep link URL,uri.pathwill not return '/', and the URL will not match any routes in the Go router.To validate these changes, new tests have been added. In
path_utils_test.dart, tests have been added to verify that the trailing slash is not removed from a URL that is not just the path. Inparser_test.dart, a new test has been added to verify that a URI with an empty path is correctly parsed. This test covers the case whererouteInformation.uri.hasEmptyPathis true, which was not previously tested.Issues fixed:
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.///).