Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 7 additions & 2 deletions src/libs/actions/SplitExpenses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,13 @@ function initSplitExpense(
? createDynamicRoute(DYNAMIC_ROUTES.MONEY_REQUEST_SPLIT_EXPENSE_SEARCH.getRoute(reportID, originalTransactionID))
: createDynamicRoute(DYNAMIC_ROUTES.MONEY_REQUEST_SPLIT_EXPENSE.getRoute(reportID, originalTransactionID));
initDraftSplitExpenseDataForEdit(draftTransaction, transaction.transactionID, reportID);
Navigation.navigate(splitExpenseOverviewRoute);
Navigation.navigate(createDynamicRoute(DYNAMIC_ROUTES.SPLIT_EXPENSE_EDIT.getRoute(reportID, transaction.transactionID), splitExpenseOverviewRoute));
// Open the edit page only after the overview's RHP has mounted. Pushed in the same tick, the edit page replaces the overview's RHP,
// so going back from it (e.g. after Remove split) closes the RHP instead of returning to the overview to Save.
Navigation.navigate(splitExpenseOverviewRoute, {
afterTransition: () => {
Navigation.navigate(createDynamicRoute(DYNAMIC_ROUTES.SPLIT_EXPENSE_EDIT.getRoute(reportID, transaction.transactionID), splitExpenseOverviewRoute));

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 Cancel stale editor navigation after leaving the overview

If the user presses Back or navigates to another destination while the overview is still transitioning in, this callback remains queued and later opens the captured edit route over the destination they chose. Navigation.navigate schedules afterTransition through TransitionTracker, which waits for transitions to finish but does not cancel callbacks when the overview is popped; guard or cancel this continuation when its overview is no longer active.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@MelvinBot Please check this feedback

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.

The race is real, but I don't think it's worth changing here. I recommend no code change.

  • Impact is small. The edit page only reopens if the user leaves the overview while its open animation is still running, which is a few hundred milliseconds right after they tap the menu item. Even then, the edit page just opens where they didn't expect it. No data is saved or lost.
  • This matches the existing pattern. dismissModalWithReport chains a navigate through an uncancelled afterTransition the same way.
  • A guard adds more risk than it removes. navigate doesn't return the cancel handle, so the only option is an active-route check inside the callback. isActiveRoute strips query params from the active route but not from the route you pass in. The overview route is dynamic and can carry query params, for example from Search. A mismatch there would block the edit page every time and break the main flow. I can't test that flow in the browser, because the test account has no per diem rates.
How the timing works

navigate passes afterTransition to TransitionTracker.runAfterTransitions with waitForUpcomingTransition: true. runAfterTransitions waits for the next transition to start, then until no transitions are active. If the user goes Back during the overview's push, the pop is just another transition. The callback then fires after the pop ends. Each wait is capped at 1000 ms (MAX_TRANSITION_START_WAIT_MS, MAX_TRANSITION_DURATION_MS).

If you'd still like a guard, reply and I'll add one. It would compare paths without query params.


view run

},
});
return;
}
if (isSearchTopmostFullScreenRoute()) {
Expand Down
51 changes: 51 additions & 0 deletions tests/actions/IOUTest/SplitTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7199,6 +7199,57 @@ describe('initSplitExpense', () => {
expect(freshDraft).toBeFalsy();
});

it('opens the split edit page only after the overview transition when navigating straight to editing a split', async () => {
const {navigate} = jest.requireMock<{navigate: jest.Mock<void, [string, {afterTransition?: () => void}?]>}>('@src/libs/Navigation/Navigation');
const originalTransactionID = 'edit-nav-original';
const firstChildTransactionID = 'edit-nav-child-1';
const secondChildTransactionID = 'edit-nav-child-2';

// Given an existing split with two children, like a per diem split whose Delete opens the split edit page
await Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION}${originalTransactionID}`, {
transactionID: originalTransactionID,
amount: -100,
currency: 'USD',
merchant: 'Test Merchant',
created: DateUtils.getDBTime(),
reportID: CONST.REPORT.SPLIT_REPORT_ID,
});
await Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION}${firstChildTransactionID}`, {
transactionID: firstChildTransactionID,
amount: -50,
currency: 'USD',
merchant: 'Test Merchant',
comment: {originalTransactionID, source: CONST.IOU.TYPE.SPLIT},
created: DateUtils.getDBTime(),
reportID: 'edit-nav-report',
});
const secondChildTransaction: Transaction = {
transactionID: secondChildTransactionID,
amount: -50,
currency: 'USD',
merchant: 'Test Merchant',
comment: {originalTransactionID, source: CONST.IOU.TYPE.SPLIT},
created: DateUtils.getDBTime(),
reportID: 'edit-nav-report',
};
await Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION}${secondChildTransactionID}`, secondChildTransaction);
await waitForBatchedUpdates();
navigate.mockClear();

// When the split flow opens straight to editing one of the splits
initSplitExpense(secondChildTransaction, undefined, undefined, undefined, undefined, undefined, getCurrencyDecimalsLocal, getCurrencySymbolLocal, {navigateToEditSplitExpense: true});
await waitForBatchedUpdates();

// Then only the overview is opened at first, so the edit page can't replace the overview's RHP in the same tick
expect(navigate).toHaveBeenCalledTimes(1);
const afterTransition = navigate.mock.calls.at(0)?.[1]?.afterTransition;
expect(afterTransition).toEqual(expect.any(Function));

// And the edit page is opened on top of the overview once the overview transition ends, so going back returns to the overview
afterTransition?.();
expect(navigate).toHaveBeenCalledTimes(2);
});

it('redirects to the restricted action page and does not create a split draft when the workspace is billing-restricted', async () => {
const Navigation = jest.requireMock('@src/libs/Navigation/Navigation');
const transaction: Transaction = {
Expand Down
Loading