Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
b745fb8
perf: avoid rebuilding Search filter contents on hover
sumo-slonik Aug 7, 2026
fa50d80
final code cleanup
sumo-slonik Aug 7, 2026
42db692
fix selected item order
sumo-slonik Aug 7, 2026
544b133
polish comments and tests
sumo-slonik Aug 7, 2026
b462141
perf: keep filter contents mounted without Onyx or memoize changes
sumo-slonik Aug 10, 2026
58da995
perf: memoize the personal detail derivations behind the people filters
sumo-slonik Aug 10, 2026
67ca78b
fix: address review findings on the filters popover
sumo-slonik Aug 10, 2026
8413798
Shorten the filter hover intent delay to 30ms
sumo-slonik Aug 19, 2026
245a13f
Merge branch 'main' into perf/spend-filters-hover
sumo-slonik Aug 20, 2026
20efc0d
adjust PR to rorys POC
sumo-slonik Aug 25, 2026
8b4421f
document the Activity effect lifecycle and the option list cache sizing
sumo-slonik Aug 25, 2026
5f2c043
Merge remote-tracking branch 'upstream/main' into perf/spend-filters-…
sumo-slonik Aug 25, 2026
68ac880
keep the shared debounce hook untouched and drop stale hover activati…
sumo-slonik Aug 25, 2026
bc3e89e
fix the filter pane bugs from review and bound the option list caches
sumo-slonik Aug 26, 2026
11c0ee5
read the offset of a revealed list before the frame that restores it
sumo-slonik Aug 27, 2026
2f9349b
tidy the filters popup declarations and the negatable value comparison
sumo-slonik Aug 27, 2026
84dd129
show a filter's content once the cursor comes to rest on its row
sumo-slonik Aug 28, 2026
347335f
drop what a filter row had pending once the cursor leaves the list
sumo-slonik Aug 28, 2026
3ee04be
show the row the cursor ended on when it leaves the filter list
sumo-slonik Aug 28, 2026
64f9c63
keep every visited filter content mounted
sumo-slonik Aug 31, 2026
957014e
show every filter as the cursor reaches it and withhold only the cont…
sumo-slonik Sep 1, 2026
b389daa
code cleaned up after design review
sumo-slonik Sep 2, 2026
4acd75e
reveal a filter list as it was built rather than as it was left
sumo-slonik Sep 3, 2026
cb36f2c
reset a revealed filter list from one place, so the section lists get…
sumo-slonik Sep 3, 2026
6f18ca9
release a filter row only when the cursor heads for the content, and …
sumo-slonik Sep 4, 2026
4aa3727
wait for the cursor with the shared debounce hook, which now takes co…
sumo-slonik Sep 7, 2026
4ec6b1e
pull the pointer rest radius out of the filters popover into a hook, …
sumo-slonik Sep 7, 2026
27c3174
release a swept-out filter row once its wait elapses, and keep the wi…
sumo-slonik Sep 7, 2026
f94a354
drop the revealed list reset, so a kept filter list comes back as it …
sumo-slonik Sep 7, 2026
7a28f61
pin every debounce caller cap so only the filters wait is uncapped, a…
sumo-slonik Sep 7, 2026
b49f964
name the debounced filters wait after the function it invokes
sumo-slonik Sep 8, 2026
c6a5547
lift the personal detail options derivation out of an IIFE into a nam…
sumo-slonik Sep 8, 2026
b9a517e
Merge branch 'main' into perf/spend-filters-hover
sumo-slonik Sep 8, 2026
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
4 changes: 4 additions & 0 deletions src/CONST/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2194,6 +2194,8 @@ const CONST = {
SEARCH_OPTION_LIST_DEBOUNCE_TIME: 300,
ACCESSIBILITY_ANNOUNCEMENT_DEBOUNCE_TIME: 1000,
SUGGESTION_DEBOUNCE_TIME: 100,
/** How long the cursor has to rest on an advanced filter row before its content may derive the contact list */
SEARCH_FILTER_HOVER_INTENT_DELAY: 30,

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.

Is 30 the intended final value? In PR description, I saw that it is 80

RESIZE_DEBOUNCE_TIME: 100,
UNREAD_UPDATE_DEBOUNCE_TIME: 300,
USE_DEBOUNCED_STATE_DELAY: 300,
Expand Down Expand Up @@ -7008,6 +7010,8 @@ const CONST = {
RESULTS_PAGE_SIZE: 50,
EXITING_ANIMATION_DURATION: 200,
ME: 'me',
/** How far the cursor may wander from where it last counted as moving over the advanced filter list and still count as resting */
HOVER_INTENT_REST_RADIUS_PX: 8,
DATA_TYPES: {
EXPENSE: 'expense',
EXPENSE_REPORT: 'expense-report',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ type FilterListProps = FilterItemCallbacks & {
selectedFilter?: SearchFilter['key'];
style?: StyleProp<ViewStyle>;
contentContainerStyle?: StyleProp<ViewStyle>;

/** Called as the cursor travels over the list. Web only - it reports the movement inside a row, which `onHoverIn` only reports entering. */
onPointerMove?: (event: {clientX: number; clientY: number}) => void;

/** Called when the cursor leaves the list, so the consumer can settle whatever it was still waiting on for the last row. Web only. */
onPointerLeave?: (event: {clientX: number}) => void;
};

type FilterItemProps = FilterItemCallbacks & {
Expand Down Expand Up @@ -102,7 +108,7 @@ function FilterItem({filterKey, isSelected, onPress, onHoverIn, onFocus}: Filter
);
}

function FilterList({type, policyID, selectedFilter, style, contentContainerStyle, onHoverIn, onFocus, onPress}: FilterListProps) {
function FilterList({type, policyID, selectedFilter, style, contentContainerStyle, onHoverIn, onFocus, onPress, onPointerMove, onPointerLeave}: FilterListProps) {
const styles = useThemeStyles();
const typeFiltersKeys = useAdvancedSearchFilters(type, policyID);

Expand All @@ -111,6 +117,8 @@ function FilterList({type, policyID, selectedFilter, style, contentContainerStyl
style={[style]}
contentContainerStyle={[contentContainerStyle]}
showsVerticalScrollIndicator={false}
onMouseMove={onPointerMove}
onMouseLeave={onPointerLeave}
>
{typeFiltersKeys.map((section, index) => (
<View key={`${section.at(0)}`}>
Expand Down
3 changes: 2 additions & 1 deletion src/components/Search/FilterComponents/UserSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ function UserSelector({value = [], isNegatable, policyID, selectionListTextInput
return acc;
}, new Set<string>());

const expensifyTeamExclusions = getExpensifyTeamExclusions(personalDetails, policies, currentUserPersonalDetails.email);
// getExpensifyTeamExclusions walks every personal detail, so it is skipped while the selector withholds its options.
const expensifyTeamExclusions = ready ? getExpensifyTeamExclusions(personalDetails, policies, currentUserPersonalDetails.email) : CONST.EMPTY_OBJECT;

// Snapshot the pre-selected accountIDs from when the filter first opened so they can be floated to the
// top on first render without repinning rows that are toggled afterwards.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import LoadingIndicator from '@components/LoadingIndicator';
import type {ListFilterContentWrapperProps} from '@components/Search/FilterComponents/AdvancedFilters/SearchAdvancedFiltersContent';
import ListFilterContent from '@components/Search/FilterComponents/ListFilterContent';

Expand All @@ -6,12 +7,22 @@ import useThemeStyles from '@hooks/useThemeStyles';
import {isFilterNegatable} from '@libs/SearchQueryUtils';

import React, {useState} from 'react';
import {View} from 'react-native';

function ListFilterContentPopupWrapper({baseFilterKey, value, isNegated: initialIsNegated, type, policyID, onChange}: ListFilterContentWrapperProps) {
function ListFilterContentPopupWrapper({baseFilterKey, value, isNegated: initialIsNegated, type, policyID, ready, onChange}: ListFilterContentWrapperProps) {
const styles = useThemeStyles();
const [isNegated, setIsNegated] = useState(initialIsNegated);
const isFilterKeyNegatable = isFilterNegatable(baseFilterKey);

// The filter is its own loading state, so its controls do not render behind the spinner.
if (ready === false) {
return (
<View style={[styles.mt6, styles.flex1]}>
<LoadingIndicator />
</View>
);
}

return (
<ListFilterContent
baseFilterKey={baseFilterKey}
Expand Down

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.

These changes only kick in on wide web — the popover is web-only, and small-screen/mobile go through the separate full-page filters flow, which still rebuilds each time. So the PR both leaves mobile perf unchanged and introduces a behavior split: e.g. on wide web the From/To/Amount/... search text is preserved across filter switches, on small device it isn't.

@sumo-slonik Could we make the behavior consistent across form factors?

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.

Fair point on the routing, but the gain isn't web-only. The hover intent and the kept panes are popover-bound, but memoizing the personal detail derivations is platform-neutral: createOptionList −46%, getValidOptions plus the selected mapping −23%. Those caches live at module level, so the full-page flow picks them up too, through ListFilterContentPageWrapper down to usePersonalDetailSearchSelector, as do the other consumers of that hook on native.

The behaviour split only exists within a single opening of the popover, since that's how long the kept panes live, reopen the filters and the search box is empty, same as on a small screen

Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@ import SearchAdvancedFiltersContent from '@components/Search/FilterComponents/Ad
import useUpdateFilterQuery from '@components/Search/hooks/useUpdateFilterQuery';
import type {SearchQueryJSON} from '@components/Search/types';

import {useDebounceWithControls} from '@hooks/useDebounce';
import useOnyx from '@hooks/useOnyx';
import usePointerMovement from '@hooks/usePointerMovement';
import useStyleUtils from '@hooks/useStyleUtils';
import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';

import {getFilterNegatableValue} from '@libs/SearchUIUtils';
import {getFilterNegatableValue, hasFilterContentValuesChanged} from '@libs/SearchUIUtils';
import type {SearchFilter} from '@libs/SearchUIUtils';

import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {SearchAdvancedFiltersForm} from '@src/types/form';

import React, {useRef, useState} from 'react';
import React, {Activity, useRef, useState} from 'react';
import {View} from 'react-native';

import AmountFilterContentPopupWrapper from './AmountFilterContentPopupWrapper';
Expand All @@ -28,43 +31,197 @@ type SearchAdvancedFiltersPopupProps = {
queryJSON: SearchQueryJSON;
};

/** Which filter contents are mounted and what each was given. */
type MountedFilterState = {
/** The filter whose content is shown. */
activeFilter: SearchFilter['key'];

/** The mounted contents, in visit order. They stay mounted until the popover closes. */
mountedFilters: Array<SearchFilter['key']>;

/** The filter values each mounted instance was built from. A revisit compares against it. */
formAtMount: Partial<Record<SearchFilter['key'], Partial<SearchAdvancedFiltersForm>>>;

/** The filter values each content was last shown with. It goes on rendering with them while hidden. */
formWhileHidden: Partial<Record<SearchFilter['key'], Partial<SearchAdvancedFiltersForm>>>;

/** How many times each content has been remounted. Part of its key, so a bump replaces the instance. */
contentVersions: Partial<Record<SearchFilter['key'], number>>;

/** The deferred filters now allowed to derive. One left out stands as its own loading state. */
readyFilters: Array<SearchFilter['key']>;
};

const filterComponents = {
List: ListFilterContentPopupWrapper,
Text: TextInputFilterContentPopupWrapper,
Amount: AmountFilterContentPopupWrapper,
Date: DateFilterContentPopupWrapper,
ReportField: ReportFieldFilterContentPopupWrapper,
} as const;

/** The filter the popover opens on. */
const INITIAL_FILTER = CONST.SEARCH.SYNTAX_FILTER_KEYS.TYPE;

/** The filters whose contents are derived from the whole contact list, the one derivation heavy enough to be felt. */
const DEFERRED_CONTENT_FILTERS = new Set<SearchFilter['key']>([
CONST.SEARCH.SYNTAX_FILTER_KEYS.FROM,
CONST.SEARCH.SYNTAX_FILTER_KEYS.TO,
CONST.SEARCH.SYNTAX_FILTER_KEYS.ATTENDEE,
CONST.SEARCH.SYNTAX_FILTER_KEYS.ASSIGNEE,
]);

type MountedFilterContentProps = {
/** The filter whose content this is. */
filterKey: SearchFilter['key'];

/** The filter values the content reads. */
values: Partial<SearchAdvancedFiltersForm> | undefined;

/** Whether the content may derive itself, or has to stand as its own loading state for now. */
ready: boolean;

/** Called with the values a change in the content produces. */
onChange: (values: Partial<SearchAdvancedFiltersForm>) => void;
};

// React Compiler caches the whole `mountedFilters.map()` in one slot, so every element is rebuilt on each change. Each
// content sits in its own component, so a hover ends the render at the boundary of those whose props did not change.
// `onChange` changes with the form, so an edit still re-renders them all.
function MountedFilterContent({filterKey, values, ready, onChange}: MountedFilterContentProps) {
const styles = useThemeStyles();

return (
<View style={styles.flex1}>
<SearchAdvancedFiltersContent
values={values}
baseFilterKey={filterKey}
components={filterComponents}
ready={ready}
onChange={onChange}
/>
</View>
);
}

function SearchAdvancedFiltersPopup({queryJSON}: SearchAdvancedFiltersPopupProps) {
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const {windowHeight} = useWindowDimensions();
const [selectedFilter, setSelectedFilter] = useState<SearchFilter['key']>(CONST.SEARCH.SYNTAX_FILTER_KEYS.TYPE);
const filterContentRef = useRef<View>(null);
const [searchAdvancedFiltersForm] = useOnyx(ONYXKEYS.FORMS.SEARCH_ADVANCED_FILTERS_FORM);

const filterContentRef = useRef<View>(null);
const [mountedFilterState, setMountedFilterState] = useState<MountedFilterState>(() => ({
activeFilter: INITIAL_FILTER,
mountedFilters: [INITIAL_FILTER],
formAtMount: {[INITIAL_FILTER]: searchAdvancedFiltersForm},
formWhileHidden: {},
contentVersions: {},
readyFilters: [],
}));
const {activeFilter, mountedFilters, formWhileHidden, contentVersions, readyFilters} = mountedFilterState;
const {updateFilterQueryParams} = useUpdateFilterQuery(queryJSON);

// Shows a filter's content. A visited one stays mounted, so a return reveals it rather than building it again.
const showFilter = (filterKey: SearchFilter['key']) => {
setMountedFilterState((currentState) => {
if (currentState.activeFilter === filterKey) {
return currentState;
}

const isMounted = currentState.mountedFilters.includes(filterKey);
// A content decides its selection pinning on mount, so one whose values moved on since it was built is
// remounted rather than revealed. Only the values that content reads count.
const isStale = isMounted && hasFilterContentValuesChanged(filterKey, currentState.formAtMount[filterKey], searchAdvancedFiltersForm);
const isBuilt = !isMounted || isStale;

return {
activeFilter: filterKey,
mountedFilters: isMounted ? currentState.mountedFilters : [...currentState.mountedFilters, filterKey],
formAtMount: isBuilt ? {...currentState.formAtMount, [filterKey]: searchAdvancedFiltersForm} : currentState.formAtMount,
// The filter being left keeps the values it had while shown, so hiding it costs no render.
formWhileHidden: {...currentState.formWhileHidden, [currentState.activeFilter]: searchAdvancedFiltersForm},
contentVersions: isStale ? {...currentState.contentVersions, [filterKey]: (currentState.contentVersions[filterKey] ?? 0) + 1} : currentState.contentVersions,
// A remounted content derives itself from scratch, so it waits for the cursor again like a new one.
readyFilters: isStale ? currentState.readyFilters.filter((key) => key !== filterKey) : currentState.readyFilters,
};
});
};

/** Lets the shown filter derive what it withheld. It reads the filter from the updater, so a wait outlives its render. */
const markShownFilterReady = () => {
setMountedFilterState((currentState) => {
if (!DEFERRED_CONTENT_FILTERS.has(currentState.activeFilter) || currentState.readyFilters.includes(currentState.activeFilter)) {
return currentState;
}

return {...currentState, readyFilters: [...currentState.readyFilters, currentState.activeFilter]};
});
};

// Elapses once the cursor comes to rest on a row.
const {invoke: debouncedMarkShownFilterReady, cancel: cancelReadyWait} = useDebounceWithControls(markShownFilterReady, CONST.TIMING.SEARCH_FILTER_HOVER_INTENT_DELAY);

const hoverFilter = (filterKey: SearchFilter['key']) => {
showFilter(filterKey);
debouncedMarkShownFilterReady();
};

const {trackMovement: trackPointerMovement, stopTracking} = usePointerMovement(CONST.SEARCH.HOVER_INTENT_REST_RADIUS_PX, debouncedMarkShownFilterReady);

// The direction comes from the last tracked position rather than the exit point, because `SafeTriangle` covers the
// path to the content with an overlay and the cursor leaves the list above it as often as through its edge.
const stopTrackingPointer = (event: {clientX: number}) => {
const lastMovement = stopTracking();

if (lastMovement && event.clientX <= lastMovement.x) {
return;
}

cancelReadyWait();
markShownFilterReady();

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.

onMouseLeave releases the contact list in every direction

Sweeping the cursor off the bottom or left of the filter list — or out of the popover entirely — marks the last row ready and builds the whole contact list for a pane nobody is going to look at. Could we only release when the cursor leaves toward the content pane (e.g. checking relatedTarget or the exit coordinates)?

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.

Done, but not via relatedTarget: SafeTriangle's overlay swallows that path. The direction comes from
the last tracked position; a leftward exit keeps the row withheld.

Comment thread
sumo-slonik marked this conversation as resolved.
Resolved
};

// Moving the focus is deliberate and never passes over rows on the way, so nothing is withheld from it.
const focusFilter = (filterKey: SearchFilter['key']) => {
cancelReadyWait();
showFilter(filterKey);
markShownFilterReady();
};

const mayDeriveContent = (filterKey: SearchFilter['key']) => !DEFERRED_CONTENT_FILTERS.has(filterKey) || readyFilters.includes(filterKey);

return (
<SafeTriangle submenuRef={filterContentRef}>
<View style={[styles.flexRow, StyleUtils.getHeight(Math.min(windowHeight, CONST.ADVANCED_FILTERS_POPOVER_HEIGHT))]}>
<FilterList
style={[styles.typeFiltersPopupContainer]}
type={searchAdvancedFiltersForm?.type}
policyID={getFilterNegatableValue(CONST.SEARCH.SYNTAX_FILTER_KEYS.POLICY_ID, searchAdvancedFiltersForm)}
selectedFilter={selectedFilter}
onHoverIn={setSelectedFilter}
onFocus={setSelectedFilter}
selectedFilter={activeFilter}
onHoverIn={hoverFilter}
onPointerMove={trackPointerMovement}
onPointerLeave={stopTrackingPointer}
onFocus={focusFilter}
/>
<View
ref={filterContentRef}
style={[styles.filterContentContainer]}
>
<SearchAdvancedFiltersContent
values={searchAdvancedFiltersForm}
baseFilterKey={selectedFilter}
components={{
List: ListFilterContentPopupWrapper,
Text: TextInputFilterContentPopupWrapper,
Amount: AmountFilterContentPopupWrapper,
Date: DateFilterContentPopupWrapper,
ReportField: ReportFieldFilterContentPopupWrapper,
}}
onChange={updateFilterQueryParams}
/>
{mountedFilters.map((filterKey) => (
// `Activity` keeps a hidden content mounted while taking it out of layout and unmounting its
// effects, so it holds no Onyx subscriptions until it is shown again.
<Activity
key={`${filterKey}-${contentVersions[filterKey] ?? 0}`}
mode={filterKey === activeFilter ? 'visible' : 'hidden'}
>
Comment thread
sumo-slonik marked this conversation as resolved.
Resolved
<MountedFilterContent
filterKey={filterKey}
values={filterKey === activeFilter ? searchAdvancedFiltersForm : formWhileHidden[filterKey]}
ready={mayDeriveContent(filterKey)}
onChange={updateFilterQueryParams}
/>
</Activity>
))}
</View>
</View>
</SafeTriangle>
Expand Down
16 changes: 10 additions & 6 deletions src/components/Search/SearchAutocompleteList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -470,13 +470,17 @@ function SearchAutocompleteList({
// debounce below so they don't fire a server request on every keystroke.
const hasUpstreamDebounce = inputQueryValue !== undefined;

const debounceHandleSearch = useDebounce(() => {
if (!handleSearch || !autocompleteQueryWithoutFilters) {
return;
}
const debounceHandleSearch = useDebounce(
() => {
if (!handleSearch || !autocompleteQueryWithoutFilters) {
return;
}

handleSearch(autocompleteQueryWithoutFilters);
}, CONST.TIMING.SEARCH_OPTION_LIST_DEBOUNCE_TIME);
handleSearch(autocompleteQueryWithoutFilters);
},
CONST.TIMING.SEARCH_OPTION_LIST_DEBOUNCE_TIME,
{maxWait: CONST.TIMING.SEARCH_OPTION_LIST_DEBOUNCE_TIME},
);

useEffect(() => {
if (!handleSearch || !autocompleteQueryWithoutFilters) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ function useSelectionListScroll<TData>(listRef: RefObject<Pick<FlashListRef<TDat
}
};

const debouncedScrollToIndex = useDebounce(scrollToIndex, CONST.TIMING.LIST_SCROLLING_DEBOUNCE_TIME, {leading: true, trailing: true});
// maxWait keeps the list following the focused row while an arrow key is held.
const debouncedScrollToIndex = useDebounce(scrollToIndex, CONST.TIMING.LIST_SCROLLING_DEBOUNCE_TIME, {
leading: true,
trailing: true,
maxWait: CONST.TIMING.LIST_SCROLLING_DEBOUNCE_TIME,
});

return {scrollToIndex, debouncedScrollToIndex};
}
Expand Down
Loading
Loading