: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: Fix heatmap url deletion (#72721)
Jordan Mryyan1aaec79d8561
diff --git a/frontend/src/scenes/heatmaps/components/heatmapsBrowserLogic.test.ts b/frontend/src/scenes/heatmaps/components/heatmapsBrowserLogic.test.tsindex 5a0c615d6dab..04faad859ce4 100644--- a/frontend/src/scenes/heatmaps/components/heatmapsBrowserLogic.test.ts+++ b/frontend/src/scenes/heatmaps/components/heatmapsBrowserLogic.test.ts@@ -1,18 +1,55 @@-import { normalizeHeatmapDataUrl } from './heatmapsBrowserLogic'--describe('normalizeHeatmapDataUrl', () => {- it.each([- ['example.com', null],- [' ', null],- ['', null],- [null, null],- ['h', null],- ['https://', null],- ['https://example.com', { href: 'https://example.com/', matchType: 'exact' }],- ['https://example.com/pricing', { href: 'https://example.com/pricing', matchType: 'exact' }],- [' https://example.com/pricing ', { href: 'https://example.com/pricing', matchType: 'exact' }],- ['https://example.com/users/*', { href: 'https://example.com/users/*', matchType: 'pattern' }],- ] as const)('normalizeHeatmapDataUrl(%s) → %s', (input, expected) => {- expect(normalizeHeatmapDataUrl(input)).toEqual(expected)+import { router } from 'kea-router'+import { expectLogic } from 'kea-test-utils'++import api from 'lib/api'++import { initKeaTests } from '~/test/init'++import { heatmapsBrowserLogic, normalizeHeatmapDataUrl } from './heatmapsBrowserLogic'++describe('heatmapsBrowserLogic', () => {+ describe('normalizeHeatmapDataUrl', () => {+ it.each([+ ['example.com', null],+ [' ', null],+ ['', null],+ [null, null],+ ['h', null],+ ['https://', null],+ ['https://example.com', { href: 'https://example.com/', matchType: 'exact' }],+ ['https://example.com/pricing', { href: 'https://example.com/pricing', matchType: 'exact' }],+ [' https://example.com/pricing ', { href: 'https://example.com/pricing', matchType: 'exact' }],+ ['https://example.com/users/*', { href: 'https://example.com/users/*', matchType: 'pattern' }],+ ] as const)('normalizeHeatmapDataUrl(%s) → %s', (input, expected) => {+ expect(normalizeHeatmapDataUrl(input)).toEqual(expected)+ })+ })++ describe('page URL query-param sync', () => {+ beforeEach(() => {+ initKeaTests()+ jest.spyOn(api, 'queryHogQL').mockResolvedValue({ results: [] } as any)+ router.actions.push('/heatmaps/new')+ })++ afterEach(() => {+ jest.restoreAllMocks()+ })++ it('keeps the page URL cleared on the first delete instead of resurrecting it from the querystring', async () => {+ const logic = heatmapsBrowserLogic()+ logic.mount()+ await expectLogic(logic).toFinishAllListeners()++ logic.actions.setDisplayUrl('https://example.com/pricing')+ await expectLogic(logic).toFinishAllListeners()+ expect(router.values.searchParams.pageURL).toBe('https://example.com/pricing')++ logic.actions.setDisplayUrl('')+ await expectLogic(logic).toFinishAllListeners()++ expect(logic.values.displayUrl).toBe('')+ expect(router.values.searchParams.pageURL).toBeUndefined()+ })})})diff --git a/frontend/src/scenes/heatmaps/components/heatmapsBrowserLogic.ts b/frontend/src/scenes/heatmaps/components/heatmapsBrowserLogic.tsindex a453b0884a61..b0b192862197 100644--- a/frontend/src/scenes/heatmaps/components/heatmapsBrowserLogic.ts+++ b/frontend/src/scenes/heatmaps/components/heatmapsBrowserLogic.ts@@ -715,38 +715,52 @@ export const heatmapsBrowserLogic = kea<heatmapsBrowserLogicType>([},})),- actionToUrl(({ values }) => ({- setDisplayUrl: ({ url }) => {- const searchParams = { ...router.values.searchParams, pageURL: url }- if (!url || url.trim() === '') {+ actionToUrl(({ values }) => {+ const currentUrlSearchParams = (): Record<string, any> => {+ const searchParams = { ...router.values.searchParams }+ if (values.displayUrl?.trim()) {+ searchParams.pageURL = values.displayUrl+ } else {delete searchParams.pageURL}- return [router.values.location.pathname, searchParams, router.values.hashParams, { replace: true }]- },- setDataUrl: ({ url }) => {- const searchParams = { ...router.values.searchParams, dataUrl: url }- if (!url || url.trim() === '') {+ if (values.dataUrl?.trim()) {+ searchParams.dataUrl = values.dataUrl+ } else {delete searchParams.dataUrl}- return [router.values.location.pathname, searchParams, router.values.hashParams, { replace: true }]- },- patchHeatmapFilters: () => {- const searchParams = { ...router.values.searchParams, heatmapFilters: values.heatmapFilters }- return [router.values.location.pathname, searchParams, router.values.hashParams, { replace: true }]- },- setHeatmapColorPalette: ({ palette }) => {- const searchParams = { ...router.values.searchParams, heatmapPalette: palette }- return [router.values.location.pathname, searchParams, router.values.hashParams, { replace: true }]- },- setHeatmapFixedPositionMode: ({ mode }) => {- const searchParams = { ...router.values.searchParams, heatmapFixedPositionMode: mode }- return [router.values.location.pathname, searchParams, router.values.hashParams, { replace: true }]- },- setCommonFilters: ({ filters }) => {- const searchParams = { ...router.values.searchParams, commonFilters: filters }- return [router.values.location.pathname, searchParams, router.values.hashParams, { replace: true }]- },- })),+ return searchParams+ }+ return {+ setDisplayUrl: () => [+ router.values.location.pathname,+ currentUrlSearchParams(),+ router.values.hashParams,+ { replace: true },+ ],+ setDataUrl: () => [+ router.values.location.pathname,+ currentUrlSearchParams(),+ router.values.hashParams,+ { replace: true },+ ],+ patchHeatmapFilters: () => {+ const searchParams = { ...router.values.searchParams, heatmapFilters: values.heatmapFilters }+ return [router.values.location.pathname, searchParams, router.values.hashParams, { replace: true }]+ },+ setHeatmapColorPalette: ({ palette }) => {+ const searchParams = { ...router.values.searchParams, heatmapPalette: palette }+ return [router.values.location.pathname, searchParams, router.values.hashParams, { replace: true }]+ },+ setHeatmapFixedPositionMode: ({ mode }) => {+ const searchParams = { ...router.values.searchParams, heatmapFixedPositionMode: mode }+ return [router.values.location.pathname, searchParams, router.values.hashParams, { replace: true }]+ },+ setCommonFilters: ({ filters }) => {+ const searchParams = { ...router.values.searchParams, commonFilters: filters }+ return [router.values.location.pathname, searchParams, router.values.hashParams, { replace: true }]+ },+ }+ }),beforeUnmount(() => {// Disposables handle cleanup automatically