: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(dashboards): size HogQLX link cells by their visible text (#123801)
Marcus Hof45d590317afc
diff --git a/frontend/src/queries/nodes/DataVisualization/Components/Table.test.ts b/frontend/src/queries/nodes/DataVisualization/Components/Table.test.tsindex 5a99ead8995c..7a406d8823c3 100644--- a/frontend/src/queries/nodes/DataVisualization/Components/Table.test.ts+++ b/frontend/src/queries/nodes/DataVisualization/Components/Table.test.ts@@ -91,4 +91,40 @@ describe('estimateColumnWidths', () => {expect(widths[1]).toBe(widths[columnCount - 2])expect(widths[1]).toBeGreaterThan(150)})++ it('sizes HogQLX links by their visible text', () => {+ const link = (text: string): TableDataCell<any> => {+ const value = ['__hx_tag', 'a', 'href', `https://example.com/${'x'.repeat(100)}`, 'children', [text]]+ return { value, formattedValue: value, type: 'STRING' }+ }+ const getCell = (_rowIndex: number, columnIndex: number): TableDataCell<any> =>+ columnIndex === 0 ? link('2026-11') : cell('2026-11')++ const [linkWidth, textWidth] = estimateColumnWidths(['period', 'period'], 3, getCell)++ expect(linkWidth).toBeLessThan(MAX_COLUMN_WIDTH)+ expect(linkWidth).toBe(textWidth)+ })++ it.each([+ ['a sparkline with data', ['__hx_tag', 'Sparkline', 'data', [1, 2, 3]]],+ ['a sparkline that takes its data from children', ['__hx_tag', 'Sparkline', 'children', [1, 2, 3, 4, 5]]],+ ['a recording button', ['__hx_tag', 'RecordingButton', 'sessionId', 'abc']],+ ])('keeps the widest width for %s', (_, value) => {+ const [width] = estimateColumnWidths(['trend'], 1, () => ({ value, formattedValue: value, type: 'STRING' }))++ expect(width).toBe(MAX_COLUMN_WIDTH)+ })++ it('sizes a HogQLX link without children by its href', () => {+ const link = (href: string): TableDataCell<any> => {+ const value = ['__hx_tag', 'a', 'href', href]+ return { value, formattedValue: value, type: 'STRING' }+ }++ const [short] = estimateColumnWidths(['url'], 1, () => link('/a'))+ const [long] = estimateColumnWidths(['url'], 1, () => link(`/${'x'.repeat(30)}`))++ expect(short).toBeLessThan(long)+ })})diff --git a/frontend/src/queries/nodes/DataVisualization/Components/Table.tsx b/frontend/src/queries/nodes/DataVisualization/Components/Table.tsxindex 40ba03c6af81..de948f699e13 100644--- a/frontend/src/queries/nodes/DataVisualization/Components/Table.tsx+++ b/frontend/src/queries/nodes/DataVisualization/Components/Table.tsx@@ -10,6 +10,7 @@ import { dayjs } from 'lib/dayjs'import { InsightEmptyState, InsightErrorState } from 'scenes/insights/EmptyStates'import { themeLogic } from '~/layout/navigation-3000/themeLogic'+import { HOGQLX_TAGS_NO_ATTRIBUTES, parseHogQLX } from '~/queries/nodes/HogQLX/render'import { VisualizationNode, HogQLQueryResponse, NodeKind } from '~/queries/schema/schema-general'import { QueryContext } from '~/queries/types'@@ -109,12 +110,38 @@ export const MAX_COLUMN_WIDTH = 320const COLUMN_WIDTH_SAMPLE_CELLS = 5000const MIN_COLUMN_WIDTH_SAMPLE_ROWS = 10+// Tags that renderHogQLX renders as their children's text. Keep in sync with render.tsx.+const HOGQLX_TEXT_TAGS = new Set([...HOGQLX_TAGS_NO_ATTRIBUTES, 'a', 'blink', 'marquee', 'redacted'])++// Counts the visible text of a parsed HogQLX value. Other tags (sparklines, buttons, images) and plain+// objects render as widgets or JSON, so they get the widest column.+function getHogQLXTextLength(value: unknown): number {+ if (value == null) {+ return 0+ }+ if (typeof value !== 'object') {+ return String(value).length+ }+ if (Array.isArray(value)) {+ return value.reduce((total: number, child) => total + getHogQLXTextLength(child), 0)+ }+ const { __hx_tag: tag, children, source, href } = value as Record<string, unknown>+ if (typeof tag === 'string' && HOGQLX_TEXT_TAGS.has(tag)) {+ const content = children ?? source+ // Links without content show their href+ return content ? getHogQLXTextLength(content) : tag === 'a' ? getHogQLXTextLength(href) : 0+ }+ return Infinity+}+function getCellTextLength(cell: TableDataCell<any>): number {if (cell.isTransposedHeader && cell.sourceColumnName) {return cell.sourceColumnName.length}if (cell.formattedValue !== null && typeof cell.formattedValue === 'object') {- return Infinity+ return Array.isArray(cell.formattedValue) && cell.formattedValue[0] === '__hx_tag'+ ? getHogQLXTextLength(parseHogQLX(cell.formattedValue))+ : Infinity}return String(cell.formattedValue ?? cell.value ?? '').length}diff --git a/frontend/src/queries/nodes/HogQLX/render.tsx b/frontend/src/queries/nodes/HogQLX/render.tsxindex e063f077dfc7..30b04e231b47 100644--- a/frontend/src/queries/nodes/HogQLX/render.tsx+++ b/frontend/src/queries/nodes/HogQLX/render.tsx@@ -16,7 +16,7 @@ import { imageDimension, imageSource } from './image'// NB!!! Sync this list with posthog/hogql/hogqlx.py// These tags only get the `key` and `children` attributes.-const HOGQLX_TAGS_NO_ATTRIBUTES = [+export const HOGQLX_TAGS_NO_ATTRIBUTES = ['em','strong','span',