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
26 changes: 21 additions & 5 deletions src/pages/inbox/report/ReportActionsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,25 +125,34 @@ function ReportActionsView({reportID, onLayout}: ReportActionsViewProps) {
setConciergeHadMessagesAtSessionStart,
});

// hasOnceLoadedReportActions is RAM-only and resets to falsy on a page
// refresh, but cached report actions persist in Onyx. Gating the session
// start on it alone would leave sessionStartTime null until openReport
// returns, during which filterActions collapses the cached history down to
// just the synthetic CREATED action (an almost-empty chat flash). Start the
// session as soon as cached actions exist so messages render immediately on
// refresh, matching the skeleton-suppression gate below.
const canStartConciergeSession = !!hasOnceLoadedReportActions || allReportActions.length > 0;

useLayoutEffect(() => {
if (!isConciergeMainDM || !hasOnceLoadedReportActions) {
if (!isConciergeMainDM || !canStartConciergeSession) {
return;
}
startSession(oldestUnreadReportAction ? report?.lastReadTime : undefined);
// eslint-disable-next-line react-hooks/exhaustive-deps -- startSession is stable; captured values at mount only
}, [isConciergeMainDM, startSession, hasOnceLoadedReportActions]);
}, [isConciergeMainDM, startSession, canStartConciergeSession]);

// On native the component stays mounted in the navigation stack, so the
// effect above never re-fires (its isConciergeMainDM dep is always true).
// Re-trigger startSession when the globally-focused report matches this
// report so the session age check runs after navigating away and back.
useLayoutEffect(() => {
if (!isConciergeMainDM || !hasOnceLoadedReportActions || currentReportID !== reportID) {
if (!isConciergeMainDM || !canStartConciergeSession || currentReportID !== reportID) {
return;
}
startSession(oldestUnreadReportAction ? report?.lastReadTime : undefined);
// eslint-disable-next-line react-hooks/exhaustive-deps -- only react to currentReportID returning to this report
}, [currentReportID, reportID, isConciergeMainDM, hasOnceLoadedReportActions, startSession]);
}, [currentReportID, reportID, isConciergeMainDM, canStartConciergeSession, startSession]);

const isSingleExpenseReport = reportPreviewAction?.childMoneyRequestCount === 1;
const isMissingTransactionThreadReportID = !transactionThreadReport?.reportID;
Expand Down Expand Up @@ -176,7 +185,14 @@ function ReportActionsView({reportID, onLayout}: ReportActionsViewProps) {
// data has been loaded at least once. Before the first openReport response,
// hasOlderActions is unreliable, so we can't determine whether to show the
// greeting or onboarding messages. The skeleton avoids flashing wrong content.
const shouldShowSkeletonForConciergePanel = isConciergeHiddenHistory && !hasOnceLoadedReportActions && !isOffline;
// hasOnceLoadedReportActions is RAM-only and resets on a page refresh, but
// cached report actions persist in Onyx. For the main DM, render those cached
// actions immediately (matching production) instead of flashing a skeleton on
// every refresh; the side panel always opens fresh so it keeps gating on
// hasOnceLoadedReportActions only. allReportActions excludes the synthetic
// CREATED action that is always injected for Concierge, so it is empty only on
// a genuinely cold load with no cached history.
const shouldShowSkeletonForConciergePanel = isConciergeHiddenHistory && !hasOnceLoadedReportActions && !(isConciergeMainDM && allReportActions.length > 0) && !isOffline;

const shouldShowSkeleton = shouldShowSkeletonForConciergePanel || shouldShowSkeletonForInitialLoad || shouldShowSkeletonForAppLoad;

Expand Down
35 changes: 33 additions & 2 deletions tests/ui/ReportActionsViewTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ describe('ReportActionsView', () => {
},
];

const setupMainDMConciergeMocks = (sessionStartTime: string | null = SESSION_START, showFullHistory = false) => {
const setupMainDMConciergeMocks = (sessionStartTime: string | null = SESSION_START, showFullHistory = false, hasOnceLoadedReportActions = true) => {
jest.spyOn(ReportActionsUtils, 'shouldReportActionBeVisible').mockReturnValue(true);
mockUseNetwork.mockReturnValue({isOffline: false});
mockUseIsInSidePanel.mockReturnValue(false);
Expand All @@ -574,7 +574,7 @@ describe('ReportActionsView', () => {
return [false, {status: 'loaded'}];
}
if (key.includes('reportLoadingState')) {
return [{isLoadingInitialReportActions: false, hasOnceLoadedReportActions: true}, {status: 'loaded'}];
return [{isLoadingInitialReportActions: false, hasOnceLoadedReportActions}, {status: 'loaded'}];
}
if (key.includes('reportActions')) {
return [[], {status: 'loaded'}];
Expand Down Expand Up @@ -737,5 +737,36 @@ describe('ReportActionsView', () => {

expect(mockStartSession).toHaveBeenCalled();
});

it('should render cached actions without a skeleton on refresh when hasOnceLoadedReportActions resets but actions are cached', () => {
// Simulates a page refresh: hasOnceLoadedReportActions is RAM-only and resets to false,
// but report actions persist in Onyx cache. We should render them immediately (production behavior).
setupMainDMConciergeMocks(SESSION_START, false, false);

mockUsePaginatedReportActions.mockReturnValue({
...defaultPaginatedReportActionsResult,
reportActions: oldReportActions,
hasOlderActions: false,
});

renderReportActionsView({reportID: CONCIERGE_REPORT_ID});

expect(screen.queryByTestId('ReportActionsSkeletonView')).toBeNull();
expect(mockReportActionsList).toHaveBeenCalled();
});

it('should show a skeleton on a cold load when hasOnceLoadedReportActions is false and there are no cached actions', () => {
setupMainDMConciergeMocks(SESSION_START, false, false);

mockUsePaginatedReportActions.mockReturnValue({
...defaultPaginatedReportActionsResult,
reportActions: [],
hasOlderActions: false,
});

renderReportActionsView({reportID: CONCIERGE_REPORT_ID});

expect(screen.getByTestId('ReportActionsSkeletonView')).toBeTruthy();
});
});
});
Loading