Skip to content

[go_router] Navigating back does not update router location since go_router 5.2.0 #115832

Closed
flutter/packages
#2904

Description

@abubakarmvp

Note: for version lower than 5.0.0 routing is working as expected.

Hi,
i have routes defined something like

GoRoute(
            path: '/login',
            name: loginRouteName,
            pageBuilder: (context, state) => NoTransitionPage(
              key: state.pageKey,
              child: const LoginScreen(),
            ),
            routes: [
              GoRoute(
                path: 'reset',
                name: resetRouteName,
                pageBuilder: (context, state) => NoTransitionPage(
                  key: state.pageKey,
                  child: const ResetEmailScreen(),
                ),],);
go_router_4.5.1.mp4
go_router_5.2.0.mp4

As you can see from video (go_router_5.2.0) when i go to subroute 'reset' and pop back to the 'login' route. the path is not changed and i cannot go to 'reset' route again. I am using goNamed() for navigation. The same issue is happening on all other platforms.

Flutter doctor

[✓] Flutter (Channel stable, 3.3.8, on macOS 12.5.1 21G83 darwin-x64, locale en-AE)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 14.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.3)
[✓] VS Code (version 1.72.2)
[✓] Connected device (3 available)
[✓] HTTP Host Availability

Flutter doctor -v

[✓] Flutter (Channel stable, 3.3.8, on macOS 12.5.1 21G83 darwin-x64, locale en-AE)
• Flutter version 3.3.8 on channel stable at /Users/mac/Documents/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 52b3dc2 (13 days ago), 2022-11-09 12:09:26 +0800
• Engine revision 857bd6b74c
• Dart version 2.18.4
• DevTools version 2.15.0

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
• Android SDK at /Users/mac/Library/Android/sdk
• Platform android-33, build-tools 30.0.3
• Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
• All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 14B47b
• CocoaPods version 1.11.3

[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.3)
• Android Studio at /Applications/Android Studio.app/Contents
• 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 11.0.13+0-b1751.21-8125866)

[✓] VS Code (version 1.72.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.52.0

[✓] Connected device (3 available)
• sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64 • Android 13 (API 33) (emulator)
• macOS (desktop) • macos • darwin-x64 • macOS 12.5.1 21G83 darwin-x64
• Chrome (web) • chrome • web-javascript • Google Chrome 107.0.5304.110

[✓] HTTP Host Availability
• All required HTTP hosts are available

• No issues found!

Activity

  1. added
    in triagePresently being triaged by the triage team
    on Nov 23, 2022
  2. huycozy commented on Nov 23, 2022

    @huycozy
    Member

    Hi @abubakarmvp, please provide a completed and minimal reproducible code sample so that we may verify this. Thank you!

  3. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Nov 23, 2022
  4. abubakarmvp commented on Nov 23, 2022

    @abubakarmvp
    Author

    Hi,
    This is the minimal reproducible code.

    Sample Code
    import 'package:flutter/material.dart';
    import 'package:go_router/go_router.dart';
    
    GoRouter get router => GoRouter(
          initialLocation: '/ab',
          routes: <RouteBase>[
            GoRoute(
              path: '/ab',
              pageBuilder: (context, state) => NoTransitionPage(
                key: state.pageKey,
                child: const ScreenAb(),
              ),
              routes: [
                GoRoute(
                    path: 'abc',
                    pageBuilder: (context, state) => NoTransitionPage(
                        key: state.pageKey, child: const ScreenABC()))
              ],
            ),
          ],
        );
    
    void main() {
      runApp(const MyApp());
    }
    
    class MyApp extends StatelessWidget {
      const MyApp({super.key});
    
      @override
      Widget build(BuildContext context) {
        return MaterialApp.router(
          title: 'Flutter Demo',
          debugShowCheckedModeBanner: false,
          routerConfig: router,
          theme: ThemeData(
            primarySwatch: Colors.blue,
          ),
        );
      }
    }
    
    class ScreenAb extends StatelessWidget {
      const ScreenAb({super.key});
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          body: Center(
              child: InkWell(
                  onTap: () {
                    context.go('/ab/abc');
                  },
                  child: const Text('Forgot password?',
                      style: TextStyle(color: Color(0xff468316))))),
        );
      }
    }
    
    class ScreenABC extends StatelessWidget {
      const ScreenABC({Key? key}) : super(key: key);
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
            body: GestureDetector(
                onTap: () {
                  context.pop();
                },
                child: const Center(child: Text('screen 2'))));
      }
    }
  5. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Nov 23, 2022
  6. ValentinVignal commented on Nov 23, 2022

    @ValentinVignal
    Contributor

    I can reproduce the issue with go_router 5.2.0
    However, with the previous version (5.1.10), there is no issue. It looks like the regression was introduced in flutter/packages#2786

  7. huycozy commented on Nov 24, 2022

    @huycozy
    Member

    @abubakarmvp thanks for providing more information. And thank @ValentinVignal for reporting a working version.
    This is a regression issue:

    5.1.10 5.2.0
    ✅ ❌

    ✅: No Issue ❌: Issue reproduced

    Demo
    5.1.10 5.2.0
    5.1.10.mov
    5.2.0.mov
    Completed sample code
    import 'package:flutter/material.dart';
    import 'package:go_router/go_router.dart';
    
    void main() {
      runApp(const MyApp());
    }
    
    class MyApp extends StatelessWidget {
      const MyApp({super.key});
    
      GoRouter get router => GoRouter(
            initialLocation: '/ab',
            routes: <RouteBase>[
              GoRoute(
                path: '/ab',
                pageBuilder: (context, state) => NoTransitionPage(
                  key: state.pageKey,
                  child: const ScreenAb(),
                ),
                routes: [
                  GoRoute(
                    path: 'abc',
                    pageBuilder: (context, state) => NoTransitionPage(
                      key: state.pageKey,
                      child: const ScreenABC(),
                    ),
                  ),
                ],
              ),
            ],
          );
    
      @override
      Widget build(BuildContext context) {
        return MaterialApp.router(
          title: 'Flutter Demo',
          debugShowCheckedModeBanner: false,
          routerConfig: router,
          theme: ThemeData(
            primarySwatch: Colors.blue,
          ),
        );
      }
    }
    
    class ScreenAb extends StatelessWidget {
      const ScreenAb({super.key});
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          body: Center(
              child: InkWell(
                  onTap: () {
                    context.go('/ab/abc');
                  },
                  child: const Text('Forgot password?', style: TextStyle(color: Color(0xff468316))))),
        );
      }
    }
    
    class ScreenABC extends StatelessWidget {
      const ScreenABC({Key? key}) : super(key: key);
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
            body: GestureDetector(
                onTap: () {
                  context.pop();
                },
                child: const Center(child: Text('screen 2'))));
      }
    }
    
    flutter doctor -v (stable and master)
    [✓] Flutter (Channel stable, 3.3.8, on macOS 13.0 22A380 darwin-x64, locale en-VN)
        • Flutter version 3.3.8 on channel stable at /Users/huynq/Documents/GitHub/flutter
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 52b3dc25f6 (23 hours ago), 2022-11-09 12:09:26 +0800
        • Engine revision 857bd6b74c
        • Dart version 2.18.4
        • DevTools version 2.15.0
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
        • Android SDK at /Users/huynq/Library/Android/sdk
        • Platform android-33, build-tools 31.0.0
        • ANDROID_HOME = /Users/huynq/Library/Android/sdk
        • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 14.0.1)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Build 14A400
        • CocoaPods version 1.11.3
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2021.3)
        • Android Studio at /Applications/Android Studio.app/Contents
        • 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 11.0.13+0-b1751.21-8125866)
    
    [✓] IntelliJ IDEA Community Edition (version 2022.2.2)
        • IntelliJ at /Applications/IntelliJ IDEA CE.app
        • Flutter plugin version 70.0.5
        • Dart plugin version 222.4167.21
    
    [✓] IntelliJ IDEA Community Edition (version 2022.1.1)
        • IntelliJ at /Users/huynq/Library/Application Support/JetBrains/Toolbox/apps/IDEA-C/ch-0/221.5591.52/IntelliJ IDEA CE.app
        • 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
    
    [✓] VS Code (version 1.73.0)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.52.0
    
    [✓] Connected device (3 available)
        • iPhone 14 Pro Max (mobile) • 332079AF-E895-4685-910E-7B1E18B0C6B8 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-16-0 (simulator)
        • macOS (desktop)            • macos                                • darwin-x64     • macOS 13.0 22A380 darwin-x64
        • Chrome (web)               • chrome                               • web-javascript • Google Chrome 107.0.5304.110
    
    [✓] HTTP Host Availability
        • All required HTTP hosts are available
    
    • No issues found!
    
    [!] Flutter (Channel master, 3.6.0-7.0.pre.33, on macOS 13.0 22A380 darwin-x64, locale en-VN)
        • Flutter version 3.6.0-7.0.pre.33 on channel master at /Users/huynq/Documents/GitHub/flutter_master
        ! Warning: `flutter` on your path resolves to /Users/huynq/Documents/GitHub/flutter/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/huynq/Documents/GitHub/flutter_master. Consider adding /Users/huynq/Documents/GitHub/flutter_master/bin to the front of your path.
        ! Warning: `dart` on your path resolves to /Users/huynq/Documents/GitHub/flutter/bin/dart, which is not inside your current Flutter SDK checkout at /Users/huynq/Documents/GitHub/flutter_master. Consider adding /Users/huynq/Documents/GitHub/flutter_master/bin to the front of your path.
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision b7023e843a (2 hours ago), 2022-11-22 20:47:07 -0500
        • Engine revision f75287af0b
        • Dart version 2.19.0 (build 2.19.0-416.0.dev)
        • DevTools version 2.19.0
        • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
        • Android SDK at /Users/huynq/Library/Android/sdk
        • Platform android-33, build-tools 31.0.0
        • ANDROID_HOME = /Users/huynq/Library/Android/sdk
        • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 14.0.1)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Build 14A400
        • CocoaPods version 1.11.3
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2021.3)
        • Android Studio at /Applications/Android Studio.app/Contents
        • 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 11.0.13+0-b1751.21-8125866)
    
    [✓] IntelliJ IDEA Community Edition (version 2022.2.2)
        • IntelliJ at /Applications/IntelliJ IDEA CE.app
        • Flutter plugin version 70.0.5
        • Dart plugin version 222.4167.21
    
    [✓] IntelliJ IDEA Community Edition (version 2022.1.1)
        • IntelliJ at /Users/huynq/Library/Application Support/JetBrains/Toolbox/apps/IDEA-C/ch-0/221.5591.52/IntelliJ IDEA CE.app
        • 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
    
    [✓] VS Code (version 1.73.1)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.52.0
    
    [✓] Connected device (4 available)
        • SM T225 (mobile)           • R9JT3004VRJ                          • android-arm64  • Android 12 (API 31)
        • iPhone 14 Pro Max (mobile) • 332079AF-E895-4685-910E-7B1E18B0C6B8 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-16-0 (simulator)
        • macOS (desktop)            • macos                                • darwin-x64     • macOS 13.0 22A380 darwin-x64
        • Chrome (web)               • chrome                               • web-javascript • Google Chrome 107.0.5304.110
    
    [✓] HTTP Host Availability
        • All required HTTP hosts are available
    
    ! Doctor found issues in 1 category.
    
  8. added
    c: regressionIt was better in the past than it is now
    packageflutter/packages repository. See also p: labels.
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    and removed
    in triagePresently being triaged by the triage team
    on Nov 24, 2022
  9. 5 remaining items

  10. haashem commented on Nov 27, 2022

    @haashem

    I have the same issue, open named_routes.dart in example folder. run the app.

    Select a row, then pop back, select the same row. it will not go forward!
    version 5.2.0
    navigation

  11. added
    P2Important issues not at the top of the work list
    on Nov 29, 2022
  12. chunhtai commented on Dec 1, 2022

    @chunhtai
    Contributor

    maybe related #115962

  13. self-assigned this
    on Dec 1, 2022
  14. added
    customer: crowdAffects or could affect many people, though not necessarily a specific customer.
    on Dec 5, 2022
  15. VCasecnikovs commented on Dec 5, 2022

    @VCasecnikovs

    Have the same issue

  16. angjelkom commented on Dec 6, 2022

    @angjelkom

    I know we all spend our free time to contribute to these plugins and everyone is doing amazing job.

    With that said its a bit worrying that the very basic (core) example of using go_router its broken. I know this is a main branch and stuff like this tend to happen but even so we are talking about a simple navigation being broken from a single commit.

    Such commits should include better testing or we need better unit tests, as again even for a main branch as simple core feature shouldn't get broken, like a simple navigation in this case.

    Apologize if this sounds too harsh but I'm just saying we should all pay attention more and yes this is our free time we are spending so its not a demand, rather than an advice.

    With that said thanks again to all contributors, you are doing awesome job!

  17. angjelkom commented on Dec 6, 2022

    @angjelkom

    @chunhtai found the cause the culprit is your pull #2786:

    void _handleStateMayChange() {
        final String newLocation;
        if (routerDelegate.currentConfiguration.isNotEmpty &&
            routerDelegate.currentConfiguration.matches.last
                is ImperativeRouteMatch) {
          newLocation = (routerDelegate.currentConfiguration.matches.last
                  as ImperativeRouteMatch)
              .matches
              .uri
              .toString();
        } else {
          newLocation = _routerDelegate.currentConfiguration.uri.toString();
        }
        if (_location != newLocation) {
          _location = newLocation;
          notifyListeners();
        }
      }
    

    in the _handleStateMayChange function which triggers router rebuild, you are accessing the new location via the uri property of the currentConfiguration of the router which is basically the location of the routeInformation.

    The problem here is that the uri property doesn't get updated when the navigation is popped and that's because nothing triggers GoRouteInformationParser rebuild when popping the route (context.pop()), and when pushing a route (context.go()) a rebuild is triggered on GoRouteInformationParser which reflects the change.

    So the location stays same when checking in _handleStateMayChange so rebuild on the GoRouter doesn't get triggered, and when we try to go to the same route again this part of the GoRouteInformationProvider ignores it:

    set value(RouteInformation other) {
        final bool shouldNotify =
            _value.location != other.location || _value.state != other.state;
        _value = other;
        if (shouldNotify) {
          notifyListeners();
        }
      }
    

    Hope this gives you an idea how to add a quick fix.

  18. moved this to Done in GoRouteron Dec 7, 2022
  19. konnic commented on Dec 8, 2022

    @konnic

    @chunhtai thanks a lot for the quick fix, this helps a lot!

    I just tried it out and was wondering one thing. When popping a page from e.g. /resource/sub the updated URL is /resource/. I would've expected that the updated URL would be /resource without the trailing slash.

    Would you consider this a bug? If yes, I'm happy to open up an issue.

  20. chunhtai commented on Dec 8, 2022

    @chunhtai
    Contributor

    @konnic yes, please file a bug and pin me on it.

  21. github-actions commented on Mar 5, 2023

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  22. locked as resolved and limited conversation to collaborators on Mar 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listc: regressionIt was better in the past than it is nowcustomer: crowdAffects or could affect many people, though not necessarily a specific customer.found in release: 3.3Found to occur in 3.3found in release: 3.6Found to occur in 3.6has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: go_routerThe go_router packagepackageflutter/packages repository. See also p: labels.

Type

No type

Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions