From 247cd96001b2f5663b77829ba2ddbdcf13e37acf Mon Sep 17 00:00:00 2001 From: bartektomczyk Date: Sat, 9 Dec 2023 11:09:17 +0100 Subject: [PATCH 1/4] fix: handle reconnect with proper id --- .../Navigation/AppNavigator/AuthScreens.tsx | 34 ++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/src/libs/Navigation/AppNavigator/AuthScreens.tsx b/src/libs/Navigation/AppNavigator/AuthScreens.tsx index 7286615e6ba6..0fc05f7802f3 100644 --- a/src/libs/Navigation/AppNavigator/AuthScreens.tsx +++ b/src/libs/Navigation/AppNavigator/AuthScreens.tsx @@ -50,8 +50,8 @@ type AuthScreensProps = { /** Opt-in experimental mode that prevents certain Onyx keys from persisting to disk */ isUsingMemoryOnlyKeys: OnyxEntry; - /** The last Onyx update ID was applied to the client */ - lastUpdateIDAppliedToClient: OnyxEntry; + /** Information about any currently running demos */ + demoInfo: OnyxEntry; }; const loadReportAttachments = () => require('../../../pages/home/report/ReportAttachments').default as React.ComponentType; @@ -63,6 +63,7 @@ const loadConciergePage = () => require('../../../pages/ConciergePage').default let timezone: Timezone | null; let currentAccountID = -1; let isLoadingApp = false; +let lastUpdateIDAppliedToClient: number; Onyx.connect({ key: ONYXKEYS.SESSION, @@ -112,6 +113,21 @@ Onyx.connect({ }, }); +Onyx.connect({ + key: ONYXKEYS.ONYX_UPDATES_LAST_UPDATE_ID_APPLIED_TO_CLIENT, + callback: (value: number) => { + lastUpdateIDAppliedToClient = value; + }, +}); + +function handleNetworkReconnect() { + if (isLoadingApp) { + App.openApp(); + } else { + App.reconnectApp(lastUpdateIDAppliedToClient); + } +} + const RootStack = createCustomStackNavigator(); // 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 @@ -129,7 +145,7 @@ const modalScreenListeners = { }, }; -function AuthScreens({lastUpdateIDAppliedToClient, session, lastOpenedPublicRoomID, isUsingMemoryOnlyKeys = false}: AuthScreensProps) { +function AuthScreens({session, lastOpenedPublicRoomID, isUsingMemoryOnlyKeys = false}: AuthScreensProps) { const styles = useThemeStyles(); const StyleUtils = useStyleUtils(); const {isSmallScreenWidth} = useWindowDimensions(); @@ -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, @@ -329,7 +339,7 @@ export default withOnyx({ isUsingMemoryOnlyKeys: { key: ONYXKEYS.IS_USING_MEMORY_ONLY_KEYS, }, - lastUpdateIDAppliedToClient: { - key: ONYXKEYS.ONYX_UPDATES_LAST_UPDATE_ID_APPLIED_TO_CLIENT, + demoInfo: { + key: ONYXKEYS.DEMO_INFO, }, })(AuthScreensMemoized); From c3a1fa8ed46b0a9443f5e4a2fb29f5efc876c1bd Mon Sep 17 00:00:00 2001 From: bartektomczyk Date: Sat, 9 Dec 2023 11:52:11 +0100 Subject: [PATCH 2/4] fix: fixed TS issues --- src/libs/Navigation/AppNavigator/AuthScreens.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/Navigation/AppNavigator/AuthScreens.tsx b/src/libs/Navigation/AppNavigator/AuthScreens.tsx index 0fc05f7802f3..f53c6c58f0a9 100644 --- a/src/libs/Navigation/AppNavigator/AuthScreens.tsx +++ b/src/libs/Navigation/AppNavigator/AuthScreens.tsx @@ -63,7 +63,7 @@ const loadConciergePage = () => require('../../../pages/ConciergePage').default let timezone: Timezone | null; let currentAccountID = -1; let isLoadingApp = false; -let lastUpdateIDAppliedToClient: number; +let lastUpdateIDAppliedToClient: OnyxEntry; Onyx.connect({ key: ONYXKEYS.SESSION, @@ -115,7 +115,7 @@ Onyx.connect({ Onyx.connect({ key: ONYXKEYS.ONYX_UPDATES_LAST_UPDATE_ID_APPLIED_TO_CLIENT, - callback: (value: number) => { + callback: (value: OnyxEntry) => { lastUpdateIDAppliedToClient = value; }, }); From 1a3a02d6786c1f9467129646f67dbf039ed0e071 Mon Sep 17 00:00:00 2001 From: bartektomczyk Date: Tue, 2 Jan 2024 08:59:17 +0100 Subject: [PATCH 3/4] fix: rebasing --- src/libs/Navigation/AppNavigator/AuthScreens.tsx | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/libs/Navigation/AppNavigator/AuthScreens.tsx b/src/libs/Navigation/AppNavigator/AuthScreens.tsx index f53c6c58f0a9..d62c1e2f04b7 100644 --- a/src/libs/Navigation/AppNavigator/AuthScreens.tsx +++ b/src/libs/Navigation/AppNavigator/AuthScreens.tsx @@ -49,9 +49,6 @@ type AuthScreensProps = { /** Opt-in experimental mode that prevents certain Onyx keys from persisting to disk */ isUsingMemoryOnlyKeys: OnyxEntry; - - /** Information about any currently running demos */ - demoInfo: OnyxEntry; }; const loadReportAttachments = () => require('../../../pages/home/report/ReportAttachments').default as React.ComponentType; @@ -339,7 +336,4 @@ export default withOnyx({ isUsingMemoryOnlyKeys: { key: ONYXKEYS.IS_USING_MEMORY_ONLY_KEYS, }, - demoInfo: { - key: ONYXKEYS.DEMO_INFO, - }, })(AuthScreensMemoized); From 022e32f46342b5e5fc74818941760a931d4f7694 Mon Sep 17 00:00:00 2001 From: bartektomczyk Date: Tue, 9 Jan 2024 09:34:33 +0100 Subject: [PATCH 4/4] fix: added initialLastUpdateIDAppliedToClient for mount event --- src/libs/Navigation/AppNavigator/AuthScreens.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/libs/Navigation/AppNavigator/AuthScreens.tsx b/src/libs/Navigation/AppNavigator/AuthScreens.tsx index d62c1e2f04b7..03a3612d4566 100644 --- a/src/libs/Navigation/AppNavigator/AuthScreens.tsx +++ b/src/libs/Navigation/AppNavigator/AuthScreens.tsx @@ -49,6 +49,9 @@ type AuthScreensProps = { /** Opt-in experimental mode that prevents certain Onyx keys from persisting to disk */ isUsingMemoryOnlyKeys: OnyxEntry; + + /** The last Onyx update ID was applied to the client */ + initialLastUpdateIDAppliedToClient: OnyxEntry; }; const loadReportAttachments = () => require('../../../pages/home/report/ReportAttachments').default as React.ComponentType; @@ -142,7 +145,7 @@ const modalScreenListeners = { }, }; -function AuthScreens({session, lastOpenedPublicRoomID, isUsingMemoryOnlyKeys = false}: AuthScreensProps) { +function AuthScreens({session, lastOpenedPublicRoomID, isUsingMemoryOnlyKeys = false, initialLastUpdateIDAppliedToClient}: AuthScreensProps) { const styles = useThemeStyles(); const StyleUtils = useStyleUtils(); const {isSmallScreenWidth} = useWindowDimensions(); @@ -187,7 +190,7 @@ function AuthScreens({session, lastOpenedPublicRoomID, isUsingMemoryOnlyKeys = f if (shouldGetAllData) { App.openApp(); } else { - App.reconnectApp(lastUpdateIDAppliedToClient); + App.reconnectApp(initialLastUpdateIDAppliedToClient); } PriorityMode.autoSwitchToFocusMode(); @@ -336,4 +339,7 @@ export default withOnyx({ isUsingMemoryOnlyKeys: { key: ONYXKEYS.IS_USING_MEMORY_ONLY_KEYS, }, + initialLastUpdateIDAppliedToClient: { + key: ONYXKEYS.ONYX_UPDATES_LAST_UPDATE_ID_APPLIED_TO_CLIENT, + }, })(AuthScreensMemoized);