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): reserve blast radius height while counts load (#105556)

Gustavo H. Strassburger40eeb716559d
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 8e907186be01..4848924b8798 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -9028,6 +9028,10 @@ snapshots:
hash: v1.k794b7964.879c80254780c71338fb0258376f5469a8944e3a87cfa3c8cc2564ed3a7a5467.f82OTEBhWE3vzszLX0hUYSdbFRGGAFBBJLr6DO6d6SM
scenes-app-feature-flags--stale-feature-flag-with-ai-assessment--light:
hash: v1.k794b7964.79f79b458c0f5a3173f3242bc43461c49515d6a59bcc6fb8205d66a026c9c1e5.79aA16orR_C8exlJGbtSPlLaYQRUoY4VBJl4AyeDG5M
+ scenes-app-feature-flags-blast-radius-skeleton--default--dark:
+ hash: v1.k794b7964.6e2aed6abcdd4160369bfbc432c524e74e2f098d6f50e3fe3b399ca8405800b5.6TWeGoyr8JriDoOrnT1JNGOrAg6S1NanG1njnBNQS7o
+ scenes-app-feature-flags-blast-radius-skeleton--default--light:
+ hash: v1.k794b7964.91a322f11f2e80430058975600a034eb01656ce880781e40de1d8068952a5c25.YBRgpdE3RApL9kYeVGseSx--zMLi4M1wmuWiVs1ez5g
scenes-app-feature-flags-code-examples--code-instructions-node-with-group-multivariate-flag-local-evaluation--dark:
hash: v1.k794b7964.33b7e69158cdb17991413a077b7dac6e915f6899c917fea9086f39fb02409699.paRiPQ8Dk84qM73rCI6ccr0k9jO1Oy0PpXtRG5PfiTM
scenes-app-feature-flags-code-examples--code-instructions-node-with-group-multivariate-flag-local-evaluation--light:
diff --git a/frontend/src/scenes/feature-flags/BlastRadiusSkeleton.stories.tsx b/frontend/src/scenes/feature-flags/BlastRadiusSkeleton.stories.tsx
new file mode 100644
index 000000000000..b9c181adc019
--- /dev/null
+++ b/frontend/src/scenes/feature-flags/BlastRadiusSkeleton.stories.tsx
@@ -0,0 +1,27 @@
+import { Meta, StoryObj } from '@storybook/react'
+
+import { BlastRadiusSkeleton } from './BlastRadiusSkeleton'
+
+const meta: Meta<typeof BlastRadiusSkeleton> = {
+ title: 'Scenes-App/Feature Flags/Blast Radius Skeleton',
+ component: BlastRadiusSkeleton,
+ args: { targetName: 'users' },
+ parameters: {
+ testOptions: {
+ // The story's content is the loader itself, so the runner must not wait for it to disappear
+ waitForLoadersToDisappear: false,
+ },
+ },
+ decorators: [
+ (Story) => (
+ <div className="text-xs text-muted w-80">
+ <Story />
+ </div>
+ ),
+ ],
+}
+export default meta
+
+type Story = StoryObj<typeof BlastRadiusSkeleton>
+
+export const Default: Story = {}
diff --git a/frontend/src/scenes/feature-flags/BlastRadiusSkeleton.tsx b/frontend/src/scenes/feature-flags/BlastRadiusSkeleton.tsx
new file mode 100644
index 000000000000..0b7316e70a9c
--- /dev/null
+++ b/frontend/src/scenes/feature-flags/BlastRadiusSkeleton.tsx
@@ -0,0 +1,29 @@
+import { WrappingLoadingSkeleton } from 'lib/ui/WrappingLoadingSkeleton/WrappingLoadingSkeleton'
+
+import { MatchingActorsLink } from './MatchingActorsLink'
+
+export interface BlastRadiusSkeletonProps {
+ /** Plural aggregation target name, e.g. "users" or "organizations". */
+ targetName: string
+}
+
+/**
+ * Holds the space of the loaded blast-radius summary, so the controls below a release condition do not
+ * move when the counts arrive. It renders the summary's own markup under the shimmer, so the reserved
+ * height follows the summary's typography and the link's margin without a copied layout.
+ */
+export function BlastRadiusSkeleton({ targetName }: BlastRadiusSkeletonProps): JSX.Element {
+ return (
+ <div role="status" className="flex flex-col">
+ <span className="sr-only">Calculating affected {targetName}…</span>
+ <WrappingLoadingSkeleton>
+ {/* `inert` keeps the hidden link out of the tab order; React 18 types lack the attribute */}
+ <div className="flex flex-col" {...{ inert: '' }}>
+ <span>Filters match: ~0 {targetName}</span>
+ <span>Rollout will be to ~0 {targetName} - 100%</span>
+ <MatchingActorsLink properties={undefined} resolvedGroupTypeIndex={null} targetName={targetName} />
+ </div>
+ </WrappingLoadingSkeleton>
+ </div>
+ )
+}
diff --git a/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditions.matchingUsersLink.test.tsx b/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditions.matchingUsersLink.test.tsx
index 8a61d6a3b5da..506a9c8c6e8f 100644
--- a/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditions.matchingUsersLink.test.tsx
+++ b/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditions.matchingUsersLink.test.tsx
@@ -72,7 +72,7 @@ describe('feature flag release conditions matching users link', () => {
[
'FeatureFlagReleaseConditions',
<FeatureFlagReleaseConditions id="1234" filters={buildFilters()} onChange={jest.fn()} />,
- 'View matching users',
+ 'users',
'/persons',
],
[
@@ -83,13 +83,13 @@ describe('feature flag release conditions matching users link', () => {
filters={buildFilters()}
onChange={jest.fn()}
/>,
- 'View matching users',
+ 'users',
'/persons',
],
[
'FeatureFlagReleaseConditions, group-targeted',
<FeatureFlagReleaseConditions id="1234" filters={buildFilters(0)} onChange={jest.fn()} />,
- 'View matching organizations',
+ 'organizations',
'/groups/0',
],
[
@@ -100,18 +100,18 @@ describe('feature flag release conditions matching users link', () => {
filters={buildFilters(0)}
onChange={jest.fn()}
/>,
- 'View matching organizations',
+ 'organizations',
'/groups/0',
],
] as const
test.each(cases)(
'%s links a condition to the matching actors once counts load',
- async (_name, component, linkText, expectedPath) => {
+ async (_name, component, targetName, expectedPath) => {
const { getByText } = render(<Provider>{component}</Provider>)
await waitFor(() => {
- const link = getByText(linkText).closest('a')
+ const link = getByText(`View matching ${targetName}`).closest('a')
expect(link).toBeInTheDocument()
expect(link).toHaveAttribute('href', expect.stringContaining(expectedPath))
// The condition's own properties have to reach the link, not just the actor list route.
@@ -119,4 +119,16 @@ describe('feature flag release conditions matching users link', () => {
})
}
)
+
+ test.each(cases)('%s names what is loading while counts are pending', async (_name, component, targetName) => {
+ useMocks({
+ post: {
+ '/api/projects/:team/feature_flags/user_blast_radius': () => new Promise(() => {}),
+ },
+ })
+ const { findByText } = render(<Provider>{component}</Provider>)
+
+ const status = await findByText(`Calculating affected ${targetName}…`)
+ expect(status.parentElement).toHaveAttribute('role', 'status')
+ })
})
diff --git a/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditions.tsx b/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditions.tsx
index 0efea6ca0469..1117c808fdc6 100644
--- a/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditions.tsx
+++ b/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditions.tsx
@@ -24,7 +24,6 @@ import { LemonField } from 'lib/lemon-ui/LemonField'
import { LemonRadio } from 'lib/lemon-ui/LemonRadio'
import { LemonSlider } from 'lib/lemon-ui/LemonSlider'
import { LemonTag } from 'lib/lemon-ui/LemonTag/LemonTag'
-import { Spinner } from 'lib/lemon-ui/Spinner/Spinner'
import { dateFilterToText, dateStringToComponents } from 'lib/utils/dateFilters'
import { clamp } from 'lib/utils/numbers'
import { capitalizeFirstLetter, pluralize } from 'lib/utils/strings'
@@ -50,6 +49,7 @@ import { FractionalRolloutWarning } from 'products/feature_flags/frontend/Fracti
import { resolveAggregationGroupTypeIndex } from './aggregation'
import { BlastRadiusErrorMessage } from './BlastRadiusErrorMessage'
+import { BlastRadiusSkeleton } from './BlastRadiusSkeleton'
import { EARLY_ACCESS_GROUP_TARGETING_DISABLED_REASON, MATCHING_ESTIMATE_TOOLTIP } from './constants'
import { featureFlagLogic } from './featureFlagLogic'
import {
@@ -450,7 +450,7 @@ export function FeatureFlagReleaseConditions({
return (
<div
role="status"
- className="basis-full flex items-start gap-2 mt-1 text-secondary"
+ className="basis-full flex items-start gap-2 mt-1 min-h-[calc(3lh_+_0.25rem)] text-secondary"
>
<IconErrorOutline className="text-danger text-base shrink-0 mt-0.5" />
<BlastRadiusErrorMessage
@@ -477,8 +477,8 @@ export function FeatureFlagReleaseConditions({
}
if (affected === undefined || affected < 0 || total === undefined) {
return (
- <div className="basis-full flex items-center mt-1">
- <Spinner />
+ <div className="basis-full mt-1 text-secondary">
+ <BlastRadiusSkeleton targetName={pluralName} />
</div>
)
}
diff --git a/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditionsCollapsible.tsx b/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditionsCollapsible.tsx
index 80a38ddf6409..ffc608557d9b 100644
--- a/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditionsCollapsible.tsx
+++ b/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditionsCollapsible.tsx
@@ -37,7 +37,6 @@ import {
LemonLabel,
LemonMenu,
LemonSelect,
- Spinner,
Tooltip,
} from '@posthog/lemon-ui'
@@ -75,6 +74,7 @@ import { FractionalRolloutWarning } from 'products/feature_flags/frontend/Fracti
import { resolveAggregationGroupTypeIndex } from './aggregation'
import { BlastRadiusErrorMessage } from './BlastRadiusErrorMessage'
+import { BlastRadiusSkeleton } from './BlastRadiusSkeleton'
import { EARLY_ACCESS_GROUP_TARGETING_DISABLED_REASON, MATCHING_ESTIMATE_TOOLTIP } from './constants'
import { EarlyExitIndicator } from './EarlyExitIndicator'
import { FeatureFlagConditionDragHandle } from './FeatureFlagConditionDragHandle'
@@ -694,7 +694,7 @@ const ConditionContent = ({
{blastRadiusError ? (
<div
role="status"
- className="text-xs text-muted mt-2 flex items-start gap-2"
+ className="text-xs text-muted mt-2 flex items-start gap-2 min-h-[calc(3lh_+_0.25rem)]"
>
<IconErrorOutline className="text-danger text-sm shrink-0 mt-0.5" />
<BlastRadiusErrorMessage
@@ -781,9 +781,8 @@ const ConditionContent = ({
})()}
</div>
) : (
- <div className="text-xs text-muted mt-2 flex items-center gap-1">
- <Spinner className="text-sm" /> Calculating affected{' '}
- {resolvedTargetName}…
+ <div className="text-xs text-muted mt-2">
+ <BlastRadiusSkeleton targetName={resolvedTargetName} />
</div>
)}
</div>
diff --git a/frontend/src/scenes/feature-flags/featureFlagReleaseConditionsLogic.test.ts b/frontend/src/scenes/feature-flags/featureFlagReleaseConditionsLogic.test.ts
index 4e86d1de0b07..31d461a8b8d1 100644
--- a/frontend/src/scenes/feature-flags/featureFlagReleaseConditionsLogic.test.ts
+++ b/frontend/src/scenes/feature-flags/featureFlagReleaseConditionsLogic.test.ts
@@ -409,6 +409,54 @@ describe('the feature flag release conditions logic', () => {
})
})
+ it('copies both counts of the source condition when duplicating a condition set', async () => {
+ jest.spyOn(api, 'create').mockResolvedValueOnce({ affected: 500, total: 1000 })
+
+ logic = featureFlagReleaseConditionsLogic({
+ id: 'duplicate-counts-test',
+ filters: generateFeatureFlagFilters([
+ { properties: [], rollout_percentage: 50, variant: null, sort_key: 'A' },
+ ]),
+ })
+
+ await expectLogic(logic, () => {
+ logic.mount()
+ })
+ .toDispatchActions(['setAffectedCount', 'setTotalCount'])
+ .toDispatchActions(['setAffectedCount', 'setTotalCount'])
+
+ await expectLogic(logic, () => {
+ nextUuid = 'DUP'
+ logic.actions.duplicateConditionSet(0)
+ })
+ .toDispatchActions(['setAffectedCount', 'setTotalCount'])
+ .toMatchValues({
+ affectedCounts: { A: 500, DUP: 500 },
+ totalCounts: { A: 1000, DUP: 1000 },
+ })
+ })
+
+ it('estimates a duplicated condition itself when the source has no counts yet', async () => {
+ // The source's estimate never resolves, so the copy cannot inherit its counts.
+ const createSpy = jest.spyOn(api, 'create').mockReturnValue(new Promise(() => {}))
+ try {
+ logic = featureFlagReleaseConditionsLogic({
+ id: 'duplicate-pending-counts-test',
+ filters: generateFeatureFlagFilters([
+ { properties: [], rollout_percentage: 50, variant: null, sort_key: 'A' },
+ ]),
+ })
+ logic.mount()
+
+ await expectLogic(logic, () => {
+ nextUuid = 'DUP'
+ logic.actions.duplicateConditionSet(0)
+ }).toDispatchActions([logic.actionCreators.calculateBlastRadiusForCondition('DUP', [], null)])
+ } finally {
+ createSpy.mockRestore()
+ }
+ })
+
it('uses explicit sortKey when provided to addConditionSet', async () => {
jest.spyOn(api, 'create')
.mockReturnValueOnce(Promise.resolve({ affected: 500, total: 1000 }))
diff --git a/frontend/src/scenes/feature-flags/featureFlagReleaseConditionsLogic.ts b/frontend/src/scenes/feature-flags/featureFlagReleaseConditionsLogic.ts
index 82e850d8715b..92108224a921 100644
--- a/frontend/src/scenes/feature-flags/featureFlagReleaseConditionsLogic.ts
+++ b/frontend/src/scenes/feature-flags/featureFlagReleaseConditionsLogic.ts
@@ -741,15 +741,29 @@ export const featureFlagReleaseConditionsLogic = kea<featureFlagReleaseCondition
actions.calculateBlastRadius()
}
},
- duplicateConditionSet: async ({ index }, breakpoint) => {
+ duplicateConditionSet: ({ index }) => {
const newGroup = values.filters.groups[values.filters.groups.length - 1]
- if (newGroup?.sort_key) {
- actions.openCondition(newGroup.sort_key)
+ if (!newGroup?.sort_key) {
+ return
}
- await breakpoint(1000) // in ms
+ actions.openCondition(newGroup.sort_key)
const sourceSortKey = values.filters.groups[index]?.sort_key
- const valueForSourceCondition = sourceSortKey ? values.affectedCounts[sourceSortKey] : undefined
- actions.setAffectedCount(newGroup.sort_key, valueForSourceCondition)
+ const affected = sourceSortKey ? values.affectedCounts[sourceSortKey] : undefined
+ const total = sourceSortKey ? values.totalCounts[sourceSortKey] : undefined
+ if (affected !== undefined && total !== undefined) {
+ actions.setAffectedCount(newGroup.sort_key, affected)
+ actions.setTotalCount(newGroup.sort_key, total)
+ return
+ }
+ // The source is still loading or its estimate failed, so the copy needs its own estimate
+ actions.calculateBlastRadiusForCondition(
+ newGroup.sort_key,
+ newGroup.properties,
+ resolveAggregationGroupTypeIndex(
+ newGroup.aggregation_group_type_index,
+ values.filters?.aggregation_group_type_index
+ )
+ )
},
updateConditionSet: async ({ index, newProperties }, breakpoint) => {
const group: FeatureFlagGroupTypeWithSortKey | undefined = values.filters.groups[index]