: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(experiments): disable reload and retry buttons while recalculating (#66155)
Rodrigo Iloroc27c739d4f52
diff --git a/frontend/src/scenes/experiments/ExperimentView/ExperimentReloadAction.tsx b/frontend/src/scenes/experiments/ExperimentView/ExperimentReloadAction.tsxindex 1da6820f61d7..6ac1de26f211 100644--- a/frontend/src/scenes/experiments/ExperimentView/ExperimentReloadAction.tsx+++ b/frontend/src/scenes/experiments/ExperimentView/ExperimentReloadAction.tsx@@ -134,7 +134,7 @@ export const ExperimentReloadAction = ({}))const loadingText =- progress && progress.total > 0 ? `Loading ${progress.completed} of ${progress.total}` : 'Loading…'+ progress && progress.total > 0 ? `Loaded ${progress.completed} of ${progress.total} metrics` : 'Loading…'return (<div className="flex flex-col">diff --git a/frontend/src/scenes/experiments/MetricsView/new/MetricErrorState.tsx b/frontend/src/scenes/experiments/MetricsView/new/MetricErrorState.tsxindex 11868287737a..6dbf9ead2e7c 100644--- a/frontend/src/scenes/experiments/MetricsView/new/MetricErrorState.tsx+++ b/frontend/src/scenes/experiments/MetricsView/new/MetricErrorState.tsx@@ -19,10 +19,18 @@ type MetricErrorStateProps = {metric: ExperimentMetricquery?: Record<string, any>onRetry?: () => void+ /** Disables the "Try again" button (with a tooltip) while a recalculation is already in flight. */+ retryDisabledReason?: stringheight?: number}-export const MetricErrorState = ({ error, query, onRetry, height = 200 }: MetricErrorStateProps): JSX.Element => {+export const MetricErrorState = ({+ error,+ query,+ onRetry,+ retryDisabledReason,+ height = 200,+}: MetricErrorStateProps): JSX.Element => {const { openSupportForm } = useActions(supportLogic)const errorMessage = parseErrorMessage(error.detail)@@ -51,6 +59,7 @@ export const MetricErrorState = ({ error, query, onRetry, height = 200 }: Metrictype="primary"size="xsmall"onClick={onRetry}+ disabledReason={retryDisabledReason}sideAction={query? {diff --git a/frontend/src/scenes/experiments/MetricsView/new/MetricRowGroup.tsx b/frontend/src/scenes/experiments/MetricsView/new/MetricRowGroup.tsxindex 94b007133ab1..3845cf16eb22 100644--- a/frontend/src/scenes/experiments/MetricsView/new/MetricRowGroup.tsx+++ b/frontend/src/scenes/experiments/MetricsView/new/MetricRowGroup.tsx@@ -246,6 +246,11 @@ function CollapsibleBreakdownSection({metric={metric}query={query}onRetry={onRetry}+ retryDisabledReason={+ isRecalculating+ ? 'Recalculation in progress'+ : undefined+ }/>)}</td>@@ -835,6 +840,7 @@ export function MetricRowGroup({error={error}query={debugQuery}onRetry={handleRetry}+ retryDisabledReason={isRecalculating ? 'Recalculation in progress' : undefined}/></td></tr>diff --git a/frontend/src/scenes/experiments/MetricsView/shared/ChartEmptyState.tsx b/frontend/src/scenes/experiments/MetricsView/shared/ChartEmptyState.tsxindex 263c42252bb0..3837a8d301c5 100644--- a/frontend/src/scenes/experiments/MetricsView/shared/ChartEmptyState.tsx+++ b/frontend/src/scenes/experiments/MetricsView/shared/ChartEmptyState.tsx@@ -15,6 +15,8 @@ interface ChartEmptyStateProps {error?: anyquery?: Record<string, any>onRetry?: () => void+ /** Disables the "Try again" button (with a tooltip) while a recalculation is already in flight. */+ retryDisabledReason?: string}export function ChartEmptyState({@@ -24,6 +26,7 @@ export function ChartEmptyState({metric,query,onRetry,+ retryDisabledReason,}: ChartEmptyStateProps): JSX.Element | null {/*** early return if experiment has not started@@ -69,7 +72,14 @@ export function ChartEmptyState({<ErrorChecklist error={error} metric={metric} />) : (// Use rich error state for all other errors- <MetricErrorState error={error} metric={metric} query={query} onRetry={onRetry} height={height} />+ <MetricErrorState+ error={error}+ metric={metric}+ query={query}+ onRetry={onRetry}+ retryDisabledReason={retryDisabledReason}+ height={height}+ />)}</div>)diff --git a/frontend/src/scenes/experiments/experimentMetricsLogic.ts b/frontend/src/scenes/experiments/experimentMetricsLogic.tsindex 9b387442e83a..7fc659e829df 100644--- a/frontend/src/scenes/experiments/experimentMetricsLogic.ts+++ b/frontend/src/scenes/experiments/experimentMetricsLogic.ts@@ -483,10 +483,20 @@ export const experimentMetricsLogic = kea<experimentMetricsLogicType>([if (!resolvedIds) {return}++ /**+ * Mark loading up front so the reload button disables on click, not only once the create POST+ * returns. Without this there's a window (the POST round-trip) where the button stays clickable.+ * Cleared by setCurrentRecalculation on success, or in the catch below on failure.+ */+ actions.setRecalculationLoading(true)try {const { projectId, experimentId } = resolvedIds- // 201 with a new pending run, or 200 with the already-active one. No results yet.- // Create a recalculation workflow. 201: a new run. 200: one is already running, poll it.++ /**+ * 201 with a new pending run, or 200 with the already-active one. No results yet.+ * Create a recalculation workflow. 201: a new run. 200: one is already running, poll it.+ */const recalculation = await experimentsMetricsRecalculationCreate(String(projectId), experimentId, {trigger,})@@ -526,6 +536,10 @@ export const experimentMetricsLogic = kea<experimentMetricsLogicType>([actions.pollRecalculation(recalculation.id)}} catch (error: any) {+ /**+ * Re-enable the reload button: the run never started, so nothing else will clear loading.+ */+ actions.setRecalculationLoading(false)lemonToast.error(error?.detail || 'Failed to trigger metrics recalculation')}},