@@ -1956,7 +1956,9 @@ function updateSplitTransactions({
19561956 waypoints : splits . at ( 0 ) ?. waypoints ? JSON . stringify ( splits . at ( 0 ) ?. waypoints ) : undefined ,
19571957 copiedComments : splits . at ( 0 ) ?. copiedComments ? JSON . stringify ( splits . at ( 0 ) ?. copiedComments ) : undefined ,
19581958 } as RevertSplitTransactionParams ;
1959- write = ( ) => apiWrite ( WRITE_COMMANDS . REVERT_SPLIT_TRANSACTION , parameters , onyxData ) ;
1959+ write = ( ) => {
1960+ apiWrite ( WRITE_COMMANDS . REVERT_SPLIT_TRANSACTION , parameters , onyxData ) ;
1961+ } ;
19601962 } else {
19611963 // Prepare splitApiParams for the Transaction_Split API call which requires a specific format for the splits
19621964 // The format is: splits[0][amount], splits[0][category], splits[0][tag] etc.
@@ -1973,7 +1975,9 @@ function updateSplitTransactions({
19731975 } ;
19741976
19751977 const command = isCreationOfSplits ? WRITE_COMMANDS . SPLIT_TRANSACTION : WRITE_COMMANDS . UPDATE_SPLIT_TRANSACTION ;
1976- write = ( ) => apiWrite ( command , splitParameters , onyxData ) ;
1978+ write = ( ) => {
1979+ apiWrite ( command , splitParameters , onyxData ) ;
1980+ } ;
19771981 }
19781982
19791983 // API.write() applies optimisticData synchronously, so the destination screen re-renders from the
@@ -2019,18 +2023,20 @@ function updateSplitTransactionsFromSplitExpensesFlow(params: UpdateSplitTransac
20192023 // splits belonging to the current expense report, or the only remaining split moved to selfDM.
20202024 // In any of these cases we must navigate away from the soon-to-be-empty report so the user
20212025 // isn't stranded on a "Not Found" page.
2022- const expenseReportTransactions = expenseReportID ? Object . values ( params . allTransactionsList ?? { } ) . filter ( ( itemTransaction ) => itemTransaction ?. reportID === expenseReportID ) : [ ] ;
2026+ // Scanned once and reused below. The two consumers differ in how they treat a missing
2027+ // expenseReportID: areAllExpenseReportTransactionsSplitChildren must see an empty list, while the
2028+ // last-transaction check historically matched transactions whose reportID is also undefined, so
2029+ // the guard stays on the derived value rather than on the scan itself.
2030+ const transactionsMatchingExpenseReportID = Object . values ( params . allTransactionsList ?? { } ) . filter ( ( itemTransaction ) => itemTransaction ?. reportID === expenseReportID ) ;
2031+ const expenseReportTransactions = expenseReportID ? transactionsMatchingExpenseReportID : [ ] ;
20232032 const areAllExpenseReportTransactionsSplitChildren =
20242033 expenseReportTransactions . length > 0 && expenseReportTransactions . every ( ( itemTransaction ) => itemTransaction ?. comment ?. originalTransactionID === originalTransactionID ) ;
20252034 const anyRemainingSplitStaysInExpenseReport = splitExpenses . some ( ( expense ) => expense . reportID === expenseReportID ) ;
20262035 const reverseSplitKeepsOriginalInExpenseReport = isReverseSplitOperation && splitExpenses . at ( 0 ) ?. reportID === expenseReportID ;
20272036 const willExpenseReportBecomeEmpty =
20282037 ! ! expenseReportID && areAllExpenseReportTransactionsSplitChildren && ! anyRemainingSplitStaysInExpenseReport && ! reverseSplitKeepsOriginalInExpenseReport ;
20292038 const isLastTransactionInReport =
2030- willExpenseReportBecomeEmpty ||
2031- ( isReverseSplitOperation &&
2032- ! reverseSplitKeepsOriginalInExpenseReport &&
2033- Object . values ( params . allTransactionsList ?? { } ) . filter ( ( itemTransaction ) => itemTransaction ?. reportID === expenseReportID ) . length === 1 ) ;
2039+ willExpenseReportBecomeEmpty || ( isReverseSplitOperation && ! reverseSplitKeepsOriginalInExpenseReport && transactionsMatchingExpenseReportID . length === 1 ) ;
20342040 const fallbackReportID = params . expenseReport ?. chatReportID ?? params . expenseReport ?. parentReportID ;
20352041
20362042 if ( isLastTransactionInReport && fallbackReportID ) {
0 commit comments