Skip to content
Merged
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
24 changes: 22 additions & 2 deletions src/pages/iou/request/IOURequestStartPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ function IOURequestStartPage({
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {canBeMissing: true});
const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID}`, {canBeMissing: true});
const policy = usePolicy(report?.policyID);
const [selectedTab, selectedTabResult] = useOnyx(`${ONYXKEYS.COLLECTION.SELECTED_TAB}${CONST.TAB.IOU_REQUEST_TYPE}`, {canBeMissing: true});
const [lastSelectedTab, selectedTabResult] = useOnyx(`${ONYXKEYS.COLLECTION.SELECTED_TAB}${CONST.TAB.IOU_REQUEST_TYPE}`, {canBeMissing: true});
const [selectedTab, setSelectedTab] = useState(lastSelectedTab);

const isLoadingSelectedTab = shouldUseTab ? isLoadingOnyxValue(selectedTabResult) : false;
const [transaction, transactionResult] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${getNonEmptyStringOnyxID(route?.params.transactionID)}`, {canBeMissing: true});
const isLoadingTransaction = isLoadingOnyxValue(transactionResult);
Expand Down Expand Up @@ -135,6 +137,16 @@ function IOURequestStartPage({
Performance.markEnd(CONST.TIMING.OPEN_CREATE_EXPENSE);
}, []);

useEffect(() => {
if (isLoadingSelectedTab || selectedTab) {
return;
}
setSelectedTab(lastSelectedTab);
// We only want to set the selected tab when selectedTab is not set yet, don't want to run this effect again when lastSelectedTab changes
// eslint-disable-next-line react-compiler/react-compiler
// eslint-disable-next-line react-hooks/exhaustive-deps
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a comment so everyone knows why the ESLint rules are disabled without looking for context?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mjasikowski I updated

Copy link
Contributor

@mjasikowski mjasikowski Jan 9, 2026

Choose a reason for hiding this comment

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

@nkdengineer sorry, but your comment doesn't explain why the rules are getting disabled, It only explains the usage of useEffect()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mjasikowski I updated.

}, [isLoadingSelectedTab, selectedTab]);
Copy link
Contributor

Choose a reason for hiding this comment

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

this caused

We should let this useEffect run when lastSelectedTab is changed. It won't be a problem as there's a early return check.


const navigateBack = () => {
Navigation.closeRHPFlow();
};
Expand Down Expand Up @@ -177,6 +189,14 @@ function IOURequestStartPage({
],
);

const onTabSelected = useCallback(
(newIouType: IOURequestType) => {
setSelectedTab(newIouType);
resetIOUTypeIfChanged(newIouType);
},
[resetIOUTypeIfChanged],
);

// Clear out the temporary expense if the reportID in the URL has changed from the transaction's reportID.
useFocusEffect(
useCallback(() => {
Expand Down Expand Up @@ -253,7 +273,7 @@ function IOURequestStartPage({
<OnyxTabNavigator
id={CONST.TAB.IOU_REQUEST_TYPE}
defaultSelectedTab={defaultSelectedTab}
onTabSelected={resetIOUTypeIfChanged}
onTabSelected={onTabSelected}
tabBar={TabSelector}
onTabBarFocusTrapContainerElementChanged={setTabBarContainerElement}
onActiveTabFocusTrapContainerElementChanged={setActiveTabContainerElement}
Expand Down
Loading