: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(dashboards): reflect experiment widget pick immediately (#66330)
Matt Puae956b842ee86
diff --git a/products/dashboards/frontend/widgets/experiments/ExperimentResultsWidget.tsx b/products/dashboards/frontend/widgets/experiments/ExperimentResultsWidget.tsxindex 430fc6d2c4c3..75e074e4926a 100644--- a/products/dashboards/frontend/widgets/experiments/ExperimentResultsWidget.tsx+++ b/products/dashboards/frontend/widgets/experiments/ExperimentResultsWidget.tsx@@ -1,4 +1,5 @@import posthog from 'posthog-js'+import { useState } from 'react'import { LemonDivider, LemonSkeleton } from '@posthog/lemon-ui'@@ -172,6 +173,9 @@ export function ExperimentResultsWidget({}: DashboardWidgetComponentProps): JSX.Element {const payload = result as ExperimentResultsWidgetResult | null | undefined+ // Reflect the empty-state pick immediately rather than waiting for the persist + refresh round-trip.+ const [optimisticExperimentId, setOptimisticExperimentId] = useState<number | null>(null)+if (loading) {return <ExperimentResultsLoadingSkeleton />}@@ -207,10 +211,16 @@ export function ExperimentResultsWidget({<div className="w-64 max-w-full"><ExperimentPickerSelectpickerKey={`results-tile-${tileId}`}- value={null}+ value={optimisticExperimentId}fullWidth- onChange={(value) => {- void onUpdateConfig(patchExperimentResultsWidgetConfig(config, value))+ onChange={async (value) => {+ setOptimisticExperimentId(value)+ try {+ await onUpdateConfig(patchExperimentResultsWidgetConfig(config, value))+ } catch {+ // Persist failed — drop the optimistic pick so we don't show a selection that wasn't saved.+ setOptimisticExperimentId((current) => (current === value ? null : current))+ }}}dataAttr="experiment-results-widget-empty-state-select"/>diff --git a/products/dashboards/frontend/widgets/experiments/ExperimentResultsWidgetTileFilters.tsx b/products/dashboards/frontend/widgets/experiments/ExperimentResultsWidgetTileFilters.tsxindex 0b302ea04fcd..aef7b7013dc7 100644--- a/products/dashboards/frontend/widgets/experiments/ExperimentResultsWidgetTileFilters.tsx+++ b/products/dashboards/frontend/widgets/experiments/ExperimentResultsWidgetTileFilters.tsx@@ -1,5 +1,5 @@import { useActions, useValues } from 'kea'-import { useEffect, useRef } from 'react'+import { useEffect, useRef, useState } from 'react'import type { DashboardWidgetTileFiltersProps } from '../registry'import { useWidgetTileConfigPersist } from '../widgetTileFiltersHooks'@@ -45,10 +45,21 @@ export function ExperimentResultsWidgetTileFilters({configRef.current = configconst { persistConfigNow } = useWidgetTileConfigPersist(onUpdateConfig)+ // Reflect the pick immediately rather than waiting for the persist round-trip to update `config`.+ const [optimisticExperimentId, setOptimisticExperimentId] = useState<number | null | undefined>(undefined)+ const selectedExperimentId = optimisticExperimentId !== undefined ? optimisticExperimentId : experimentId+const applyExperimentId = async (value: number | null): Promise<void> => {+ setOptimisticExperimentId(value)const nextConfig = patchExperimentResultsWidgetConfig(configRef.current, value)configRef.current = nextConfig- await persistConfigNow(nextConfig)+ try {+ // persist resolves only after `config` reflects the pick, so clearing here never flickers.+ await persistConfigNow(nextConfig)+ } finally {+ // Only clear if a newer pick hasn't superseded this one.+ setOptimisticExperimentId((current) => (current === value ? undefined : current))+ }}if (!onUpdateConfig) {@@ -70,7 +81,7 @@ export function ExperimentResultsWidgetTileFilters({<div className="w-64 max-w-full"><ExperimentPickerSelectpickerKey={`results-tile-${tileId}`}- value={experimentId}+ value={selectedExperimentId}disabled={!!disabledReason}fullWidthonChange={(value) => {