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(exports): crop vertical funnel subscription images to content width (#65144)

Sam Pennington5c4ae10400c7
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 9b6632ad4920..20c0a8418068 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -2025,9 +2025,9 @@ snapshots:
exporter-funnels--funnel-left-to-right-insight-no-results--light:
hash: v1.k794b7964.9225d8fd25066264d4b17b2f2e1eaf912252f71215ef01f66375d816baa65b5b.yGj1DdorkpQ8jghwVu41iGfk8HiK4RXLIK3ZId8F4XM
exporter-funnels--funnel-time-to-convert-insight--dark:
- hash: v1.k794b7964.ae95e2f08e4f77fad255f664db0a893a1c15c54cf06b22b86c5720d748cc5272.flYoAn4dUHCHzE8xLzYfuZz2uZSESWzpjH-QB3dAjtk
+ hash: v1.k794b7964.27a64388f221ba267e44e5654b440d9156566d81f1dccfc6b2b8f291bef1f020.7JRykGuHsI7XSM9fEjmPelfJwyq6pn1qj9jWzzVGyXQ
exporter-funnels--funnel-time-to-convert-insight--light:
- hash: v1.k794b7964.ba5c06bdc53233f8995560cf8b1b2e8f9a07b243407ccfc8bb58c2988aab70db.yoH2pKZi1VhDSkHtgUpcVOAU8m-TJec314YPYN4LrwU
+ hash: v1.k794b7964.8144520c78faf425e617a9dc456bd36c1678eaffc97372aa34ca615a453dbee1.BuGQUT4vcnXX6An8fcX66vX4wGjk-oJt6hBDrGzAck8
exporter-funnels--funnel-top-to-bottom-breakdown-insight--dark:
hash: v1.k794b7964.5182db968bb635e30a4cc271ac90914e6fcb3ab6c0c950f04771e28ce29fc5c0.Nnboxh2AuuQTdI6H1WlRoh3UEe0_4ACG_se-WTwTqcc
exporter-funnels--funnel-top-to-bottom-breakdown-insight--light:
@@ -5905,9 +5905,9 @@ snapshots:
scenes-app-mcp-analytics-dashboard-cards--flagged-sessions--light:
hash: v1.k794b7964.1fc4aa2b1af4e2350dcf08445ed27f288245d6d4b5c556ffd79660262ab94964.acTG62SpX_gAoM0rfPK8SfUFhCFYqYyF4irVU9ZwyAg
scenes-app-mcp-analytics-dashboard-cards--key-metrics--dark:
- hash: v1.k794b7964.30a761d8a47452414e6f158ad50484885f81394fb58c075ff1f2e66c36c1fe6e.bV_JfGaoE60VA3pGReyVwyQ23zmdaaflqKtTyQVTeq4
+ hash: v1.k794b7964.aca3a4846c0d7a7d98e39f8bbb475dc7c8273baa79ddd40f88fa9773ba55a5da.euJc2UPkmZl3aXjH0Aj8-n255F8uqYJTuOU0IcfoV9Q
scenes-app-mcp-analytics-dashboard-cards--key-metrics--light:
- hash: v1.k794b7964.376099d576081c78dc740e794c25f4094489df28bac5fd4727422ca36635adee.GA6VOP1ygkbjHOeReQaUqZNIhU_LdIirGX3H_t9mMy8
+ hash: v1.k794b7964.548c850bd70d7706d212278ab300f1b1dd8f2deaa0678516df8523320592d513.JPqnrPw-UE4MRf9ZgoaQnwdnk07ldoqEeSB7lmzXwWQ
scenes-app-mcp-analytics-dashboard-cards--share-by-harness--dark:
hash: v1.k794b7964.91754923c079ce0c9fc46b83fe672ee4f967701bde08562b80fee6cacdbeeb01.eWYTt2AnIb5vZmQehDXCSkxR03Ld6ryyA6rYoyG-J1g
scenes-app-mcp-analytics-dashboard-cards--share-by-harness--light:
@@ -6333,13 +6333,13 @@ snapshots:
scenes-app-revenue-analytics--revenue-analytics-dashboard-area-mode--light:
hash: v1.k794b7964.73363c9dc8d269b1bdca387dd6b982058982a8cb609a737b73e26b44b14f951c.2aoXnujRadIzXrpspIVsa2vcyZGsPUcEL0GYKoGc5Ss
scenes-app-revenue-analytics--revenue-analytics-dashboard-bar-mode--dark:
- hash: v1.k794b7964.909b5eeaf1855ee758218ca35e344272822b29820ce5bf0051f90cae5cea4602.dq5wdDYjdSKyYsIQFTiahdQpmMEBbX2Fc2JWrAzSOEU
+ hash: v1.k794b7964.2a24477bf27410562209198b9b1b1c65a1e4465f23d75d91e3f6f5a3ab8183e6.Fiqv6yBO2YQJCSlmgtKDyt_hOAFiyXy83PziL3f8yXk
scenes-app-revenue-analytics--revenue-analytics-dashboard-bar-mode--light:
- hash: v1.k794b7964.f794a5111b857c6bbcdef6a532ed700184a65e7d36fe7a7068582cf08a8eb0bc.xGrhk7yarlGtCqpI6CdfDyuvY7GXyT-5r8u2FO7BiRU
+ hash: v1.k794b7964.5706501264920ef1063ad3d5decfeebb03039c71726a79fb5a9b9d2b360f5212.PIT5oDcm1GgMGcR9HHREpiFtJMRAis_ddZumXCJLFr4
scenes-app-revenue-analytics--revenue-analytics-dashboard-sync-in-progress--dark:
- hash: v1.k794b7964.266208b782900d5e2e26a5220cb871fd48d89d91f52f4ff665640b71fc78fc28.6D1n65FigrpEjIhjnX58hCwrr__V0vle8k_7DCFKccY
+ hash: v1.k794b7964.c7019c2b2db43ded3c18f14cf86e71a59ccc9609805738c7e144f0beeaf4dd74.o25nfhA0VOW4aPs2p2H2alOW0qyQfr8zQAGJj16BMAk
scenes-app-revenue-analytics--revenue-analytics-dashboard-sync-in-progress--light:
- hash: v1.k794b7964.fdda12c2a8bf8b84b93daaac139cbe6bbde8d8d4afe52cbadeaef7fb73b119f2.jbx3AQPO5xfAg9ekBEOYdYqXIljWj5EaRYIlLbEjfq0
+ hash: v1.k794b7964.0aea4adce4e2eba6a7cf76f7633154c6ad7e865a1ffae5da197b4ffd4c39037b._9CV6cSN8EO6J5rJQaObxtN9sVYl5m5aPqqh0nLVEwo
scenes-app-revenue-analytics-mrr-breakdown-modal--mrr-breakdown-modal--dark:
hash: v1.k794b7964.938ab51f3ea5a625ceb998fec10ef2a20f0a83858d872d2f79d7d7ccb54cc708.1hsX-zh8Cg_rIt1a86SahGk6XjfkO60W_XEDOCYvl0s
scenes-app-revenue-analytics-mrr-breakdown-modal--mrr-breakdown-modal--light:
diff --git a/packages/quill/packages/charts/src/core/hooks/clearCanvas.test.ts b/packages/quill/packages/charts/src/core/hooks/clearCanvas.test.ts
new file mode 100644
index 000000000000..74d3136c6f5b
--- /dev/null
+++ b/packages/quill/packages/charts/src/core/hooks/clearCanvas.test.ts
@@ -0,0 +1,62 @@
+import type { ChartDimensions } from '../types'
+
+import { clearAndPrepare } from './clearCanvas'
+
+function makeCtx(backingWidth: number): {
+ ctx: CanvasRenderingContext2D
+ transforms: number[][]
+} {
+ const transforms: number[][] = []
+ const ctx = {
+ canvas: { width: backingWidth } as HTMLCanvasElement,
+ save: () => {},
+ setTransform: (a: number, b: number, c: number, d: number, e: number, f: number) =>
+ transforms.push([a, b, c, d, e, f]),
+ clearRect: () => {},
+ } as unknown as CanvasRenderingContext2D
+ return { ctx, transforms }
+}
+
+function dims(width: number): ChartDimensions {
+ return { width, height: 200, plotLeft: 48, plotTop: 16, plotWidth: width - 64, plotHeight: 152 }
+}
+
+describe('clearAndPrepare', () => {
+ const originalDpr = window.devicePixelRatio
+
+ afterEach(() => {
+ Object.defineProperty(window, 'devicePixelRatio', { value: originalDpr, configurable: true })
+ })
+
+ it('scales the transform by the backing-store ratio, ignoring a mismatched window.devicePixelRatio', () => {
+ // Backing sized at dpr=1 (canvas.width === css width) while the global now reports 2 — the
+ // export's resize-under-device_scale_factor=2 case. The transform must follow the backing
+ // (1), not the stale global (2), or every coordinate doubles and the chart magnifies/clips.
+ Object.defineProperty(window, 'devicePixelRatio', { value: 2, configurable: true })
+ const { ctx, transforms } = makeCtx(784)
+
+ clearAndPrepare(ctx, dims(784))
+
+ expect(transforms[0][0]).toBe(1)
+ expect(transforms[0][3]).toBe(1)
+ })
+
+ it('uses the backing ratio for a normal hi-dpi canvas', () => {
+ Object.defineProperty(window, 'devicePixelRatio', { value: 2, configurable: true })
+ const { ctx, transforms } = makeCtx(1568)
+
+ clearAndPrepare(ctx, dims(784))
+
+ expect(transforms[0][0]).toBe(2)
+ expect(transforms[0][3]).toBe(2)
+ })
+
+ it('falls back to window.devicePixelRatio when dimensions have no width', () => {
+ Object.defineProperty(window, 'devicePixelRatio', { value: 3, configurable: true })
+ const { ctx, transforms } = makeCtx(0)
+
+ clearAndPrepare(ctx, dims(0))
+
+ expect(transforms[0][0]).toBe(3)
+ })
+})
diff --git a/packages/quill/packages/charts/src/core/hooks/clearCanvas.ts b/packages/quill/packages/charts/src/core/hooks/clearCanvas.ts
index 5b31d991ac34..368f960b6e9f 100644
--- a/packages/quill/packages/charts/src/core/hooks/clearCanvas.ts
+++ b/packages/quill/packages/charts/src/core/hooks/clearCanvas.ts
@@ -1,9 +1,15 @@
import type { ChartDimensions } from '../types'
/** Reset the transform to device-pixel scale and clear the whole canvas, leaving the ctx in a
- * saved state the caller restores after drawing. Shared by the static and hover draw loops. */
+ * saved state the caller restores after drawing. Shared by the static and hover draw loops.
+ *
+ * The scale is derived from the backing store the canvas was actually sized with
+ * (`canvas.width / dimensions.width`) rather than a fresh `window.devicePixelRatio` read. A
+ * redraw can run at a different devicePixelRatio than the one that sized the backing (e.g. a
+ * headless export that resizes the viewport under device_scale_factor=2); reading it again here
+ * would scale the transform inconsistently with the canvas and magnify/clip the drawing. */
export function clearAndPrepare(ctx: CanvasRenderingContext2D, dimensions: ChartDimensions): void {
- const dpr = window.devicePixelRatio || 1
+ const dpr = dimensions.width > 0 ? ctx.canvas.width / dimensions.width : window.devicePixelRatio || 1
ctx.save()
ctx.setTransform(dpr, 0, 0, dpr, 0, 0)
ctx.clearRect(0, 0, dimensions.width, dimensions.height)
diff --git a/products/exports/backend/tasks/image_exporter.py b/products/exports/backend/tasks/image_exporter.py
index 60a1b98a5c56..fee08e51887e 100644
--- a/products/exports/backend/tasks/image_exporter.py
+++ b/products/exports/backend/tasks/image_exporter.py
@@ -92,7 +92,15 @@ MEASURE_CONTENT_WIDTH_JS = f"""
return replayElement.offsetWidth;
}}
- // Check for left-to-right funnel (FunnelBarVertical)
+ // Left-to-right funnel (FunnelStepsBarChart, quill-charts). The bars + legend carry an
+ // explicit pixel width on this element, while every ancestor stretches to fill the wide
+ // export viewport — so measure this element directly rather than the stretched wrapper.
+ const funnelStepsCanvas = document.querySelector('[data-attr="funnel-steps-bar-chart-canvas"]');
+ if (funnelStepsCanvas) {{
+ return Math.ceil(funnelStepsCanvas.getBoundingClientRect().width) + {CONTENT_PADDING};
+ }}
+
+ // Legacy left-to-right funnel (FunnelBarVertical, table-based)
// Top-to-bottom funnels use FunnelBarHorizontal and don't need width expansion
const funnelElement = document.querySelector('.FunnelBarVertical');
if (funnelElement) {{
diff --git a/products/exports/backend/tasks/test/test_image_exporter.py b/products/exports/backend/tasks/test/test_image_exporter.py
index e2047a0a8ce9..451150b1b111 100644
--- a/products/exports/backend/tasks/test/test_image_exporter.py
+++ b/products/exports/backend/tasks/test/test_image_exporter.py
@@ -810,6 +810,24 @@ class TestDimensionHelpers(SimpleTestCase):
assert image_exporter._cap_height(raw_height, effective_max, "https://example.com", final=final) == expected
+class TestMeasureContentWidthJS(SimpleTestCase):
+ # The vertical funnel (FunnelStepsBarChart, quill-charts) renders neither a <table> nor a
+ # .FunnelBarVertical, so the measurement JS must target its own selector. If that selector is
+ # absent — or is checked after the generic <table> fallback — funnel measurement returns null,
+ # _resolve_width keeps the wide 4000px funnel viewport, and the bars end up stranded on the left
+ # of a mostly-empty image. The selector must stay in sync with the data-attr rendered by
+ # FunnelStepsBarChart.tsx.
+ def test_funnel_canvas_selector_is_present_and_measured_before_table_fallback(self) -> None:
+ js = image_exporter.MEASURE_CONTENT_WIDTH_JS
+
+ canvas_index = js.find("funnel-steps-bar-chart-canvas")
+ table_fallback_index = js.find("tableElement")
+
+ assert canvas_index != -1, "vertical funnels would fall through to the table path and never get cropped"
+ assert table_fallback_index != -1
+ assert canvas_index < table_fallback_index
+
+
class TestIsBrowserlessConnectionError(SimpleTestCase):
@parameterized.expand(
[
diff --git a/products/product_analytics/frontend/insights/funnels/FunnelStepsBarChart/FunnelStepsBarChart.tsx b/products/product_analytics/frontend/insights/funnels/FunnelStepsBarChart/FunnelStepsBarChart.tsx
index 47eea2ca5d71..c2c9934ec9db 100644
--- a/products/product_analytics/frontend/insights/funnels/FunnelStepsBarChart/FunnelStepsBarChart.tsx
+++ b/products/product_analytics/frontend/insights/funnels/FunnelStepsBarChart/FunnelStepsBarChart.tsx
@@ -131,7 +131,11 @@ export function FunnelStepsBarChart({
<ScrollableShadows direction="horizontal" className="flex-1" contentClassName="flex h-full flex-col">
<div className="flex flex-1 flex-col" data-attr="funnel-steps-bar-chart">
{/* eslint-disable-next-line react/forbid-dom-props */}
- <div className="flex min-h-[150px] flex-1" style={{ width: chartWidth }}>
+ <div
+ className="flex min-h-[150px] flex-1"
+ style={{ width: chartWidth }}
+ data-attr="funnel-steps-bar-chart-canvas"
+ >
<BarChart<FunnelStepsBarSeriesMeta>
series={series}
labels={labels}