posthog icon indicating copy to clipboard operation
posthog copied to clipboard

fix: Defensive clause to prevent slice error on cohort breakdowns

Open ordehi opened this issue 6 months ago • 1 comments

[!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?.length exists.
return cohort.filters?.properties?.values?.length ? (…) : (legacy UI)
  1. 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

ordehi avatar Jun 13 '25 20:06 ordehi

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%)

compressed-size-action

github-actions[bot] avatar Jun 13 '25 21:06 github-actions[bot]

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

👉 Review this PR's diff of snapshots.

posthog-bot avatar Jun 16 '25 13:06 posthog-bot

📸 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 storybook locally and make the fix now. (Often, the cause is ResizeObserver being 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.

👉 Review this PR's diff of snapshots.

posthog-bot avatar Jun 16 '25 13:06 posthog-bot