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
17 changes: 11 additions & 6 deletions src/components/Search/SearchRouter/SearchRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import useLocalize from '@hooks/useLocalize';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useThemeStyles from '@hooks/useThemeStyles';
import {scrollToRight} from '@libs/InputUtils';
import backHistory from '@libs/Navigation/helpers/backHistory';
import type {SearchOption} from '@libs/OptionsListUtils';
import type {OptionData} from '@libs/ReportUtils';
import {getAutocompleteQueryWithComma, getQueryWithoutAutocompletedPart} from '@libs/SearchAutocompleteUtils';
Expand Down Expand Up @@ -219,7 +220,9 @@ function SearchRouter({onRouterClose, shouldHideInputCaret, isSearchRouterDispla
}

onRouterClose();
Navigation.navigate(ROUTES.SEARCH_ROOT.getRoute({query: updatedQuery}));
backHistory().then(() => {

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.

Coming from this issue #62026, Adding the backHistory promise caused a slight delay on Android, so to resolve this, we've limited the promise to the web only, context: #62026 (comment)

Navigation.navigate(ROUTES.SEARCH_ROOT.getRoute({query: updatedQuery}));
});

setTextInputValue('');
setAutocompleteQueryValue('');
Expand Down Expand Up @@ -284,11 +287,13 @@ function SearchRouter({onRouterClose, shouldHideInputCaret, isSearchRouterDispla
}
} else {
onRouterClose();
if (item?.reportID) {
Navigation.navigateToReportWithPolicyCheck({reportID: item?.reportID});
} else if ('login' in item) {
navigateToAndOpenReport(item.login ? [item.login] : [], false);
}
backHistory().then(() => {
if (item?.reportID) {
Navigation.navigateToReportWithPolicyCheck({reportID: item?.reportID});
} else if ('login' in item) {
navigateToAndOpenReport(item.login ? [item.login] : [], false);
}
});
}
},
[autocompleteSubstitutions, onRouterClose, onSearchQueryChange, submitSearch, textInputValue],
Expand Down
22 changes: 22 additions & 0 deletions src/libs/Navigation/helpers/backHistory/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import {isMobileChrome} from '@libs/Browser';

/**
* This function is used to trigger a browser back navigation and resolves a promise once the navigation is complete (only on mobile Chrome).
* More details - https://github.com/Expensify/App/issues/58946.
*/
export default function backHistory() {
return new Promise<void>((resolve) => {
if (!isMobileChrome()) {
resolve();
return;
}

const onPopState = () => {
window.removeEventListener('popstate', onPopState);
resolve();
};

window.addEventListener('popstate', onPopState);
window.history.back();
});
}