: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(data-warehouse): stop re-deriving the source catalog on unrelated flag refreshes (#68550)
Paul D'Ambracbc3f0ca6a2f
diff --git a/products/data_warehouse/frontend/scenes/NewSourceScene/SourceCatalog.tsx b/products/data_warehouse/frontend/scenes/NewSourceScene/SourceCatalog.tsxindex 63bd69588ad2..c30e9d3a7e09 100644--- a/products/data_warehouse/frontend/scenes/NewSourceScene/SourceCatalog.tsx+++ b/products/data_warehouse/frontend/scenes/NewSourceScene/SourceCatalog.tsx@@ -1,4 +1,5 @@import { useActions, useValues } from 'kea'+import { memo } from 'react'import { IconMegaphone, IconPlusSmall } from '@posthog/icons'import { LemonButton, LemonInput, LemonModal, LemonTag, LemonTextArea, Link } from '@posthog/lemon-ui'@@ -23,7 +24,10 @@ export interface SourceCatalogProps {allowedSources?: ExternalDataSourceType[]}-function SourceTile({+// Memoized so the whole grid doesn't re-render per keystroke in the search input or request+// modal: item references are stable across unrelated updates (catalogItems has a result+// equality check) and the callbacks are kea actions.+const SourceTile = memo(function SourceTile({item,accessDisabledReason,onNotify,@@ -83,7 +87,7 @@ function SourceTile({{content}</Link>)-}+})function RequestSourceTile({ onRequest }: { onRequest: () => void }): JSX.Element {return (diff --git a/products/data_warehouse/frontend/scenes/NewSourceScene/sourceCatalogLogic.ts b/products/data_warehouse/frontend/scenes/NewSourceScene/sourceCatalogLogic.tsindex b09192046be9..a1cac810c43f 100644--- a/products/data_warehouse/frontend/scenes/NewSourceScene/sourceCatalogLogic.ts+++ b/products/data_warehouse/frontend/scenes/NewSourceScene/sourceCatalogLogic.ts@@ -7,6 +7,7 @@ import { lemonToast } from '@posthog/lemon-ui'import { FeatureFlagKey } from 'lib/constants'import { featureFlagLogic } from 'lib/logic/featureFlagLogic'import { createFuse } from 'lib/utils/fuseSearch'+import { objectsEqual } from 'lib/utils/objects'import { getSourceDisplayStatus } from 'scenes/data-pipelines/utils/nonHogFunctionTemplatesLogic'import { urls } from 'scenes/urls'import { userLogic } from 'scenes/userLogic'@@ -181,6 +182,10 @@ export const sourceCatalogLogic = kea<sourceCatalogLogicType>([return [...managed, ...selfManaged]},+ // featureFlags is a broad dependency that changes identity on every flag refresh;+ // keeping the previous array when the derived catalog is unchanged stops the Fuse+ // index and every tile from re-deriving on unrelated flag updates.+ { resultEqualityCheck: objectsEqual },],categoriesWithCounts: [diff --git a/products/data_warehouse/frontend/scenes/NewSourceScene/tests/sourceCatalogLogic.test.ts b/products/data_warehouse/frontend/scenes/NewSourceScene/tests/sourceCatalogLogic.test.tsindex dfe87af87933..ff6f6ec8e94f 100644--- a/products/data_warehouse/frontend/scenes/NewSourceScene/tests/sourceCatalogLogic.test.ts+++ b/products/data_warehouse/frontend/scenes/NewSourceScene/tests/sourceCatalogLogic.test.ts@@ -1,3 +1,5 @@+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'+import { useMocks } from '~/mocks/jest'import type { SourceConfig } from '~/queries/schema/schema-general'import { initKeaTests } from '~/test/init'@@ -78,4 +80,20 @@ describe('sourceCatalogLogic', () => {expect(logic.values.sourceRequestModalOpen).toBe(false)expect(logic.values.sourceRequestText).toEqual('')})++ it('keeps catalogItems and the search index stable across unrelated feature flag refreshes', () => {+ // featureFlags is a broad dependency that changes identity on every flag load; without+ // result equality that re-derived the whole catalog, rebuilt the Fuse index, and handed+ // every tile a fresh item object per refresh.+ const logic = sourceCatalogLogic()+ featureFlagLogic.mount()+ const initialItems = logic.values.catalogItems+ const initialFuse = logic.values.catalogFuse+ expect(initialItems.length).toBeGreaterThan(0)++ featureFlagLogic.actions.setFeatureFlags(['some-unrelated-flag'], { 'some-unrelated-flag': true })++ expect(logic.values.catalogItems).toBe(initialItems)+ expect(logic.values.catalogFuse).toBe(initialFuse)+ })})