: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(replay-vision): measure the feed grid through a callback ref (#126725)
Tue Haulund72534b629ad2
diff --git a/products/replay_vision/frontend/replay_scanners/components/HighlightFeedTab.tsx b/products/replay_vision/frontend/replay_scanners/components/HighlightFeedTab.tsxindex 4dc4dcb774cb..9fd09a8624b5 100644--- a/products/replay_vision/frontend/replay_scanners/components/HighlightFeedTab.tsx+++ b/products/replay_vision/frontend/replay_scanners/components/HighlightFeedTab.tsx@@ -1,6 +1,6 @@import clsx from 'clsx'import { useActions, useValues } from 'kea'-import { RefObject, useEffect, useLayoutEffect, useRef, useState } from 'react'+import { useEffect, useLayoutEffect, useState } from 'react'import { useInView } from 'react-intersection-observer'import { LemonButton, LemonSkeleton, Spinner } from '@posthog/lemon-ui'@@ -42,12 +42,11 @@ function FeedSkeleton(): JSX.Element {)}-/** Reads the column count the grid's container queries chose; call it from inside the grid so it remounts with it. */-function useGridColumns(grid: RefObject<HTMLElement>): number {+/** Reads the column count the grid's container queries chose. */+function useGridColumns(element: HTMLElement | null): number {const [columns, setColumns] = useState(1)// Measured before paint, so the first frame already shows the right number of placeholders.useLayoutEffect(() => {- const element = grid.currentif (!element) {return}@@ -57,12 +56,12 @@ function useGridColumns(grid: RefObject<HTMLElement>): number {const observer = new ResizeObserver(measure)observer.observe(element)return () => observer.disconnect()- }, [grid])+ }, [element])return columns}/** Loads the next page as the reader nears the end, and closes the feed once the ranking runs out. */-function FeedEnd({ itemCount, grid }: { itemCount: number; grid: RefObject<HTMLElement> }): JSX.Element | null {+function FeedEnd({ itemCount, grid }: { itemCount: number; grid: HTMLElement | null }): JSX.Element | null {const { feedHasMore, feedItemsLoading, feedMoreFailed } = useValues(highlightFeedLogic)const columns = useGridColumns(grid)const { loadMoreFeed } = useActions(highlightFeedLogic)@@ -109,7 +108,8 @@ export function HighlightFeedTab(): JSX.Element {const { feedItems, feedItemsLoading, feedReloading, feedFailed, dateFrom, emptyReason } =useValues(highlightFeedLogic)const { loadFeed } = useActions(highlightFeedLogic)- const gridRef = useRef<HTMLDivElement>(null)+ // A callback ref, because a child's layout effect runs before React attaches the parent's object ref.+ const [grid, setGrid] = useState<HTMLDivElement | null>(null)const items = feedItems ?? []// Every card carrying a no-evidence reason means the window produced no findings. A feed that mixes a@@ -156,7 +156,7 @@ export function HighlightFeedTab(): JSX.Element {)}{items.length > 0 ? (<div- ref={gridRef}+ ref={setGrid}className={clsx(FEED_GRID, 'transition-opacity', feedReloading && 'opacity-40')}aria-busy={feedReloading}// `inert` keeps the stale cards out of keyboard reach; React 18 types lack the attribute.@@ -173,7 +173,7 @@ export function HighlightFeedTab(): JSX.Element {// Keyed by the observation alone, so a card that stays across a reload keeps its loaded poster.<HighlightFeedRow key={item.observation.id} item={item} position={index} />))}- <FeedEnd itemCount={items.length} grid={gridRef} />+ <FeedEnd itemCount={items.length} grid={grid} /></div>) : feedFailed ? null : emptyReason ? (<div className="mx-auto w-full max-w-xl">