: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): Guard settings tab controls while a save is in flight (#93587)
Juraj Majerikc1f98d6e1c90
diff --git a/frontend/src/scenes/experiments/ExperimentView/SettingsTab.tsx b/frontend/src/scenes/experiments/ExperimentView/SettingsTab.tsxindex 9dff912654ce..1c86f4949f77 100644--- a/frontend/src/scenes/experiments/ExperimentView/SettingsTab.tsx+++ b/frontend/src/scenes/experiments/ExperimentView/SettingsTab.tsx@@ -20,7 +20,7 @@ import { getCupedSelection, resolveCupedEnabled, resolveCupedLookbackDays } fromimport { resolveSequentialEnabled } from './sequential'export function SettingsTab(): JSX.Element {- const { experiment, statsMethod, variants } = useValues(experimentLogic)+ const { experiment, statsMethod, variants, experimentUpdateLoading } = useValues(experimentLogic)const { updateExperimentSettings } = useActions(experimentLogic)const { openStatsEngineModal, openCupedModal } = useActions(modalsLogic)const { experimentsConfig } = useValues(experimentsConfigLogic)@@ -107,6 +107,7 @@ export function SettingsTab(): JSX.Element {<h2 className="font-semibold text-lg">Baseline variant</h2><LemonSelectvalue={getBaselineVariantKey(experiment)}+ loading={experimentUpdateLoading}options={variants.map((v) => ({value: v.key,label: v.key,@@ -125,6 +126,7 @@ export function SettingsTab(): JSX.Element {<LemonCheckboxlabel="Require completed conversion or retention window"checked={experiment.only_count_matured_users ?? false}+ disabled={experimentUpdateLoading}onChange={(checked) => {updateExperimentSettings({ only_count_matured_users: checked })}}diff --git a/frontend/src/scenes/experiments/experimentLogic.tsx b/frontend/src/scenes/experiments/experimentLogic.tsxindex 2d196e0a820a..9d365de7ab20 100644--- a/frontend/src/scenes/experiments/experimentLogic.tsx+++ b/frontend/src/scenes/experiments/experimentLogic.tsx@@ -2973,6 +2973,10 @@ export const experimentLogic = kea<experimentLogicType>([// Settings like stats config, CUPED, and conversion-window handling change// how metrics and exposures are computed, so persist then re-query.await asyncActions.updateExperiment({ ...update, update_feature_flag_params: false })+ // Unlaunched experiments have no results to recalculate, so don't promise a recalculation.+ lemonToast.success(+ values.isExperimentLaunched ? 'Settings saved. Recalculating results…' : 'Settings saved'+ )actions.refreshExperimentResults(true, 'experiment_config_change')},resetRunningExperiment: async () => {diff --git a/products/experiments/frontend/modals/CupedModal/CupedModal.tsx b/products/experiments/frontend/modals/CupedModal/CupedModal.tsxindex 6bb7e32e3064..8e0c9f66521e 100644--- a/products/experiments/frontend/modals/CupedModal/CupedModal.tsx+++ b/products/experiments/frontend/modals/CupedModal/CupedModal.tsx@@ -1,4 +1,4 @@-import { useActions, useValues } from 'kea'+import { useActions, useAsyncActions, useValues } from 'kea'import { LemonButton, LemonInput, LemonLabel, LemonModal, LemonSelect } from '@posthog/lemon-ui'@@ -10,8 +10,9 @@ import { experimentsConfigLogic } from 'scenes/settings/environment/experimentsCimport { DEFAULT_LOOKBACK_DAYS, MAX_LOOKBACK_DAYS, MIN_LOOKBACK_DAYS } from 'products/experiments/frontend/constants'export function CupedModal(): JSX.Element {- const { experiment } = useValues(experimentLogic)- const { updateExperimentSettings, setExperiment, restoreUnmodifiedExperiment } = useActions(experimentLogic)+ const { experiment, experimentUpdateLoading } = useValues(experimentLogic)+ const { setExperiment, restoreUnmodifiedExperiment } = useActions(experimentLogic)+ const { updateExperimentSettings } = useAsyncActions(experimentLogic)const { experimentsConfig } = useValues(experimentsConfigLogic)const { closeCupedModal } = useActions(modalsLogic)const { isCupedModalOpen } = useValues(modalsLogic)@@ -60,8 +61,13 @@ export function CupedModal(): JSX.Element {})}- const onSave = (): void => {- updateExperimentSettings({ stats_config: experiment.stats_config })+ const onSave = async (): Promise<void> => {+ try {+ await updateExperimentSettings({ stats_config: experiment.stats_config })+ } catch {+ // Keep the modal open so the user can retry+ return+ }closeCupedModal()}@@ -76,7 +82,7 @@ export function CupedModal(): JSX.Element {<LemonButton type="secondary" onClick={onClose}>Cancel</LemonButton>- <LemonButton type="primary" onClick={onSave}>+ <LemonButton type="primary" loading={experimentUpdateLoading} onClick={() => void onSave()}>Save</LemonButton></div>diff --git a/products/experiments/frontend/modals/StatsMethodModal/StatsMethodModal.tsx b/products/experiments/frontend/modals/StatsMethodModal/StatsMethodModal.tsxindex b44dbc014cdb..5967295c1e79 100644--- a/products/experiments/frontend/modals/StatsMethodModal/StatsMethodModal.tsx+++ b/products/experiments/frontend/modals/StatsMethodModal/StatsMethodModal.tsx@@ -1,4 +1,4 @@-import { useActions, useValues } from 'kea'+import { useActions, useAsyncActions, useValues } from 'kea'import { LemonButton, LemonInput, LemonLabel, LemonSelect } from '@posthog/lemon-ui'import { LemonModal } from '@posthog/lemon-ui'@@ -20,8 +20,9 @@ import { ExperimentStatsMethod } from '~/types'import { CONFIDENCE_LEVEL_OPTIONS } from 'products/experiments/frontend/constants'export function StatsMethodModal(): JSX.Element {- const { experiment, statsMethod } = useValues(experimentLogic)- const { updateExperimentSettings, setExperiment, restoreUnmodifiedExperiment } = useActions(experimentLogic)+ const { experiment, statsMethod, experimentUpdateLoading } = useValues(experimentLogic)+ const { setExperiment, restoreUnmodifiedExperiment } = useActions(experimentLogic)+ const { updateExperimentSettings } = useAsyncActions(experimentLogic)const { closeStatsEngineModal } = useActions(modalsLogic)const { isStatsEngineModalOpen } = useValues(modalsLogic)const { experimentsConfig } = useValues(experimentsConfigLogic)@@ -125,8 +126,14 @@ export function StatsMethodModal(): JSX.Element {</LemonButton><LemonButtontype="primary"- onClick={() => {- updateExperimentSettings({ stats_config: experiment.stats_config })+ loading={experimentUpdateLoading}+ onClick={async () => {+ try {+ await updateExperimentSettings({ stats_config: experiment.stats_config })+ } catch {+ // Keep the modal open so the user can retry+ return+ }closeStatsEngineModal()}}>