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(dashboards): keep layouts identity stable across per-tile refreshes (#68449)

Paul D'Ambra4d2b4f6cfb47
diff --git a/frontend/src/scenes/dashboard/dashboardLogic.test.ts b/frontend/src/scenes/dashboard/dashboardLogic.test.ts
index f8fe2d6b9635..2e94a1af93c8 100644
--- a/frontend/src/scenes/dashboard/dashboardLogic.test.ts
+++ b/frontend/src/scenes/dashboard/dashboardLogic.test.ts
@@ -306,6 +306,24 @@ describe('dashboardLogic', () => {
logic.mount()
})
+ it('keeps the layouts reference stable when a tile refresh changes results but not geometry', async () => {
+ await expectLogic(logic).toFinishAllListeners()
+
+ const initialLayouts = logic.values.layouts
+ const firstTile = logic.values.dashboard!.tiles[0]
+
+ await expectLogic(logic, () => {
+ // A refresh response: same insight, new object identity and results, untouched layouts.
+ dashboardsModel.actions.updateDashboardInsight({
+ ...firstTile.insight!,
+ result: [{ count: 42 }],
+ })
+ }).toFinishAllListeners()
+
+ expect(logic.values.tiles[0].insight!.result).toEqual([{ count: 42 }])
+ expect(logic.values.layouts).toBe(initialLayouts)
+ })
+
it('saving without changes does not call api', async () => {
await expectLogic(logic).toFinishAllListeners()
diff --git a/frontend/src/scenes/dashboard/dashboardLogic.tsx b/frontend/src/scenes/dashboard/dashboardLogic.tsx
index befaf3299083..df8a7acf583d 100644
--- a/frontend/src/scenes/dashboard/dashboardLogic.tsx
+++ b/frontend/src/scenes/dashboard/dashboardLogic.tsx
@@ -44,6 +44,7 @@ import { featureFlagLogic, getFeatureFlagPayload } from 'lib/logic/featureFlagLo
import { accessLevelSatisfied } from 'lib/utils/accessControlUtils'
import { clearDOMTextSelection, getJSHeapMemory, uuid } from 'lib/utils/dom'
import { DashboardEventSource, eventUsageLogic } from 'lib/utils/eventUsageLogic'
+import { objectsEqual } from 'lib/utils/objects'
import { shouldCancelQuery } from 'lib/utils/requests'
import { toParams } from 'lib/utils/url'
import { BREAKPOINTS, dashboardToSaveableTemplate, getDashboardTileDisplayName } from 'scenes/dashboard/dashboardUtils'
@@ -1858,7 +1859,14 @@ export const dashboardLogic = kea<dashboardLogicType>([
return size
},
],
- layouts: [(s) => [s.tiles], (tiles) => calculateLayouts(tiles)],
+ layouts: [
+ (s) => [s.tiles],
+ (tiles) => calculateLayouts(tiles),
+ // Tile refreshes replace `tiles` once per insight response without touching geometry;
+ // keeping the result reference stable stops react-grid-layout re-laying-out every tile
+ // N times per dashboard refresh cycle.
+ { resultEqualityCheck: objectsEqual },
+ ],
layout: [
(s) => [s.layouts, s.sizeKey],
(layouts: ResponsiveLayouts, sizeKey: DashboardLayoutSize | undefined) =>