Skip to content

Commit

Permalink
Merge pull request Expensify#32776 from barttom/fix/32583/network-rec…
Browse files Browse the repository at this point in the history
…onnect-in-outh-screens

fix: handle reconnect with proper id
  • Loading branch information
aldo-expensify authored Jan 12, 2024
2 parents f6a2e78 + 022e32f commit c8631be
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions src/libs/Navigation/AppNavigator/AuthScreens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type AuthScreensProps = {
isUsingMemoryOnlyKeys: OnyxEntry<boolean>;

/** The last Onyx update ID was applied to the client */
lastUpdateIDAppliedToClient: OnyxEntry<number>;
initialLastUpdateIDAppliedToClient: OnyxEntry<number>;
};

const loadReportAttachments = () => require('../../../pages/home/report/ReportAttachments').default as React.ComponentType;
Expand All @@ -63,6 +63,7 @@ const loadConciergePage = () => require('../../../pages/ConciergePage').default
let timezone: Timezone | null;
let currentAccountID = -1;
let isLoadingApp = false;
let lastUpdateIDAppliedToClient: OnyxEntry<number>;

Onyx.connect({
key: ONYXKEYS.SESSION,
Expand Down Expand Up @@ -112,6 +113,21 @@ Onyx.connect({
},
});

Onyx.connect({
key: ONYXKEYS.ONYX_UPDATES_LAST_UPDATE_ID_APPLIED_TO_CLIENT,
callback: (value: OnyxEntry<number>) => {
lastUpdateIDAppliedToClient = value;
},
});

function handleNetworkReconnect() {
if (isLoadingApp) {
App.openApp();
} else {
App.reconnectApp(lastUpdateIDAppliedToClient);
}
}

const RootStack = createCustomStackNavigator<AuthScreensParamList>();
// We want to delay the re-rendering for components(e.g. ReportActionCompose)
// that depends on modal visibility until Modal is completely closed and its focused
Expand All @@ -129,7 +145,7 @@ const modalScreenListeners = {
},
};

function AuthScreens({lastUpdateIDAppliedToClient, session, lastOpenedPublicRoomID, isUsingMemoryOnlyKeys = false}: AuthScreensProps) {
function AuthScreens({session, lastOpenedPublicRoomID, isUsingMemoryOnlyKeys = false, initialLastUpdateIDAppliedToClient}: AuthScreensProps) {
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const {isSmallScreenWidth} = useWindowDimensions();
Expand All @@ -156,13 +172,7 @@ function AuthScreens({lastUpdateIDAppliedToClient, session, lastOpenedPublicRoom
}

NetworkConnection.listenForReconnect();
NetworkConnection.onReconnect(() => {
if (isLoadingApp) {
App.openApp();
} else {
App.reconnectApp(lastUpdateIDAppliedToClient);
}
});
NetworkConnection.onReconnect(handleNetworkReconnect);
PusherConnectionManager.init();
Pusher.init({
appKey: CONFIG.PUSHER.APP_KEY,
Expand All @@ -180,7 +190,7 @@ function AuthScreens({lastUpdateIDAppliedToClient, session, lastOpenedPublicRoom
if (shouldGetAllData) {
App.openApp();
} else {
App.reconnectApp(lastUpdateIDAppliedToClient);
App.reconnectApp(initialLastUpdateIDAppliedToClient);
}

PriorityMode.autoSwitchToFocusMode();
Expand Down Expand Up @@ -329,7 +339,7 @@ export default withOnyx<AuthScreensProps, AuthScreensProps>({
isUsingMemoryOnlyKeys: {
key: ONYXKEYS.IS_USING_MEMORY_ONLY_KEYS,
},
lastUpdateIDAppliedToClient: {
initialLastUpdateIDAppliedToClient: {
key: ONYXKEYS.ONYX_UPDATES_LAST_UPDATE_ID_APPLIED_TO_CLIENT,
},
})(AuthScreensMemoized);

0 comments on commit c8631be

Please sign in to comment.