: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(flags): stop stale parent prop from resetting rollout to 0% (#68484)
posthog[bot]d5128f10183b
diff --git a/frontend/src/scenes/feature-flags/featureFlagReleaseConditionsLogic.test.ts b/frontend/src/scenes/feature-flags/featureFlagReleaseConditionsLogic.test.tsindex 53fe07fbed89..07327cca6fce 100644--- a/frontend/src/scenes/feature-flags/featureFlagReleaseConditionsLogic.test.ts+++ b/frontend/src/scenes/feature-flags/featureFlagReleaseConditionsLogic.test.ts@@ -1610,4 +1610,58 @@ describe('the feature flag release conditions logic', () => {)})})++ describe('propsChanged does not clobber fresher local edits', () => {+ it('keeps a local rollout edit when the parent prop has not caught up', async () => {+ logic?.unmount()++ logic = featureFlagReleaseConditionsLogic({+ id: 'stale-prop-test',+ filters: generateFeatureFlagFilters([+ { properties: [], rollout_percentage: 0, variant: null, sort_key: 'group-1' },+ ]),+ })+ logic.mount()++ // User drags the rollout to 100 locally+ logic.actions.updateConditionSet(0, 100)+ expect(logic.values.filters.groups[0].rollout_percentage).toEqual(100)++ // A re-render fires propsChanged with the pre-edit parent snapshot (0%) before the+ // local edit has round-tripped back to the parent. It must not reset the fresher edit.+ await expectLogic(logic, () => {+ featureFlagReleaseConditionsLogic({+ id: 'stale-prop-test',+ filters: generateFeatureFlagFilters([+ { properties: [], rollout_percentage: 0, variant: null, sort_key: 'group-1' },+ ]),+ })+ }).toNotHaveDispatchedActions(['setFilters'])++ expect(logic.values.filters.groups[0].rollout_percentage).toEqual(100)+ })++ it('adopts a genuine external filters change from the parent', async () => {+ logic?.unmount()++ logic = featureFlagReleaseConditionsLogic({+ id: 'external-change-test',+ filters: generateFeatureFlagFilters([+ { properties: [], rollout_percentage: 0, variant: null, sort_key: 'group-1' },+ ]),+ })+ logic.mount()++ await expectLogic(logic, () => {+ featureFlagReleaseConditionsLogic({+ id: 'external-change-test',+ filters: generateFeatureFlagFilters([+ { properties: [], rollout_percentage: 25, variant: null, sort_key: 'group-1' },+ ]),+ })+ }).toDispatchActions(['setFilters'])++ expect(logic.values.filters.groups[0].rollout_percentage).toEqual(25)+ })+ })})diff --git a/frontend/src/scenes/feature-flags/featureFlagReleaseConditionsLogic.ts b/frontend/src/scenes/feature-flags/featureFlagReleaseConditionsLogic.tsindex ac07ac887da1..006866c980c0 100644--- a/frontend/src/scenes/feature-flags/featureFlagReleaseConditionsLogic.ts+++ b/frontend/src/scenes/feature-flags/featureFlagReleaseConditionsLogic.ts@@ -859,11 +859,26 @@ export const featureFlagReleaseConditionsLogic = kea<featureFlagReleaseCondition},],}),- propsChanged(({ props, values, actions }) => {+ propsChanged(({ props, values, actions }, oldProps) => {// Compare only the fields that affect release conditions and blast radius,// excluding payloads which don't affect targeting- const { payloads: _newPayloads, ...newRelevant } = props.filters- const { payloads: _oldPayloads, ...oldRelevant } = values.filters+ const { payloads: _newPayloads, ...newRelevant } = props.filters ?? {}+ const { payloads: _prevPropPayloads, ...prevPropRelevant } = oldProps?.filters ?? {}++ // Only adopt the incoming filters when the parent actually pushed a new value.+ // The child emits its edits up to the parent, which stores them and echoes them+ // back down as this prop. A re-render caused by the child's own edit can fire+ // propsChanged before that edit has round-tripped back to the parent, so+ // props.filters still holds the pre-edit snapshot. Adopting it here would clobber+ // the fresher local edit and silently reset the rollout percentage (e.g. back to a+ // newly-added condition set's 0% default). Reacting only to genuine parent changes+ // breaks that loop while still syncing external updates (template application,+ // variant removal, flag reload).+ if (objectsEqual(newRelevant, prevPropRelevant)) {+ return+ }++ const { payloads: _oldPayloads, ...oldRelevant } = values.filters ?? {}if (!objectsEqual(newRelevant, oldRelevant)) {actions.setFilters(props.filters)}