[go_router] Fix key collisions when sibling ShellRoutes coexist during push#11143
Open
Gorniv wants to merge 2 commits intoflutter:mainfrom
Open
[go_router] Fix key collisions when sibling ShellRoutes coexist during push#11143Gorniv wants to merge 2 commits intoflutter:mainfrom
Gorniv wants to merge 2 commits intoflutter:mainfrom
Conversation
There was a problem hiding this comment.
Code Review
This pull request resolves key collision issues within go_router that occurred when navigating between sibling ShellRoute branches. The fix involves generating unique navigator and page keys for each ShellRouteMatch and using the navigator key object directly for _CustomNavigator's key instead of its hash code. These changes are well-tested with a new regression test that forces key hash collisions to verify the fix's robustness. The implementation is sound and effectively addresses the described problem.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes key collisions in
go_routerwhenpush()navigates from oneShellRoutebranch to a siblingShellRoutebranch under the same parent.In that scenario, both shell branches can temporarily coexist in the widget tree. Before this change, that could cause framework assertions such as
Multiple widgets used the same GlobalKeybecause:_CustomNavigatorwas keyed withGlobalObjectKey(navigatorKey.hashCode), which could collide when two navigator keys had the samehashCodeShellRouteMatchreused the configuration-timeShellRoute.navigatorKeyShellRouteMatch.pageKeywas derived only fromroute.hashCode, so multiple matches for the sameShellRoutecould share page identityThis PR fixes the problem for regular
ShellRouteby:GlobalKey<NavigatorState>for eachShellRouteMatchpageKeyfrom that per-match navigator key_CustomNavigatorwithGlobalObjectKey(navigatorKey)instead ofGlobalObjectKey(navigatorKey.hashCode)The change is intentionally scoped to
ShellRouteonly.StatefulShellRoutekeeps its existing stablepageKeybehavior because applying per-match page identity there can create duplicateStatefulNavigationShellinstances with the same internalGlobalKey.This PR also adds a regression test that reproduces the old crash by forcing a navigator key hash collision, verifies that pushing to a sibling shell route no longer crashes, and confirms that the previous shell route state is preserved after
pop().No screenshots are included since this is a routing/runtime fix rather than a visual UI change.
Pre-Review Checklist
[shared_preferences]///).