: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): keep highlight posters across feed reloads (#126566)
Tue Haulundf71f18ec713e
diff --git a/frontend/src/lib/components/NotificationsMenu/useAutoMarkRead.test.ts b/frontend/src/lib/components/NotificationsMenu/useAutoMarkRead.test.tsindex b4b191aee280..7abe92d10c5e 100644--- a/frontend/src/lib/components/NotificationsMenu/useAutoMarkRead.test.ts+++ b/frontend/src/lib/components/NotificationsMenu/useAutoMarkRead.test.ts@@ -92,4 +92,17 @@ describe('useAutoMarkRead', () => {act(() => jest.advanceTimersByTime(AUTO_MARK_READ_DWELL_MS * 2))expect(onDwell).not.toHaveBeenCalled()})++ it('fires again once per new resetKey while the item stays mounted', () => {+ const onDwell = jest.fn()+ let resetKey = 'load-1'+ const { rerender } = renderHook(() => useAutoMarkRead(true, onDwell, AUTO_MARK_READ_DWELL_MS, resetKey))+ act(() => jest.advanceTimersByTime(AUTO_MARK_READ_DWELL_MS * 2))+ expect(onDwell).toHaveBeenCalledTimes(1)++ resetKey = 'load-2'+ rerender()+ act(() => jest.advanceTimersByTime(AUTO_MARK_READ_DWELL_MS * 2))+ expect(onDwell).toHaveBeenCalledTimes(2)+ })})diff --git a/frontend/src/lib/components/NotificationsMenu/useAutoMarkRead.ts b/frontend/src/lib/components/NotificationsMenu/useAutoMarkRead.tsindex 556f9ca982dc..a5de69ca4f3e 100644--- a/frontend/src/lib/components/NotificationsMenu/useAutoMarkRead.ts+++ b/frontend/src/lib/components/NotificationsMenu/useAutoMarkRead.ts@@ -9,11 +9,13 @@ export const AUTO_MARK_READ_DWELL_MS = 3000// barely peeking past the scroll edges don't get marked read.const VISIBILITY_THRESHOLD = 0.5+const NOT_FIRED = Symbol('not-fired')+/*** Marks a notification (or collapsed group) read once it has stayed continuously* visible in the viewport for `dwellMs`. Scrolling it out of view — or the browser* tab becoming hidden — resets the timer, so the dwell must be uninterrupted.- * `onDwell` fires at most once per mounted item.+ * `onDwell` fires at most once per mounted item, or once per `resetKey` value when one is passed.** `active` gates the whole thing: pass the item's unread state so an already-read* item is never observed, and pass false to disarm (e.g. an expanded group whose@@ -24,7 +26,8 @@ const VISIBILITY_THRESHOLD = 0.5export function useAutoMarkRead(active: boolean,onDwell: () => void,- dwellMs: number = AUTO_MARK_READ_DWELL_MS+ dwellMs: number = AUTO_MARK_READ_DWELL_MS,+ resetKey?: unknown): (node?: Element | null) => void {const { ref, inView } = useInView({ threshold: VISIBILITY_THRESHOLD, skip: !active })const { isVisible: pageVisible } = usePageVisibility()@@ -36,18 +39,18 @@ export function useAutoMarkRead(onDwellRef.current = onDwell})- const firedRef = useRef(false)+ const firedForRef = useRef<unknown>(NOT_FIRED)useEffect(() => {- if (!active || firedRef.current || !inView || !pageVisible) {+ if (!active || firedForRef.current === resetKey || !inView || !pageVisible) {return}const timer = setTimeout(() => {- firedRef.current = true+ firedForRef.current = resetKeyonDwellRef.current()}, dwellMs)return () => clearTimeout(timer)- }, [active, inView, pageVisible, dwellMs])+ }, [active, inView, pageVisible, dwellMs, resetKey])return ref}diff --git a/products/replay_vision/frontend/components/ObservationThumbnail.tsx b/products/replay_vision/frontend/components/ObservationThumbnail.tsxindex 5f01fbe92b4e..a6afba9c105d 100644--- a/products/replay_vision/frontend/components/ObservationThumbnail.tsx+++ b/products/replay_vision/frontend/components/ObservationThumbnail.tsx@@ -1,7 +1,9 @@+import clsx from 'clsx'import { useValues } from 'kea'import { useEffect, useRef, useState } from 'react'import { IconVideoCamera } from '@posthog/icons'+import { LemonSkeleton } from '@posthog/lemon-ui'import { teamLogic } from 'scenes/teamLogic'@@ -16,6 +18,8 @@ interface ObservationThumbnailProps {className?: string/** `small` (up to 480px wide) for posters at most 240px wide, so it stays sharp at 2x. Defaults to `large`. */size?: VisionObservationsThumbnailRetrieveSize+ /** A new value clears a failed load, so a caller that keeps the poster mounted across data reloads can retry it. */+ retryKey?: unknownchildren?: React.ReactNode}@@ -27,18 +31,20 @@ export function ObservationThumbnail({chapter,className,size = VisionObservationsThumbnailRetrieveSize.Large,+ retryKey,children,}: ObservationThumbnailProps): JSX.Element {const { currentTeamId } = useValues(teamLogic)const [attempt, setAttempt] = useState(0)const [failedId, setFailedId] = useState<string | null>(null)+ const [loadedSrc, setLoadedSrc] = useState<string | null>(null)const retryTimer = useRef<ReturnType<typeof setTimeout> | null>(null)// A row's instance is reused as the table pages, so a failure can outlive the observation it was for.useEffect(() => {setAttempt(0)setFailedId(null)- }, [observation.id, chapter])+ }, [observation.id, chapter, retryKey])useEffect(() => {return () => {@@ -62,6 +68,7 @@ export function ObservationThumbnail({? getVisionObservationsThumbnailRetrieveUrl(String(currentTeamId), observation.id, { chapter, size }): undefinedconst src = baseSrc !== undefined && attempt > 0 ? `${baseSrc}&retry=${attempt}` : baseSrc+ const loaded = loadedSrc === srcconst onError = (): void => {// One retry: the redirect target can blink, and the poster would stay blank for the whole mount.@@ -73,16 +80,23 @@ export function ObservationThumbnail({}return (- <div className={`relative aspect-video overflow-hidden rounded border bg-surface-secondary ${className ?? ''}`}>+ <div className={clsx('relative aspect-video overflow-hidden rounded border bg-surface-secondary', className)}>{src && (- <img- src={src}- alt=""- className="absolute inset-0 size-full object-cover"- loading="lazy"- decoding="async"- onError={onError}- />+ <>+ {!loaded && <LemonSkeleton className="absolute inset-0 size-full rounded-none" />}+ <img+ src={src}+ alt=""+ className={clsx(+ 'absolute inset-0 size-full object-cover transition-opacity duration-300 motion-reduce:transition-none',+ loaded ? 'opacity-100' : 'opacity-0'+ )}+ loading="lazy"+ decoding="async"+ onLoad={() => setLoadedSrc(src)}+ onError={onError}+ />+ </>)}<div className="absolute inset-0 flex items-center justify-center">{children ?? (!src && <IconVideoCamera className="text-xl text-tertiary" aria-hidden />)}diff --git a/products/replay_vision/frontend/replay_scanners/components/HighlightFeedCard.tsx b/products/replay_vision/frontend/replay_scanners/components/HighlightFeedCard.tsxindex e79d283fdfd9..549b881d9e0c 100644--- a/products/replay_vision/frontend/replay_scanners/components/HighlightFeedCard.tsx+++ b/products/replay_vision/frontend/replay_scanners/components/HighlightFeedCard.tsx@@ -265,9 +265,15 @@ export function highlightFeedRowTitle(observation: ReplayObservationApi): string*/export function HighlightFeedRow({ item, position }: HighlightFeedRowProps): JSX.Element {const { observation, reason } = item- const { feedLoad, dateFrom, categories } = useValues(highlightFeedLogic)+ const { feedLoad, feedReloading, dateFrom, categories } = useValues(highlightFeedLogic)const { cardSeen, dismissItem } = useActions(highlightFeedLogic)- const rowRef = useAutoMarkRead(true, () => cardSeen(item, position), CARD_SEEN_DWELL_MS)+ // Re-armed per feed load, so a card kept across a reload counts toward the new load.+ const rowRef = useAutoMarkRead(+ !feedReloading,+ () => cardSeen(item, position),+ CARD_SEEN_DWELL_MS,+ feedLoad?.feedLoadId+ )const result = readResult(observation)// Fall back to the result's own scanner_type when the snapshot is absent, like highlightCardHeadline.const scannerType =@@ -358,7 +364,11 @@ export function HighlightFeedRow({ item, position }: HighlightFeedRowProps): JSX{/* Clicks pass through the poster to the card's link, which sits beneath it. */}<div className="pointer-events-none relative overflow-hidden rounded-md border">{!observation.viewed && <span className="absolute inset-x-0 top-0 z-20 h-1 bg-accent" aria-hidden />}- <ObservationThumbnail observation={observation} className="rounded-none border-0" />+ <ObservationThumbnail+ observation={observation}+ className="rounded-none border-0"+ retryKey={feedLoad?.feedLoadId}+ />{!observation.viewed && <UnviewedObservationTag className="absolute top-2 left-2 z-10" />}</div><footer className="flex items-center gap-2">diff --git a/products/replay_vision/frontend/replay_scanners/components/HighlightFeedTab.tsx b/products/replay_vision/frontend/replay_scanners/components/HighlightFeedTab.tsxindex c7cfa83b8588..1d15d068c742 100644--- a/products/replay_vision/frontend/replay_scanners/components/HighlightFeedTab.tsx+++ b/products/replay_vision/frontend/replay_scanners/components/HighlightFeedTab.tsx@@ -17,11 +17,26 @@ const FEED_GRID = 'grid grid-cols-1 items-start gap-4 @[72rem]:grid-cols-2 @[120/** A single column stays card-sized rather than stretching one poster across the whole scene. */const FEED_WIDTH = 'mx-auto w-full max-w-3xl @[72rem]:max-w-none'+function CardSkeleton(): JSX.Element {+ return (+ <div className="flex flex-col gap-3 rounded-lg border bg-surface-primary p-4">+ <LemonSkeleton className="h-5 w-1/2" />+ <div className="flex flex-col gap-1.5">+ <LemonSkeleton className="h-4 w-full" />+ <LemonSkeleton className="h-4 w-3/4" />+ </div>+ <LemonSkeleton className="h-3 w-2/3" />+ <LemonSkeleton className="aspect-video w-full rounded-md" />+ <LemonSkeleton className="h-4 w-1/3" />+ </div>+ )+}+function FeedSkeleton(): JSX.Element {return (<div className={clsx(FEED_WIDTH, FEED_GRID)} aria-busy>{[0, 1, 2, 3].map((i) => (- <LemonSkeleton key={i} className="h-80 rounded-lg" />+ <CardSkeleton key={i} />))}</div>)@@ -53,7 +68,7 @@ function FeedEnd({ itemCount }: { itemCount: number }): JSX.Element | null {if (feedHasMore) {return (<div ref={ref} aria-busy>- <LemonSkeleton className="h-80 rounded-lg" />+ <CardSkeleton /></div>)}@@ -65,7 +80,7 @@ function FeedEnd({ itemCount }: { itemCount: number }): JSX.Element | null {}export function HighlightFeedTab(): JSX.Element {- const { feedItems, feedItemsLoading, feedReloading, feedLoad, feedFailed, dateFrom, emptyReason } =+ const { feedItems, feedItemsLoading, feedReloading, feedFailed, dateFrom, emptyReason } =useValues(highlightFeedLogic)const { loadFeed } = useActions(highlightFeedLogic)@@ -127,11 +142,8 @@ export function HighlightFeedTab(): JSX.Element {</p>)}{items.map((item, index) => (- <HighlightFeedRow- key={`${feedLoad?.feedLoadId}-${item.observation.id}`}- item={item}- position={index}- />+ // 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} /></div>diff --git a/products/replay_vision/frontend/replay_scanners/components/HighlightPickRow.tsx b/products/replay_vision/frontend/replay_scanners/components/HighlightPickRow.tsxindex 7c29b3c039b4..313f41791a77 100644--- a/products/replay_vision/frontend/replay_scanners/components/HighlightPickRow.tsx+++ b/products/replay_vision/frontend/replay_scanners/components/HighlightPickRow.tsx@@ -1,4 +1,4 @@-import { useActions } from 'kea'+import { useActions, useValues } from 'kea'import { LemonButton } from '@posthog/lemon-ui'@@ -25,9 +25,10 @@ interface HighlightPickRowProps {export function HighlightPickRow({ item, position, isActive, rank }: HighlightPickRowProps): JSX.Element {const { highlightPick, cardSeen } = useActions(highlightPicksLogic)+ const { picksLoad } = useValues(highlightPicksLogic)const { observation, reason } = itemconst { title, scannerName } = highlightPickSummary(observation)- const rowRef = useAutoMarkRead(true, () => cardSeen(item, position), CARD_SEEN_DWELL_MS)+ const rowRef = useAutoMarkRead(true, () => cardSeen(item, position), CARD_SEEN_DWELL_MS, picksLoad?.feedLoadId)return (<LemonButton@@ -43,7 +44,12 @@ export function HighlightPickRow({ item, position, isActive, rank }: HighlightPi><span className={cn('flex w-full min-w-0 items-center gap-3 py-1', observation.viewed && 'opacity-60')}><span className="relative w-28 shrink-0">- <ObservationThumbnail observation={observation} className="w-full" size="small" />+ <ObservationThumbnail+ observation={observation}+ className="w-full"+ size="small"+ retryKey={picksLoad?.feedLoadId}+ />{rank !== undefined && <HighlightPickRankBadge rank={rank} size="small" />}{!observation.viewed && (<span className="absolute inset-y-0 left-0 w-1 rounded-l bg-accent" aria-hidden />diff --git a/products/replay_vision/frontend/replay_scanners/components/HighlightPicksList.tsx b/products/replay_vision/frontend/replay_scanners/components/HighlightPicksList.tsxindex b3e4634aeadf..f9fe356863de 100644--- a/products/replay_vision/frontend/replay_scanners/components/HighlightPicksList.tsx+++ b/products/replay_vision/frontend/replay_scanners/components/HighlightPicksList.tsx@@ -16,7 +16,7 @@ const LIST_TOP_COUNT = 5export function HighlightPicksList(): JSX.Element {const picksLogic = useMountedLogic(highlightPicksLogic)- const { picks, picksLoad, picksLoading, picksFailed, activeSessionId } = useValues(picksLogic)+ const { picks, picksLoading, picksFailed, activeSessionId } = useValues(picksLogic)const { loadPicks, docsOpened } = useActions(picksLogic)const { startedScanner, burstDone, burstStalled } = useValues(highlightPicksStarterLogic(picksLogic.props))const burstActive = startedScanner !== null && (!burstDone || burstStalled)@@ -68,7 +68,7 @@ export function HighlightPicksList(): JSX.Element {<div className="flex flex-col gap-0.5 p-1">{picks.map((item, index) => (<HighlightPickRow- key={`${picksLoad?.feedLoadId}-${item.observation.id}`}+ key={item.observation.id}item={item}position={index}rank={index < LIST_TOP_COUNT ? index + 1 : undefined}