: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): stop search results crashing when a recording expires (#107308)
posthog[bot]462a2f5c74d6
diff --git a/products/replay_vision/frontend/search/SearchResults.test.tsx b/products/replay_vision/frontend/search/SearchResults.test.tsxnew file mode 100644index 000000000000..8f53f2377da4--- /dev/null+++ b/products/replay_vision/frontend/search/SearchResults.test.tsx@@ -0,0 +1,65 @@+import { act, render, waitFor } from '@testing-library/react'+import { router } from 'kea-router'++import { urls } from 'scenes/urls'++import { useMocks } from '~/mocks/jest'+import { initKeaTests } from '~/test/init'++import type { ObservationSearchResultApi } from '../generated/api.schemas'+import { type ResultsView, observationSearchLogic } from './observationSearchLogic'+import { SearchResults } from './SearchResults'++describe('SearchResults', () => {+ const results = [+ {+ observation: { id: 'obs-1', session_id: 's-expired', created_at: '2026-01-01T00:00:00Z' },+ matched_content: 'User rage-clicked the coupon field',+ distance: 0.1,+ },+ ] as unknown as ObservationSearchResultApi[]++ // The availability check resolves after the first render, so a result goes from playable to expired+ // while mounted. Hooks that only run on one side of that branch crash the whole view.+ it.each<ResultsView>(['grid', 'list'])(+ 'marks a result expired after it first rendered as playable in the %s view',+ async (view) => {+ let releaseRecordings: () => void = () => {}+ const recordingsReleased = new Promise<void>((resolve) => {+ releaseRecordings = resolve+ })+ useMocks({+ get: {+ '/api/environments/:team_id/session_recordings': async () => {+ await recordingsReleased+ return [200, { results: [], has_next: false }]+ },+ },+ })+ initKeaTests()+ router.actions.push(urls.replayVision(), { tab: 'search' })+ const logicProps = { teamId: 1, userId: 'user-1' }+ const logic = observationSearchLogic(logicProps)+ logic.mount()+ logic.actions.setView(view)++ const { container, unmount } = render(<SearchResults {...logicProps} />)+ act(() => logic.actions.searchSuccess(results, 'confused users', false))++ expect(container.querySelector('[data-attr="vision-search-result-watch"]')).not.toBeNull()+ expect(container.querySelector('[data-attr="vision-recording-expired-tag"]')).toBeNull()++ await act(async () => {+ releaseRecordings()+ await recordingsReleased+ })++ await waitFor(() =>+ expect(container.querySelector('[data-attr="vision-recording-expired-tag"]')).not.toBeNull()+ )+ expect(container.querySelector('[data-attr="vision-search-result-watch"]')).toBeNull()+ unmount()+ logic.unmount()+ }+ )+})diff --git a/products/replay_vision/frontend/search/SearchResults.tsx b/products/replay_vision/frontend/search/SearchResults.tsxindex 94aa1c0b32da..f6284832cdb4 100644--- a/products/replay_vision/frontend/search/SearchResults.tsx+++ b/products/replay_vision/frontend/search/SearchResults.tsx@@ -34,7 +34,7 @@ import { snippetSegments } from './snippetSegments'function watchMomentUrl(observation: ReplayObservationApi,citedMs: number | null,- { location, searchParams, hashParams }: typeof router.values+ { location, searchParams, hashParams }: Pick<typeof router.values, 'location' | 'searchParams' | 'hashParams'>): string {return combineUrl(location.pathname,@@ -66,7 +66,8 @@ function WatchLink({compact?: booleanonOpen: (target: SearchResultTarget) => void}): JSX.Element {- const routerValues = useValues(router)+ // useValues returns lazy getters that each call a hook, so read them before the expired branch.+ const { location, searchParams, hashParams } = useValues(router)const citedMs = firstCitedTimestampMs(observation)/* The card clips its own corners and draws its own edge, so the poster goes edge to edge there. */const thumbnail = (@@ -98,7 +99,7 @@ function WatchLink({}return (<Link- to={watchMomentUrl(observation, citedMs, routerValues)}+ to={watchMomentUrl(observation, citedMs, { location, searchParams, hashParams })}onClick={() => onOpen('watch')}className={clsx('relative block text-primary group', compact && 'w-28')}data-attr="vision-search-result-watch"