fix: Defensive clause to prevent slice error on cohort breakdowns
[!IMPORTANT] 👉 Stay up-to-date with PostHog coding conventions for a smoother review.
Problem
Hovering a cohort in the breakdown-selector (or anything that renders CohortPopoverInfo) could crash the UI with
Cannot read properties of undefined (reading 'slice')
Error tracking: https://us.posthog.com/project/2/error_tracking/5b1857ae-8d61-4ee6-80e1-5e723829b312
CohortPopoverInfo assumed every cohort’s filter JSON contained filters.properties.values (an array of criteria groups). Static cohorts and some legacy cohorts ship only:
{ "filters": { "properties": {} } }
=> values is undefined, .slice() explodes.
Changes
- Guard clause: only render the “new criteria” path when
filters?.properties?.values?.lengthexists.
return cohort.filters?.properties?.values?.length ? (…) : (legacy UI)
- TypeScript cast: silenced an index-signature complaint when mapping
criteria→ human label:
(BEHAVIORAL_TYPE_TO_LABEL as Record<string, { label: string }>)[…]
No backend changes, no cohort list changes, just crash-proofing the pop-over.
How did you test this code?
Tested locally
Size Change: -21 B (0%)
Total Size: 2.57 MB
ℹ️ View Unchanged
| Filename | Size | Change |
|---|---|---|
frontend/dist/toolbar.js |
2.57 MB | -21 B (0%) |
📸 UI snapshots have been updated
1 snapshot changes in total. 0 added, 1 modified, 0 deleted:
chromium: 0 added, 1 modified, 0 deleted (diff for shard 2)webkit: 0 added, 0 modified, 0 deleted
Triggered by this commit.
📸 UI snapshots have been updated
1 snapshot changes in total. 0 added, 1 modified, 0 deleted:
[!CAUTION]
Detected flapping snapshots
These snapshots have auto-updated more than once since the last human commit:
scenes-app-insights-funnels--funnel-top-to-bottom-breakdown-edit--dark.png(chromium, shard 2)The flippy-flappies are deadly and must be fixed ASAP. They're productivity killers. Run
pnpm storybooklocally and make the fix now. (Often, the cause isResizeObserverbeing used instead of the better CSS container queries.)
chromium: 0 added, 1 modified, 0 deleted (diff for shard 2)webkit: 0 added, 0 modified, 0 deleted
Triggered by this commit.