: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(web-analytics): reload button refreshes all tiles, not just overview (#62823)
Lucas Ricoyc77884c13da9
diff --git a/frontend/src/scenes/web-analytics/webTileHeaderHooks.test.tsx b/frontend/src/scenes/web-analytics/webTileHeaderHooks.test.tsxnew file mode 100644index 000000000000..b301810ffc33--- /dev/null+++ b/frontend/src/scenes/web-analytics/webTileHeaderHooks.test.tsx@@ -0,0 +1,62 @@+import { cleanup, renderHook } from '@testing-library/react'++import { examples } from '~/queries/examples'+import { dataNodeCollectionLogic } from '~/queries/nodes/DataNode/dataNodeCollectionLogic'+import { insightVizDataNodeKey } from '~/queries/nodes/InsightViz/InsightViz'+import { QuerySchema } from '~/queries/schema/schema-general'+import { initKeaTests } from '~/test/init'+import { InsightLogicProps } from '~/types'++import { WEB_ANALYTICS_DATA_COLLECTION_NODE_ID } from './common'+import { useWebTileExportAdapter } from './webTileHeaderHooks'++const worldMapQuery = examples.WebAnalyticsWorldMap as QuerySchema++describe('useWebTileExportAdapter', () => {+ let collection: ReturnType<typeof dataNodeCollectionLogic.build>++ beforeEach(() => {+ initKeaTests()+ collection = dataNodeCollectionLogic({ key: WEB_ANALYTICS_DATA_COLLECTION_NODE_ID })+ collection.mount()+ })++ afterEach(() => {+ cleanup()+ collection?.unmount()+ })++ const registeredIds = (): string[] => collection.values.mountedDataNodes.map((node) => node.id)++ // Regression: the tile header renders before its chart, so this hook would let insightDataLogic build+ // the shared, key-only dataNodeLogic first without a collection id, dropping the tile from "reload all".+ it('registers the tile data node into the web analytics collection', () => {+ const insightProps: InsightLogicProps = {+ dashboardItemId: 'new-AdHoc.web-analytics-test-tile' as any,+ dataNodeCollectionId: WEB_ANALYTICS_DATA_COLLECTION_NODE_ID,+ }++ renderHook(() => useWebTileExportAdapter(worldMapQuery, insightProps))++ expect(registeredIds()).toContain(insightVizDataNodeKey(insightProps))+ })++ it('rebinds to the new node when insightProps change (tab switch)', () => {+ const firstProps: InsightLogicProps = {+ dashboardItemId: 'new-AdHoc.web-analytics-tab-a' as any,+ dataNodeCollectionId: WEB_ANALYTICS_DATA_COLLECTION_NODE_ID,+ }+ const secondProps: InsightLogicProps = {+ dashboardItemId: 'new-AdHoc.web-analytics-tab-b' as any,+ dataNodeCollectionId: WEB_ANALYTICS_DATA_COLLECTION_NODE_ID,+ }++ const { rerender } = renderHook(({ insightProps }) => useWebTileExportAdapter(worldMapQuery, insightProps), {+ initialProps: { insightProps: firstProps },+ })+ expect(registeredIds()).toContain(insightVizDataNodeKey(firstProps))++ rerender({ insightProps: secondProps })+ expect(registeredIds()).toContain(insightVizDataNodeKey(secondProps))+ })+})diff --git a/frontend/src/scenes/web-analytics/webTileHeaderHooks.tsx b/frontend/src/scenes/web-analytics/webTileHeaderHooks.tsxindex 74a1db41e320..7232b5964468 100644--- a/frontend/src/scenes/web-analytics/webTileHeaderHooks.tsx+++ b/frontend/src/scenes/web-analytics/webTileHeaderHooks.tsx@@ -1,4 +1,4 @@-import { useActions, useValues } from 'kea'+import { useActions, useMountedLogic, useValues } from 'kea'import { useMemo } from 'react'import { IconExpand45 } from '@posthog/icons'@@ -8,6 +8,8 @@ import { copyToClipboard } from 'lib/utils/copyToClipboard'import { addProductIntentForCrossSell } from 'lib/utils/product-intents'import { insightDataLogic } from 'scenes/insights/insightDataLogic'+import { DataNodeLogicProps, dataNodeLogic } from '~/queries/nodes/DataNode/dataNodeLogic'+import { insightVizDataCollectionId, insightVizDataNodeKey } from '~/queries/nodes/InsightViz/InsightViz'import {ProductIntentContext,ProductKey,@@ -37,6 +39,27 @@ export function useWebTileExportAdapter(query: QuerySchema | undefined,insightProps: InsightLogicProps): ExportAdapter | null {+ // This header hook renders before the tile's chart. insightDataLogic (mounted below) connects to+ // the shared, key-only dataNodeLogic without forwarding dataNodeCollectionId, so it would build+ // that logic first and bind it to a fallback collection — dropping the tile from the dashboard's+ // "reload all" (only the overview, which isn't an insight viz, kept reloading). Bind the node to+ // the web analytics collection up front, keyed by the node key so it tracks tab switches, so the+ // chart reuses the same correctly-bound instance and reload reaches every tile.+ const dataNodeKey = insightVizDataNodeKey(insightProps)+ const collectionBoundDataNodeLogic = useMemo(+ () =>+ dataNodeLogic({+ key: dataNodeKey,+ dataNodeCollectionId: insightVizDataCollectionId(insightProps, dataNodeKey),+ loadPriority: insightProps.loadPriority,+ } as DataNodeLogicProps),+ // Rebind only when the node key changes (tile/tab switch); avoid re-running on every render so+ // we never clobber the query the chart sets on the shared instance.+ // eslint-disable-next-line react-hooks/exhaustive-deps+ [dataNodeKey]+ )+ useMountedLogic(collectionBoundDataNodeLogic)+const builtInsightDataLogic = insightDataLogic(insightProps)const { insightDataRaw } = useValues(builtInsightDataLogic)