Skip to content

Commit ac63040

Browse files
committed
fix: clear pre-mount promotion marker after successful submit
1 parent d41ecba commit ac63040

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

src/libs/actions/Report/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3089,6 +3089,15 @@ async function clearPromotedDraftReportForPreMount(reportID: string) {
30893089
return Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_PRE_MOUNT_PROMOTION}${reportID}`, null);
30903090
}
30913091

3092+
/**
3093+
* Clears only the promotion marker left by `promoteDraftReportForPreMount`, once the caller has handed off to the
3094+
* real submission for this reportID. The REPORT row is left alone - it is no longer speculative, and the real
3095+
* submission's own optimistic/success data owns it from here.
3096+
*/
3097+
function clearPromotedDraftReportPreMountMarker(reportID: string) {
3098+
return Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_PRE_MOUNT_PROMOTION}${reportID}`, null);
3099+
}
3100+
30923101
/**
30933102
* Saves the comment left by the user as they are typing. By saving this data the user can switch between chats, close
30943103
* tab, refresh etc without worrying about loosing what they typed out.
@@ -8564,6 +8573,7 @@ export {
85648573
saveReportDraft,
85658574
promoteDraftReportForPreMount,
85668575
clearPromotedDraftReportForPreMount,
8576+
clearPromotedDraftReportPreMountMarker,
85678577
moveIOUReportToPolicy,
85688578
moveIOUReportToPolicyAndInviteSubmitter,
85698579
convertIOUReportToExpenseReport,

src/pages/iou/request/step/IOURequestStepConfirmation.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import useTheme from '@hooks/useTheme';
3636
import useThemeStyles from '@hooks/useThemeStyles';
3737

3838
import {setMoneyRequestBillable, setMoneyRequestReimbursable} from '@libs/actions/IOU/MoneyRequest';
39-
import {clearPromotedDraftReportForPreMount, promoteDraftReportForPreMount} from '@libs/actions/Report';
39+
import {clearPromotedDraftReportForPreMount, clearPromotedDraftReportPreMountMarker, promoteDraftReportForPreMount} from '@libs/actions/Report';
4040
import {setTransactionReport} from '@libs/actions/Transaction';
4141
import {isMobileSafari} from '@libs/Browser';
4242
import {canUseTouchScreen} from '@libs/DeviceCapabilities';
@@ -681,13 +681,21 @@ function IOURequestStepConfirmation({
681681
const promotedReportID = promotedDraftReportIDRef.current;
682682
// Read the latest submission state at cleanup time because submission can start or finish after this effect runs.
683683
const hasSubmitIntent = !!getPendingSubmitFollowUpAction();
684+
if (!promotedReportID || promotedReportID !== preMountDestinationReportID || Navigation.getIsFullscreenPreInsertedUnderRHP()) {
685+
return;
686+
}
687+
688+
promotedDraftReportIDRef.current = undefined;
689+
684690
// eslint-disable-next-line react-hooks/exhaustive-deps
685-
if (!promotedReportID || promotedReportID !== preMountDestinationReportID || hasSubmitIntent || formHasBeenSubmitted.current || Navigation.getIsFullscreenPreInsertedUnderRHP()) {
691+
if (hasSubmitIntent || formHasBeenSubmitted.current) {
692+
// Submission owns the REPORT row from here - only drop the now-irrelevant promotion marker so
693+
// startup cleanup does not mistake this now-real report for an interrupted speculative one.
694+
clearPromotedDraftReportPreMountMarker(promotedReportID);
686695
return;
687696
}
688697

689698
clearPromotedDraftReportForPreMount(promotedReportID);
690-
promotedDraftReportIDRef.current = undefined;
691699
};
692700
}, [preMountDestinationReportID, formHasBeenSubmitted]);
693701

0 commit comments

Comments
 (0)