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(web-analytics): Keep live filters from resetting mid-edit (#62056)

Jordan Mryyanc7210b96613c
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 1207fd366744..aa418587d61e 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -4883,9 +4883,9 @@ snapshots:
scenes-app-feature-flags--new-multivariate-flag-variant-key-error--light:
hash: v1.k794b7964.c7275b6430fbd53565f881d1330f2ea1479f8be838d1ae1689108b3249678f64.h7Ktlbp1VMFYhF6bSwLOS_Jfp_uV71Ia5aQMq9lVDPA
scenes-app-feature-flags--new-remote-config-flag-payload-error--dark:
- hash: v1.k794b7964.a6d78a11cd747b9112dd991820d8761b799ffed11abd8249cd7e5b0e43b2ba8d.VgLTpNiieD59TcJ6fTxCkC2LRMPrQ0XSwobH3-XyOGE
+ hash: v1.k794b7964.1af099f2e9f8811e94353c341bcf179757201966841c188ec9e81de48dab7a0b.VbS43TXKb_YBiGph4kYhjf-kfrelIfJT7eUthuLvLhY
scenes-app-feature-flags--new-remote-config-flag-payload-error--light:
- hash: v1.k794b7964.7b9594f461cd8f64bb3f910eee70c50ff892a11fbf942f3ca2c9405580aee19c.5c4FR1Eo4orcBQHwvE357ngasRDvyePLNE6JTky4C0U
+ hash: v1.k794b7964.b9a810e0ef7fd0381418549f7faa7e08fdbea09e2e39adb17def4c30b32f33bc.PewDd2-CK0EyzOQTvSoDWW63tiGlbkAcle_Eq_ElSME
scenes-app-feature-flags-code-examples--code-instructions-node-with-group-multivariate-flag-local-evaluation--dark:
hash: v1.k794b7964.3ce50a6c3abbe37a320a41b9b595595f1f563ee2810f7039c1077de0de2ce541.NshMoutmoo5MZNYuOO7ESAXGz5weprcVLeWqVRJevZA
scenes-app-feature-flags-code-examples--code-instructions-node-with-group-multivariate-flag-local-evaluation--light:
diff --git a/frontend/src/lib/components/PropertyFilters/PathItemFilters.tsx b/frontend/src/lib/components/PropertyFilters/PathItemFilters.tsx
index c5057e217895..dbf02d3e2cc1 100644
--- a/frontend/src/lib/components/PropertyFilters/PathItemFilters.tsx
+++ b/frontend/src/lib/components/PropertyFilters/PathItemFilters.tsx
@@ -1,5 +1,4 @@
import { BindLogic, useActions, useValues } from 'kea'
-import { useEffect } from 'react'
import { IconPlusSmall } from '@posthog/icons'
import { LemonButton } from '@posthog/lemon-ui'
@@ -29,11 +28,7 @@ export function PathItemFilters({
}: PropertyFiltersProps): JSX.Element {
const logicProps = { propertyFilters, onChange, pageKey }
const { filtersWithNew, filterIdsWithNew } = useValues(propertyFilterLogic(logicProps))
- const { setFilter, remove, setFilters } = useActions(propertyFilterLogic(logicProps))
-
- useEffect(() => {
- setFilters(propertyFilters ?? [])
- }, [propertyFilters, setFilters])
+ const { setFilter, remove } = useActions(propertyFilterLogic(logicProps))
return (
<BindLogic logic={propertyFilterLogic} props={logicProps}>
diff --git a/frontend/src/lib/components/PropertyFilters/PropertyFilters.test.tsx b/frontend/src/lib/components/PropertyFilters/PropertyFilters.test.tsx
index d218b15411f5..a80ead0382e4 100644
--- a/frontend/src/lib/components/PropertyFilters/PropertyFilters.test.tsx
+++ b/frontend/src/lib/components/PropertyFilters/PropertyFilters.test.tsx
@@ -236,4 +236,51 @@ describe('PropertyFilters', () => {
expect(logic.values._filtersState).toBe(stateBefore)
expect(screen.getByTestId('property-filter-0')).toBeInTheDocument()
})
+
+ it('keeps an in-progress filter when re-rendered with a new same-content array', async () => {
+ // Regression: a parent that re-renders frequently (e.g. a live-streaming
+ // dashboard) passes a freshly `.filter()`-ed array each render. A property
+ // picked but not yet given a value is never committed via onChange, so it is
+ // absent from that array — it must not be wiped when the array reference churns.
+ const onChange = jest.fn()
+ const { rerender } = render(
+ <Provider>
+ <PropertyFilters
+ pageKey="in-progress"
+ onChange={onChange}
+ propertyFilters={[]}
+ taxonomicGroupTypes={[TaxonomicFilterGroupType.EventProperties]}
+ />
+ </Provider>
+ )
+
+ await userEvent.click(screen.getByTestId('new-prop-filter-in-progress'))
+ await waitFor(() => {
+ expect(screen.getByTestId('taxonomic-filter-searchfield')).toBeInTheDocument()
+ })
+ await userEvent.type(screen.getByTestId('taxonomic-filter-searchfield'), '$browser')
+ await waitFor(() => {
+ expect(screen.getByTestId('prop-filter-event_properties-0').textContent).toMatch(/Browser/)
+ })
+ await userEvent.click(screen.getByTestId('prop-filter-event_properties-0'))
+
+ // Property chosen, value not set yet → uncommitted, so the parent isn't notified.
+ expect(onChange).not.toHaveBeenCalled()
+ expect(screen.getByTestId('taxonomic-value-select')).toBeInTheDocument()
+
+ // Parent re-renders with a new array reference holding the same (empty) content.
+ rerender(
+ <Provider>
+ <PropertyFilters
+ pageKey="in-progress"
+ onChange={onChange}
+ propertyFilters={[]}
+ taxonomicGroupTypes={[TaxonomicFilterGroupType.EventProperties]}
+ />
+ </Provider>
+ )
+
+ // The in-progress filter (and its value selector) survive.
+ expect(screen.getByTestId('taxonomic-value-select')).toBeInTheDocument()
+ })
})
diff --git a/frontend/src/lib/components/PropertyFilters/PropertyFilters.tsx b/frontend/src/lib/components/PropertyFilters/PropertyFilters.tsx
index 88247d487d81..2e53b27d0ab7 100644
--- a/frontend/src/lib/components/PropertyFilters/PropertyFilters.tsx
+++ b/frontend/src/lib/components/PropertyFilters/PropertyFilters.tsx
@@ -1,10 +1,9 @@
import './PropertyFilters.scss'
import { BindLogic, useActions, useValues } from 'kea'
-import React, { useEffect, useState } from 'react'
+import React, { useState } from 'react'
import { TaxonomicPropertyFilter } from 'lib/components/PropertyFilters/components/TaxonomicPropertyFilter'
-import { parseProperties } from 'lib/components/PropertyFilters/utils'
import {
AllowedProperties,
ExcludedOperators,
@@ -101,13 +100,9 @@ export function PropertyFilters({
}: PropertyFiltersProps): JSX.Element {
const logicProps = { propertyFilters, onChange, pageKey, sendAllKeyUpdates }
const { filters, filtersWithNew, filterIds, filterIdsWithNew } = useValues(propertyFilterLogic(logicProps))
- const { remove, setFilters, setFilter } = useActions(propertyFilterLogic(logicProps))
+ const { remove, setFilter } = useActions(propertyFilterLogic(logicProps))
const [allowOpenOnInsert, setAllowOpenOnInsert] = useState<boolean>(false)
- useEffect(() => {
- setFilters(propertyFilters ? parseProperties(propertyFilters) : [])
- }, [propertyFilters, setFilters])
-
const displayedFilters = allowNew && editable ? filtersWithNew : filters
const displayedFilterIds = allowNew && editable ? filterIdsWithNew : filterIds
diff --git a/frontend/src/lib/components/PropertyFilters/propertyFilterLogic.ts b/frontend/src/lib/components/PropertyFilters/propertyFilterLogic.ts
index 52b4c9a67fde..96d4b6d6d07e 100644
--- a/frontend/src/lib/components/PropertyFilters/propertyFilterLogic.ts
+++ b/frontend/src/lib/components/PropertyFilters/propertyFilterLogic.ts
@@ -1,5 +1,5 @@
import equal from 'fast-deep-equal'
-import { actions, kea, key, listeners, path, props, reducers, selectors } from 'kea'
+import { actions, kea, key, listeners, path, props, propsChanged, reducers, selectors } from 'kea'
import { PropertyFilterLogicProps } from 'lib/components/PropertyFilters/types'
import {
@@ -59,6 +59,13 @@ export const propertyFilterLogic = kea<propertyFilterLogicType>([
path((key) => ['lib', 'components', 'PropertyFilters', 'propertyFilterLogic', key]),
props({} as PropertyFilterLogicProps),
key((props) => props.pageKey),
+ propsChanged(({ actions, props }, oldProps) => {
+ // parseProperties so non-array shapes (PropertyGroup / legacy dicts) don't crash setFilters,
+ // matching the reducer's initial-state path.
+ if (!equal(props.propertyFilters ?? [], oldProps.propertyFilters ?? [])) {
+ actions.setFilters(props.propertyFilters ? parseProperties(props.propertyFilters) : [])
+ }
+ }),
actions({
update: true,