Skip to content

Commit 8b020b9

Browse files
mountinyOSBotify
authored andcommitted
Merge pull request #62562 from callstack-internal/fix-blinking-old-type-of-report
[CP Staging] Fix blinking old type of report (cherry picked from commit e48ca86) (cherry-picked to staging by mountiny)
1 parent b3316ae commit 8b020b9

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

src/components/MoneyRequestReportView/MoneyRequestReportActionsList.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,16 @@ type MoneyRequestReportListProps = {
7575
reportActions?: OnyxTypes.ReportAction[];
7676

7777
/** List of transactions belonging to this report */
78-
transactions: OnyxTypes.Transaction[];
78+
transactions?: OnyxTypes.Transaction[];
7979

8080
/** If the report has newer actions to load */
8181
hasNewerActions: boolean;
8282

8383
/** If the report has older actions to load */
8484
hasOlderActions: boolean;
85+
86+
/** Whether report actions are still loading */
87+
isLoadingInitialReportActions?: boolean;
8588
};
8689

8790
function getParentReportAction(parentReportActions: OnyxEntry<OnyxTypes.ReportActions>, parentReportActionID: string | undefined): OnyxEntry<OnyxTypes.ReportAction> {
@@ -91,7 +94,15 @@ function getParentReportAction(parentReportActions: OnyxEntry<OnyxTypes.ReportAc
9194
return parentReportActions[parentReportActionID];
9295
}
9396

94-
function MoneyRequestReportActionsList({report, policy, reportActions = [], transactions = [], hasNewerActions, hasOlderActions}: MoneyRequestReportListProps) {
97+
function MoneyRequestReportActionsList({
98+
report,
99+
policy,
100+
reportActions = [],
101+
transactions = [],
102+
hasNewerActions,
103+
hasOlderActions,
104+
isLoadingInitialReportActions,
105+
}: MoneyRequestReportListProps) {
95106
const styles = useThemeStyles();
96107
const {translate} = useLocalize();
97108
const {preferredLocale} = useLocalize();
@@ -484,7 +495,7 @@ function MoneyRequestReportActionsList({report, policy, reportActions = [], tran
484495
isActive={isFloatingMessageCounterVisible}
485496
onClick={scrollToBottomAndMarkReportAsRead}
486497
/>
487-
{isEmpty(visibleReportActions) && isEmpty(transactions) ? (
498+
{isEmpty(visibleReportActions) && isEmpty(transactions) && !isLoadingInitialReportActions ? (
488499
<>
489500
<MoneyRequestViewReportFields
490501
report={report}

src/components/MoneyRequestReportView/MoneyRequestReportView.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ function MoneyRequestReportView({report, policy, reportMetadata, shouldDisplayRe
100100

101101
const transactionThreadReportID = getOneTransactionThreadReportID(reportID, reportActions ?? [], isOffline);
102102

103-
const [transactions = undefined] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION, {
103+
const [transactions] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION, {
104104
selector: (allTransactions: OnyxCollection<OnyxTypes.Transaction>) => selectAllTransactionsForReport(allTransactions, reportID, reportActions),
105105
canBeMissing: true,
106106
});
@@ -123,8 +123,14 @@ function MoneyRequestReportView({report, policy, reportMetadata, shouldDisplayRe
123123
// If true we will use standard `ReportActionsView` to display report data and a special header, anything else is handled via `MoneyRequestReportActionsList`
124124
const isTransactionThreadView = isReportTransactionThread(report);
125125

126-
const isEmptyTransactionReport = transactions && transactionThreadReportID === undefined && !isLoadingInitialReportActions;
127-
const shouldDisplayMoneyRequestActionsList = !!isEmptyTransactionReport && shouldDisplayReportTableView(report, transactions);
126+
// Prevent flash by ensuring transaction data is fully loaded before deciding which view to render
127+
// We need to wait for both the selector to finish AND ensure we're not in a loading state where transactions could still populate
128+
const isTransactionDataReady = transactions !== undefined;
129+
const isStillLoadingData = !!isLoadingInitialReportActions || !!reportMetadata?.isLoadingOlderReportActions || !!reportMetadata?.isLoadingNewerReportActions;
130+
const shouldWaitForData = (!isTransactionDataReady || (isStillLoadingData && transactions?.length === 0)) && !isTransactionThreadView;
131+
132+
const isEmptyTransactionReport = transactions && transactions.length === 0 && transactionThreadReportID === undefined;
133+
const shouldDisplayMoneyRequestActionsList = !!isEmptyTransactionReport || shouldDisplayReportTableView(report, transactions ?? []);
128134

129135
const reportHeaderView = useMemo(
130136
() =>
@@ -160,7 +166,7 @@ function MoneyRequestReportView({report, policy, reportMetadata, shouldDisplayRe
160166
[activeWorkspaceID, backToRoute, isTransactionThreadView, parentReportAction, policy, report, reportActions, transactionThreadReportID],
161167
);
162168

163-
if (!!(isLoadingInitialReportActions && reportActions.length === 0 && !isOffline) || !transactions) {
169+
if (!!(isLoadingInitialReportActions && reportActions.length === 0 && !isOffline) || shouldWaitForData) {
164170
return <InitialLoadingSkeleton styles={styles} />;
165171
}
166172

@@ -214,6 +220,7 @@ function MoneyRequestReportView({report, policy, reportMetadata, shouldDisplayRe
214220
reportActions={reportActions}
215221
hasOlderActions={hasOlderActions}
216222
hasNewerActions={hasNewerActions}
223+
isLoadingInitialReportActions={isLoadingInitialReportActions}
217224
/>
218225
) : (
219226
<ReportActionsView

0 commit comments

Comments
 (0)