Skip to content

: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.

fix(web-analytics): thread uniqueKey through all dashboard tile renderers (#59973)

Lucas Ricoy1246fd97b090
diff --git a/frontend/src/queries/nodes/DataNode/dataNodeCollectionLogic.test.ts b/frontend/src/queries/nodes/DataNode/dataNodeCollectionLogic.test.ts
new file mode 100644
index 000000000000..e9af9bb964f3
--- /dev/null
+++ b/frontend/src/queries/nodes/DataNode/dataNodeCollectionLogic.test.ts
@@ -0,0 +1,95 @@
+import { expectLogic } from 'kea-test-utils'
+
+import { dataNodeCollectionLogic } from '~/queries/nodes/DataNode/dataNodeCollectionLogic'
+import { initKeaTests } from '~/test/init'
+
+describe('dataNodeCollectionLogic', () => {
+ let logic: ReturnType<typeof dataNodeCollectionLogic.build>
+
+ beforeEach(() => {
+ initKeaTests()
+ logic = dataNodeCollectionLogic({ key: 'test-collection' })
+ logic.mount()
+ })
+
+ afterEach(() => {
+ logic?.unmount()
+ })
+
+ it('reloadAll fires loadData on every mounted data node with force_async', () => {
+ const loadDataA = jest.fn()
+ const loadDataB = jest.fn()
+ const loadDataC = jest.fn()
+ const cancelQuery = jest.fn()
+
+ logic.actions.mountDataNode('tile-a', { id: 'tile-a', loadData: loadDataA, cancelQuery })
+ logic.actions.mountDataNode('tile-b', { id: 'tile-b', loadData: loadDataB, cancelQuery })
+ logic.actions.mountDataNode('tile-c', { id: 'tile-c', loadData: loadDataC, cancelQuery })
+
+ logic.actions.reloadAll()
+
+ expect(loadDataA).toHaveBeenCalledTimes(1)
+ expect(loadDataA).toHaveBeenCalledWith('force_async')
+ expect(loadDataB).toHaveBeenCalledTimes(1)
+ expect(loadDataB).toHaveBeenCalledWith('force_async')
+ expect(loadDataC).toHaveBeenCalledTimes(1)
+ expect(loadDataC).toHaveBeenCalledWith('force_async')
+ })
+
+ it('mountDataNode dedupes by id, replacing the prior loadData reference', () => {
+ const stale = jest.fn()
+ const fresh = jest.fn()
+ const cancelQuery = jest.fn()
+
+ logic.actions.mountDataNode('tile-a', { id: 'tile-a', loadData: stale, cancelQuery })
+ logic.actions.mountDataNode('tile-a', { id: 'tile-a', loadData: fresh, cancelQuery })
+
+ logic.actions.reloadAll()
+
+ expect(stale).not.toHaveBeenCalled()
+ expect(fresh).toHaveBeenCalledWith('force_async')
+ })
+
+ it('unmountDataNode removes the node so reloadAll skips it', () => {
+ const loadDataA = jest.fn()
+ const loadDataB = jest.fn()
+ const cancelQuery = jest.fn()
+
+ logic.actions.mountDataNode('tile-a', { id: 'tile-a', loadData: loadDataA, cancelQuery })
+ logic.actions.mountDataNode('tile-b', { id: 'tile-b', loadData: loadDataB, cancelQuery })
+ logic.actions.unmountDataNode('tile-a')
+
+ logic.actions.reloadAll()
+
+ expect(loadDataA).not.toHaveBeenCalled()
+ expect(loadDataB).toHaveBeenCalledWith('force_async')
+ })
+
+ it('areAnyLoading reflects per-node load state', async () => {
+ const cancelQuery = jest.fn()
+ logic.actions.mountDataNode('tile-a', { id: 'tile-a', loadData: jest.fn(), cancelQuery })
+ logic.actions.mountDataNode('tile-b', { id: 'tile-b', loadData: jest.fn(), cancelQuery })
+
+ await expectLogic(logic).toMatchValues({ areAnyLoading: false })
+
+ logic.actions.collectionNodeLoadData('tile-a')
+ await expectLogic(logic).toMatchValues({ areAnyLoading: true })
+
+ logic.actions.collectionNodeLoadDataSuccess('tile-a')
+ await expectLogic(logic).toMatchValues({ areAnyLoading: false })
+ })
+
+ it('cancelAllLoading only cancels nodes whose status is loading', () => {
+ const cancelA = jest.fn()
+ const cancelB = jest.fn()
+ logic.actions.mountDataNode('tile-a', { id: 'tile-a', loadData: jest.fn(), cancelQuery: cancelA })
+ logic.actions.mountDataNode('tile-b', { id: 'tile-b', loadData: jest.fn(), cancelQuery: cancelB })
+
+ logic.actions.collectionNodeLoadData('tile-a')
+ // tile-b never started loading
+ logic.actions.cancelAllLoading()
+
+ expect(cancelA).toHaveBeenCalledTimes(1)
+ expect(cancelB).not.toHaveBeenCalled()
+ })
+})
diff --git a/frontend/src/scenes/web-analytics/tiles/WebAnalyticsTile.tsx b/frontend/src/scenes/web-analytics/tiles/WebAnalyticsTile.tsx
index a8241545f5a6..8bb6cd755e47 100644
--- a/frontend/src/scenes/web-analytics/tiles/WebAnalyticsTile.tsx
+++ b/frontend/src/scenes/web-analytics/tiles/WebAnalyticsTile.tsx
@@ -650,9 +650,11 @@ export const WebStatsTrendTile = ({
insightProps,
attachTo,
headerSlot,
+ uniqueKey,
}: QueryWithInsightProps<InsightVizNode> & {
showIntervalTile?: boolean
headerSlot?: React.ReactNode
+ uniqueKey: string
}): JSX.Element => {
const { togglePropertyFilter, setDateInterval, zoomIntoPeriod, resetZoom } = useActions(webAnalyticsLogic)
const {
@@ -808,7 +810,7 @@ export const WebStatsTrendTile = ({
)
}
>
- <Query attachTo={attachTo} query={query} readOnly={true} context={context} />
+ <Query uniqueKey={uniqueKey} attachTo={attachTo} query={query} readOnly={true} context={context} />
</WebAnalyticsTileSkeletonGate>
</div>
)
@@ -818,7 +820,8 @@ export const AveragePageViewVisualizationTile = ({
query,
insightProps,
attachTo,
-}: QueryWithInsightProps<DataVisualizationNode>): JSX.Element => {
+ uniqueKey,
+}: QueryWithInsightProps<DataVisualizationNode> & { uniqueKey: string }): JSX.Element => {
const { setDateInterval } = useActions(webAnalyticsLogic)
const {
dateFilter: { interval },
@@ -833,6 +836,7 @@ export const AveragePageViewVisualizationTile = ({
</div>
</div>
<Query
+ uniqueKey={uniqueKey}
attachTo={attachTo}
query={query}
readOnly={true}
@@ -847,7 +851,8 @@ export const MarketingAnalyticsTrendTile = ({
showIntervalTile,
insightProps,
attachTo,
-}: QueryWithInsightProps<InsightVizNode> & { showIntervalTile?: boolean }): JSX.Element => {
+ uniqueKey,
+}: QueryWithInsightProps<InsightVizNode> & { showIntervalTile?: boolean; uniqueKey: string }): JSX.Element => {
const { setDateInterval, setChartDisplayType, setTileColumnSelection } = useActions(marketingAnalyticsLogic)
const { dateFilter, chartDisplayType, tileColumnSelection } = useValues(marketingAnalyticsLogic)
@@ -891,6 +896,7 @@ export const MarketingAnalyticsTrendTile = ({
</div>
)}
<Query
+ uniqueKey={uniqueKey}
attachTo={attachTo}
query={query}
readOnly={true}
@@ -1152,7 +1158,11 @@ export const WebGoalsTile = ({
insightProps,
attachTo,
headerSlot,
-}: QueryWithInsightProps<DataTableNode> & { headerSlot?: React.ReactNode }): JSX.Element | null => {
+ uniqueKey,
+}: QueryWithInsightProps<DataTableNode> & {
+ headerSlot?: React.ReactNode
+ uniqueKey: string
+}): JSX.Element | null => {
const { actions, actionsLoading } = useValues(actionsModel)
const { updateHasSeenProductIntroFor } = useActions(userLogic)
@@ -1176,7 +1186,15 @@ export const WebGoalsTile = ({
)
}
- return <WebGoalsTileContent query={query} insightProps={insightProps} attachTo={attachTo} headerSlot={headerSlot} />
+ return (
+ <WebGoalsTileContent
+ query={query}
+ insightProps={insightProps}
+ attachTo={attachTo}
+ headerSlot={headerSlot}
+ uniqueKey={uniqueKey}
+ />
+ )
}
const WebGoalsTileContent = ({
@@ -1184,13 +1202,17 @@ const WebGoalsTileContent = ({
insightProps,
attachTo,
headerSlot,
-}: QueryWithInsightProps<DataTableNode> & { headerSlot?: React.ReactNode }): JSX.Element => {
+ uniqueKey,
+}: QueryWithInsightProps<DataTableNode> & {
+ headerSlot?: React.ReactNode
+ uniqueKey: string
+}): JSX.Element => {
const { addProductIntentForCrossSell } = useActions(teamLogic)
const context = useMemo((): QueryContext => {
return { ...webAnalyticsDataTableQueryContext, insightProps }
}, [insightProps])
- const dataNodeLogicProps = buildDataTableTileDataNodeLogicProps({ query, insightProps, context })
+ const dataNodeLogicProps = buildDataTableTileDataNodeLogicProps({ query, insightProps, context, uniqueKey })
return (
<div className="border rounded bg-surface-primary flex-1">
@@ -1217,7 +1239,7 @@ const WebGoalsTileContent = ({
dataNodeLogicProps={dataNodeLogicProps}
skeleton={<TableTileSkeleton numericColumns={4} />}
>
- <Query attachTo={attachTo} query={query} readOnly={true} context={context} />
+ <Query uniqueKey={uniqueKey} attachTo={attachTo} query={query} readOnly={true} context={context} />
</WebAnalyticsTileSkeletonGate>
</div>
)
@@ -1228,7 +1250,11 @@ export const WebExternalClicksTile = ({
insightProps,
attachTo,
headerSlot,
-}: QueryWithInsightProps<DataTableNode> & { headerSlot?: React.ReactNode }): JSX.Element | null => {
+ uniqueKey,
+}: QueryWithInsightProps<DataTableNode> & {
+ headerSlot?: React.ReactNode
+ uniqueKey: string
+}): JSX.Element | null => {
const { productTab, shouldStripQueryParams } = useValues(webAnalyticsLogic)
const { setShouldStripQueryParams } = useActions(webAnalyticsLogic)
@@ -1237,7 +1263,7 @@ export const WebExternalClicksTile = ({
const context = useMemo((): QueryContext => {
return { ...webAnalyticsDataTableQueryContext, insightProps }
}, [insightProps])
- const dataNodeLogicProps = buildDataTableTileDataNodeLogicProps({ query, insightProps, context })
+ const dataNodeLogicProps = buildDataTableTileDataNodeLogicProps({ query, insightProps, context, uniqueKey })
return (
<div className="border rounded bg-surface-primary flex-1 flex flex-col">
@@ -1258,7 +1284,7 @@ export const WebExternalClicksTile = ({
dataNodeLogicProps={dataNodeLogicProps}
skeleton={<TableTileSkeleton numericColumns={2} />}
>
- <Query attachTo={attachTo} query={query} readOnly={true} context={context} />
+ <Query uniqueKey={uniqueKey} attachTo={attachTo} query={query} readOnly={true} context={context} />
</WebAnalyticsTileSkeletonGate>
</div>
)
@@ -1268,7 +1294,8 @@ export const WebVitalsPathBreakdownTile = ({
query,
insightProps,
attachTo,
-}: QueryWithInsightProps<WebVitalsPathBreakdownQuery>): JSX.Element => {
+ uniqueKey,
+}: QueryWithInsightProps<WebVitalsPathBreakdownQuery> & { uniqueKey: string }): JSX.Element => {
const { isPathCleaningEnabled } = useValues(webAnalyticsLogic)
const { setIsPathCleaningEnabled } = useActions(webAnalyticsLogic)
@@ -1291,6 +1318,7 @@ export const WebVitalsPathBreakdownTile = ({
)}
</div>
<Query
+ uniqueKey={uniqueKey}
attachTo={attachTo}
query={query}
readOnly
@@ -1456,6 +1484,7 @@ export const WebQuery = ({
query={adjustedQuery}
insightProps={insightProps}
headerSlot={headerSlot}
+ uniqueKey={uniqueKey}
/>
)
}
@@ -1467,6 +1496,7 @@ export const WebQuery = ({
query={query}
showIntervalTile={showIntervalSelect}
insightProps={insightProps}
+ uniqueKey={uniqueKey}
/>
)
} else if (query.kind === NodeKind.InsightVizNode) {
@@ -1477,12 +1507,21 @@ export const WebQuery = ({
showIntervalTile={showIntervalSelect}
insightProps={insightProps}
headerSlot={headerSlot}
+ uniqueKey={uniqueKey}
/>
)
}
if (query.kind === NodeKind.DataTableNode && query.source.kind === NodeKind.WebGoalsQuery) {
- return <WebGoalsTile attachTo={attachTo} query={query} insightProps={insightProps} headerSlot={headerSlot} />
+ return (
+ <WebGoalsTile
+ attachTo={attachTo}
+ query={query}
+ insightProps={insightProps}
+ headerSlot={headerSlot}
+ uniqueKey={uniqueKey}
+ />
+ )
}
if (query.kind === NodeKind.DataTableNode && query.source.kind === NodeKind.MarketingAnalyticsTableQuery) {
@@ -1502,11 +1541,25 @@ export const WebQuery = ({
}
if (query.kind === NodeKind.WebVitalsPathBreakdownQuery) {
- return <WebVitalsPathBreakdownTile attachTo={attachTo} query={query} insightProps={insightProps} />
+ return (
+ <WebVitalsPathBreakdownTile
+ attachTo={attachTo}
+ query={query}
+ insightProps={insightProps}
+ uniqueKey={uniqueKey}
+ />
+ )
}
if (query.kind === NodeKind.DataVisualizationNode) {
- return <AveragePageViewVisualizationTile attachTo={attachTo} query={query} insightProps={insightProps} />
+ return (
+ <AveragePageViewVisualizationTile
+ attachTo={attachTo}
+ query={query}
+ insightProps={insightProps}
+ uniqueKey={uniqueKey}
+ />
+ )
}
if (query.kind === NodeKind.DataTableNode && query.source.kind === NodeKind.HogQLQuery) {