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(heatmaps): stop refetching the in-app heatmap on window resize (#107778)

Jordan Mryyand85999f9d7f6
diff --git a/frontend/src/lib/components/heatmaps/heatmapDataLogic.test.ts b/frontend/src/lib/components/heatmaps/heatmapDataLogic.test.ts
index 998833679ce5..edf0f9e0c2d8 100644
--- a/frontend/src/lib/components/heatmaps/heatmapDataLogic.test.ts
+++ b/frontend/src/lib/components/heatmaps/heatmapDataLogic.test.ts
@@ -1,8 +1,53 @@
-import { eventFilterParam, heatmapApiPath, isWithinBounds } from 'lib/components/heatmaps/heatmapDataLogic'
+import { expectLogic } from 'kea-test-utils'
+
+import {
+ eventFilterParam,
+ heatmapApiPath,
+ heatmapDataLogic,
+ isWithinBounds,
+} from 'lib/components/heatmaps/heatmapDataLogic'
import { CommonFilters, HeatmapBoundsFilter } from 'lib/components/heatmaps/types'
+import { initKeaTests } from '~/test/init'
+import { toolbarConfigLogic } from '~/toolbar/toolbarConfigLogic'
import { AppContext } from '~/types'
+describe('heatmapDataLogic window resize', () => {
+ const originalInnerWidth = window.innerWidth
+
+ beforeEach(() => {
+ jest.spyOn(global, 'fetch').mockImplementation(() =>
+ Promise.resolve(new Response(JSON.stringify({ results: [] }), { status: 200 }))
+ )
+ initKeaTests()
+ toolbarConfigLogic.build({ apiURL: 'http://localhost', accessToken: 'test-token' }).mount()
+ })
+
+ afterEach(() => {
+ jest.restoreAllMocks()
+ Object.defineProperty(window, 'innerWidth', { configurable: true, value: originalInnerWidth })
+ })
+
+ it.each([
+ ['in-app', false],
+ ['toolbar', true],
+ ] as const)('%s context refetches on resize: %s', async (context, refetches) => {
+ const logic = heatmapDataLogic({ context })
+ logic.mount()
+ await expectLogic(logic, () => logic.actions.setHref('https://example.com/pricing'))
+ .toDispatchActions(['loadHeatmapSuccess'])
+ .toFinishAllListeners()
+ const heatmapRequests = jest.mocked(global.fetch).mock.calls.filter(([url]) => String(url).includes('heatmap'))
+ expect(heatmapRequests).toHaveLength(1)
+ expect(logic.values.rawHeatmap).toEqual({ results: [] })
+
+ Object.defineProperty(window, 'innerWidth', { configurable: true, value: window.innerWidth - 200 })
+ window.dispatchEvent(new Event('resize'))
+
+ expect(logic.values.rawHeatmapLoading).toBe(refetches)
+ })
+})
+
describe('isWithinBounds', () => {
const staticArea: HeatmapBoundsFilter = {
areaFixed: false,
diff --git a/frontend/src/lib/components/heatmaps/heatmapDataLogic.ts b/frontend/src/lib/components/heatmaps/heatmapDataLogic.ts
index 79e8a3aa3317..ed920ef221d0 100644
--- a/frontend/src/lib/components/heatmaps/heatmapDataLogic.ts
+++ b/frontend/src/lib/components/heatmaps/heatmapDataLogic.ts
@@ -754,9 +754,6 @@ export const heatmapDataLogic = kea<heatmapDataLogicType>([
setHref: () => {
actions.loadHeatmap()
},
- setWindowWidthOverride: () => {
- actions.loadHeatmap()
- },
setSelectedArea: ({ area }) => {
if (area) {
actions.loadAreaEvents({})
@@ -816,10 +813,7 @@ export const heatmapDataLogic = kea<heatmapDataLogicType>([
},
})),
subscriptions(({ actions }) => ({
- windowWidth: () => {
- actions.loadHeatmap()
- },
- windowHeight: () => {
+ analysisWidth: () => {
actions.loadHeatmap()
},
})),