:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(taxonomic-filter): search beyond first page for clientFilterFirstPage groups (#60963)
Adam Leithb73d208e9114
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex 3c79467f9e06..51d590f9280e 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -4929,7 +4929,7 @@ snapshots:scenes-app-insights-funnels--funnel-left-to-right-edit--dark:hash: v1.k794b7964.293297b83994468984576e5c15fa2cbbb2c4c0a7a8234959b9deba539efa383b.xupnP9sdcp25xPBOMzrhSHwtRpKPLKHaqLDBncapvQAscenes-app-insights-funnels--funnel-left-to-right-edit--light:- hash: v1.k794b7964.c63132bb5b13cbe97938ebdb2e59e320ebc338bd12b2d3bfd6af81e56270650a.3gc3UBg-8GVo4HkNBH7UrogK2q1uh9pXPDjTdYGT8nc+ hash: v1.k794b7964.6c391cbc05b64230fbd8defdbb960b131fd433409817497873fb9ffc705cd360.dtIb8VK_HAoAvzi8YbVjGpt2Y8yONsVV7mEiD9DrclQscenes-app-insights-funnels--funnel-left-to-right-edit-viewports--medium--dark:hash: v1.k794b7964.dad9df902a133cafd6b3314a3800fcb45dabbbb59a0766c87c226549392104fc.u8mciTuIKrwI-d3yiUx6dVpr3oLoJJ7tgvRU7hutwhUscenes-app-insights-funnels--funnel-left-to-right-edit-viewports--medium--light:diff --git a/frontend/src/lib/components/TaxonomicFilter/hooks/useGroupList.test.tsx b/frontend/src/lib/components/TaxonomicFilter/hooks/useGroupList.test.tsxindex d9b3454e4aca..1b8aeb6c29a5 100644--- a/frontend/src/lib/components/TaxonomicFilter/hooks/useGroupList.test.tsx+++ b/frontend/src/lib/components/TaxonomicFilter/hooks/useGroupList.test.tsx@@ -164,6 +164,51 @@ describe('useGroupList', () => {})})+ describe('clientFilterFirstPage', () => {+ it('filters the cached first page locally without refetching when the whole list fits one page', async () => {+ apiGet.mockResolvedValue({+ results: [{ name: 'Internal team' }, { name: 'Power users' }, { name: 'Zzzbeta' }],+ count: 3,+ })+ const group = makeGroup({+ type: TaxonomicFilterGroupType.Cohorts,+ endpoint: 'api/projects/1/cohorts/',+ clientFilterFirstPage: true,+ })+ const { result, rerender } = renderHook(({ q }: { q: string }) => useGroupList({ group, searchQuery: q }), {+ initialProps: { q: '' },+ })+ await waitFor(() => expect(result.current.totalResultCount).toBe(3))+ rerender({ q: 'zzzbeta' })+ await waitFor(() => expect(result.current.items.map((i: any) => i.name)).toEqual(['Zzzbeta']))+ // First page covered the whole list — no extra request for the typed query.+ expect(apiGet).toHaveBeenCalledTimes(1)+ })++ it('falls back to a server search when the dataset is larger than the cached first page', async () => {+ const firstPage = Array.from({ length: 100 }, (_, i) => ({ name: `Cohort ${i + 1}` }))+ apiGet.mockImplementation((url: string) => {+ if (url.includes('search=needle')) {+ return Promise.resolve({ results: [{ name: 'Needle cohort' }], count: 1 })+ }+ // Empty-query first page: 100 of 150 total.+ return Promise.resolve({ results: firstPage, count: 150 })+ })+ const group = makeGroup({+ type: TaxonomicFilterGroupType.Cohorts,+ endpoint: 'api/projects/1/cohorts/',+ clientFilterFirstPage: true,+ })+ const { result, rerender } = renderHook(({ q }: { q: string }) => useGroupList({ group, searchQuery: q }), {+ initialProps: { q: '' },+ })+ await waitFor(() => expect(result.current.totalResultCount).toBe(150))+ // "Needle cohort" is not in the first page — only a server search finds it.+ rerender({ q: 'needle' })+ await waitFor(() => expect(result.current.items.map((i: any) => i.name)).toEqual(['Needle cohort']))+ })+ })+describe('keyword shortcuts', () => {it('prepends QuickFilterItems when enabled and group provides shortcuts', () => {const shortcut: QuickFilterItem = {diff --git a/frontend/src/lib/components/TaxonomicFilter/hooks/useGroupList.ts b/frontend/src/lib/components/TaxonomicFilter/hooks/useGroupList.tsindex d12e41b8edef..f9a085f6fa97 100644--- a/frontend/src/lib/components/TaxonomicFilter/hooks/useGroupList.ts+++ b/frontend/src/lib/components/TaxonomicFilter/hooks/useGroupList.ts@@ -239,6 +239,56 @@ export function useGroupList(input: UseGroupListInput): UseGroupListResult {const remoteItemsRaw: ListStorage = remote.data ?? EMPTY_LIST_STORAGE+ // A `clientFilterFirstPage` group can only fuse what it cached — the+ // empty-search first page. When the server holds more rows than fit on+ // that page, local fuse silently misses every match outside it (e.g. a+ // team with >100 cohorts can't find cohort #137 by name). Once we learn+ // the dataset is bigger than one page, fall back to a real server search+ // for typed queries; the snappy local path still serves the common case+ // where the whole list fits in the first page.+ const firstPageIncomplete = clientFilter && remoteItemsRaw.count > remoteItemsRaw.results.length+ const serverSearchEnabled = firstPageIncomplete && !!trimmedSearch && !needsMoreSearchCharacters++ const serverSearchKey = useMemo(+ () => [+ 'taxonomic-list-search',+ group.type,+ group.endpoint,+ group.scopedEndpoint ?? null,+ isExpanded,+ trimmedSearch,+ limit,+ showNumericalPropsOnly,+ hideBehavioralCohorts,+ ],+ [+ group.type,+ group.endpoint,+ group.scopedEndpoint,+ isExpanded,+ trimmedSearch,+ limit,+ showNumericalPropsOnly,+ hideBehavioralCohorts,+ ]+ )++ const serverSearch = useTaxonomicResource<ListStorage>(+ serverSearchKey,+ ({ signal }) =>+ fetchTaxonomicListPage({+ group,+ searchQuery: trimmedSearch,+ offset: 0,+ limit,+ isExpanded,+ showNumericalPropsOnly,+ hideBehavioralCohorts,+ signal,+ }),+ { enabled: serverSearchEnabled, staleTime: 60_000, keepPreviousData: true }+ )+// Per-fetch Fuse index over the cached first page. Built lazily on// first non-empty query, then re-used across keystrokes until the// page changes (refetch / invalidate).@@ -258,11 +308,17 @@ export function useGroupList(input: UseGroupListInput): UseGroupListResult {if (!clientFilter || !trimmedSearch) {return remoteItemsRaw}+ // Dataset bigger than one page: the server search is authoritative.+ // Show the local fuse of the cached first page until it resolves so+ // there's no blank flash, then swap in the full server result.+ if (serverSearchEnabled && serverSearch.data) {+ return serverSearch.data+ }const filtered = remoteFuse? (remoteFuse.search(trimmedSearch).map((r: any) => r.item.item) as TaxonomicDefinitionTypes[]): []return { results: filtered, searchQuery, count: filtered.length }- }, [clientFilter, trimmedSearch, remoteItemsRaw, remoteFuse, searchQuery])+ }, [clientFilter, trimmedSearch, remoteItemsRaw, remoteFuse, searchQuery, serverSearchEnabled, serverSearch.data])// ---- Combined items + keyword shortcuts --------------------------------const keywordShortcuts: QuickFilterItem[] = useMemo(() => {@@ -299,8 +355,10 @@ export function useGroupList(input: UseGroupListInput): UseGroupListResult {const rowCount = items.length + (isExpandable ? 1 : 0)// ---- Loading / empty state ---------------------------------------------- const isLoading = remote.isLoading- const isFetching = remote.isFetching+ // Fold the server-search fallback into the busy flags so the skeleton+ // (not "no results") shows while it's in flight on a >1-page dataset.+ const isLoading = remote.isLoading || (serverSearchEnabled && serverSearch.isLoading)+ const isFetching = remote.isFetching || (serverSearchEnabled && serverSearch.isFetching)const showNonCapturedEventOption = useMemo(() => {if (!allowNonCapturedEvents) {