: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
feat(error-tracking): keep issue list column headers visible while scrolling (#107658)
Hugues Pouillote067ff57a54b
diff --git a/frontend/src/layout/scenes/components/SceneStickyBar.tsx b/frontend/src/layout/scenes/components/SceneStickyBar.tsxindex 60f90b15e47c..8ac904b63ebc 100644--- a/frontend/src/layout/scenes/components/SceneStickyBar.tsx+++ b/frontend/src/layout/scenes/components/SceneStickyBar.tsx@@ -1,3 +1,5 @@+import { RefObject, forwardRef, useEffect, useState } from 'react'+import { cn } from 'lib/utils/css-classes'interface SceneStickyBarProps {@@ -7,14 +9,13 @@ interface SceneStickyBarProps {hasSceneTitleSection?: boolean}-export function SceneStickyBar({- children,- className,- showBorderBottom = true,- hasSceneTitleSection = true,-}: SceneStickyBarProps): JSX.Element {+export const SceneStickyBar = forwardRef<HTMLDivElement, SceneStickyBarProps>(function SceneStickyBar(+ { children, className, showBorderBottom = true, hasSceneTitleSection = true },+ ref+): JSX.Element {return (<div+ ref={ref}className={cn('scene-sticky-bar @2xl/main-content:sticky z-20 bg-primary @2xl/main-content:top-[34px] space-y-2 py-2 -mx-4 px-4 rounded-t-xl',// Without a scene title section the bar pins itself. Sticky offsets start inside the@@ -27,4 +28,36 @@ export function SceneStickyBar({{children}</div>)+})++/**+ * Returns the sticky offset, in pixels, of the bottom edge of a pinned `SceneStickyBar`: its `top` plus its height.+ * Use it to pin other sticky content (for example a `LemonTable` with `stickyHeader`) directly below the bar.+ * The value updates when the bar changes size (for example when its filters wrap) or when the scene resizes.+ */+export function useSceneStickyBarBottom(barRef: RefObject<HTMLElement>): number {+ const [bottom, setBottom] = useState(0)++ useEffect(() => {+ const bar = barRef.current+ if (!bar || typeof ResizeObserver === 'undefined') {+ return+ }+ const update = (): void => {+ // `top` is only set from the breakpoint where the bar is sticky. Below it, `top` is `auto`.+ const top = parseFloat(getComputedStyle(bar).top)+ setBottom((Number.isNaN(top) ? 0 : top) + bar.offsetHeight)+ }+ const observer = new ResizeObserver(update)+ observer.observe(bar)+ // The bar's `top` changes at a container breakpoint, which can occur without a change to the bar's size.+ // The parent's size changes when the scene crosses that breakpoint, so observe it too.+ if (bar.parentElement) {+ observer.observe(bar.parentElement)+ }+ update()+ return () => observer.disconnect()+ }, [barRef])++ return bottom}diff --git a/frontend/src/lib/lemon-ui/LemonTable/LemonTable.scss b/frontend/src/lib/lemon-ui/LemonTable/LemonTable.scssindex 720a44c89840..8ca1e9b66712 100644--- a/frontend/src/lib/lemon-ui/LemonTable/LemonTable.scss+++ b/frontend/src/lib/lemon-ui/LemonTable/LemonTable.scss@@ -386,3 +386,71 @@ body:not(.storybook-test-runner) {}}}++// One rounded corner of the table's border box, centered on `$origin`: the header background inside the+// curve, the border on it, and the page background outside it. The page background matches SceneStickyBar,+// which sits above a pinned header, and hides the rows that scroll behind the corner.+@function lemon-table-corner($origin) {+ @return radial-gradient(+ circle at $origin,+ var(--lemon-table-background-color) calc(var(--radius) - 1.5px),+ var(--color-border-primary) calc(var(--radius) - 1px),+ var(--color-border-primary) calc(var(--radius) - 0.5px),+ var(--color-bg-primary) var(--radius)+ );+}++// Sticky header: the header row pins to the scene's scroll container, from the same breakpoint as+// SceneStickyBar. A sticky element pins to its nearest scroll container, so the table must not be one.+// `overflow: clip` still clips (rounded corners, wide content) but does not make a scroll container.+// LemonTable only adds the class while the table fits its container, so nothing needs to scroll horizontally.+// Stickiness is disabled in snapshots due to flakiness, the same as sticky columns.+body:not(.storybook-test-runner) .LemonTable.LemonTable--sticky-header {+ @container main-content (min-width: 42rem) {+ overflow: clip;++ // Let the header paint over the table's 1px border, so that the pinned header can draw its own+ // top border and rounded corners. The table's top edge is scrolled away at that point.+ overflow-clip-margin: 1px;++ > .ScrollableShadows,+ > .ScrollableShadows > .ScrollableShadows__inner {+ overflow: clip !important; // Override the inline overflow style of the scroll viewport+ overflow-clip-margin: 1px;+ }++ .LemonTable__content > table > thead {+ position: sticky;++ // The extra 1px leaves room for the header's top border, which ::before draws above the header.+ top: calc(var(--lemon-table-sticky-header-top, 0px) + 1px);+ z-index: 7; // Above sticky and pinned cells (6), below the scrollable shadows (8)++ > tr > th {+ background: var(--lemon-table-background-color);+ }++ // The table's top border and rounded corners scroll away when the header pins, so the header+ // draws a copy of them. At rest the copy lies exactly over the table's own border,+ // so it only shows once the header pins.+ &::before {+ position: absolute;+ inset: -1px -1px auto;+ z-index: 7; // Above sticky and pinned header cells (6)+ height: var(--radius);+ pointer-events: none;+ content: '';+ background:+ lemon-table-corner(100% 100%) left top / var(--radius) var(--radius) no-repeat,+ lemon-table-corner(0 100%) right top / var(--radius) var(--radius) no-repeat,+ linear-gradient(var(--color-border-primary), var(--color-border-primary)) top / 100% 1px no-repeat;+ }+ }++ // Keep the loading overlay above the sticky header, so the header cannot be used while the table loads.+ // The overlay comes after the table in the DOM, so at the same z-index it paints above the header.+ &.LemonTable--loading .LemonTable__overlay {+ z-index: 7;+ }+ }+}diff --git a/frontend/src/lib/lemon-ui/LemonTable/LemonTable.test.tsx b/frontend/src/lib/lemon-ui/LemonTable/LemonTable.test.tsxindex e6ed65d34162..b2d2a246d993 100644--- a/frontend/src/lib/lemon-ui/LemonTable/LemonTable.test.tsx+++ b/frontend/src/lib/lemon-ui/LemonTable/LemonTable.test.tsx@@ -1,6 +1,6 @@import '@testing-library/jest-dom'-import { cleanup, fireEvent, render, screen } from '@testing-library/react'+import { act, cleanup, fireEvent, render, screen } from '@testing-library/react'import { router } from 'kea-router'import { initKeaTests } from '~/test/init'@@ -234,4 +234,62 @@ describe('LemonTable', () => {const spannedColumns = Array.from(groupingRow.querySelectorAll('th')).reduce((sum, th) => sum + th.colSpan, 0)expect(spannedColumns).toBe(3)})++ describe('sticky header', () => {+ const renderWithWidths = (props: { stickyHeader?: boolean }, tableWidth: number, viewportWidth = 500): void => {+ jest.spyOn(HTMLElement.prototype, 'offsetWidth', 'get').mockImplementation(function (this: HTMLElement) {+ return this.tagName === 'TABLE' ? tableWidth : 0+ })+ jest.spyOn(Element.prototype, 'clientWidth', 'get').mockImplementation(function (this: Element) {+ return this.classList.contains('ScrollableShadows__inner') ? viewportWidth : 0+ })+ render(<LemonTable rowKey="id" dataSource={DATA} columns={COLUMNS} {...props} />)+ }++ afterEach(() => {+ jest.restoreAllMocks()+ })++ it('pins the header when the table fits its container', () => {+ renderWithWidths({ stickyHeader: true }, 400)+ expect(document.querySelector('.LemonTable')).toHaveClass('LemonTable--sticky-header')+ })++ it('keeps horizontal scrolling instead when the table is wider than its container', () => {+ renderWithWidths({ stickyHeader: true }, 800)+ expect(document.querySelector('.LemonTable')).not.toHaveClass('LemonTable--sticky-header')+ })++ it('switches between pinning and horizontal scrolling when the table or its container resizes', () => {+ const resizeCallbacks: (() => void)[] = []+ jest.spyOn(globalThis, 'ResizeObserver').mockImplementation((callback: ResizeObserverCallback) => {+ resizeCallbacks.push(() => callback([], {} as ResizeObserver))+ return { observe: () => null, unobserve: () => null, disconnect: () => null } as ResizeObserver+ })+ let tableWidth = 400+ jest.spyOn(HTMLElement.prototype, 'offsetWidth', 'get').mockImplementation(function (this: HTMLElement) {+ return this.tagName === 'TABLE' ? tableWidth : 0+ })+ jest.spyOn(Element.prototype, 'clientWidth', 'get').mockImplementation(function (this: Element) {+ return this.classList.contains('ScrollableShadows__inner') ? 500 : 0+ })+ render(<LemonTable rowKey="id" dataSource={DATA} columns={COLUMNS} stickyHeader />)+ const table = document.querySelector('.LemonTable')+ expect(table).toHaveClass('LemonTable--sticky-header')+ expect(resizeCallbacks.length).toBeGreaterThan(0)++ tableWidth = 800+ act(() => resizeCallbacks.forEach((callback) => callback()))+ expect(table).not.toHaveClass('LemonTable--sticky-header')++ tableWidth = 400+ act(() => resizeCallbacks.forEach((callback) => callback()))+ expect(table).toHaveClass('LemonTable--sticky-header')+ })++ it('does not pin the header by default', () => {+ renderWithWidths({}, 400)+ expect(document.querySelector('.LemonTable')).not.toHaveClass('LemonTable--sticky-header')+ })+ })})diff --git a/frontend/src/lib/lemon-ui/LemonTable/LemonTable.tsx b/frontend/src/lib/lemon-ui/LemonTable/LemonTable.tsxindex e2d4a20549f3..bae048dacee3 100644--- a/frontend/src/lib/lemon-ui/LemonTable/LemonTable.tsx+++ b/frontend/src/lib/lemon-ui/LemonTable/LemonTable.tsx@@ -127,6 +127,15 @@ export interface LemonTableProps<T extends Record<string, any>, K extends BulkSe* Whether the table content is allowed to scroll inside its container.*/allowContentScroll?: boolean+ /**+ * Whether the header row stays visible while the page scrolls. The header pins to the scene's scroll+ * container from the `@2xl/main-content` breakpoint up, the same as `SceneStickyBar`. Set the+ * `--lemon-table-sticky-header-top` CSS variable on an ancestor to pin it below other sticky content.+ * The header only pins while the table fits its container: a table that must scroll horizontally+ * keeps its scroll container, which stops the header from pinning to the page.+ * Has no effect together with `allowContentScroll`.+ */+ stickyHeader?: boolean/** Row actions to display at the end of each row. Return null to hide actions for specific rows. */rowActions?: (record: T, recordIndex: number) => React.ReactNode | null/** Whether to hide the sorting indicator when no sort is active. Defaults to false. */@@ -180,6 +189,7 @@ export function LemonTable<T extends Record<string, any>, K extends BulkSelectiomaxHeaderWidth,hideScrollbar,allowContentScroll = false,+ stickyHeader = false,rowActions,hideSortingIndicatorWhenInactive = false,bulkSelection,@@ -372,6 +382,8 @@ export function LemonTable<T extends Record<string, any>, K extends BulkSelectio}, [baseColumnGroups, selectionColumn])const columns = useMemo(() => columnGroups.flatMap((group) => group.children), [columnGroups])+ const canStickHeader = stickyHeader && !allowContentScroll+ const tableFitsContainer = useTableFitsContainer(canStickHeader, scrollRef, tableRef)const previousPageRef = useRef<number | null>(null)useEffect(() => {@@ -448,6 +460,7 @@ export function LemonTable<T extends Record<string, any>, K extends BulkSelectiostealth && 'LemonTable--stealth',!uppercaseHeader && 'LemonTable--lowercase-header',allowContentScroll && 'h-full min-h-0 overflow-hidden',+ canStickHeader && tableFitsContainer && 'LemonTable--sticky-header',className)}// eslint-disable-next-line react/forbid-dom-props@@ -830,3 +843,34 @@ export function LemonTable<T extends Record<string, any>, K extends BulkSelectio</>)}++/**+ * Whether the table is no wider than its scroll viewport, so the viewport can stop scrolling horizontally.+ * Only measures when `enabled` is true.+ */+function useTableFitsContainer(+ enabled: boolean,+ viewportRef: React.RefObject<HTMLDivElement>,+ tableRef: React.RefObject<HTMLTableElement>+): boolean {+ const [fits, setFits] = useState(false)++ useEffect(() => {+ const viewport = viewportRef.current+ const table = tableRef.current+ if (!enabled || !viewport || !table || typeof ResizeObserver === 'undefined') {+ setFits(false)+ return+ }+ // Compare the table's own width with the viewport. This stays correct while the viewport clips+ // instead of scrolls, so the result cannot flap between the two modes.+ const update = (): void => setFits(table.offsetWidth <= viewport.clientWidth)+ const observer = new ResizeObserver(update)+ observer.observe(viewport)+ observer.observe(table)+ update()+ return () => observer.disconnect()+ }, [enabled, viewportRef, tableRef])++ return fits+}diff --git a/frontend/src/queries/nodes/DataTable/DataTable.tsx b/frontend/src/queries/nodes/DataTable/DataTable.tsxindex 683a857fe6c5..eea26390526b 100644--- a/frontend/src/queries/nodes/DataTable/DataTable.tsx+++ b/frontend/src/queries/nodes/DataTable/DataTable.tsx@@ -1072,6 +1072,7 @@ export function DataTable({data-attr={dataAttr}className="DataTable"allowContentScroll={context?.dataTableAllowContentScroll}+ stickyHeader={context?.dataTableStickyHeader}loading={responseLoading && !nextDataLoading && !newDataLoading}columns={lemonColumns}tableLayout={context?.tableLayout}diff --git a/frontend/src/queries/types.ts b/frontend/src/queries/types.tsindex b0b2512038ee..da2b78e770b9 100644--- a/frontend/src/queries/types.ts+++ b/frontend/src/queries/types.ts@@ -65,6 +65,8 @@ export interface QueryContext<Q extends QuerySchema = QuerySchema> {dataTableMaxPaginationRows?: number/** Keep the Data Table toolbar fixed while its table content scrolls. */dataTableAllowContentScroll?: boolean+ /** Keep the Data Table header row visible while the page scrolls. See `LemonTable`'s `stickyHeader`. */+ dataTableStickyHeader?: boolean/** Override the nouns used by Data Table counts and pagination. */dataTableNouns?: [string, string]compactDataTableToolbar?: booleandiff --git a/products/error_tracking/frontend/scenes/ErrorTrackingScene/tabs/issues/IssuesList.tsx b/products/error_tracking/frontend/scenes/ErrorTrackingScene/tabs/issues/IssuesList.tsxindex 38f698908bc3..2accd99d8b05 100644--- a/products/error_tracking/frontend/scenes/ErrorTrackingScene/tabs/issues/IssuesList.tsx+++ b/products/error_tracking/frontend/scenes/ErrorTrackingScene/tabs/issues/IssuesList.tsx@@ -1,5 +1,5 @@import { BindLogic, useValues } from 'kea'-import { useMemo } from 'react'+import { useMemo, useRef } from 'react'import { IconArrowRight } from '@posthog/icons'import { Tooltip } from '@posthog/lemon-ui'@@ -7,7 +7,7 @@ import { Tooltip } from '@posthog/lemon-ui'import { dayjs } from 'lib/dayjs'import { humanFriendlyLargeNumber } from 'lib/utils/numbers'-import { SceneStickyBar } from '~/layout/scenes/components/SceneStickyBar'+import { SceneStickyBar, useSceneStickyBarBottom } from '~/layout/scenes/components/SceneStickyBar'import { insightVizDataNodeKey } from '~/queries/nodes/InsightViz/insightVizKeys'import { Query } from '~/queries/Query/Query'import { ErrorTrackingIssue } from '~/queries/schema/schema-general'@@ -161,7 +161,10 @@ const insightProps: InsightLogicProps = {export function IssuesList(): JSX.Element {const { query } = useValues(errorTrackingSceneLogic)- const context = useIssueQueryContext()+ // Keep the column headers visible below the filter bar while the list scrolls+ const context: QueryContext = { ...useIssueQueryContext(), dataTableStickyHeader: true }+ const stickyBarRef = useRef<HTMLDivElement>(null)+ const stickyBarBottom = useSceneStickyBarBottom(stickyBarRef)return (<BindLogic@@ -170,12 +173,16 @@ export function IssuesList(): JSX.Element {>{/* first:-mt-4 tucks the bar flush under the tab bar, but only when no bannerrenders above — an unconditional -mt-4 would cover the banner's bottom edge */}- <SceneStickyBar className="first:-mt-4" showBorderBottom={false}>+ <SceneStickyBar ref={stickyBarRef} className="first:-mt-4" showBorderBottom={false}><IssuesFilters /><ListOptions /></SceneStickyBar>- <div data-attr="error-tracking-issue-row">+ <div+ data-attr="error-tracking-issue-row"+ // eslint-disable-next-line react/forbid-dom-props+ style={{ '--lemon-table-sticky-header-top': `${stickyBarBottom}px` } as React.CSSProperties}+ ><Query query={query} context={context} /></div></BindLogic>