Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 29 additions & 20 deletions src/libs/Navigation/AppNavigator/AuthScreens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import type {RouteProp} from '@react-navigation/native';
import {findFocusedRoute, useNavigation} from '@react-navigation/native';
import React, {memo, useEffect, useMemo, useRef, useState} from 'react';
import type {OnyxEntry} from 'react-native-onyx';
import Onyx, {useOnyx, withOnyx} from 'react-native-onyx';
import Onyx, {useOnyx} from 'react-native-onyx';
import ActiveWorkspaceContextProvider from '@components/ActiveWorkspaceProvider';
import ComposeProviders from '@components/ComposeProviders';
import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
import OptionsListContextProvider from '@components/OptionListContextProvider';
import {SearchContextProvider} from '@components/Search/SearchContext';
import {useSearchRouterContext} from '@components/Search/SearchRouter/SearchRouterContext';
Expand Down Expand Up @@ -53,6 +54,7 @@ import SCREENS from '@src/SCREENS';
import type * as OnyxTypes from '@src/types/onyx';
import type {SelectedTimezone, Timezone} from '@src/types/onyx/PersonalDetails';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue';
import type ReactComponentModule from '@src/types/utils/ReactComponentModule';
import createRootStackNavigator from './createRootStackNavigator';
import {reportsSplitsWithEnteringAnimation, workspaceSplitsWithoutEnteringAnimation} from './createRootStackNavigator/GetStateForActionHandlers';
Expand All @@ -67,7 +69,7 @@ import RightModalNavigator from './Navigators/RightModalNavigator';
import WelcomeVideoModalNavigator from './Navigators/WelcomeVideoModalNavigator';
import useRootNavigatorScreenOptions from './useRootNavigatorScreenOptions';

type AuthScreensProps = {
type AuthScreensContentProps = {
/** Session of currently logged in user */
session: OnyxEntry<OnyxTypes.Session>;

Expand Down Expand Up @@ -210,7 +212,29 @@ const modalScreenListenersWithCancelSearch = {
},
};

function AuthScreens({session, lastOpenedPublicRoomID, initialLastUpdateIDAppliedToClient}: AuthScreensProps) {
// AuthScreens has been migrated to useOnyx. In the previous version, withOnyx waited until all the Onyx values are loaded and then rendered the component first time.
// To avoid breaking functionalities that rely on this logic, we keep the same behavior by waiting for the Onyx values to be loaded before rendering the component.
function AuthScreens() {
const [session] = useOnyx(ONYXKEYS.SESSION);
const [lastOpenedPublicRoomID, lastOpenedPublicRoomIDStatus] = useOnyx(ONYXKEYS.LAST_OPENED_PUBLIC_ROOM_ID);
const [initialLastUpdateIDAppliedToClient, initialLastUpdateIDAppliedToClientStatus] = useOnyx(ONYXKEYS.ONYX_UPDATES_LAST_UPDATE_ID_APPLIED_TO_CLIENT);
const isLastOpenedPublicRoomIDLoading = isLoadingOnyxValue(lastOpenedPublicRoomIDStatus);
const isInitialLastUpdateIDAppliedToClientLoading = isLoadingOnyxValue(initialLastUpdateIDAppliedToClientStatus);

if (isLastOpenedPublicRoomIDLoading || isInitialLastUpdateIDAppliedToClientLoading) {
return <FullScreenLoadingIndicator />;
}

return (
<AuthScreensContent
session={session}
lastOpenedPublicRoomID={lastOpenedPublicRoomID}
initialLastUpdateIDAppliedToClient={initialLastUpdateIDAppliedToClient}
/>
);
}

function AuthScreensContent({session, lastOpenedPublicRoomID, initialLastUpdateIDAppliedToClient}: AuthScreensContentProps) {
const theme = useTheme();
const {shouldUseNarrowLayout} = useResponsiveLayout();
const rootNavigatorScreenOptions = useRootNavigatorScreenOptions();
Expand Down Expand Up @@ -662,20 +686,5 @@ function AuthScreens({session, lastOpenedPublicRoomID, initialLastUpdateIDApplie

AuthScreens.displayName = 'AuthScreens';

const AuthScreensMemoized = memo(AuthScreens, () => true);

// Migration to useOnyx cause re-login if logout from deeplinked report in desktop app
// Further analysis required and more details can be seen here:
// https://github.com/Expensify/App/issues/50560
// eslint-disable-next-line
export default withOnyx<AuthScreensProps, AuthScreensProps>({
session: {
key: ONYXKEYS.SESSION,
},
lastOpenedPublicRoomID: {
key: ONYXKEYS.LAST_OPENED_PUBLIC_ROOM_ID,
},
initialLastUpdateIDAppliedToClient: {
key: ONYXKEYS.ONYX_UPDATES_LAST_UPDATE_ID_APPLIED_TO_CLIENT,
},
})(AuthScreensMemoized);
// This memo is needed because <AuthScreens> is one of the main components in the app and navigation root and is relevant for the app performance.
export default memo(AuthScreens);
14 changes: 13 additions & 1 deletion src/libs/Navigation/linkingConfig/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1563,7 +1563,19 @@ const config: LinkingOptions<RootNavigatorParamList>['config'] = {
path: ROUTES.HOME,
exact: true,
},
[SCREENS.REPORT]: ROUTES.REPORT_WITH_ID.route,
[SCREENS.REPORT]: {
path: ROUTES.REPORT_WITH_ID.route,
// If params are defined, but reportID is explicitly undefined, we will get the url /r/undefined.
// We want to avoid that situation, so we will return an empty string instead.
parse: {
// eslint-disable-next-line
reportID: (reportID: string | undefined) => reportID ?? '',
},
stringify: {
// eslint-disable-next-line
reportID: (reportID: string | undefined) => reportID ?? '',
},
},
},
},

Expand Down
2 changes: 1 addition & 1 deletion src/libs/actions/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ function setUpPoliciesAndNavigate(session: OnyxEntry<OnyxTypes.Session>) {
if (!isLoggingInAsNewUser && exitTo) {
Navigation.waitForProtectedRoutes()
.then(() => {
Navigation.navigate(exitTo);
Navigation.navigate(exitTo, {forceReplace: true});
})
.then(endSignOnTransition);
} else {
Expand Down
17 changes: 4 additions & 13 deletions src/libs/actions/Session/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {HybridAppRoute, Route} from '@src/ROUTES';
import ROUTES from '@src/ROUTES';
import SCREENS from '@src/SCREENS';
import type Credentials from '@src/types/onyx/Credentials';
import type Response from '@src/types/onyx/Response';
import type Session from '@src/types/onyx/Session';
Expand Down Expand Up @@ -843,19 +842,11 @@ function clearSignInData() {
}

/**
* Reset all current params of the Home route
* Reset navigation state after logout
*/
function resetHomeRouteParams() {
function resetNavigationState() {
Navigation.isNavigationReady().then(() => {
const routes = navigationRef.current?.getState()?.routes;
const homeRoute = routes?.find((route) => route.name === SCREENS.HOME);

const emptyParams: Record<string, undefined> = {};
Object.keys(homeRoute?.params ?? {}).forEach((paramKey) => {
emptyParams[paramKey] = undefined;
});

Navigation.setParams(emptyParams, homeRoute?.key ?? '');
navigationRef.resetRoot(navigationRef.getRootState());
Onyx.set(ONYXKEYS.IS_CHECKING_PUBLIC_ROOM, false);
});
}
Expand All @@ -875,7 +866,7 @@ function cleanupSession() {
PersistedRequests.clear();
NetworkConnection.clearReconnectionCallbacks();
SessionUtils.resetDidUserLogInDuringSession();
resetHomeRouteParams();
resetNavigationState();
clearCache().then(() => {
Log.info('Cleared all cache data', true, {}, true);
});
Expand Down