From 7b8a16cf7becc0c44be95c85a3abfd3269eb7798 Mon Sep 17 00:00:00 2001 From: George Gritsouk <989898+gggritso@users.noreply.github.com> Date: Wed, 19 Nov 2025 16:59:30 -0500 Subject: [PATCH 1/3] Extract function --- .../searchQueryBuilder/tokens/freeText.tsx | 36 +++++++++++-------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/static/app/components/searchQueryBuilder/tokens/freeText.tsx b/static/app/components/searchQueryBuilder/tokens/freeText.tsx index 6efdaaebed18a5..7a884cd2022eb6 100644 --- a/static/app/components/searchQueryBuilder/tokens/freeText.tsx +++ b/static/app/components/searchQueryBuilder/tokens/freeText.tsx @@ -41,6 +41,8 @@ import {FieldKind, FieldValueType} from 'sentry/utils/fields'; import {isCtrlKeyPressed} from 'sentry/utils/isCtrlKeyPressed'; import useOrganization from 'sentry/utils/useOrganization'; +import type {FilterKeyItem} from './filterKeyListBox/types'; + type SearchQueryBuilderInputProps = { item: Node; state: ListState; @@ -409,6 +411,24 @@ function SearchQueryBuilderInputInternal({ updateSelectionIndex(); }, [updateSelectionIndex]); + const renderItem = useCallback( + (keyItem: FilterKeyItem) => + itemIsSection(keyItem) ? ( +
+ {keyItem.options.map(child => ( + + {child.label} + + ))} +
+ ) : ( + + {keyItem.label} + + ), + [] + ); + return ( - {keyItem => - itemIsSection(keyItem) ? ( -
- {keyItem.options.map(child => ( - - {child.label} - - ))} -
- ) : ( - - {keyItem.label} - - ) - } + {renderItem}
); From f6b1481c67e2d12b25fe115b80e8265120b055d1 Mon Sep 17 00:00:00 2001 From: George Gritsouk <989898+gggritso@users.noreply.github.com> Date: Wed, 19 Nov 2025 16:59:43 -0500 Subject: [PATCH 2/3] Only render if open --- static/app/components/searchQueryBuilder/tokens/freeText.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/static/app/components/searchQueryBuilder/tokens/freeText.tsx b/static/app/components/searchQueryBuilder/tokens/freeText.tsx index 7a884cd2022eb6..a83ef7677b07c1 100644 --- a/static/app/components/searchQueryBuilder/tokens/freeText.tsx +++ b/static/app/components/searchQueryBuilder/tokens/freeText.tsx @@ -710,7 +710,7 @@ function SearchQueryBuilderInputInternal({ state.collection.getLastKey() === item.key ? 'query-builder-input' : undefined } > - {renderItem} + {isOpen ? renderItem : null} ); From 0d9e55794ee0ea038a1f44a13b06fc3a8c30c878 Mon Sep 17 00:00:00 2001 From: George Gritsouk <989898+gggritso@users.noreply.github.com> Date: Wed, 19 Nov 2025 17:51:42 -0500 Subject: [PATCH 3/3] Add clarifying comment --- static/app/components/searchQueryBuilder/tokens/freeText.tsx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/static/app/components/searchQueryBuilder/tokens/freeText.tsx b/static/app/components/searchQueryBuilder/tokens/freeText.tsx index a83ef7677b07c1..e9784a9570249a 100644 --- a/static/app/components/searchQueryBuilder/tokens/freeText.tsx +++ b/static/app/components/searchQueryBuilder/tokens/freeText.tsx @@ -710,6 +710,11 @@ function SearchQueryBuilderInputInternal({ state.collection.getLastKey() === item.key ? 'query-builder-input' : undefined } > + {/* `useComboBoxState` inside the combo box component eagerly iterates + `children`, which can be very slow if there are many items. If the combo + box is not even open, do not pass any `children`. This prevents the + combo box from iterating anything while it's closed, which improves + render performance when the combo box is closed. */} {isOpen ? renderItem : null}