Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: switching navigators nested navigators same route#12128

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
hannojg wants to merge1 commit intoreact-navigation:6.x
base:6.x
Choose a base branch
Loading
frommargelo:fix/switching-navigators-nested-navigators-same-route

Conversation

hannojg
Copy link
Contributor

@hannojghannojg commentedSep 1, 2024
edited
Loading

Please provide enough information so that others can review your pull request.

Motivation

When switching navigators there exists a bug where nested state of a screen route isn't cleared.

Imagine you have:

<StackA.Navigator><StackA.Screenname="foo"><StackB.Navigator><StackB.Screenname="bar"/></StackB.Navigator></StackA.Screen></StackA.Navigator>

In this case screenfoo contains a nested navigator.

Now, when we switch to another stack, that also contains a screen calledfoowhich isn't a nested navigator, the state data with the route won't be cleared from the navigator:

<StackC.Navigator><StackC.Screenname="foo"/></StackC.Navigator>

If you inspect the navigation state you see that the route "bar" is still there:

    {"stale":false,"type":"stack","key":"stack-rZFXS0CY_SZilbnrYS1HH","index":0,"routeNames": ["foo",      ],"routes": [        {"key":"foo-doNEBgosyONdZtX8ZWz8c","name":"foo","params": {"screen":"bar"          },"state": {"stale":false,"type":"stack","key":"stack-oLBLSVP1ye_WdX_iKbumb","index":0,"routeNames": ["bar",            ],"routes": [              {"key":"bar-0uZC9OCaawZsYZ99vU2tZ","name":"bar"              }            ]          }        }      ]    }

We have a use case where we switch between an authenticated and unauthenticated stack. They both share for the initial screen the same screen name.
If the user logs out, and then logs in again, the user will be brought back to the screen where the user left off, as we kept the "bar" route in state.
As we switched to a navigator that doesn't have nested routes, I'd expect the route to be cleared.

Test plan

Adding unit tests to verify the behaviour should be sufficient.

Note: For now I just added a failing unit test. Will provide a fix tmrw! (additional note: this is a fix for expensify)

@hannojg
Copy link
ContributorAuthor

note: the test works if I wait for the cleanup timeout to happen. However, in our original application there is still a bug where after the cleanup another setState is running which is overwriting the state again. Trying to update the test to reflect this edge case.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

1 participant
@hannojg

[8]ページ先頭

©2009-2025 Movatter.jp