diff --git a/src/pages/home/sidebar/SidebarLinksData.js b/src/pages/home/sidebar/SidebarLinksData.js index baae0fda33e3..4f55d5eafca9 100644 --- a/src/pages/home/sidebar/SidebarLinksData.js +++ b/src/pages/home/sidebar/SidebarLinksData.js @@ -5,6 +5,8 @@ import React, {useCallback, useMemo, useRef} from 'react'; import {View} from 'react-native'; import {withOnyx} from 'react-native-onyx'; import _ from 'underscore'; +import networkPropTypes from '@components/networkPropTypes'; +import {withNetwork} from '@components/OnyxProvider'; import withCurrentReportID from '@components/withCurrentReportID'; import withNavigationFocus from '@components/withNavigationFocus'; import useLocalize from '@hooks/useLocalize'; @@ -48,6 +50,8 @@ const propTypes = { /** Beta features list */ betas: PropTypes.arrayOf(PropTypes.string), + network: networkPropTypes.isRequired, + /** The policies which the user has access to */ // eslint-disable-next-line react/forbid-prop-types policies: PropTypes.object, @@ -62,7 +66,7 @@ const defaultProps = { policies: {}, }; -function SidebarLinksData({isFocused, allReportActions, betas, chatReports, currentReportID, insets, isLoadingApp, onLinkClick, policies, priorityMode}) { +function SidebarLinksData({isFocused, allReportActions, betas, chatReports, currentReportID, insets, isLoadingApp, onLinkClick, policies, priorityMode, network}) { const styles = useThemeStyles(); const {translate} = useLocalize(); @@ -70,16 +74,18 @@ function SidebarLinksData({isFocused, allReportActions, betas, chatReports, curr const isLoading = isLoadingApp; const optionListItems = useMemo(() => { const reportIDs = SidebarUtils.getOrderedReportIDs(null, chatReports, betas, policies, priorityMode, allReportActions); + if (deepEqual(reportIDsRef.current, reportIDs)) { return reportIDsRef.current; } // We need to update existing reports only once while loading because they are updated several times during loading and causes this regression: https://github.com/Expensify/App/issues/24596#issuecomment-1681679531 - if (!isLoading || !reportIDsRef.current) { + // However, if the user is offline, we need to update the reports unconditionally, since the loading of report data might be stuck in this case. + if (!isLoading || !reportIDsRef.current || network.isOffline) { reportIDsRef.current = reportIDs; } return reportIDsRef.current || []; - }, [allReportActions, betas, chatReports, policies, priorityMode, isLoading]); + }, [allReportActions, betas, chatReports, policies, priorityMode, isLoading, network.isOffline]); // We need to make sure the current report is in the list of reports, but we do not want // to have to re-generate the list every time the currentReportID changes. To do that @@ -194,6 +200,7 @@ const policySelector = (policy) => export default compose( withCurrentReportID, withNavigationFocus, + withNetwork(), withOnyx({ chatReports: { key: ONYXKEYS.COLLECTION.REPORT,