Skip to content
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 is catching app links twice on Android #147848

Open
ishchhabra opened this issue May 5, 2024 · 12 comments
Open

go_router is catching app links twice on Android #147848

ishchhabra opened this issue May 5, 2024 · 12 comments
Labels
in triage Presently being triaged by the triage team waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds

Comments

@ishchhabra
Copy link

What package does this bug report belong to?

go_router

What target platforms are you seeing this bug on?

Android

Have you already upgraded your packages?

Yes

Dependency versions

pubspec.lock
[Paste file content here]

Steps to reproduce

  1. Register link A as a deep link in AndroidManifest
  2. Create a dummy server that redirects link B to link A
  3. Using adb shell, start an andorid.intent.action.VIEW with link B

Expected results

When link B redirects the user to link A, the deep link should be caught once.

Actual results

The deep link gets caught twice

Code sample

Code sample

https://github.com/ishchhabra/go_router_applink_bug_app

Screenshots or Videos

No response

Logs

No response

Flutter Doctor output

Doctor output
[√] Flutter (Channel stable, 3.19.5, on Microsoft Windows [Version 10.0.22631.3447], locale en-US)
    • Flutter version 3.19.5 on channel stable at E:\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 300451adae (6 weeks ago), 2024-03-27 21:54:07 -0500
    • Engine revision e76c956498
    • Dart version 3.3.3
    • DevTools version 2.31.1

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at C:\Users\ishch\AppData\Local\Android\sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-b2043.56-9586694)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop Windows apps (Visual Studio Build Tools 2022 17.6.4)
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools
    • Visual Studio Build Tools 2022 version 17.6.33815.320
    • Windows 10 SDK version 10.0.22000.0

[√] Android Studio (version 2022.2)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-b2043.56-9586694)

[√] VS Code (version 1.89.0)
    • VS Code at C:\Users\ishch\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.88.0

[√] Connected device (4 available)
    • sdk gphone x86 (mobile) • emulator-5554 • android-x86    • Android 11 (API 30) (emulator)
    • Windows (desktop)       • windows       • windows-x64    • Microsoft Windows [Version 10.0.22631.3447]
    • Chrome (web)            • chrome        • web-javascript • Google Chrome 116.0.5845.141
    • Edge (web)              • edge          • web-javascript • Microsoft Edge 124.0.2478.80

[√] Network resources
    • All expected network resources are available.

• No issues found!
@huycozy
Copy link
Member

huycozy commented May 6, 2024

Hi @ishchhabra
Perhaps this is similar to #137037 even though the case is not really the same (you can also check it to see if it assembles your case). To confirm this, could you clarify:

  • Does the issue occur if you start link A directly but not via link B?

@huycozy huycozy added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 6, 2024
@ishchhabra
Copy link
Author

@huycozy While the two seem similar, they are not exactly the same. The issue you mentioned talks about the builder being triggered twice, whereas this issue talks about even the redirect (which is mentioned as the workaround in that issue) being triggered twice. No, the issue does not occur if I start the link A directly - in that case, the redirect is only triggered once.

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 6, 2024
@huycozy
Copy link
Member

huycozy commented May 7, 2024

Your sample code has a minor issue (typo?) on /applinks route path, it should be /applink to sync with path data on AndroidManifest; otherwise no routes for location error will occur.

Once I updated it, I got another error below:

I/flutter (15789): /applinks route trigerred

════════ Exception caught by foundation library ════════════════════════════════
The following assertion was thrown while dispatching notifications for GoRouteInformationProvider:
A redirect-only route must redirect to location different from itself.
 The offending route: GoRoute#a104f(name: null, path: "/applink", Redirect Only)
'package:go_router/src/parser.dart':
Failed assertion: line 114 pos 18: '!matchList.last.route.redirectOnly'

Then I continued updating the route declaration as:

final _router = GoRouter(
  routes: [
    GoRoute(
      path: '/',
      builder: (context, state) => const MyHomePage(title: 'Flutter Demo Home Page'),
    ),
    GoRoute(
      path: '/applink',
      builder: (context, state) => const MyHomePage(title: 'App Link'),
    ),
  ],
  redirect: (context, state) {
    if (state.matchedLocation == '/applink') {
      print("/applinks route trigerred");
      return '/applink';
    }
    return null;
  },
);

Now I can see the log applinks route trigerred is printed twice from the output console. But the issue also occurs if I trigger direct link with:

adb shell am start -a android.intent.action.VIEW "http://10.0.2.2:8020/applink"

With this result, this is similar to #137037, right? Please retry with this updated sample code and confirm. If your sample code needs to persist as the original, please update it to pass the error above. Thanks!

@huycozy huycozy added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 7, 2024
@ishchhabra
Copy link
Author

My bad, while trying to extract the minimal code from the application where I encountered this, I made some mistakes. I have updated the code. It is similar to the route declaration you mentioned above, but rather than using the global redirect, I added redirect only to the specific route. I also tried the route declaration you mentioned, but in both the cases, i did not see the console print twice on adb shell am start -a android.intent.action.VIEW "http://10.0.2.2:8020/applink" but only on adb shell am start -a android.intent.action.VIEW "http://10.0.2.2:8020". Are there OS or any other differences that could be relevant here as well?

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 7, 2024
@huycozy
Copy link
Member

huycozy commented May 8, 2024

Well, I pulled your latest change on your sample repo and ran it. I see the console printed only one time as expected (in both cases). I checked this on Android 11 emulator as yours (I see it from your flutter doctor ouput).

Demo
Screen.Recording.2024-05-08.at.12.36.40.mp4

Please take a look at my demo to see if there are any different steps.

@huycozy huycozy added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 8, 2024
@ishchhabra
Copy link
Author

That is weird. With the code on the sample repo, following is what I see:

windows_recording.mp4

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 8, 2024
@huycozy
Copy link
Member

huycozy commented May 8, 2024

The only different step I can observe between my and your demo is that: you triggered deep link when app was in foreground whilst I did it when app in background. I tried the same steps as yours but only one log is printed (expected).

Could you check go_router version which is fetched on your end? You can find it on pubspec.lock file. If you can try checking this without go_router package to narrow the scope of investigation, it would be appreciated.

@huycozy huycozy added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 8, 2024
@ishchhabra
Copy link
Author

  go_router:
    dependency: "direct main"
    description:
      name: go_router
      sha256: "9e0f7d1a3e7dc5010903e330fbc5497872c4c3cf6626381d69083cc1d5113c1e"
      url: "https://pub.dev"
    source: hosted
    version: "14.0.2"

The go_router version being pulled in 14.0.2. Could you elaborate on how I would check this without the go_router package? I'm not sure where the handler code (print statement) would go in case I'm not using go_router.

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 8, 2024
@huycozy
Copy link
Member

huycozy commented May 9, 2024

Thanks for the update. I see it's already the latest package version (same to me). You can test it without using go_router package like this:

Snippet code of route without using go_router
return MaterialApp(
  title: 'Flutter Demo',
  theme: ThemeData(
    colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
    useMaterial3: true,
  ),
  // routerConfig: _router,
  onGenerateRoute: (settings) {
    if (settings.name == '/applink') {
      print("/applink route triggered");
      return MaterialPageRoute(builder: (context) {
        return const MyHomePage(title: 'applink');
      });
    }
    return MaterialPageRoute(builder: (context) {
      return const MyHomePage(title: 'Flutter Demo Home Page');
    });
  },
);

@huycozy huycozy added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 9, 2024
@ishchhabra
Copy link
Author

Just tried with the code snippet you provided. The bug also exists without using go_router

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 9, 2024
@huycozy
Copy link
Member

huycozy commented May 10, 2024

Strangely, it only prints once with that same code (without go_router) on my end. I wonder if there is problem with device/emulator. Could you try on another one?

Also, what is your Python version? (I'm using Python 3.11.7). Could you check if Python server sends twice?

@huycozy huycozy added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 10, 2024
@mako-yolo
Copy link

I have exactly the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in triage Presently being triaged by the triage team waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds
Projects
None yet
Development

No branches or pull requests

3 participants