: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(replay-vision): reveal highlight cards with their posters and add chapter carousels (#126865)
Tue Haulunda9a9721be1a6
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex 5e21cd185a8a..daf02ae64b1e 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -14899,9 +14899,9 @@ snapshots:scenes-app-replay-vision--experiment-variants-waiting-for-observations--light:hash: v1.k794b7964.a1555dab4c0006028e8c240451c56c6aed5e31c8a8e68c893e3d6a07b562bba6.VYeYPsjZ_p0Rt4cbZzF7lbxjxurMjLXff9kJRsy49gUscenes-app-replay-vision--home-highlight-feed--dark:- hash: v1.k794b7964.ec0e951c9f685c26a91a3de09630807894d078b885b465b508fcdb78d5686754.J0OllnltGLUmsAB7kwoxpIHPzUA74zDs-B_hNDfcxPI+ hash: v1.k794b7964.bdefa12f8b1fd3c372d13eed61076a004f3bb4259d737bec9c09bd061fbd9359.DY7EZQgzN_Fsjqen3WwoyFAW4Wxli-3CTT1m7g6mfNgscenes-app-replay-vision--home-highlight-feed--light:- hash: v1.k794b7964.6b2f825b29d4078f079b7aeaeb0417f19f3ec0f10e84b9bdce737891d6c0eb43.qGm3jeKMbDPI4AjNjYGEGutCQjGXkGwjq6c5vAQEmTc+ hash: v1.k794b7964.2c2b41d8fdf182d402a7b63b53fdd49048b7cbd4638d34ee76ead066a537c653.579SnEEXXsj4wAf31vrZmwJv6CETMTgDOos_NgdrCwUscenes-app-replay-vision--home-highlight-feed-empty--dark:hash: v1.k794b7964.aa2a535d2294cab79f8090ef68ef9b8a74c930928c50c011df3eabb0ee7f455b.LrXy7q5Igei_2wtEYnbLH-pTAC_cBJSgkLKp5xAiNcQscenes-app-replay-vision--home-highlight-feed-empty--light:diff --git a/products/replay_vision/frontend/components/ObservationThumbnail.tsx b/products/replay_vision/frontend/components/ObservationThumbnail.tsxindex a6afba9c105d..2e55e4a90874 100644--- a/products/replay_vision/frontend/components/ObservationThumbnail.tsx+++ b/products/replay_vision/frontend/components/ObservationThumbnail.tsx@@ -25,6 +25,78 @@ interface ObservationThumbnailProps {const RETRY_DELAY_MS = 2000+/** Just under the endpoint's redirect cache, after which a remount refetches the poster. */+const DECODED_TTL_MS = 9 * 60 * 1000++const MAX_DECODED_ENTRIES = 500++const decodedThumbnails = new Map<string, number>()++const thumbnailPreloads = new Map<string, Promise<void>>()++function isDecoded(src: string): boolean {+ const decodedAt = decodedThumbnails.get(src)+ if (decodedAt === undefined) {+ return false+ }+ if (Date.now() - decodedAt < DECODED_TTL_MS) {+ return true+ }+ decodedThumbnails.delete(src)+ thumbnailPreloads.delete(src)+ return false+}++function pruneExpired(): void {+ for (const src of decodedThumbnails.keys()) {+ isDecoded(src)+ }+}++/** Downloads and decodes a poster ahead of its card, once per URL, and resolves even when the load fails. */+export function preloadObservationThumbnail(src: string): Promise<void> {+ if (decodedThumbnails.size > MAX_DECODED_ENTRIES) {+ pruneExpired()+ }+ isDecoded(src) // Drops an expired entry, so the preload below fetches again.+ let preload = thumbnailPreloads.get(src)+ if (!preload) {+ const image = new Image()+ image.src = src+ preload = image+ .decode()+ .then(() => {+ decodedThumbnails.set(src, Date.now())+ })+ .catch(() => {+ // A failed load is not cached, so a later visit tries the poster again.+ thumbnailPreloads.delete(src)+ })+ thumbnailPreloads.set(src, preload)+ }+ return preload+}++export function observationThumbnailSrc(+ teamId: number | null,+ observation: ReplayObservationApi,+ {+ chapter,+ size = VisionObservationsThumbnailRetrieveSize.Large,+ }: { chapter?: number; size?: VisionObservationsThumbnailRetrieveSize } = {}+): string | undefined {+ // Gated on the media the list response already carried, so a page of observations without one costs+ // no requests. The URL is the endpoint rather than the asset, so a re-render after a retry still resolves.+ // Optional at runtime, whatever the generated type says: fixtures and a response cached from before+ // the field existed both reach here, and a poster must not take the scene down with it.+ const hasThumbnail = (observation.media ?? []).some((entry) =>+ chapter === undefined ? entry.kind === 'thumbnail' : entry.kind === 'chapter' && entry.position === chapter+ )+ return hasThumbnail && teamId !== null+ ? getVisionObservationsThumbnailRetrieveUrl(String(teamId), observation.id, { chapter, size })+ : undefined+}+/** The frame the scan picked out of the session, as a 16:9 poster. */export function ObservationThumbnail({observation,@@ -56,19 +128,9 @@ export function ObservationThumbnail({const failed = failedId === observation.id- // Gated on the media the list response already carried, so a page of observations without one costs- // no requests. The URL is the endpoint rather than the asset, so a re-render after a retry still resolves.- // Optional at runtime, whatever the generated type says: fixtures and a response cached from before- // the field existed both reach here, and a poster must not take the scene down with it.- const hasThumbnail = (observation.media ?? []).some((entry) =>- chapter === undefined ? entry.kind === 'thumbnail' : entry.kind === 'chapter' && entry.position === chapter- )- const baseSrc =- hasThumbnail && currentTeamId !== null && !failed- ? getVisionObservationsThumbnailRetrieveUrl(String(currentTeamId), observation.id, { chapter, size })- : undefined+ const baseSrc = failed ? undefined : observationThumbnailSrc(currentTeamId, observation, { chapter, size })const src = baseSrc !== undefined && attempt > 0 ? `${baseSrc}&retry=${attempt}` : baseSrc- const loaded = loadedSrc === src+ const loaded = src !== undefined && (loadedSrc === src || isDecoded(src))const onError = (): void => {// One retry: the redirect target can blink, and the poster would stay blank for the whole mount.@@ -91,9 +153,12 @@ export function ObservationThumbnail({'absolute inset-0 size-full object-cover transition-opacity duration-300 motion-reduce:transition-none',loaded ? 'opacity-100' : 'opacity-0')}- loading="lazy"+ loading={loaded ? 'eager' : 'lazy'}decoding="async"- onLoad={() => setLoadedSrc(src)}+ onLoad={() => {+ decodedThumbnails.set(src, Date.now())+ setLoadedSrc(src)+ }}onError={onError}/></>diff --git a/products/replay_vision/frontend/replay_scanners/ReplayScannersScene.stories.tsx b/products/replay_vision/frontend/replay_scanners/ReplayScannersScene.stories.tsxindex 296788868ec7..2256a441705c 100644--- a/products/replay_vision/frontend/replay_scanners/ReplayScannersScene.stories.tsx+++ b/products/replay_vision/frontend/replay_scanners/ReplayScannersScene.stories.tsx@@ -1252,9 +1252,31 @@ export const HomeHighlightFeed: StoryObj = {confidence: 0.8,title: 'Plan limit blocked an export',summary: 'The export stopped at the plan limit and the user opened billing.',+ chapters: [+ { kind: 'activity', start_ms: 0, end_ms: 42000, title: 'Built a report' },+ {+ kind: 'activity',+ start_ms: 42000,+ end_ms: 97000,+ title: 'Hit the plan limit',+ },+ {+ kind: 'activity',+ start_ms: 97000,+ end_ms: 130000,+ title: 'Opened billing',+ },+ ],},signals_count: 0,},+ media: [0, 1, 2].map((position) => ({+ id: `00000000-0000-0000-0000-0000000000c${position}`,+ kind: 'chapter',+ position,+ asset_id: 4100 + position,+ video_start_ms: position * 40000,+ })),viewed: true,}),reason: { kind: 'embedding_pick', watch_category: 'revenue', similar_count: 0 },diff --git a/products/replay_vision/frontend/replay_scanners/components/HighlightFeedCard.tsx b/products/replay_vision/frontend/replay_scanners/components/HighlightFeedCard.tsxindex 704332072a97..929f18df14ee 100644--- a/products/replay_vision/frontend/replay_scanners/components/HighlightFeedCard.tsx+++ b/products/replay_vision/frontend/replay_scanners/components/HighlightFeedCard.tsx@@ -1,18 +1,27 @@+import clsx from 'clsx'import { useActions, useValues } from 'kea'import { combineUrl } from 'kea-router'+import { useCallback, useEffect, useMemo, useState } from 'react'+import { useInView } from 'react-intersection-observer'-import { IconFlag, IconPlayFilled } from '@posthog/icons'+import { IconChevronLeft, IconChevronRight, IconFlag, IconPlayFilled } from '@posthog/icons'import { LemonButton, LemonTag, Link, Tooltip } from '@posthog/lemon-ui'import { useAutoMarkRead } from 'lib/components/NotificationsMenu/useAutoMarkRead'import { TZLabel } from 'lib/components/TZLabel'import posthog from 'lib/posthog-typed'+import { inStorybookTestRunner } from 'lib/utils/dom'import { colonDelimitedDuration } from 'lib/utils/durations'import { pluralize } from 'lib/utils/strings'+import { teamLogic } from 'scenes/teamLogic'import { urls } from 'scenes/urls'import { readResult } from '../../components/ObservationCard'-import { ObservationThumbnail } from '../../components/ObservationThumbnail'+import {+ ObservationThumbnail,+ observationThumbnailSrc,+ preloadObservationThumbnail,+} from '../../components/ObservationThumbnail'import { scannerTypeIcon } from '../../components/ScannerTypeBadge'import { UnviewedObservationTag } from '../../components/UnviewedObservationTag'import type {@@ -24,6 +33,7 @@ import type {import { OBSERVATION_ORIGIN_PARAM, HIGHLIGHT_FEED_ORIGIN } from '../../utils/breadcrumbs'import { citedTextToPlainText } from '../../utils/citations'import { hasScannerPage, scannerLabel } from '../../utils/observation'+import { TimelineChapter, readChapters } from '../../utils/recordingTimeline'import { feedCategoriesParam, highlightFeedLogic } from '../highlightFeedLogic'import { CARD_SEEN_DWELL_MS, cardProperties } from '../highlightFeedTelemetry'import { SCANNER_TYPE_TAG_TYPE, ScannerType } from '../types'@@ -91,9 +101,12 @@ export function highlightStartSeconds(keyMomentMs: number | null): number {}/** The observation page. `t` is always set, so the player opens expanded, and `from` makes the back button return to the feed. */-export function highlightFeedObservationUrl(observation: ReplayObservationApi): string {+export function highlightFeedObservationUrl(observation: ReplayObservationApi, startMs?: number): string {return combineUrl(urls.replayVisionObservation(observation.id), {- t: highlightStartSeconds(observationKeyMomentMs(observation)),+ t:+ startMs === undefined+ ? highlightStartSeconds(observationKeyMomentMs(observation))+ : Math.floor(startMs / 1000),[OBSERVATION_ORIGIN_PARAM]: HIGHLIGHT_FEED_ORIGIN,}).url}@@ -142,10 +155,132 @@ export function highlightCardHeadline(return { title, body: rest ? { text: rest } : null }}+const CAROUSEL_ARROW =+ 'pointer-events-auto absolute top-1/2 z-10 flex size-8 -translate-y-1/2 cursor-pointer items-center justify-center rounded-full bg-black/60 text-lg text-white opacity-0 transition-opacity hover:bg-black/80 focus-visible:opacity-100 group-hover:opacity-100'++/** Slide 0 is the key-moment poster, so `slide - 1` indexes `chapters`. */+function ChapterCarousel({+ observation,+ chapters,+ slide,+ onSlide,+ retryKey,+}: {+ observation: ReplayObservationApi+ chapters: TimelineChapter[]+ slide: number+ onSlide: (slide: number) => void+ retryKey: unknown+}): JSX.Element {+ const { currentTeamId } = useValues(teamLogic)+ const [reached, setReached] = useState(1)+ useEffect(() => {+ setReached((previous) => Math.max(previous, slide + 1))+ const next = chapters[slide]+ const src = next && observationThumbnailSrc(currentTeamId, observation, { chapter: next.position })+ if (src) {+ void preloadObservationThumbnail(src)+ }+ }, [slide, chapters, currentTeamId, observation])+ const current = slide === 0 ? null : chapters[slide - 1]+ const go = (event: React.MouseEvent, target: number): void => {+ // The arrows sit over the card's link, so a press must not open the observation.+ event.preventDefault()+ event.stopPropagation()+ onSlide(target)+ }+ return (+ <>+ <div+ className="flex motion-safe:transition-transform motion-safe:duration-300 ease-out"+ // eslint-disable-next-line react/forbid-dom-props+ style={{ transform: `translateX(-${slide * 100}%)` }}+ >+ <div className="w-full shrink-0">+ <ObservationThumbnail+ observation={observation}+ className="rounded-none border-0"+ retryKey={retryKey}+ />+ </div>+ {chapters.map((chapter, index) => (+ <div key={chapter.position} className="w-full shrink-0">+ {index < reached ? (+ <ObservationThumbnail+ observation={observation}+ chapter={chapter.position}+ className="rounded-none border-0"+ />+ ) : (+ <div className="aspect-video bg-surface-secondary" />+ )}+ </div>+ ))}+ </div>+ {/* Disabled rather than removed at the ends, so a focused arrow keeps focus. */}+ <button+ type="button"+ className={clsx(CAROUSEL_ARROW, 'left-2', slide === 0 && 'invisible')}+ aria-label="Previous chapter"+ disabled={slide === 0}+ onClick={(event) => go(event, slide - 1)}+ >+ <IconChevronLeft />+ </button>+ <button+ type="button"+ className={clsx(CAROUSEL_ARROW, 'right-2', slide === chapters.length && 'invisible')}+ aria-label="Next chapter"+ disabled={slide === chapters.length}+ onClick={(event) => go(event, slide + 1)}+ >+ <IconChevronRight />+ </button>+ <div className="absolute inset-x-0 bottom-0 z-[5] flex flex-col gap-1.5 bg-gradient-to-t from-black/75 via-black/40 to-transparent px-2.5 pt-8 pb-2">+ <div className="flex min-w-0 items-baseline gap-1.5 text-xs text-white" aria-live="polite">+ {current ? (+ <>+ <span className="shrink-0 font-semibold tabular-nums">+ {colonDelimitedDuration(Math.floor(current.startMs / 1000), null)}+ </span>+ <span className="min-w-0 truncate">{current.title}</span>+ </>+ ) : (+ <span className="min-w-0 truncate">{pluralize(chapters.length, 'chapter')}</span>+ )}+ {slide > 0 && (+ <span className="ml-auto shrink-0 tabular-nums opacity-75">+ {slide}/{chapters.length}+ </span>+ )}+ </div>+ <div className="flex gap-1" aria-hidden>+ {chapters.map((chapter, index) => (+ <span+ key={chapter.position}+ className={clsx(+ 'h-1 flex-1 rounded-full transition-colors',+ index + 1 === slide ? 'bg-white' : 'bg-white/35'+ )}+ />+ ))}+ </div>+ </div>+ </>+ )+}++/** Entrance delays across a row, one per grid column, written out so Tailwind generates each class. */+const ROW_STAGGER = ['delay-0', 'delay-80', 'delay-160', 'delay-240']+const SKIP_RISE = inStorybookTestRunner()+interface HighlightFeedRowProps {item: HighlightFeedItemApi/** Zero-based place in the feed, captured so we can see how deep people read. */position: number+ columnIndex?: number+ /** The card belongs to the last result, kept on screen while a new one loads, so it must not count as seen. */+ stale?: boolean}function HighlightCardPerson({@@ -263,17 +398,36 @@ export function highlightFeedRowTitle(observation: ReplayObservationApi): string* picked, then the key-moment poster and a button that starts the player there. The whole card* opens the observation page.*/-export function HighlightFeedRow({ item, position }: HighlightFeedRowProps): JSX.Element {+export function HighlightFeedRow({+ item,+ position,+ columnIndex = 0,+ stale = false,+}: HighlightFeedRowProps): JSX.Element {const { observation, reason } = itemconst { feedLoad, feedReloading, dateFrom, categories } = useValues(highlightFeedLogic)const { cardSeen, dismissItem } = useActions(highlightFeedLogic)// Re-armed per feed load, so a card kept across a reload counts toward the new load.const rowRef = useAutoMarkRead(- !feedReloading,+ !feedReloading && !stale,() => cardSeen(item, position),CARD_SEEN_DWELL_MS,feedLoad?.feedLoadId)+ const { ref: inViewRef, inView } = useInView({+ triggerOnce: true,+ fallbackInView: true,+ // Snapshots capture the full page without scrolling, so cards there start in place and never observe.+ initialInView: SKIP_RISE,+ skip: SKIP_RISE,+ })+ const setRowRef = useCallback(+ (node: HTMLElement | null): void => {+ rowRef(node)+ inViewRef(node)+ },+ [rowRef, inViewRef]+ )const result = readResult(observation)// Fall back to the result's own scanner_type when the snapshot is absent, like highlightCardHeadline.const scannerType =@@ -296,19 +450,30 @@ export function HighlightFeedRow({ item, position }: HighlightFeedRowProps): JSXaffectedPeople: reason.kind === 'embedding_pick' ? (reason.affected_people ?? null) : null,cardContext: cardProperties(feedLoad, item, position, 'feed_tab'),}+ const chapters = useMemo(() => readChapters(observation).filter((chapter) => chapter.hasFrame), [observation])+ const [slide, setSlide] = useState(0)+ const currentChapter = slide === 0 ? null : (chapters[slide - 1] ?? null)+ const watchFromMs = currentChapter ? currentChapter.startMs : keyMomentMs+ const openUrl = currentChapter ? highlightFeedObservationUrl(observation, currentChapter.startMs) : observationUrlconst captureOpened = (): void => {posthog.capture('replay_vision_highlight_clip_clicked', {...cardProperties(feedLoad, item, position, 'feed_tab'),scanner_type: scannerType,has_key_moment: keyMomentMs !== null,target: 'observation',+ chapter_count: chapters.length,+ chapter_slide: slide,})}return (- // Fades in from part opacity at the poster's pace, so the slot never goes blank between placeholder and card.<article- ref={rowRef}- className="group relative flex min-w-0 flex-col gap-3 rounded-lg border bg-surface-primary p-4 hover:border-accent focus-within:border-accent ease-out starting:opacity-30 motion-safe:transition-opacity motion-safe:duration-300"+ ref={setRowRef}+ className={clsx(+ 'group relative flex min-w-0 flex-col gap-3 rounded-lg border bg-surface-primary p-4 hover:border-accent focus-within:border-accent',+ 'ease-out motion-safe:transition-[opacity,translate] motion-safe:duration-500',+ ROW_STAGGER[Math.min(columnIndex, ROW_STAGGER.length - 1)],+ !inView && 'motion-safe:translate-y-4 motion-safe:opacity-0'+ )}data-attr="vision-highlight-feed-row"><header className="flex min-w-0 items-center gap-2">@@ -333,7 +498,7 @@ export function HighlightFeedRow({ item, position }: HighlightFeedRowProps): JSX</header><div className="flex min-w-0 flex-col gap-1"><Link- to={observationUrl}+ to={openUrl}onClick={captureOpened}className="text-default after:absolute after:inset-0 after:content-['']"data-attr="vision-highlight-feed-row-open"@@ -363,13 +528,31 @@ export function HighlightFeedRow({ item, position }: HighlightFeedRowProps): JSX</p></div>{/* 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">+ <div className="pointer-events-none relative overflow-hidden rounded-md border bg-surface-primary">{!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"- retryKey={feedLoad?.feedLoadId}- />+ {chapters.length > 0 ? (+ <ChapterCarousel+ observation={observation}+ chapters={chapters}+ slide={slide}+ onSlide={(next) => {+ posthog.capture('replay_vision_highlight_chapter_slid', {+ ...cardProperties(feedLoad, item, position, 'feed_tab'),+ chapter_count: chapters.length,+ from_slide: slide,+ to_slide: next,+ })+ setSlide(next)+ }}+ retryKey={feedLoad?.feedLoadId}+ />+ ) : (+ <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">@@ -377,13 +560,13 @@ export function HighlightFeedRow({ item, position }: HighlightFeedRowProps): JSXtype="secondary"size="small"icon={<IconPlayFilled />}- to={observationUrl}+ to={openUrl}onClick={captureOpened}className="relative z-10"data-attr="vision-highlight-feed-row-watch">- {keyMomentMs !== null- ? `Watch from ${colonDelimitedDuration(Math.floor(keyMomentMs / 1000), null)}`+ {watchFromMs !== null+ ? `Watch from ${colonDelimitedDuration(Math.floor(watchFromMs / 1000), null)}`: 'Watch session'}</LemonButton>{similarCount > 0 && <HighlightFeedGroupToggle {...groupProps} />}diff --git a/products/replay_vision/frontend/replay_scanners/components/HighlightFeedTab.tsx b/products/replay_vision/frontend/replay_scanners/components/HighlightFeedTab.tsxindex 9fd09a8624b5..b7acc12df568 100644--- a/products/replay_vision/frontend/replay_scanners/components/HighlightFeedTab.tsx+++ b/products/replay_vision/frontend/replay_scanners/components/HighlightFeedTab.tsx@@ -1,12 +1,17 @@import clsx from 'clsx'import { useActions, useValues } from 'kea'-import { useEffect, useLayoutEffect, useState } from 'react'+import { useEffect, useLayoutEffect, useRef, useState } from 'react'import { useInView } from 'react-intersection-observer'import { LemonButton, LemonSkeleton, Spinner } from '@posthog/lemon-ui'+import { inStorybookTestRunner } from 'lib/utils/dom'+import { teamLogic } from 'scenes/teamLogic'++import { observationThumbnailSrc, preloadObservationThumbnail } from '../../components/ObservationThumbnail'+import { HighlightFeedItemApi } from '../../generated/api.schemas'import { isHighlightFeedBlock } from '../highlightFeedEmptyState'-import { feedWindowPhrase, highlightFeedLogic } from '../highlightFeedLogic'+import { FEED_PAGE_SIZE, feedWindowPhrase, highlightFeedLogic } from '../highlightFeedLogic'import { HighlightFeedBlockedBanner } from './HighlightFeedBlockedBanner'import { FILLER_REASON_KINDS, HighlightFeedRow } from './HighlightFeedCard'import { HighlightFeedEmptyState } from './HighlightFeedEmptyState'@@ -17,35 +22,86 @@ 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>- )-}+const POSTER_WAIT_CAP_MS = 10000+const SKIP_POSTER_WAIT = inStorybookTestRunner()-function FeedSkeleton(): JSX.Element {- return (- <div className={clsx(FEED_WIDTH, FEED_GRID)} aria-busy>- {[0, 1, 2, 3].map((i) => (- <CardSkeleton key={i} />- ))}- </div>- )+/** The cards whose posters are ready, so a card never shows an empty poster frame. */+function useRevealedItems(+ items: HighlightFeedItemApi[],+ feedLoadId: string | undefined+): { visible: HighlightFeedItemApi[]; pendingCount: number; holding: boolean } {+ const { currentTeamId } = useValues(teamLogic)+ const [revealed, setRevealed] = useState<Set<string>>(() => new Set())+ const [revealedLoadId, setRevealedLoadId] = useState<string | undefined>(undefined)+ const lastShown = useRef<HighlightFeedItemApi[]>([])+ // Each card's cap runs from when it first waited, so a re-run of the effect doesn't restart it.+ const deadlines = useRef(new Map<string, number>())+ const pendingItems = items.filter((item) => !revealed.has(item.observation.id))+ const pendingKey = pendingItems.map((item) => item.observation.id).join(',')+ // A filter change keeps the last result on screen until the new result's posters are ready.+ const holding = revealedLoadId !== undefined && feedLoadId !== revealedLoadId++ useEffect(() => {+ const reveal = (batch: HighlightFeedItemApi[]): void => {+ setRevealed((previous) => new Set([...previous, ...batch.map((item) => item.observation.id)]))+ setRevealedLoadId(feedLoadId)+ }+ if (pendingItems.length === 0) {+ reveal(pendingItems)+ return+ }+ // Each card shows once its own poster is ready, in feed order, so no gap opens above a slow poster.+ let cancelled = false+ let revealedUpTo = 0+ const ready = pendingItems.map(() => false)+ const timers: ReturnType<typeof setTimeout>[] = []+ pendingItems.forEach((item, index) => {+ const src = observationThumbnailSrc(currentTeamId, item.observation)+ const id = item.observation.id+ if (!deadlines.current.has(id)) {+ deadlines.current.set(id, Date.now() + POSTER_WAIT_CAP_MS)+ }+ const waitMs = Math.max(0, (deadlines.current.get(id) ?? 0) - Date.now())+ void Promise.race([+ src ? preloadObservationThumbnail(src) : Promise.resolve(),+ new Promise((resolve) => timers.push(setTimeout(resolve, waitMs))),+ ]).then(() => {+ ready[index] = true+ let end = revealedUpTo+ while (end < ready.length && ready[end]) {+ end+++ }+ if (!cancelled && end > revealedUpTo) {+ reveal(pendingItems.slice(revealedUpTo, end))+ revealedUpTo = end+ }+ })+ })+ return () => {+ cancelled = true+ timers.forEach(clearTimeout)+ }+ // eslint-disable-next-line react-hooks/exhaustive-deps+ }, [pendingKey, feedLoadId])++ // Cut at the first card still waiting, so a card kept from the last result can't show above a new one and shift later.+ const firstPending = items.findIndex((item) => !revealed.has(item.observation.id))+ // Snapshots wait for images on their own, and a capture mid-reveal would show a partial feed.+ const visible = SKIP_POSTER_WAIT+ ? items+ : holding+ ? lastShown.current+ : firstPending === -1+ ? items+ : items.slice(0, firstPending)+ lastShown.current = visible+ return { visible, pendingCount: SKIP_POSTER_WAIT ? 0 : pendingItems.length, holding: !SKIP_POSTER_WAIT && holding }}/** 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.+ // Measured before paint, so the first frame already staggers each row correctly.useLayoutEffect(() => {if (!element) {return@@ -61,18 +117,18 @@ function useGridColumns(element: HTMLElement | null): number {}/** 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: HTMLElement | null }): JSX.Element | null {+function FeedEnd({ itemCount, pendingCount }: { itemCount: number; pendingCount: number }): JSX.Element | null {const { feedHasMore, feedItemsLoading, feedMoreFailed } = useValues(highlightFeedLogic)- const columns = useGridColumns(grid)const { loadMoreFeed } = useActions(highlightFeedLogic)- // Starts the request a little before the end is on screen, so a steady scroll rarely waits.- const { ref, inView } = useInView({ rootMargin: '600px 0px' })+ // Starts the request well before the end is on screen, so a steady scroll rarely reaches the spinner.+ const { ref, inView } = useInView({ rootMargin: '4000px 0px' })useEffect(() => {- if (inView && feedHasMore && !feedItemsLoading && !feedMoreFailed) {+ // Cards waiting on posters keep the end in place, so stop at one page ahead rather than chain requests.+ if (inView && feedHasMore && !feedItemsLoading && !feedMoreFailed && pendingCount < FEED_PAGE_SIZE) {loadMoreFeed({})}- }, [inView, feedHasMore, feedItemsLoading, feedMoreFailed, loadMoreFeed])+ }, [inView, feedHasMore, feedItemsLoading, feedMoreFailed, pendingCount, loadMoreFeed])if (feedMoreFailed) {return (@@ -84,17 +140,11 @@ function FeedEnd({ itemCount, grid }: { itemCount: number; grid: HTMLElement | n</div>)}- if (feedHasMore) {- // Fills the rest of the last row, or a whole new row when it is full, where the next cards will land.- const placeholders = columns - (itemCount % columns)+ if (feedHasMore || pendingCount > 0) {return (- <>- {Array.from({ length: placeholders }, (_, index) => (- <div key={index} ref={index === 0 ? ref : undefined} aria-busy>- <CardSkeleton />- </div>- ))}- </>+ <div ref={ref} className="col-span-full flex h-16 items-center justify-center" aria-busy>+ <Spinner className="text-2xl text-secondary" />+ </div>)}return itemCount > 3 ? (@@ -105,13 +155,17 @@ function FeedEnd({ itemCount, grid }: { itemCount: number; grid: HTMLElement | n}export function HighlightFeedTab(): JSX.Element {- const { feedItems, feedItemsLoading, feedReloading, feedFailed, dateFrom, emptyReason } =+ const { feedItems, feedItemsLoading, feedReloading, feedFailed, dateFrom, emptyReason, feedLoad } =useValues(highlightFeedLogic)const { loadFeed } = useActions(highlightFeedLogic)// 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 ?? []+ const allItems = feedItems ?? []+ const { visible: items, pendingCount, holding } = useRevealedItems(allItems, feedLoad?.feedLoadId)+ const dimmed = feedReloading || holding+ const columns = useGridColumns(grid)+ const firstReveal = items.length === 0 && allItems.length > 0// Every card carrying a no-evidence reason means the window produced no findings. A feed that mixes a// finding with padding needs no explaining, so this stays off unless the whole feed is padding.const onlyFiller = items.length > 0 && items.every((item) => FILLER_REASON_KINDS.has(item.reason.kind))@@ -122,12 +176,14 @@ export function HighlightFeedTab(): JSX.Element {{!(emptyReason === 'no-scanners' && items.length === 0) && <HighlightFeedHeader className={FEED_WIDTH} />}{/* The first render comes before the mount starts the load, and a filter change keeps the lastresult until the new one lands, so an empty screen is only drawn from a finished load. */}- {(feedItems === null && !feedFailed) || (feedItemsLoading && items.length === 0) ? (- <FeedSkeleton />+ {(feedItems === null && !feedFailed) || (feedItemsLoading && items.length === 0) || firstReveal ? (+ <div className="flex justify-center py-32" role="status" aria-label="Loading the feed">+ <Spinner className="text-4xl text-secondary" />+ </div>) : (<div className={clsx(FEED_WIDTH, 'relative flex flex-col gap-4')}>{/* The last result stays while a filter change loads, dimmed so it doesn't read as the new one. */}- {feedReloading && (+ {dimmed && (<divclassName="pointer-events-none absolute inset-0 z-10 flex justify-center pt-32"data-attr="vision-highlight-feed-reloading"@@ -157,10 +213,10 @@ export function HighlightFeedTab(): JSX.Element {{items.length > 0 ? (<divref={setGrid}- className={clsx(FEED_GRID, 'transition-opacity', feedReloading && 'opacity-40')}- aria-busy={feedReloading}+ className={clsx(FEED_GRID, 'transition-opacity', dimmed && 'opacity-40')}+ aria-busy={dimmed}// `inert` keeps the stale cards out of keyboard reach; React 18 types lack the attribute.- {...(feedReloading ? { inert: '' } : {})}+ {...(dimmed ? { inert: '' } : {})}>{/* Three newest clips and nothing else is the answer, not a half-loaded feed, so say sorather than leaving the reader to infer it from three identical reason lines. */}@@ -171,9 +227,15 @@ export function HighlightFeedTab(): JSX.Element {)}{items.map((item, 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} />+ <HighlightFeedRow+ key={item.observation.id}+ item={item}+ position={index}+ columnIndex={index % columns}+ stale={dimmed}+ />))}- <FeedEnd itemCount={items.length} grid={grid} />+ <FeedEnd itemCount={items.length} pendingCount={pendingCount} /></div>) : feedFailed ? null : emptyReason ? (<div className="mx-auto w-full max-w-xl">diff --git a/products/replay_vision/frontend/utils/recordingTimeline.ts b/products/replay_vision/frontend/utils/recordingTimeline.tsindex ff21105f81a8..92ad5954f05e 100644--- a/products/replay_vision/frontend/utils/recordingTimeline.ts+++ b/products/replay_vision/frontend/utils/recordingTimeline.ts@@ -72,7 +72,7 @@ function readNumber(value: unknown): number | null {return typeof value === 'number' && Number.isFinite(value) ? value : null}-function readChapters(summary: ReplayObservationApi): TimelineChapter[] {+export function readChapters(summary: ReplayObservationApi): TimelineChapter[] {const raw = readModelOutput(summary)?.chaptersif (!Array.isArray(raw)) {return []