Skip to content

Commit b6239ef

Browse files
committed
fix(cmd-k): Decouple debounce timer from async result count changes
filteredActionCount in the debounce effect deps caused the 500ms timer to restart when async results arrived (e.g. DSN lookup), delaying or losing the searched event. Now sync the count to a ref and read it inside the timeout callback so the timer only resets on query changes.
1 parent e7dfcc1 commit b6239ef

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

static/app/components/commandPalette/useCommandPaletteAnalytics.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ export function useCommandPaletteAnalytics(filteredActionCount: number): {
6161
analyticsState.current.state = state;
6262
}, [state]);
6363

64+
// Sync filtered count to ref so the debounce timer reads the latest value
65+
// without restarting on async result changes (e.g. DSN lookup)
66+
useEffect(() => {
67+
analyticsState.current.prevFilteredCount = filteredActionCount;
68+
}, [filteredActionCount]);
69+
6470
// Debounced query tracking
6571
useEffect(() => {
6672
const s = analyticsState.current;
@@ -74,13 +80,13 @@ export function useCommandPaletteAnalytics(filteredActionCount: number): {
7480
trackAnalytics('command_palette.searched', {
7581
organization,
7682
query: state.query,
77-
result_count: filteredActionCount,
83+
result_count: s.prevFilteredCount,
7884
session_id: s.sessionId,
7985
});
8086
}, 500);
8187

8288
return () => clearTimeout(timer);
83-
}, [state.query, filteredActionCount, organization]);
89+
}, [state.query, organization]);
8490

8591
// Track no results
8692
useEffect(() => {

0 commit comments

Comments
 (0)