Skip to content

Commit 148a503

Browse files
authored
Merge pull request #42 from callstack-internal/feauture/bulk-edit-expenses-3-test-38
fix: bulk operation, test 38 infinite loading while offline
2 parents 3d02e0f + b6a42e4 commit 148a503

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
@@ -13156,11 +13156,13 @@ function updateMultipleMoneyRequests({transactionIDs, changes, policy, reports,
1315613156
// Offline-created expenses can be missing a transaction thread until it's opened once.
1315713157
// Ensure the thread exists before adding optimistic MODIFIED_EXPENSE actions so
1315813158
// bulk-edit comments are visible immediately while still offline.
13159+
let didCreateThreadInThisIteration = false;
1315913160
if (!transactionThreadReportID && iouReport?.reportID) {
1316013161
const optimisticTransactionThread = createTransactionThreadReport(undefined, currentUserEmail, userAccountID, iouReport, reportAction, transaction);
1316113162
if (optimisticTransactionThread?.reportID) {
1316213163
transactionThreadReportID = optimisticTransactionThread.reportID;
1316313164
transactionThread = optimisticTransactionThread;
13165+
didCreateThreadInThisIteration = true;
1316413166
}
1316513167
}
1316613168

@@ -13428,10 +13430,23 @@ function updateMultipleMoneyRequests({transactionIDs, changes, policy, reports,
1342813430

1342913431
// Optimistic report action
1343013432
if (transactionThreadReportID) {
13433+
// Backfill a CREATED action for threads never opened locally so
13434+
// MoneyRequestView renders and the skeleton doesn't loop offline.
13435+
// Skip when the thread was just created above (openReport handles it).
13436+
const threadReportActions = reportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThreadReportID}`] ?? {};
13437+
const hasCreatedAction = didCreateThreadInThisIteration || Object.values(threadReportActions).some((action) => action?.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED);
13438+
const optimisticCreatedValue: Record<string, Partial<OnyxTypes.ReportAction>> = {};
13439+
if (!hasCreatedAction) {
13440+
const optimisticCreatedAction = buildOptimisticCreatedReportAction(CONST.REPORT.OWNER_EMAIL_FAKE);
13441+
optimisticCreatedAction.pendingAction = null;
13442+
optimisticCreatedValue[optimisticCreatedAction.reportActionID] = optimisticCreatedAction;
13443+
}
13444+
1343113445
optimisticData.push({
1343213446
onyxMethod: Onyx.METHOD.MERGE,
1343313447
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThreadReportID}`,
1343413448
value: {
13449+
...optimisticCreatedValue,
1343513450
[modifiedExpenseReportActionID]: {
1343613451
...optimisticReportAction,
1343713452
reportActionID: modifiedExpenseReportActionID,

0 commit comments

Comments
 (0)