Repository: flutter
Issue: [go_router] Failed assertion: line 3817 pos 18: '!keyReservation.contains(key)': is not true.
Labels: c: regression,package,has reproducible steps,P1,p: go_router,team-go_router,triaged-go_router,:hourglass_flowing_sand:,found in release: 3.16,found in release: 3.18

### Steps to reproduce

1. Copy the paste the given code, & `pubspec.ymal`

2. dart run build_runner watch --delete-conflicting-outputs

3. Keep Clicking on the button 

From screen A -> Push to B -> Push to C -> Push Replacement to A -> (Push to B) cause the error.

Note, `B & C` is in shell route...

### Expected results

It should have push to the intented route, 

### Actual results

I see an error in the console (see the "Logs" section).

This only started happening since `go_router: ^13.0.0`  which was released 2 days ago.

Also, found similar reporting earlier, 
https://github.com/flutter/flutter/issues/107045

### Code sample

<details open><summary>Code sample</summary>

**Pubspec.yaml**

```yaml
name: go_router_bug
description: "A new Flutter project."

publish_to: 'none'


version: 1.0.0+1

environment:
  sdk: '>=3.2.3 <4.0.0'

dependencies:
  flutter:
    sdk: flutter

  cupertino_icons: ^1.0.2
  go_router: ^13.0.0

dev_dependencies:
  flutter_test:
    sdk: flutter

  flutter_lints: ^2.0.0
  build_runner: ^2.4.7
  go_router_builder: ^2.4.0

flutter:
  uses-material-design: true
```
**main.dart**
```dart
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';

part 'main.g.dart';

void main() {
  runApp(const MyApp());
}

final parentNavigationKey = GlobalKey<NavigatorState>();
final shellRouteKey = GlobalKey<NavigatorState>();

class AScreen extends StatelessWidget {
  const AScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('A Screen')),
      body: Center(
        child: FilledButton(
          onPressed: () => const BScreenRoute().push<void>(context),
          child: const Text('Push to B'),
        ),
      ),
    );
  }
}

class BScreen extends StatelessWidget {
  const BScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('B Screen')),
      body: Center(
        child: FilledButton(
          onPressed: () => const CScreenRoute().push(context),
          child: const Text('Push to C'),
        ),
      ),
    );
  }
}

class CScreen extends StatelessWidget {
  const CScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('C Screen')),
      body: Center(
        child: FilledButton(
          onPressed: () => const AScreenRoute().pushReplacement(context),
          child: const Text('Push Replacement to A'),
        ),
      ),
    );
  }
}

@TypedGoRoute<AScreenRoute>(
  path: '/a',
  name: 'a',
)
@immutable
class AScreenRoute extends GoRouteData {
  const AScreenRoute();

  @override
  Page<void> buildPage(BuildContext context, GoRouterState state) {
    return NoTransitionPage(
      key: state.pageKey,
      child: const AScreen(),
    );
  }
}

@immutable
class BScreenRoute extends GoRouteData {
  const BScreenRoute();

  @override
  Page<void> buildPage(BuildContext context, GoRouterState state) {
    return NoTransitionPage(
      key: state.pageKey,
      child: const BScreen(),
    );
  }
}

@immutable
class CScreenRoute extends GoRouteData {
  const CScreenRoute();

  @override
  Page<void> buildPage(BuildContext context, GoRouterState state) {
    return NoTransitionPage(
      key: state.pageKey,
      child: const CScreen(),
    );
  }
}

@TypedShellRoute<BAndCScreenShellRoute>(routes: [
  TypedGoRoute<BScreenRoute>(
    path: '/b',
    name: 'b',
  ),
  TypedGoRoute<CScreenRoute>(
    path: '/c',
    name: 'c',
  ),
])
@immutable
class BAndCScreenShellRoute extends ShellRouteData {
  const BAndCScreenShellRoute();

  static final GlobalKey<NavigatorState> $navigatorKey = shellRouteKey;

  @override
  Page<void> pageBuilder(
    BuildContext context,
    GoRouterState state,
    Widget navigator,
  ) {
    return NoTransitionPage(
      key: state.pageKey,
      child: navigator,
    );
  }
}

final router = GoRouter(
  navigatorKey: parentNavigationKey,
  initialLocation: '/a',
  routes: [
    $aScreenRoute,
    $bAndCScreenShellRoute,
  ],
);

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
      routeInformationProvider: router.routeInformationProvider,
      routeInformationParser: router.routeInformationParser,
      routerDelegate: router.routerDelegate,
      theme: ThemeData(
        colorScheme: const ColorScheme.highContrastLight(secondary: Colors.amber),
      ),
    );
  }
}


```

</details>


### Screenshots or Video

<details open>
<summary>Screenshots / Video demonstration</summary>

[Upload media here]

</details>


### Logs

<details open><summary>Logs</summary>

```console
estarted application in 3,265ms.

════════ Exception caught by widgets library ═══════════════════════════════════
The following assertion was thrown building HeroControllerScope:
'package:flutter/src/widgets/navigator.dart': Failed assertion: line 3817 pos 18: '!keyReservation.contains(key)': is not true.

Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
  https://github.com/flutter/flutter/issues/new?template=2_bug.yml

The relevant error-causing widget was:
    MaterialApp MaterialApp:file:///C:/flutter-bug-report/go_router_bug/lib/main.dart:148:24

When the exception was thrown, this was the stack:


Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
  https://github.com/flutter/flutter/issues/new?template=2_bug.yml

The relevant error-causing widget was:
    MaterialApp MaterialApp:file:///C:/flutter-bug-report/go_router_bug/lib/main.dart:148:24

When the exception was thrown, this was the stack:
#2      NavigatorState._debugCheckDuplicatedPageKeys.<anonymous closure> (package:flutter/src/widgets/navigator.dart:3817:18)
navigator.dart:3817
#3      NavigatorState._debugCheckDuplicatedPageKeys (package:flutter/src/widgets/navigator.dart:3822:6)
navigator.dart:3822
#4      NavigatorState._updatePages.<anonymous closure> (package:flutter/src/widgets/navigator.dart:3884:7)
navigator.dart:3884
#5      NavigatorState._updatePages (package:flutter/src/widgets/navigator.dart:3887:6)
navigator.dart:3887
#6      NavigatorState.didUpdateWidget (package:flutter/src/widgets/navigator.dart:3803:7)
navigator.dart:3803
#7      StatefulElement.update (package:flutter/src/widgets/framework.dart:5643:55)
framework.dart:5643
#8      Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15)
framework.dart:3815
#9      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16)
framework.dart:5496
#10     Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7)
framework.dart:5187
#11     ProxyElement.update (package:flutter/src/widgets/framework.dart:5800:5)
framework.dart:5800
#12     Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15)
framework.dart:3815
#13     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16)
framework.dart:5496
#14     Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7)
framework.dart:5187
#15     ProxyElement.update (package:flutter/src/widgets/framework.dart:5800:5)
framework.dart:5800
#16     _InheritedNotifierElement.update (package:flutter/src/widgets/inherited_notifier.dart:105:11)
inherited_notifier.dart:105
#17     Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15)
framework.dart:3815
#18     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16)
framework.dart:5496
#19     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5634:11)
framework.dart:5634
#20     Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7)
framework.dart:5187
#21     StatefulElement.update (package:flutter/src/widgets/framework.dart:5657:5)
framework.dart:5657
#22     Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15)
framework.dart:3815
#23     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16)
framework.dart:5496
#24     Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7)
framework.dart:5187
#25     ProxyElement.update (package:flutter/src/widgets/framework.dart:5800:5)
framework.dart:5800
#26     Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15)
framework.dart:3815
#27     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16)
#28     Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7)
framework.dart:5187
#29     StatelessElement.update (package:flutter/src/widgets/framework.dart:5547:5)
framework.dart:5547
#30     Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15)
framework.dart:3815
#31     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16)
framework.dart:5496
#32     Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7)
framework.dart:5187
#33     ProxyElement.update (package:flutter/src/widgets/framework.dart:5800:5)
framework.dart:5800
#34     Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15)
framework.dart:3815
#35     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16)
framework.dart:5496
#36     Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7)
framework.dart:5187
#37     ProxyElement.update (package:flutter/src/widgets/framework.dart:5800:5)
framework.dart:5800
#38     Element.updateChild (package:flutter/src/widgets/framework.dart:3815:15)
framework.dart:3815
#39     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5496:16)
framework.dart:5496
#40     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5634:11)
framework.dart:5634
#41     Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7)
framework.dart:5187
#42     BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2895:19)
framework.dart:2895
#43     WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:984:21)
binding.dart:984
#44     RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:457:5)
binding.dart:457
#45     SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1325:15)
binding.dart:1325
#46     SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1255:9)
binding.dart:1255
#47     SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:1113:5)
binding.dart:1113
#48     _invoke (dart:ui/hooks.dart:312:13)
hooks.dart:312
#49     PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:383:5)
platform_dispatcher.dart:383
#50     _drawFrame (dart:ui/hooks.dart:283:31)
hooks.dart:283
(elided 2 frames from class _AssertionError)
```

</details>


### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
PS C:\flutter-bug-report\go_router_bug> flutter doctor -v
[!] Flutter (Channel stable, 3.16.4, on Microsoft Windows [Version 10.0.22621.2861], locale en-IN)
    • Flutter version 3.16.4 on channel stable at C:\Users\harsh\fvm\default
    ! Warning: `flutter` on your path resolves to C:\Users\harsh\fvm\versions\stable\bin\flutter, which is not inside
      your current Flutter SDK checkout at C:\Users\harsh\fvm\default. Consider adding C:\Users\harsh\fvm\default\bin to      the front of your path.
    ! Warning: `dart` on your path resolves to C:\Users\harsh\fvm\versions\stable\bin\dart, which is not inside your
      current Flutter SDK checkout at C:\Users\harsh\fvm\default. Consider adding C:\Users\harsh\fvm\default\bin to the
      front of your path.
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 2e9cb0aa71 (13 days ago), 2023-12-11 14:35:13 -0700
    • Engine revision 54a7145303
    • Dart version 3.2.3
    • DevTools version 2.28.4
    • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly
      to perform update checks and upgrades.

[✓] Windows Version (Installed version of Windows is version 10 or higher)

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
    • Android SDK at C:\Users\harsh\AppData\Local\Android\sdk
    • Platform android-34, build-tools 33.0.1
    • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at C:\Users\harsh\AppData\Local\Google\Chrome\Application\chrome.exe

[✓] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.4.4)
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
    • Visual Studio Community 2022 version 17.4.33213.308
    • Windows 10 SDK version 10.0.22000.0

[✓] Android Studio (version 2022.1)
    • 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 11.0.15+0-b2043.56-8887301)

[✓] IntelliJ IDEA Community Edition (version 2023.2)
    • IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2023.2.1
    • 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.85.1)
    • VS Code at C:\Users\harsh\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.56.0

[✓] Connected device (4 available)
    • vivo 1907 (mobile) • 8TBYBE6H7H55USFE • android-arm64  • Android 12 (API 31)
    • Windows (desktop)  • windows          • windows-x64    • Microsoft Windows [Version 10.0.22621.2861]
    • Chrome (web)       • chrome           • web-javascript • Google Chrome 120.0.6099.129
    • Edge (web)         • edge             • web-javascript • Microsoft Edge 118.0.2088.76

[✓] Network resources
    • All expected network resources are available.

! Doctor found issues in 1 category.
```

</details>