: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
feat(insights): show stale results while an insight refreshes (#81826)
Andy Zhao69d01a543770
diff --git a/frontend/src/queries/nodes/InsightViz/ComputationTimeWithRefresh.tsx b/frontend/src/queries/nodes/InsightViz/ComputationTimeWithRefresh.tsxindex 7ce3d6cc644a..72a98748ead9 100644--- a/frontend/src/queries/nodes/InsightViz/ComputationTimeWithRefresh.tsx+++ b/frontend/src/queries/nodes/InsightViz/ComputationTimeWithRefresh.tsx@@ -4,6 +4,7 @@ import { Link, Tooltip } from '@posthog/lemon-ui'import { dayjs } from 'lib/dayjs'import { usePeriodicRerender } from 'lib/hooks/usePeriodicRerender'+import { Spinner } from 'lib/lemon-ui/Spinner'import { insightDataLogic } from 'scenes/insights/insightDataLogic'import { insightLogic } from 'scenes/insights/insightLogic'import { preflightLogic } from 'scenes/PreflightCheck/preflightLogic'@@ -17,7 +18,7 @@ export function ComputationTimeWithRefresh({ disableRefresh }: { disableRefresh?const { lastRefresh, response, query } = useValues(dataNodeLogic)const { insightProps } = useValues(insightLogic)- const { getInsightRefreshButtonDisabledReason } = useValues(insightDataLogic(insightProps))+ const { getInsightRefreshButtonDisabledReason, insightDataLoading } = useValues(insightDataLogic(insightProps))const { loadData } = useActions(insightDataLogic(insightProps))const disabledReason = getInsightRefreshButtonDisabledReason()@@ -37,21 +38,28 @@ export function ComputationTimeWithRefresh({ disableRefresh }: { disableRefresh?{!disableRefresh && (<><span className="px-1">•</span>- <Tooltip- title={- canBypassRefreshDisabled && disabledReason- ? `${disabledReason} (you can bypass this due to dev env / staff permissions)`- : undefined- }- >- <Link- onClick={() => loadData(shouldQueryBeAsync(query) ? 'force_async' : 'force_blocking')}- className={disabledReason ? 'opacity-50' : ''}- disabledReason={canBypassRefreshDisabled ? '' : disabledReason}+ {insightDataLoading ? (+ <span className="flex items-center gap-1.5">+ <Spinner textColored />+ Refreshing+ </span>+ ) : (+ <Tooltip+ title={+ canBypassRefreshDisabled && disabledReason+ ? `${disabledReason} (you can bypass this due to dev env / staff permissions)`+ : undefined+ }>- Refresh- </Link>- </Tooltip>+ <Link+ onClick={() => loadData(shouldQueryBeAsync(query) ? 'force_async' : 'force_blocking')}+ className={disabledReason ? 'opacity-50' : ''}+ disabledReason={canBypassRefreshDisabled ? '' : disabledReason}+ >+ Refresh+ </Link>+ </Tooltip>+ )}</>)}</div>diff --git a/frontend/src/queries/nodes/InsightViz/InsightVizDisplay.tsx b/frontend/src/queries/nodes/InsightViz/InsightVizDisplay.tsxindex cab2e2c3f577..5813827670c7 100644--- a/frontend/src/queries/nodes/InsightViz/InsightVizDisplay.tsx+++ b/frontend/src/queries/nodes/InsightViz/InsightVizDisplay.tsx@@ -157,6 +157,7 @@ export function InsightVizDisplay({supportsDisplay,samplingFactor,insightDataLoading,+ hasRenderableResults,erroredQueryId,timedOutQueryId,vizSpecificOptions,@@ -180,6 +181,9 @@ export function InsightVizDisplay({// Empty states that completely replace the graphconst BlockingEmptyState = (() => {if (insightDataLoading) {+ if (hasRenderableResults) {+ return null+ }return (<InsightLoadingStatequeryId={queryId}diff --git a/frontend/src/scenes/insights/insightVizDataLogic.test.ts b/frontend/src/scenes/insights/insightVizDataLogic.test.tsindex 150f20acca5e..2c8929e09684 100644--- a/frontend/src/scenes/insights/insightVizDataLogic.test.ts+++ b/frontend/src/scenes/insights/insightVizDataLogic.test.ts@@ -884,6 +884,23 @@ describe('insightVizDataLogic', () => {})})+ describe('hasRenderableResults', () => {+ it('tracks whether the loaded response contains results', async () => {+ await expectLogic(builtInsightVizDataLogic).toMatchValues({ hasRenderableResults: false })++ await expectLogic(builtInsightVizDataLogic, () => {+ builtInsightDataLogic.actions.loadDataSuccess({ result: funnelResult.result })+ }).toMatchValues({ hasRenderableResults: true })++ await expectLogic(builtInsightVizDataLogic, () => {+ builtInsightDataLogic.actions.loadDataSuccess({+ cache_key: 'cache_1_abc',+ query_status: { id: 'cache_1_abc', complete: false },+ } as Record<string, any>)+ }).toMatchValues({ hasRenderableResults: false })+ })+ })+describe('isSingleSeriesOutput', () => {it('returns true for single series without breakdown', () => {expectLogic(builtInsightVizDataLogic, () => {diff --git a/frontend/src/scenes/insights/insightVizDataLogic.ts b/frontend/src/scenes/insights/insightVizDataLogic.tsindex 7ba065c05f86..8924394d4072 100644--- a/frontend/src/scenes/insights/insightVizDataLogic.ts+++ b/frontend/src/scenes/insights/insightVizDataLogic.ts@@ -202,6 +202,7 @@ export interface insightVizDataLogicValues {hasFormula: booleanhasLegend: booleanhasOnlyDataWarehouseSeries: boolean+ hasRenderableResults: booleaninsightFilter: InsightFilter | null | undefinedinterval: IntervalType | null | undefinedisAllEventsQuery: boolean@@ -1197,6 +1198,7 @@ export interface insightVizDataLogicMeta {validationError: (insightDataError: Record<string, any> | null) => string | nullvalidationErrorCode: (insightDataError: Record<string, any> | null) => string | nulltimezone: (insightData: Record<string, any>) => any+ hasRenderableResults: (insightData: Record<string, any>) => booleanallEventNames: (querySource:| FunnelsQuery@@ -2433,6 +2435,11 @@ export const insightVizDataLogic = kea<insightVizDataLogicType>([timezone: [(s) => [s.insightData], (insightData: Record<string, any>) => insightData?.timezone || 'UTC'],+ hasRenderableResults: [+ (s) => [s.insightData],+ (insightData: Record<string, any>): boolean => insightData?.result != null || insightData?.results != null,+ ],+// all events used in the insight (useful for fetching only relevant property definitions)allEventNames: [(s) => [s.querySource, actionsModel.selectors.actions],