: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): show skeletons after metric changes (#82044)
Fernando Gomes954903d93341
diff --git a/frontend/src/scenes/experiments/experimentLogic.test.ts b/frontend/src/scenes/experiments/experimentLogic.test.tsindex ceaafc03e215..102c791c5f21 100644--- a/frontend/src/scenes/experiments/experimentLogic.test.ts+++ b/frontend/src/scenes/experiments/experimentLogic.test.ts@@ -279,6 +279,25 @@ describe('experimentLogic', () => {})})+ describe('updateExperimentMetrics', () => {+ it('keeps existing results when saving the metric definitions fails', async () => {+ const existingResult = experimentMetricResultsSuccessJson.query_status+ .results as unknown as CachedNewExperimentQueryResponse++ logic.actions.setExperiment(experiment)+ logic.actions.setPrimaryMetricsResults([existingResult])+ logic.actions.setPrimaryMetricsResultsErrors([null])+ jest.spyOn(api, 'update').mockRejectedValueOnce(new Error('network down'))++ await expectLogic(logic, () => logic.actions.updateExperimentMetrics())+ .toDispatchActions(['updateExperimentFailure'])+ .toFinishAllListeners()++ expect(logic.values.primaryMetricsResults).toEqual([existingResult])+ expect(logic.values.primaryMetricsResultsErrors).toEqual([null])+ })+ })+describe('currentRefresh tracking', () => {it('marks the refresh as in_progress while running and completed when it succeeds', async () => {logic.actions.setExperiment(experiment)diff --git a/frontend/src/scenes/experiments/experimentLogic.tsx b/frontend/src/scenes/experiments/experimentLogic.tsxindex 5f1a639946e7..ca824b3c4601 100644--- a/frontend/src/scenes/experiments/experimentLogic.tsx+++ b/frontend/src/scenes/experiments/experimentLogic.tsx@@ -2720,11 +2720,37 @@ export const experimentLogic = kea<experimentLogicType>([}},updateExperimentMetrics: async () => {- await asyncActions.updateExperiment({+ actions.updateExperiment({metrics: values.experiment.metrics,metrics_secondary: values.experiment.metrics_secondary,update_feature_flag_params: false,})++ // kea-loaders turns a rejected loader into a failure action, so awaiting its async action does+ // not throw. Await the underlying queued request instead to keep the existing result caches when+ // the save fails. The loader still owns error reporting and optimistic-concurrency recovery.+ const updatePromise = cache.inflightUpdate?.promise+ if (!updatePromise) {+ return+ }+ try {+ await updatePromise+ } catch {+ return+ }++ // Metric results are positional. Once the metric list has saved, keeping the previous arrays+ // around can briefly pair a result with the wrong metric (and gives no feedback while the+ // updated results are computed). Clear both result stores so every metric in the updated list+ // renders its existing per-variant loading skeleton. Do this only after a successful save: if+ // the update fails, the previous experiment and its results remain valid and visible.+ actions.clearMetricsResults()+ const metricsLogic = experimentMetricsLogic({ experiment: values.experiment })+ metricsLogic.actions.setPrimaryMetricsResults([])+ metricsLogic.actions.setPrimaryMetricsResultsErrors([])+ metricsLogic.actions.setSecondaryMetricsResults([])+ metricsLogic.actions.setSecondaryMetricsResultsErrors([])+// Reload results for added/edited metricsactions.refreshExperimentResults(true, 'config_change')},