Skip to content

Commit 92ee1bb

Browse files
fix(web): gate theme search on dialog open and skip stale debounced queries
1 parent cc92fc1 commit 92ee1bb

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

‎apps/web/src/components/settings/ThemeSearchSection.tsx‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ export function ThemeSearchSection({
159159
const debouncedQuery = useDebouncedValue(query.trim(), SEARCH_DEBOUNCE_MS);
160160

161161
useEffect(() => {
162+
if (!open) return;
162163
const searchKey = `${debouncedQuery}\u0000${sortBy}`;
163164
const keyChanged = prevSearchKeyRef.current !== searchKey;
164165
prevSearchKeyRef.current = searchKey;
@@ -172,6 +173,13 @@ export function ThemeSearchSection({
172173
setIsSearching(false);
173174
return;
174175
}
176+
if (debouncedQuery !== query.trim()) {
177+
// The debounced value still trails the input (dialog reopened with the
178+
// box reset, or the user is mid-keystroke). Searching it would hit Open
179+
// VSX for a query that is no longer visible; wait for the debounce to
180+
// catch up to the current input instead.
181+
return;
182+
}
175183
if (lastSearchKeyRef.current === searchKey) {
176184
// The results already match this query. A request for a newer key may
177185
// still be in flight (typed and then undone); abort it so it cannot
@@ -191,7 +199,7 @@ export function ThemeSearchSection({
191199
// once a search succeeds), so the install error the user needs to see is
192200
// preserved across that rerun.
193201
// eslint-disable-next-line react-hooks/exhaustive-deps
194-
}, [debouncedQuery, installingId, runSearch]);
202+
}, [open, query, debouncedQuery, installingId, runSearch]);
195203

196204
const handleSortChange = useCallback((value: OpenVsxThemeSort | null) => {
197205
const nextSort = SORT_OPTIONS.find((option) => option.value === value)?.value;

0 commit comments

Comments
 (0)