: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(dashboards): stop stale tile re-render from reverting display option saves (#66036)
Sam Pennington73c693348afb
diff --git a/frontend/src/scenes/insights/insightDataLogic.test.ts b/frontend/src/scenes/insights/insightDataLogic.test.tsindex 5dd2d89313e9..2a6cf2427b3b 100644--- a/frontend/src/scenes/insights/insightDataLogic.test.ts+++ b/frontend/src/scenes/insights/insightDataLogic.test.ts@@ -235,6 +235,47 @@ describe('insightDataLogic', () => {}).mount()}).toMatchValues({ query: updatedCachedQuery })})++ // On a dashboard tile, `setQuery` is shared with insightVizDataLogic, whose listener calls+ // props.setQuery (persistDisplayOptions). If a tile re-render re-syncs the incoming cached+ // query via setQuery, it loops back into a PATCH of that (stale) query, reverting a display+ // option the user just saved. propsChanged must use syncQueryFromProps on dashboard tiles.+ it('syncs a changed cached query via syncQueryFromProps, not setQuery, on a dashboard tile', async () => {+ const localUpdatedQuery = buildLocalUpdatedQuery()+ const staleCachedQuery: InsightVizNode = {+ ...baseQuery,+ source: {+ ...baseQuery.source,+ dateRange: {+ ...baseQuery.source.dateRange,+ date_from: '-14d',+ },+ },+ }++ const logic = insightDataLogic({+ dashboardItemId: Insight123,+ dashboardId: 99,+ cachedInsight: { short_id: Insight123, query: baseQuery } as any,+ })+ logic.mount()++ await expectLogic(logic, () => {+ logic.actions.setQuery(localUpdatedQuery)+ }).toMatchValues({ query: localUpdatedQuery })++ await expectLogic(logic, () => {+ insightDataLogic({+ dashboardItemId: Insight123,+ dashboardId: 99,+ cachedInsight: { short_id: Insight123, query: staleCachedQuery } as any,+ loadPriority: 1,+ }).mount()+ })+ .toDispatchActions(['syncQueryFromProps'])+ .toNotHaveDispatchedActions(['setQuery'])+ .toMatchValues({ query: staleCachedQuery })+ })})describe('reacts when the insight changes', () => {diff --git a/frontend/src/scenes/insights/insightDataLogic.tsx b/frontend/src/scenes/insights/insightDataLogic.tsxindex e767d05f29dc..80743de8cb51 100644--- a/frontend/src/scenes/insights/insightDataLogic.tsx+++ b/frontend/src/scenes/insights/insightDataLogic.tsx@@ -423,14 +423,20 @@ export const insightDataLogic = kea<insightDataLogicType>([if (!cachedQueryChanged) {return}+ // On dashboard tiles props.setQuery persists edits, and `setQuery` is shared with+ // insightVizDataLogic whose listener calls props.setQuery — so re-syncing a stale incoming+ // cached query (e.g. from a tile results refresh) via setQuery loops back and PATCHes it,+ // reverting a just-saved display option. syncQueryFromProps updates local state without the+ // loop. The insight scene keeps setQuery for its URL/draft sync.+ const syncCachedQuery = props.dashboardId != null ? actions.syncQueryFromProps : actions.setQuerytry {if (!objectsEqual(props.cachedInsight.query, values.query)) {- actions.setQuery(props.cachedInsight.query)+ syncCachedQuery(props.cachedInsight.query)}} catch {// values.query can throw if the logic's state isn't in the store yet// (e.g. when InsightCard rebuilds the logic during navigation)- actions.setQuery(props.cachedInsight.query)+ syncCachedQuery(props.cachedInsight.query)}}),afterMount(({ actions, props }) => {