Skip to content

Commit b6a42e4

Browse files
committed
fix infinite loading and missing MoneyRequestView with buildOptimisticCreatedReportAction for bulk actions
1 parent 7c91567 commit b6a42e4

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

src/libs/actions/IOU/index.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13213,11 +13213,13 @@ function updateMultipleMoneyRequests({transactionIDs, changes, policy, reports,
1321313213
// Offline-created expenses can be missing a transaction thread until it's opened once.
1321413214
// Ensure the thread exists before adding optimistic MODIFIED_EXPENSE actions so
1321513215
// bulk-edit comments are visible immediately while still offline.
13216+
let didCreateThreadInThisIteration = false;
1321613217
if (!transactionThreadReportID && iouReport?.reportID) {
1321713218
const optimisticTransactionThread = createTransactionThreadReport(undefined, currentUserEmail, userAccountID, iouReport, reportAction, transaction);
1321813219
if (optimisticTransactionThread?.reportID) {
1321913220
transactionThreadReportID = optimisticTransactionThread.reportID;
1322013221
transactionThread = optimisticTransactionThread;
13222+
didCreateThreadInThisIteration = true;
1322113223
}
1322213224
}
1322313225

@@ -13483,10 +13485,23 @@ function updateMultipleMoneyRequests({transactionIDs, changes, policy, reports,
1348313485

1348413486
// Optimistic report action
1348513487
if (transactionThreadReportID) {
13488+
// Backfill a CREATED action for threads never opened locally so
13489+
// MoneyRequestView renders and the skeleton doesn't loop offline.
13490+
// Skip when the thread was just created above (openReport handles it).
13491+
const threadReportActions = reportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThreadReportID}`] ?? {};
13492+
const hasCreatedAction = didCreateThreadInThisIteration || Object.values(threadReportActions).some((action) => action?.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED);
13493+
const optimisticCreatedValue: Record<string, Partial<OnyxTypes.ReportAction>> = {};
13494+
if (!hasCreatedAction) {
13495+
const optimisticCreatedAction = buildOptimisticCreatedReportAction(CONST.REPORT.OWNER_EMAIL_FAKE);
13496+
optimisticCreatedAction.pendingAction = null;
13497+
optimisticCreatedValue[optimisticCreatedAction.reportActionID] = optimisticCreatedAction;
13498+
}
13499+
1348613500
optimisticData.push({
1348713501
onyxMethod: Onyx.METHOD.MERGE,
1348813502
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThreadReportID}`,
1348913503
value: {
13504+
...optimisticCreatedValue,
1349013505
[modifiedExpenseReportActionID]: {
1349113506
...optimisticReportAction,
1349213507
reportActionID: modifiedExpenseReportActionID,

0 commit comments

Comments
 (0)