Skip to content

: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.

fix(flags): preserve boolean payload on condition changes (#62933)

Luca Zanic7bafb4cc01a
diff --git a/frontend/src/scenes/feature-flags/featureFlagLogic.test.ts b/frontend/src/scenes/feature-flags/featureFlagLogic.test.ts
index 68a417e3e6f1..b11311bf7afe 100644
--- a/frontend/src/scenes/feature-flags/featureFlagLogic.test.ts
+++ b/frontend/src/scenes/feature-flags/featureFlagLogic.test.ts
@@ -444,6 +444,58 @@ describe('featureFlagLogic', () => {
})
})
+ describe('setFeatureFlagFilters', () => {
+ it.each([
+ ['an empty payload snapshot', {}],
+ ['a stale payload snapshot', { true: '{"enabled":false}' }],
+ ])('preserves boolean payloads when release conditions update from %s', async (_, incomingPayloads) => {
+ const payload = '{"enabled":true}'
+
+ await expectLogic(logic, () => {
+ logic.actions.setFeatureFlagValue('filters', {
+ ...logic.values.featureFlag.filters,
+ payloads: { true: payload },
+ })
+ }).toMatchValues({
+ featureFlag: partial({
+ filters: partial({
+ payloads: { true: payload },
+ }),
+ }),
+ })
+
+ const updatedConditionFilters: FeatureFlagFilters = {
+ ...logic.values.featureFlag.filters,
+ groups: [
+ {
+ properties: [
+ {
+ key: '$browser',
+ value: 'Chrome',
+ type: PropertyFilterType.Person,
+ operator: PropertyOperator.Exact,
+ },
+ ],
+ rollout_percentage: 42,
+ variant: null,
+ },
+ ],
+ payloads: incomingPayloads,
+ }
+
+ await expectLogic(logic, () => {
+ logic.actions.setFeatureFlagFilters(updatedConditionFilters, {})
+ }).toMatchValues({
+ featureFlag: partial({
+ filters: partial({
+ groups: updatedConditionFilters.groups,
+ payloads: { true: payload },
+ }),
+ }),
+ })
+ })
+ })
+
describe('change detection', () => {
it('detects active status changes', () => {
const originalFlag = { ...MOCK_FEATURE_FLAG, active: false }
diff --git a/frontend/src/scenes/feature-flags/featureFlagLogic.ts b/frontend/src/scenes/feature-flags/featureFlagLogic.ts
index f5401a5fbd98..c7d36cc184c3 100644
--- a/frontend/src/scenes/feature-flags/featureFlagLogic.ts
+++ b/frontend/src/scenes/feature-flags/featureFlagLogic.ts
@@ -728,7 +728,18 @@ export const featureFlagLogic = kea<featureFlagLogicType>([
return featureFlag
},
setFeatureFlagFilters: (state, { filters }) => {
- return { ...state, filters }
+ if (!state) {
+ return state
+ }
+ return {
+ ...state,
+ filters: {
+ ...filters,
+ // Preserve current payloads: this action only carries release-condition changes;
+ // the child component's payloads snapshot is always stale.
+ payloads: state.filters.payloads,
+ },
+ }
},
setMultivariateOptions: (state, { multivariateOptions }) => {
if (!state) {