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(product-analytics): hold home queries until warehouse detection settles (#124195)

Georges-Antoine Assi14f7c9d189d7
diff --git a/frontend/src/scenes/insights/EmptyStates/sampleDataStateLogic.ts b/frontend/src/scenes/insights/EmptyStates/sampleDataStateLogic.ts
index 5f882dfc28db..3735df868c2e 100644
--- a/frontend/src/scenes/insights/EmptyStates/sampleDataStateLogic.ts
+++ b/frontend/src/scenes/insights/EmptyStates/sampleDataStateLogic.ts
@@ -16,6 +16,7 @@ export interface sampleDataStateLogicValues {
warehouseSetupStatus: ProductSetupStatus // productSetupStatusLogic
currentTeam: TeamPublicType | TeamType | null // teamLogic
needsWarehouseDetection: boolean
+ sampleDataPending: boolean
shouldShowSampleData: boolean
}
@@ -30,6 +31,7 @@ export interface sampleDataStateLogicActions {
export interface sampleDataStateLogicMeta {
__keaTypeGenInternalSelectorTypes: {
needsWarehouseDetection: (currentTeam: TeamPublicType | TeamType | null) => boolean
+ sampleDataPending: (needsWarehouseDetection: boolean, warehouseSetupStatus: ProductSetupStatus) => boolean
shouldShowSampleData: (needsWarehouseDetection: boolean, warehouseSetupStatus: ProductSetupStatus) => boolean
}
}
@@ -62,6 +64,11 @@ export const sampleDataStateLogic = kea<sampleDataStateLogicType>([
(currentTeam: TeamPublicType | TeamType | null): boolean =>
!isSharedView() && !!currentTeam && !currentTeam.ingested_event && !currentTeam.is_demo,
],
+ sampleDataPending: [
+ (s) => [s.needsWarehouseDetection, s.warehouseSetupStatus],
+ (needsWarehouseDetection: boolean, warehouseSetupStatus: ProductSetupStatus): boolean =>
+ needsWarehouseDetection && warehouseSetupStatus === 'loading',
+ ],
shouldShowSampleData: [
(s) => [s.needsWarehouseDetection, s.warehouseSetupStatus],
// Never show the placeholder in shared/embedded/exported views: `TeamPublicSerializer`
diff --git a/products/product_analytics/frontend/insights/home/HomeTabChartCard.tsx b/products/product_analytics/frontend/insights/home/HomeTabChartCard.tsx
index 98948199c627..abe9e9d0783f 100644
--- a/products/product_analytics/frontend/insights/home/HomeTabChartCard.tsx
+++ b/products/product_analytics/frontend/insights/home/HomeTabChartCard.tsx
@@ -4,7 +4,7 @@ import { useValues } from 'kea'
import { useMemo, type ReactNode } from 'react'
import { IconInfo } from '@posthog/icons'
-import { LemonButton, LemonCard } from '@posthog/lemon-ui'
+import { LemonButton, LemonCard, LemonSkeleton } from '@posthog/lemon-ui'
import { Tooltip } from 'lib/lemon-ui/Tooltip'
import { sampleDataStateLogic } from 'scenes/insights/EmptyStates/sampleDataStateLogic'
@@ -28,13 +28,15 @@ interface HomeTabChartCardProps {
export function HomeTabChartCard({ option, size, control, source, loadPriority }: HomeTabChartCardProps): JSX.Element {
const { currentTeamId } = useValues(teamLogic)
- const { shouldShowSampleData } = useValues(sampleDataStateLogic)
+ const { shouldShowSampleData, sampleDataPending } = useValues(sampleDataStateLogic)
const sampleData = useMemo(
() => (shouldShowSampleData ? getHomeTabSampleData(option) : undefined),
[shouldShowSampleData, option]
)
const chartKey = sampleData ? `${option.key}.sample` : option.key
- const chart = (
+ const chart = sampleDataPending ? (
+ <LemonSkeleton className="h-full w-full" />
+ ) : (
<Query
key={`${currentTeamId}.${chartKey}`}
query={option.query}
diff --git a/products/product_analytics/frontend/insights/home/HomeTabDefault.test.tsx b/products/product_analytics/frontend/insights/home/HomeTabDefault.test.tsx
index 7ee95a3efedd..3d19b306b7a1 100644
--- a/products/product_analytics/frontend/insights/home/HomeTabDefault.test.tsx
+++ b/products/product_analytics/frontend/insights/home/HomeTabDefault.test.tsx
@@ -15,6 +15,7 @@ import { savedInsightsLogic } from 'scenes/saved-insights/savedInsightsLogic'
import { teamLogic } from 'scenes/teamLogic'
import trendsNumber from '~/mocks/fixtures/api/projects/team_id/insights/trendsNumber.json'
+import { useMocks } from '~/mocks/jest'
import { dataNodeCollectionLogic } from '~/queries/nodes/DataNode/dataNodeCollectionLogic'
import { performQuery } from '~/queries/query'
import type { DataNode } from '~/queries/schema/schema-general'
@@ -236,4 +237,18 @@ describe('HomeTabDefault query reuse', () => {
).toBeInTheDocument()
)
})
+
+ it('runs live queries once warehouse detection finds data for a project without events', async () => {
+ useMocks({ get: { '/api/projects/:team_id/external_data_sources/exists/': { exists: true } } })
+ teamLogic.actions.loadCurrentTeamSuccess({ ...MOCK_DEFAULT_TEAM, ingested_event: false, is_demo: false })
+ const { container } = render(<HomeTabDefault />)
+
+ await waitFor(() => expect(mockedQuery).toHaveBeenCalledTimes(14))
+ await waitFor(() =>
+ expect(
+ within(screen.getByLabelText('Active users', { selector: 'button' })).getByText('10')
+ ).toBeInTheDocument()
+ )
+ expect(container.querySelector('[data-attr="insight-sample-data-tag"]')).toBeNull()
+ })
})
diff --git a/products/product_analytics/frontend/insights/home/HomeTabStatTile.tsx b/products/product_analytics/frontend/insights/home/HomeTabStatTile.tsx
index 27baf24fb780..7097570875e2 100644
--- a/products/product_analytics/frontend/insights/home/HomeTabStatTile.tsx
+++ b/products/product_analytics/frontend/insights/home/HomeTabStatTile.tsx
@@ -43,7 +43,7 @@ interface HomeTabStatTileProps {
export function HomeTabStatTile({ stat, compare, selected, onSelect }: HomeTabStatTileProps): JSX.Element {
const { currentTeamId, currentTeam } = useValues(teamLogic)
- const { shouldShowSampleData } = useValues(sampleDataStateLogic)
+ const { shouldShowSampleData, sampleDataPending } = useValues(sampleDataStateLogic)
const sampleData = useMemo(
() => (shouldShowSampleData ? getHomeTabSampleStatData(stat.key, stat.query) : undefined),
[shouldShowSampleData, stat.key, stat.query]
@@ -56,22 +56,23 @@ export function HomeTabStatTile({ stat, compare, selected, onSelect }: HomeTabSt
[shouldShowSampleData, stat.key, stat.trendKey, stat.trendQuery, stat.query]
)
const theme = useChartTheme()
+ const keySuffix = shouldShowSampleData ? '.sample' : sampleDataPending ? '.pending' : ''
const key = homeTabStatKey(currentTeamId, stat.key)
const logic = dataNodeLogic({
query: stat.query,
loadPriority: 0,
- key: shouldShowSampleData ? `${key}.sample` : key,
+ key: `${key}${keySuffix}`,
cachedResults: sampleData,
- doNotLoad: shouldShowSampleData,
+ doNotLoad: shouldShowSampleData || sampleDataPending,
dataNodeCollectionId: homeTabDataCollectionId(currentTeamId),
})
useAttachedLogic(logic, homeTabDefaultLogic)
const trendLogic = dataNodeLogic({
query: stat.trendQuery ?? stat.query,
loadPriority: stat.trendQuery && !stat.trendKey ? 1 : 0,
- key: `${homeTabStatTrendKey(currentTeamId, stat)}${shouldShowSampleData ? '.sample' : ''}`,
+ key: `${homeTabStatTrendKey(currentTeamId, stat)}${keySuffix}`,
cachedResults: sampleTrendData,
- doNotLoad: shouldShowSampleData,
+ doNotLoad: shouldShowSampleData || sampleDataPending,
dataNodeCollectionId: homeTabDataCollectionId(currentTeamId),
})
useAttachedLogic(trendLogic, homeTabDefaultLogic)