: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): prevent infinite re-render from soleGroupValueKeyer selector (#68516)
mendral-app[bot]eb6d4c4db53c
diff --git a/frontend/src/lib/components/TaxonomicFilter/hooks/useGroupList.ts b/frontend/src/lib/components/TaxonomicFilter/hooks/useGroupList.tsindex 362d793435f6..5b51e31356b8 100644--- a/frontend/src/lib/components/TaxonomicFilter/hooks/useGroupList.ts+++ b/frontend/src/lib/components/TaxonomicFilter/hooks/useGroupList.ts@@ -76,7 +76,7 @@ export interface UseGroupListInput {selectFirstItem?: boolean/** Set only when this is the filter's sole substantive group (no separate Recent/Pinned* tabs lead the filter). Floats these recent (most-recent first) then pinned items to- * the top of the un-searched list. Mirrors legacy infiniteListLogic's `soleGroupValueKeyer`+ * the top of the un-searched list. Mirrors legacy infiniteListLogic's `soleGroupHasGetValue`* path. */promoteRecentItemsToTop?: TaxonomicDefinitionTypes[]promotePinnedItemsToTop?: TaxonomicDefinitionTypes[]@@ -365,7 +365,7 @@ export function useGroupList(input: UseGroupListInput): UseGroupListResult {}// Sole substantive group: float its own recent/pinned items to the top of the// un-searched list (keyword shortcuts only appear while searching, so they're- // never displaced). Mirrors legacy infiniteListLogic's `soleGroupValueKeyer` path.+ // never displaced). Mirrors legacy infiniteListLogic's `soleGroupHasGetValue` path.if (!trimmedSearch && (promoteRecentItemsToTop?.length || promotePinnedItemsToTop?.length)) {const keyOf = (item: TaxonomicDefinitionTypes): string | null =>groupItemKey(group.type, group.getValue?.(item) ?? null)diff --git a/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.ts b/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.tsindex 8c09fd1a43aa..a2719034bd63 100644--- a/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.ts+++ b/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.ts@@ -536,24 +536,21 @@ export const infiniteListLogic = kea<infiniteListLogicType>([return substantive.length === 1 && substantive[0] === listGroupType},],- // Keys a group result the same way recent/pinned entries are keyed- // (`sourceGroupType::value`), so `floatRecentAndPinnedToTop` can line the tiers up.- // Null unless this is the sole substantive group — kept off `items` as a small input.- soleGroupValueKeyer: [+ // Whether the sole substantive group has a usable getValue function for+ // floating recent/pinned items. The `items` selector reads this boolean+ // (stable reference) rather than a function (unstable closure that would+ // defeat kea's reference-equality memoisation and cause infinite re-renders).+ soleGroupHasGetValue: [(s) => [s.isSoleSubstantiveGroup, s.listGroupType, s.taxonomicGroups],(- isSoleSubstantiveGroup,- listGroupType,+ isSoleSubstantiveGroup: boolean,+ listGroupType: TaxonomicFilterGroupType,taxonomicGroups: TaxonomicFilterGroup[]- ): ((item: TaxonomicDefinitionTypes) => string | null) | null => {+ ): boolean => {if (!isSoleSubstantiveGroup) {- return null- }- const getValue = taxonomicGroups.find((g) => g.type === listGroupType)?.getValue- if (!getValue) {- return null+ return false}- return (item: TaxonomicDefinitionTypes): string | null => groupItemKey(listGroupType, getValue(item))+ return !!taxonomicGroups.find((g) => g.type === listGroupType)?.getValue},],allowNonCapturedEvents: [@@ -1002,7 +999,9 @@ export const infiniteListLogic = kea<infiniteListLogicType>([s.suggestedPinnedMatches,s.suggestedRecentMatches,s.keywordShortcutItems,- s.soleGroupValueKeyer,+ s.isSoleSubstantiveGroup,+ s.soleGroupHasGetValue,+ s.taxonomicGroups,(_, props: InfiniteListLogicProps) => props.collapseUrlsToContainsRow,],(@@ -1016,7 +1015,9 @@ export const infiniteListLogic = kea<infiniteListLogicType>([suggestedPinnedMatches,suggestedRecentMatches,keywordShortcutItems,- soleGroupValueKeyer,+ isSoleSubstantiveGroup,+ soleGroupHasGetValue,+ taxonomicGroups,collapseUrlsToContainsRow) => {// Collapse URL groups to a single "URL contains <query>" shortcut row@@ -1072,16 +1073,33 @@ export const infiniteListLogic = kea<infiniteListLogicType>([// Local-only groups (count 0, no remote) are always fully loaded.const soleGroupFullyLoaded =remoteItems.results.length >= remoteItems.count && !combinedResults.includes(undefined as any)- const orderedBase = searchQuery- ? promoteMatchingProperties(combinedResults, searchQuery)- : soleGroupValueKeyer && soleGroupFullyLoaded- ? floatRecentAndPinnedToTop(+ // Build the keyer inline (instead of a separate selector returning a+ // function) so kea's reference-equality memoisation isn't defeated by a+ // fresh closure on every evaluation.+ const shouldFloat =+ !searchQuery && isSoleSubstantiveGroup && soleGroupHasGetValue && soleGroupFullyLoaded+ let orderedBase: typeof combinedResults+ if (searchQuery) {+ orderedBase = promoteMatchingProperties(combinedResults, searchQuery)+ } else if (shouldFloat) {+ const getValue = taxonomicGroups.find(+ (g: TaxonomicFilterGroup) => g.type === listGroupType+ )?.getValue+ if (getValue) {+ const keyOf = (item: TaxonomicDefinitionTypes): string | null =>+ groupItemKey(listGroupType, getValue(item))+ orderedBase = floatRecentAndPinnedToTop(combinedResults,- soleGroupValueKeyer,+ keyOf,contextFilteredRecentItems || [],contextFilteredPinnedItems || [])- : combinedResults+ } else {+ orderedBase = combinedResults+ }+ } else {+ orderedBase = combinedResults+ }// The "URL contains <query>" shortcut leads the aggregated SuggestedFilters list —// ahead of recents/pinned/top-matches — so a URL search surfaces the contains// suggestion first. Everything else keeps its existing order.