Skip to content

Commit

Permalink
Merge pull request #32633 from talhajavedmukhtar/resolvingOfflineModeBug
Browse files Browse the repository at this point in the history
[Bug resolution] for [#31822: Conversation disappears from LHN when creating an IOU with a new user in offline mode]
  • Loading branch information
arosiclair authored Dec 8, 2023
2 parents 269e866 + 812630f commit 21f5875
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/pages/home/sidebar/SidebarLinksData.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand All @@ -62,24 +66,26 @@ 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();

const reportIDsRef = useRef(null);
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
Expand Down Expand Up @@ -194,6 +200,7 @@ const policySelector = (policy) =>
export default compose(
withCurrentReportID,
withNavigationFocus,
withNetwork(),
withOnyx({
chatReports: {
key: ONYXKEYS.COLLECTION.REPORT,
Expand Down

0 comments on commit 21f5875

Please sign in to comment.