Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion src/pages/Search/SearchMoneyRequestReportPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ function SearchMoneyRequestReportPage({route}: SearchMoneyRequestPageProps) {
return;
}

openReport({reportID: reportIDFromRoute, introSelected, betas, hasReportActions});
openReport({reportID: reportIDFromRoute, introSelected, betas, hasReportActions, currentUserAccountID});
isInitialMountRef.current = false;

// oneTransactionID dependency handles the case when deleting a transaction:
Expand Down
1 change: 1 addition & 0 deletions src/pages/Share/ShareDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ function ShareDetailsPage({route}: ShareDetailsPageProps) {
newReportObject: report,
betas,
hasReportActions: false,
currentUserAccountID: personalDetail.accountID,
});
}
if (report.reportID) {
Expand Down
4 changes: 2 additions & 2 deletions src/pages/TransactionDuplicate/Review.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ function TransactionDuplicateReview() {
if (!route.params.threadReportID || report?.reportID) {
return;
}
openReport({reportID: route.params.threadReportID, introSelected, betas, hasReportActions});
}, [report?.reportID, route.params.threadReportID, introSelected, betas, hasReportActions]);
openReport({reportID: route.params.threadReportID, introSelected, betas, hasReportActions, currentUserAccountID: currentPersonalDetails.accountID});
}, [report?.reportID, route.params.threadReportID, introSelected, betas, hasReportActions, currentPersonalDetails.accountID]);

useEffect(() => {
if (!transactionID) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';

import {openReport} from '@libs/actions/Report';
import {createBackupTransaction, removeBackupTransaction, restoreOriginalTransactionFromBackup} from '@libs/actions/TransactionEdit';
import {hasRoute} from '@libs/TransactionUtils';
Expand Down Expand Up @@ -32,6 +34,7 @@ type UseDistanceTransactionBackupParams = {
};

function useDistanceTransactionBackup({transaction, isCreatingNewRequest, isEditingSplit, isDraft, introSelected, betas, transactionWasSavedRef}: UseDistanceTransactionBackupParams): void {
const {accountID: currentUserAccountID} = useCurrentUserPersonalDetails();
// This effect runs when the component is mounted and unmounted. It's purpose is to be able to properly
// discard changes if the user cancels out of making any changes. This is accomplished by backing up the
// original transaction, letting the user modify the current transaction, and then if the user ever
Expand All @@ -57,7 +60,7 @@ function useDistanceTransactionBackup({transaction, isCreatingNewRequest, isEdit
if (!transaction?.reportID || hasRoute(transaction, true)) {
return;
}
openReport({reportID: transaction?.reportID, introSelected, betas, hasReportActions: true});
openReport({reportID: transaction?.reportID, introSelected, betas, hasReportActions: true, currentUserAccountID});
};
// eslint-disable-next-line react-hooks/exhaustive-deps -- mount/unmount-only effect: backup on mount, restore-or-drop on unmount, never re-runs
}, []);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator';

import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useOnyx from '@hooks/useOnyx';
import useReportIsArchived from '@hooks/useReportIsArchived';

Expand Down Expand Up @@ -93,6 +94,7 @@ function WithWritableReportOrNotFoundImpl<TProps extends WithWritableReportOrNot
const [reportDraft] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_DRAFT}${route.params.reportID}`);
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED);
const [betas] = useOnyx(ONYXKEYS.BETAS);
const {accountID: currentUserAccountID} = useCurrentUserPersonalDetails();
const isReportArchived = useReportIsArchived(report?.reportID);

const iouTypeParamIsInvalid = !Object.values(CONST.IOU.TYPE)
Expand All @@ -104,7 +106,7 @@ function WithWritableReportOrNotFoundImpl<TProps extends WithWritableReportOrNot
if (!!report?.reportID || !route.params.reportID || !!reportDraft || !isEditing) {
return;
}
openReport({reportID: route.params.reportID, introSelected, betas});
openReport({reportID: route.params.reportID, introSelected, betas, currentUserAccountID});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid sending the default account ID

On cold starts or deep links into this edit flow, useCurrentUserPersonalDetails() can still be its provider default (accountID: CONST.DEFAULT_NUMBER_ID, i.e. 0) while session data is hydrating. Because this effect intentionally runs only once, the newly added argument can pass 0 to openReport and never retry with the real account ID; downstream whisper visibility uses a provided account ID as authoritative, so the deprecated fallback cannot recover and guided-setup/last-visible-action data can be computed for the wrong user. Please wait for a hydrated account ID or pass undefined instead of the default value.

Useful? React with 👍 / 👎.

@truph01 truph01 Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no chance for this one to be appeared

// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ function TransactionReceiptModalContent({navigation, route}: AttachmentModalScre
if ((!!report && !!transaction) || isDraftTransaction) {
return;
}
openReport({reportID, introSelected, betas, hasReportActions});
openReport({reportID, introSelected, betas, hasReportActions, currentUserAccountID: session?.accountID});
// I'm disabling the warning, as it expects to use exhaustive deps, even though we want this useEffect to run only on the first render.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useNetwork from '@hooks/useNetwork';
import useOnyx from '@hooks/useOnyx';
import useReportIsArchived from '@hooks/useReportIsArchived';
Expand Down Expand Up @@ -48,6 +49,7 @@ function ReportAddAttachmentModalContent({route, navigation}: AttachmentModalScr
const [reportLoadingState] = useOnyx(`${ONYXKEYS.COLLECTION.RAM_ONLY_REPORT_LOADING_STATE}${reportID}`);
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED);
const [betas] = useOnyx(ONYXKEYS.BETAS);
const {accountID: currentUserAccountID} = useCurrentUserPersonalDetails();
const isReportArchived = useReportIsArchived(reportID);
const canPerformWriteAction = canUserPerformWriteAction(report, isReportArchived);
const [isLoadingApp] = useOnyx(ONYXKEYS.IS_LOADING_APP);
Expand All @@ -65,8 +67,8 @@ function ReportAddAttachmentModalContent({route, navigation}: AttachmentModalScr
}, [reportActions, reportActionID]);

const fetchReport = useCallback(() => {
openReport({reportID, introSelected, reportActionID, betas, hasReportActions});
}, [reportID, introSelected, reportActionID, betas, hasReportActions]);
openReport({reportID, introSelected, reportActionID, betas, hasReportActions, currentUserAccountID});
}, [reportID, introSelected, reportActionID, betas, hasReportActions, currentUserAccountID]);

// Close the modal if user loses write access (e.g., admin switches "Who can post" to Admins only)
useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type {Attachment} from '@components/Attachments/types';

import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useNetwork from '@hooks/useNetwork';
import useOnyx from '@hooks/useOnyx';
import useOriginalReportID from '@hooks/useOriginalReportID';
Expand Down Expand Up @@ -48,6 +49,7 @@ function ReportAttachmentModalContent({route, navigation}: AttachmentModalScreen
const hasReportActions = !!reportActions;
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED);
const [betas] = useOnyx(ONYXKEYS.BETAS);
const {accountID: currentUserAccountID} = useCurrentUserPersonalDetails();

const originalReportID = useOriginalReportID(reportID, reportActionID ? (reportActions?.[reportActionID ?? CONST.DEFAULT_NUMBER_ID] ?? {reportActionID}) : undefined);
const reportActionReportID = originalReportID ?? reportID;
Expand Down Expand Up @@ -75,8 +77,8 @@ function ReportAttachmentModalContent({route, navigation}: AttachmentModalScreen
return;
}

openReport({reportID: reportActionReportID, introSelected, reportActionID, betas, hasReportActions});
}, [reportActionReportID, shouldFetchReport, introSelected, reportActionID, betas, hasReportActions]);
openReport({reportID: reportActionReportID, introSelected, reportActionID, betas, hasReportActions, currentUserAccountID});
}, [reportActionReportID, shouldFetchReport, introSelected, reportActionID, betas, hasReportActions, currentUserAccountID]);

const onCarouselAttachmentChange = (attachment: Attachment) => {
const routeToNavigate = ROUTES.REPORT_ATTACHMENTS.getRoute({
Expand Down
6 changes: 6 additions & 0 deletions tests/actions/IOUTest/DeleteMoneyRequestTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ describe('actions/IOU/DeleteMoneyRequest', () => {
personalDetails: allPersonalDetails,
newReportObject: thread,
parentReportActionID: createIOUAction?.reportActionID,
currentUserAccountID: RORY_ACCOUNT_ID,
});
await waitForBatchedUpdates();

Expand Down Expand Up @@ -658,6 +659,7 @@ describe('actions/IOU/DeleteMoneyRequest', () => {
personalDetails: allPersonalDetails,
newReportObject: thread,
parentReportActionID: createIOUAction?.reportActionID,
currentUserAccountID: RORY_ACCOUNT_ID,
});
await waitForBatchedUpdates();

Expand Down Expand Up @@ -794,6 +796,7 @@ describe('actions/IOU/DeleteMoneyRequest', () => {
personalDetails: allPersonalDetails,
newReportObject: thread,
parentReportActionID: createIOUAction?.reportActionID,
currentUserAccountID: RORY_ACCOUNT_ID,
});
await waitForBatchedUpdates();

Expand Down Expand Up @@ -942,6 +945,7 @@ describe('actions/IOU/DeleteMoneyRequest', () => {
personalDetails: allPersonalDetails,
newReportObject: thread,
parentReportActionID: createIOUAction?.reportActionID,
currentUserAccountID: RORY_ACCOUNT_ID,
});

await waitForBatchedUpdates();
Expand Down Expand Up @@ -1265,6 +1269,7 @@ describe('actions/IOU/DeleteMoneyRequest', () => {
personalDetails: allPersonalDetails,
newReportObject: thread,
parentReportActionID: createIOUAction?.reportActionID,
currentUserAccountID: RORY_ACCOUNT_ID,
});
await waitForBatchedUpdates();

Expand Down Expand Up @@ -1449,6 +1454,7 @@ describe('actions/IOU/DeleteMoneyRequest', () => {
personalDetails: allPersonalDetails,
newReportObject: thread,
parentReportActionID: createIOUAction?.reportActionID,
currentUserAccountID: RORY_ACCOUNT_ID,
});
await waitForBatchedUpdates();

Expand Down
2 changes: 2 additions & 0 deletions tests/actions/IOUTest/DuplicateTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ describe('actions/Duplicate', () => {
betas: undefined,
newReportObject: transactionThreadReport1,
parentReportActionID: iouAction1?.reportActionID,
currentUserAccountID: RORY_ACCOUNT_ID,
});
openReport({
hasReportActions: true,
Expand All @@ -487,6 +488,7 @@ describe('actions/Duplicate', () => {
betas: undefined,
newReportObject: transactionThreadReport1,
parentReportActionID: iouAction2?.reportActionID,
currentUserAccountID: RORY_ACCOUNT_ID,
});
await waitForBatchedUpdates();

Expand Down
2 changes: 2 additions & 0 deletions tests/actions/IOUTest/TrackExpenseTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2432,6 +2432,7 @@ describe('actions/IOU/TrackExpense', () => {
personalDetails: allPersonalDetails,
newReportObject: thread,
parentReportActionID: createIOUAction?.reportActionID,
currentUserAccountID: RORY_ACCOUNT_ID,
});
await waitForBatchedUpdates();

Expand Down Expand Up @@ -2545,6 +2546,7 @@ describe('actions/IOU/TrackExpense', () => {
personalDetails: allPersonalDetails,
newReportObject: thread,
parentReportActionID: createIOUAction?.reportActionID,
currentUserAccountID: RORY_ACCOUNT_ID,
});
await waitForBatchedUpdates();

Expand Down
2 changes: 2 additions & 0 deletions tests/actions/MergeTransactionTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1181,6 +1181,7 @@ describe('mergeTransactionRequest', () => {
betas: undefined,
newReportObject: thread,
parentReportActionID: sourceIOUAction.reportActionID,
currentUserAccountID: TEST_ACCOUNT_ID,
});
await waitForBatchedUpdates();

Expand Down Expand Up @@ -1371,6 +1372,7 @@ describe('mergeTransactionRequest', () => {
betas: undefined,
newReportObject: thread,
parentReportActionID: sourceIOUAction.reportActionID,
currentUserAccountID: TEST_ACCOUNT_ID,
});
await waitForBatchedUpdates();

Expand Down
15 changes: 10 additions & 5 deletions tests/actions/ReportTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ describe('actions/Report', () => {

// When the user visits the report
currentTime = DateUtils.getDBTime();
Report.openReport({hasReportActions: true, reportID: REPORT_ID, introSelected: TEST_INTRO_SELECTED, betas: undefined});
Report.openReport({hasReportActions: true, reportID: REPORT_ID, introSelected: TEST_INTRO_SELECTED, betas: undefined, currentUserAccountID: USER_1_ACCOUNT_ID});
Report.readNewestAction(REPORT_ID, true);
waitForBatchedUpdates();
return waitForBatchedUpdates();
Expand Down Expand Up @@ -1192,6 +1192,7 @@ describe('actions/Report', () => {
newReportObject: {
reportID: REPORT_ID,
},
currentUserAccountID: 1,
});
}

Expand All @@ -1211,7 +1212,7 @@ describe('actions/Report', () => {
setHasRadio(false);
await waitForBatchedUpdates();

Report.openReport({hasReportActions: true, reportID: REPORT_ID, introSelected: undefined, betas: undefined});
Report.openReport({hasReportActions: true, reportID: REPORT_ID, introSelected: undefined, betas: undefined, currentUserAccountID: 1});
await waitForBatchedUpdates();

const report = await getOnyxValue(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`);
Expand All @@ -1235,6 +1236,7 @@ describe('actions/Report', () => {
newReportObject: {
reportID: REPORT_ID,
},
currentUserAccountID: 1,
});
await waitForBatchedUpdates();

Expand Down Expand Up @@ -1309,6 +1311,7 @@ describe('actions/Report', () => {
betas: undefined,
transaction: transaction ?? undefined,
parentReportID: SELF_DM_ID,
currentUserAccountID: TEST_USER_ACCOUNT_ID,
});
await waitForBatchedUpdates();

Expand Down Expand Up @@ -1363,6 +1366,7 @@ describe('actions/Report', () => {
newReportObject: {
reportID: REPORT_ID,
},
currentUserAccountID: 1,
});
}

Expand Down Expand Up @@ -2341,6 +2345,7 @@ describe('actions/Report', () => {
reportID: '2',
},
parentReportActionID: reportActionID,
currentUserAccountID: TEST_USER_ACCOUNT_ID,
});

await waitForBatchedUpdates();
Expand Down Expand Up @@ -4917,7 +4922,7 @@ describe('actions/Report', () => {
await Onyx.set(ONYXKEYS.NVP_INTRO_SELECTED, TEST_INTRO_SELECTED);
await waitForBatchedUpdates();

Report.openReport({hasReportActions: true, reportID: REPORT_ID, introSelected: TEST_INTRO_SELECTED, betas: undefined});
Report.openReport({hasReportActions: true, reportID: REPORT_ID, introSelected: TEST_INTRO_SELECTED, betas: undefined, currentUserAccountID: 1});
await waitForBatchedUpdates();

TestHelper.expectAPICommandToHaveBeenCalled(WRITE_COMMANDS.OPEN_REPORT, 1);
Expand All @@ -4928,7 +4933,7 @@ describe('actions/Report', () => {

const REPORT_ID = '2';

Report.openReport({hasReportActions: true, reportID: REPORT_ID, introSelected: TEST_INTRO_SELECTED, betas: undefined});
Report.openReport({hasReportActions: true, reportID: REPORT_ID, introSelected: TEST_INTRO_SELECTED, betas: undefined, currentUserAccountID: 1});
await waitForBatchedUpdates();

TestHelper.expectAPICommandToHaveBeenCalled(WRITE_COMMANDS.OPEN_REPORT, 1);
Expand All @@ -4939,7 +4944,7 @@ describe('actions/Report', () => {

const REPORT_ID = '3';

Report.openReport({hasReportActions: true, reportID: REPORT_ID, introSelected: undefined, betas: undefined});
Report.openReport({hasReportActions: true, reportID: REPORT_ID, introSelected: undefined, betas: undefined, currentUserAccountID: 1});
await waitForBatchedUpdates();

TestHelper.expectAPICommandToHaveBeenCalled(WRITE_COMMANDS.OPEN_REPORT, 1);
Expand Down
Loading