: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): stop the rebuilt menu's property search loop (#116290)
Thomas Obermüller5a22c7dad943
diff --git a/frontend/src/lib/components/TaxonomicFilter/hooks/useTaxonomicResource.test.ts b/frontend/src/lib/components/TaxonomicFilter/hooks/useTaxonomicResource.test.tsindex 4d8207e82174..da81c8508ed9 100644--- a/frontend/src/lib/components/TaxonomicFilter/hooks/useTaxonomicResource.test.ts+++ b/frontend/src/lib/components/TaxonomicFilter/hooks/useTaxonomicResource.test.ts@@ -139,13 +139,16 @@ describe('useTaxonomicResource', () => {expect(fn).toHaveBeenCalledTimes(2)})- it('aborts in-flight request when last subscriber unmounts', async () => {+ it('aborts in-flight request when last subscriber unmounts, not when it re-renders', async () => {const seenSignals: AbortSignal[] = []const fn = jest.fn().mockImplementation(({ signal }: { signal: AbortSignal }) => {seenSignals.push(signal)return new Promise(() => {})})- const { unmount } = renderHook(() => useTaxonomicResource(['abort'], fn))+ const { rerender, unmount } = renderHook(() => useTaxonomicResource(['abort'], fn))+ expect(seenSignals).toHaveLength(1)+ expect(seenSignals[0].aborted).toBe(false)+ rerender()expect(seenSignals).toHaveLength(1)expect(seenSignals[0].aborted).toBe(false)unmount()diff --git a/frontend/src/lib/components/TaxonomicFilter/hooks/useTaxonomicResource.ts b/frontend/src/lib/components/TaxonomicFilter/hooks/useTaxonomicResource.tsindex a8248a66bbef..7aa1a6cda719 100644--- a/frontend/src/lib/components/TaxonomicFilter/hooks/useTaxonomicResource.ts+++ b/frontend/src/lib/components/TaxonomicFilter/hooks/useTaxonomicResource.ts@@ -22,7 +22,7 @@* If we need any of those, swap `useTaxonomicResource` for `useQuery` from* `@tanstack/react-query`. The signatures are call-compatible.*/-import { useEffect, useRef, useSyncExternalStore } from 'react'+import { useCallback, useEffect, useRef, useSyncExternalStore } from 'react'/** Leading element of `useGroupList`'s `remoteKey` — the cached-first-page / full remote fetch.* Owned here beside the cache so key producers and invalidation predicates share one source. */@@ -165,8 +165,15 @@ export function useTaxonomicResource<T>(// belongs in a separate eviction strategy (LRU cap or time-based// purge), not on unsubscribe — the latter conflicts with the// staleTime contract.- useSyncExternalStore(- (notifyChange) => {+ //+ // `subscribe` keeps one identity per cache entry because React unsubscribes and+ // subscribes again each time this function changes. With a new function on every+ // render, any re-render of the sole consumer aborts its in-flight request and the+ // fetch effect sends it again. Two such resources in one component then abort each+ // other in turn, because the abort of one re-renders the component, and that+ // re-render aborts the other. The result is an endless loop of requests.+ const subscribe = useCallback(+ (notifyChange: () => void) => {entry.subscribers.add(notifyChange)return () => {entry.subscribers.delete(notifyChange)@@ -175,6 +182,10 @@ export function useTaxonomicResource<T>(}}},+ [entry]+ )+ useSyncExternalStore(+ subscribe,() => entry.ts + ':' + (entry.error ? 'e' : 'd') + ':' + (entry.inflight ? '1' : '0'),() => '0:d:0')