-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Logged-out sign-in page URL shows /Home instead of root #94433
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
Open
sumo-slonik
wants to merge
5
commits into
Expensify:main
Choose a base branch
from
software-mansion-labs:fix/signin-page-root-url
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
01ad27d
Fix logged-out sign-in page URL to stay at the root
sumo-slonik 3a9e15d
Strengthen sign-in root URL tests with a PublicScreens render guard
sumo-slonik 0ec6b72
Tighten sign-in root URL change: minimal comments, leaner tests
sumo-slonik c8ebd45
Merge branch 'main' into fix/signin-page-root-url
sumo-slonik e15cfea
Clear preserved navigator states on logout
sumo-slonik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import {NavigationContainer} from '@react-navigation/native'; | ||
| import {render, screen} from '@testing-library/react-native'; | ||
| import React from 'react'; | ||
| import {View} from 'react-native'; | ||
| import PublicScreens from '@libs/Navigation/AppNavigator/PublicScreens'; | ||
| import getAdaptedStateFromPath from '@libs/Navigation/helpers/getAdaptedStateFromPath'; | ||
| import getPathFromState from '@libs/Navigation/helpers/getPathFromState'; | ||
| import navigationRef from '@libs/Navigation/navigationRef'; | ||
| import NAVIGATORS from '@src/NAVIGATORS'; | ||
|
|
||
| // SignInPage is the initial (and only rendered) public route, so it gets a findable testID. The `mock` | ||
| // prefix is required for the hoisted jest.mock factory to reference it; a function declaration hoists too, | ||
| // so there's no temporal-dead-zone risk when the factory runs. | ||
| function mockSignInPage() { | ||
| return <View testID="sign-in-page" />; | ||
| } | ||
|
|
||
| // Stub the public pages so the test can mount the real PublicScreens navigator without their provider trees. | ||
| jest.mock('@pages/signin/SignInPage', () => mockSignInPage); | ||
| jest.mock('@pages/ConnectionCompletePage', () => () => null); | ||
| jest.mock('@pages/LogInWithShortLivedAuthTokenPage', () => () => null); | ||
| jest.mock('@pages/signin/SAMLSignInPage', () => () => null); | ||
| jest.mock('@pages/UnlinkLoginPage', () => () => null); | ||
| jest.mock('@pages/ValidateLoginPage', () => () => null); | ||
| jest.mock('@libs/Navigation/AppNavigator/Navigators/TestToolsModalNavigator', () => () => null); | ||
| jest.mock('@libs/Navigation/AppNavigator/useRootNavigatorScreenOptions', () => () => ({basicModalNavigator: {}})); | ||
| jest.mock('@hooks/useTheme', () => () => ({overlay: '#000000'})); | ||
| jest.mock('@hooks/useStyleUtils', () => () => ({getBackgroundColorWithOpacityStyle: () => ({})})); | ||
|
|
||
| describe('Logged-out sign-in page URL', () => { | ||
| it('renders the SignInPage at the root "/" (registered under TAB_NAVIGATOR, which has no path)', () => { | ||
| render( | ||
| <NavigationContainer ref={navigationRef}> | ||
| <PublicScreens /> | ||
| </NavigationContainer>, | ||
| ); | ||
|
|
||
| expect(screen.getByTestId('sign-in-page')).toBeOnTheScreen(); | ||
|
|
||
| const rootState = navigationRef.getRootState(); | ||
| expect(rootState.routes.at(0)?.name).toBe(NAVIGATORS.TAB_NAVIGATOR); | ||
| expect(getPathFromState(rootState)).toBe('/'); | ||
| }); | ||
|
|
||
| it('redirects a legacy "/Home" URL to the root "/"', () => { | ||
| expect(getPathFromState(getAdaptedStateFromPath('/Home', undefined))).toBe('/'); | ||
| }); | ||
| }); |
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also clear
paramswhenlastRoute.name === NAVIGATORS.TAB_NAVIGATOR. Some TAB_NAVIGATOR routes carry their child tab in params rather than only instate(for example,getRehydratedTabNavigatorStateAfterPush()stores the full tab subtree inparams.state), but this reset now dropsstatewhile preserving those params. Since PublicScreens and AuthScreens share the TAB_NAVIGATOR route name, logging out from such a route can leave the previous session's tab subtree attached to the public sign-in route and let the next login hydrate back to a stale tab/path instead of starting cleanly at/.Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this comment is valid. We can get a dirty URL from leftover params after logout
Steps to reproduce:
MacOS-Chrome.mov
What do you think? @sumo-slonik