: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 the heatmap preview size and scaling (#72805)
Jordan Mryyana41757be9889
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex 594389f51df6..b9e2ef9d926e 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -6043,9 +6043,9 @@ snapshots:scenes-app-heatmap--new--light:hash: v1.k794b7964.ec5a5410104285363cbd9367af0620e4e9674399712a898f32cc400fa7a993e7.I9v4DCi_Vj_NoXXOcFYninqMnCS3vrIk9uN6cBPEBtkscenes-app-heatmap-new--authenticated-review--dark:- hash: v1.k794b7964.5f94a851cd95afa625e1458e57ba515a65dd424cb2f45317cdfff26640d51589.wjOlzli8l9ENxBP3mUgBCpjV9_m48-3SiGV4Y2p9ePU+ hash: v1.k794b7964.631bc050a0445eb0018c9ec039bd86da951df11350757600c0ccc9f25b2f7d90.YMjSo9vcVG36wTfwJwv89REgXYgfZq3tRnVRzAgQIVEscenes-app-heatmap-new--authenticated-review--light:- hash: v1.k794b7964.d22ea5d96385e16c9535a0a43f2d04fde20f44b2a91704cf2ccb2d8d9c4fd053.ZtoeN1fPwvdgP2xjSG-1ODNhzVwjM--d0UoxAQOheCI+ hash: v1.k794b7964.18064b40d625428a6dc26f718996003c59fc35de05454a30b2f3eba0e0151ebb.CmuNPtX4K6YUCcYYb053W8oXeeXMHN37CKID1YUTvkcscenes-app-heatmap-new--authenticated-with-recordings--dark:hash: v1.k794b7964.122b89252cb6afe361b75078ede94cb64d6fab9f927569d8c00407badd1ec41d.p3MJYsGNk05em46NP6ftGlG_txqprtMtLVm4Yp49RLEscenes-app-heatmap-new--authenticated-with-recordings--light:diff --git a/frontend/src/scenes/heatmaps/scenes/heatmap/HeatmapNewScene.tsx b/frontend/src/scenes/heatmaps/scenes/heatmap/HeatmapNewScene.tsxindex c6f329577621..b57e7f1658a9 100644--- a/frontend/src/scenes/heatmaps/scenes/heatmap/HeatmapNewScene.tsx+++ b/frontend/src/scenes/heatmaps/scenes/heatmap/HeatmapNewScene.tsx@@ -1,4 +1,5 @@import { useActions, useValues } from 'kea'+import useResizeObserver from 'use-resize-observer'import { IconCheckCircle, IconWarning } from '@posthog/icons'import { LemonBanner, LemonButton, LemonCard, LemonLabel, Spinner } from '@posthog/lemon-ui'@@ -411,16 +412,53 @@ function ReviewStatus({ warning, children }: { warning?: boolean; children: Reac)}-function RecordingBackgroundPreview({ html }: { html: string }): JSX.Element {+function RecordingBackgroundPreview({+ html,+ width,+ height,+}: {+ html: string+ width: number+ height: number+}): JSX.Element {+ const { ref, width: containerWidth = 0 } = useResizeObserver<HTMLDivElement>()+ const hasDims = width > 0 && height > 0+ const measured = containerWidth > 0+ // Scale the natural-size snapshot down to fit the container so the whole recorded viewport is+ // visible; never scale up past its natural size (a narrow/mobile capture stays crisp).+ const scale = hasDims && measured ? Math.min(1, containerWidth / width) : 1+return (- <div className="overflow-hidden rounded border bg-surface-secondary">- <iframe- srcDoc={html}- title="Selected session recording background"- sandbox="allow-same-origin"- tabIndex={-1}- className="w-full h-96 border-0 bg-white pointer-events-none ph-no-capture"- />+ <div ref={ref} className="overflow-hidden rounded border bg-surface-secondary w-full">+ {hasDims ? (+ measured ? (+ // eslint-disable-next-line react/forbid-dom-props+ <div className="relative" style={{ height: height * scale }}>+ <iframe+ srcDoc={html}+ title="Selected session recording background"+ sandbox="allow-same-origin"+ tabIndex={-1}+ className="absolute top-0 left-0 origin-top-left border-0 bg-white pointer-events-none ph-no-capture"+ // eslint-disable-next-line react/forbid-dom-props+ style={{ width, height, transform: `scale(${scale})` }}+ />+ </div>+ ) : (+ // Reserve the recording's aspect ratio until the observer reports a width, so a wide+ // capture never renders at full size and gets clipped before we can scale it down.+ // eslint-disable-next-line react/forbid-dom-props+ <div className="w-full" style={{ aspectRatio: `${width} / ${height}` }} />+ )+ ) : (+ <iframe+ srcDoc={html}+ title="Selected session recording background"+ sandbox="allow-same-origin"+ tabIndex={-1}+ className="w-full h-96 border-0 bg-white pointer-events-none ph-no-capture"+ />+ )}</div>)}@@ -442,7 +480,7 @@ function ReviewStep(): JSX.Element {const usesRecordingBackground = pageAccess === 'login' && !!recordingBackgroundDatareturn (- <LemonCard hoverEffect={false} className="max-w-3xl mx-auto">+ <LemonCard hoverEffect={false} className={cn('mx-auto', usesRecordingBackground ? 'max-w-5xl' : 'max-w-3xl')}><div className="flex flex-col gap-6"><div><h2 className="mb-1">{usesRecordingBackground ? 'Review background' : 'Review and create'}</h2>@@ -473,7 +511,13 @@ function ReviewStep(): JSX.Element {</dd></dl>- {recordingBackgroundData ? <RecordingBackgroundPreview html={recordingBackgroundData.html} /> : null}+ {recordingBackgroundData ? (+ <RecordingBackgroundPreview+ html={recordingBackgroundData.html}+ width={recordingBackgroundData.width}+ height={recordingBackgroundData.height}+ />+ ) : null}<div className="flex flex-col gap-2"><ReviewStatus warning={!captureEnabled}>