Skip to content

: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.

feat(replay): add a flagged follow live mode to the player (#117245)

HaynesPostHog99fdd25c3f9e
diff --git a/frontend/src/lib/constants.tsx b/frontend/src/lib/constants.tsx
index 508323eb38db..c9164b815d41 100644
--- a/frontend/src/lib/constants.tsx
+++ b/frontend/src/lib/constants.tsx
@@ -523,6 +523,7 @@ export const FEATURE_FLAGS = {
REPLAY_DEBUG_WITH_AI: 'replay-debug-with-ai', // owner: @clr182 #team-replay, player button that sends the recording JSON to PostHog AI
REPLAY_EVENT_MATCH_SCOPE: 'replay-event-match-scope', // owner: @pauldambra #team-replay, shows the "Match the whole session / only during recording" filter select
REPLAY_FILTERS_REDESIGN: 'replay-filters-redesign', // owner: @ksvat #team-replay
+ REPLAY_FOLLOW_LIVE: 'replay-follow-live', // owner: #team-replay, player toggle that keeps an ongoing recording playing as new data arrives
REPLAY_NEGATIVE_EVENT_FILTERS: 'replay-negative-event-filters', // owner: @arnohillen #team-replay
REPLAY_PLAYLIST_SURFACING_SCORE: 'replay-playlist-surfacing-score', // owner: #team-replay
REPLAY_RECOMMENDED_RECORDINGS_FILTER_EXPERIMENT: 'replay-recommended-recordings-filter-experiment', // owner: @arnohillen #team-replay multivariate=control,test
diff --git a/frontend/src/scenes/session-recordings/player/controller/FollowLive.tsx b/frontend/src/scenes/session-recordings/player/controller/FollowLive.tsx
new file mode 100644
index 000000000000..bbba3411823e
--- /dev/null
+++ b/frontend/src/scenes/session-recordings/player/controller/FollowLive.tsx
@@ -0,0 +1,34 @@
+import { useActions, useValues } from 'kea'
+
+import { IconLive } from '@posthog/icons'
+import { LemonButton } from '@posthog/lemon-ui'
+
+import { FEATURE_FLAGS } from 'lib/constants'
+import { cn } from 'lib/utils/css-classes'
+import { sessionRecordingPlayerLogic } from 'scenes/session-recordings/player/sessionRecordingPlayerLogic'
+
+export function FollowLive(): JSX.Element | null {
+ const { followLive, sessionPlayerMetaData, featureFlags } = useValues(sessionRecordingPlayerLogic)
+ const { setFollowLive } = useActions(sessionRecordingPlayerLogic)
+
+ if (!featureFlags[FEATURE_FLAGS.REPLAY_FOLLOW_LIVE] || !sessionPlayerMetaData?.ongoing) {
+ return null
+ }
+
+ return (
+ <LemonButton
+ size="xsmall"
+ active={followLive}
+ onClick={() => setFollowLive(!followLive)}
+ tooltip={
+ followLive
+ ? 'Stop following live'
+ : 'Follow live. New activity plays as it arrives, about 30 seconds behind.'
+ }
+ icon={<IconLive className={cn('text-xl', followLive && 'text-danger motion-safe:animate-pulse')} />}
+ data-attr={followLive ? 'recording-follow-live-stop' : 'recording-follow-live-start'}
+ >
+ Live
+ </LemonButton>
+ )
+}
diff --git a/frontend/src/scenes/session-recordings/player/controller/PlayerController.tsx b/frontend/src/scenes/session-recordings/player/controller/PlayerController.tsx
index 7fb3a2615d96..5547c47a78d6 100644
--- a/frontend/src/scenes/session-recordings/player/controller/PlayerController.tsx
+++ b/frontend/src/scenes/session-recordings/player/controller/PlayerController.tsx
@@ -24,6 +24,7 @@ import {
import { SessionPlayerState } from '~/types'
import { ClipRecording } from './ClipRecording'
+import { FollowLive } from './FollowLive'
import { SeekSkip, Timestamp } from './PlayerControllerTime'
import { Seekbar } from './Seekbar'
@@ -107,7 +108,8 @@ function SkipToStart(): JSX.Element {
function SkipToNext(): JSX.Element | null {
const timeoutRef = useRef<NodeJS.Timeout>()
- const { endReached, playNextAnimationInterrupted, playNextRecording } = useValues(sessionRecordingPlayerLogic)
+ const { endReached, followLive, playNextAnimationInterrupted, playNextRecording } =
+ useValues(sessionRecordingPlayerLogic)
const { reportNextRecordingTriggered, setPlayNextAnimationInterrupted } = useActions(sessionRecordingPlayerLogic)
const [animate, setAnimate] = useState(false)
@@ -136,7 +138,7 @@ function SkipToNext(): JSX.Element | null {
useEffect(() => {
clearTimeout(timeoutRef.current)
- if (endReached && playNextRecording) {
+ if (endReached && playNextRecording && !followLive) {
setAnimate(true)
setPlayNextAnimationInterrupted(false)
timeoutRef.current = setTimeout(() => {
@@ -145,7 +147,7 @@ function SkipToNext(): JSX.Element | null {
}
return () => clearTimeout(timeoutRef.current)
- }, [endReached, !!playNextRecording]) // eslint-disable-line react-hooks/exhaustive-deps
+ }, [endReached, followLive, !!playNextRecording]) // eslint-disable-line react-hooks/exhaustive-deps
useEffect(() => {
if (playNextAnimationInterrupted) {
@@ -241,6 +243,7 @@ export function PlayerController(): JSX.Element {
<SeekSkip direction="forward" />
<SkipToNext />
<Timestamp size={size} />
+ <FollowLive />
</div>
<div className="flex gap-0.5 justify-end items-center">
{ModesWithInteractions.includes(playerMode) && (
diff --git a/frontend/src/scenes/session-recordings/player/sessionRecordingDataCoordinatorLogic.test.ts b/frontend/src/scenes/session-recordings/player/sessionRecordingDataCoordinatorLogic.test.ts
index aad51e2b3d55..ec5d4db3eedf 100644
--- a/frontend/src/scenes/session-recordings/player/sessionRecordingDataCoordinatorLogic.test.ts
+++ b/frontend/src/scenes/session-recordings/player/sessionRecordingDataCoordinatorLogic.test.ts
@@ -8,14 +8,22 @@ import { processAllSnapshots, SnapshotSourceType, SourceKey, ViewportResolution
import { dayjs } from 'lib/dayjs'
import { convertSnapshotsByWindowId } from 'scenes/session-recordings/__mocks__/recording_snapshots'
-import { sessionRecordingDataCoordinatorLogic } from 'scenes/session-recordings/player/sessionRecordingDataCoordinatorLogic'
+import {
+ recordingDurationMs,
+ sessionRecordingDataCoordinatorLogic,
+} from 'scenes/session-recordings/player/sessionRecordingDataCoordinatorLogic'
import { sessionRecordingMetaLogic } from 'scenes/session-recordings/player/sessionRecordingMetaLogic'
import { teamLogic } from 'scenes/teamLogic'
import { userLogic } from 'scenes/userLogic'
import { resumeKeaLoadersErrors, silenceKeaLoadersErrors } from '~/initKea'
import { HogQLQueryResponse } from '~/queries/schema/schema-general'
-import { RecordingSnapshot, SessionRecordingSnapshotSource, SessionRecordingSnapshotSourceResponse } from '~/types'
+import {
+ RecordingSnapshot,
+ SessionRecordingSnapshotSource,
+ SessionRecordingSnapshotSourceResponse,
+ SessionRecordingType,
+} from '~/types'
import { sortedRecordingSnapshots } from '../__mocks__/recording_snapshots'
import { sessionRecordingEventUsageLogic } from '../sessionRecordingEventUsageLogic'
@@ -51,6 +59,22 @@ describe('sessionRecordingDataCoordinatorLogic', () => {
jest.spyOn(api, 'create')
})
+ describe('recordingDurationMs', () => {
+ const start = dayjs('2023-08-11T12:00:00Z')
+ const end = start.add(20, 'second')
+ const meta = { recording_duration: 10 } as SessionRecordingType
+
+ it.each([
+ { livePolling: false, expected: 10000 },
+ { livePolling: true, expected: 20000 },
+ ])(
+ 'caps a fully loaded recording at the metadata duration unless live: $livePolling',
+ ({ livePolling, expected }) => {
+ expect(recordingDurationMs(start, end, meta, true, livePolling)).toBe(expected)
+ }
+ )
+ })
+
describe('core assumptions', () => {
it('mounts other logics', async () => {
await expectLogic(logic).toMount([sessionRecordingEventUsageLogic, teamLogic, userLogic])
diff --git a/frontend/src/scenes/session-recordings/player/sessionRecordingDataCoordinatorLogic.ts b/frontend/src/scenes/session-recordings/player/sessionRecordingDataCoordinatorLogic.ts
index b7f05288e87d..108a79f1830e 100644
--- a/frontend/src/scenes/session-recordings/player/sessionRecordingDataCoordinatorLogic.ts
+++ b/frontend/src/scenes/session-recordings/player/sessionRecordingDataCoordinatorLogic.ts
@@ -234,6 +234,24 @@ export interface SessionRecordingDataCoordinatorLogicProps {
// ~5 minutes but measure from different events, so tune them together, not in isolation.
export const INGESTION_GRACE_PERIOD_MINUTES = 5
+export function recordingDurationMs(
+ start: Dayjs | null,
+ end: Dayjs | null,
+ meta: SessionRecordingType | null,
+ fullyLoaded: boolean,
+ livePolling: boolean
+): number {
+ if (!start || !end) {
+ return 0
+ }
+ const snapshotDuration = end.diff(start)
+ // metadata is not reloaded while live, so its duration falls behind the new snapshots
+ if (fullyLoaded && meta?.recording_duration && !livePolling) {
+ return Math.min(snapshotDuration, meta.recording_duration * 1000)
+ }
+ return snapshotDuration
+}
+
export function isWithinIngestionGracePeriod(start: Dayjs | null): boolean {
return start != null && now().diff(start, 'minute') <= INGESTION_GRACE_PERIOD_MINUTES
}
@@ -266,6 +284,7 @@ export interface sessionRecordingDataCoordinatorLogicValues {
snapshotsLoading: boolean // metaLogic
trackedWindow: number | null // metaLogic
uuidToIndex: Record<string, number> // metaLogic
+ livePolling: boolean // snapLogic
snapshotStore: SnapshotStore // snapLogic
sourceLoadingStates: SourceLoadingState[] // snapLogic
storeVersion: number // snapLogic
@@ -491,7 +510,8 @@ export interface sessionRecordingDataCoordinatorLogicMeta {
start: Dayjs | null,
end: Dayjs | null,
sessionPlayerMetaData: SessionRecordingType | null,
- fullyLoaded: boolean
+ fullyLoaded: boolean,
+ livePolling: boolean
) => number
segments: (
snapshots: import('@posthog/replay-shared').RecordingSnapshot[],
@@ -653,7 +673,7 @@ export const sessionRecordingDataCoordinatorLogic = kea<sessionRecordingDataCoor
'sessionNotebookCommentsLoading',
],
snapLogic,
- ['snapshotStore', 'storeVersion', 'sourceLoadingStates'],
+ ['snapshotStore', 'storeVersion', 'sourceLoadingStates', 'livePolling'],
],
}
}),
@@ -892,22 +912,14 @@ export const sessionRecordingDataCoordinatorLogic = kea<sessionRecordingDataCoor
],
durationMs: [
- (s) => [s.start, s.end, s.sessionPlayerMetaData, s.fullyLoaded],
+ (s) => [s.start, s.end, s.sessionPlayerMetaData, s.fullyLoaded, s.livePolling],
(
start: Dayjs | null,
end: Dayjs | null,
meta: SessionRecordingType | null,
- fullyLoaded: boolean
- ): number => {
- if (!start || !end) {
- return 0
- }
- const snapshotDuration = end.diff(start)
- if (fullyLoaded && meta?.recording_duration) {
- return Math.min(snapshotDuration, meta.recording_duration * 1000)
- }
- return snapshotDuration
- },
+ fullyLoaded: boolean,
+ livePolling: boolean
+ ): number => recordingDurationMs(start, end, meta, fullyLoaded, livePolling),
],
segments: [
diff --git a/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.ts b/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.ts
index b842b2847fc5..95b809816a68 100644
--- a/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.ts
+++ b/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.ts
@@ -125,6 +125,7 @@ export const ONE_SECOND_MS = 1000
// shows its error.
const MAX_PLAYER_FRAME_LOAD_RETRIES = 2
const PLAYER_FRAME_RETRY_DELAY_MS = 1000
+const LIVE_EDGE_OFFSET_MS = 5000
export type { ResourceErrorDetails, GroupedAssetErrors, DoctorDiagnostics } from './utils/asset-error-grouping'
@@ -813,6 +814,8 @@ export interface sessionRecordingPlayerLogicValues {
endReached: boolean
errorCount: number
explorerMode: SessionRecordingPlayerExplorerProps | null
+ followLive: boolean
+ followLiveRequested: boolean
forceShowPlayerChrome: boolean
fromRRWebPlayerTime: (time?: number | undefined) => number | undefined
hasLateFullSnapshot: boolean
@@ -832,6 +835,7 @@ export interface sessionRecordingPlayerLogicValues {
jumpTimeMs: number
leadingRecoveryTimestamp: number | null
leadingUnplayableMs: number
+ liveWaitingForData: boolean
logicProps: SessionRecordingPlayerLogicProps
maskingWindow: boolean
matchingEventSkipTarget: MatchingEventSkipTarget
@@ -1011,6 +1015,9 @@ export interface sessionRecordingPlayerLogicActions {
retrySnapshotLoading: () => {
value: true
} // snapshotDataLogic
+ setLivePolling: (enabled: boolean) => {
+ enabled: boolean
+ } // snapshotDataLogic
setPlayerActive: (active: boolean) => {
active: boolean
} // snapshotDataLogic
@@ -1189,6 +1196,9 @@ export interface sessionRecordingPlayerLogicActions {
setExplorerProps: (props: SessionRecordingPlayerExplorerProps | null) => {
props: SessionRecordingPlayerExplorerProps | null
}
+ setFollowLive: (followLive: boolean) => {
+ followLive: boolean
+ }
setIsCommenting: (isCommenting: boolean) => {
isCommenting: boolean
}
@@ -1308,6 +1318,7 @@ export interface sessionRecordingPlayerLogicActions {
export interface sessionRecordingPlayerLogicMeta {
key: string
__keaTypeGenInternalSelectorTypes: {
+ followLive: (followLiveRequested: boolean, featureFlags: FeatureFlagsSet) => boolean
playerFrameDocumentFailed: (playerFrameLoadFailures: number, playerFrameLoadStopped: boolean) => boolean
sessionRecordingId: (sessionRecordingId: string) => string
logicProps: (arg: any) => SessionRecordingPlayerLogicProps
@@ -1547,6 +1558,7 @@ export const sessionRecordingPlayerLogic = kea<sessionRecordingPlayerLogicType>(
'setTargetTimestamp',
'updatePlaybackPosition',
'setPlayerActive',
+ 'setLivePolling',
],
sessionRecordingDataCoordinatorLogic(props),
['loadRecordingData', 'loadRecordingMetaSuccess', 'snapshotProcessingFailed'],
@@ -1576,6 +1588,7 @@ export const sessionRecordingPlayerLogic = kea<sessionRecordingPlayerLogicType>(
setPlay: true,
setPause: true,
setEndReached: (reached: boolean = true) => ({ reached }),
+ setFollowLive: (followLive: boolean) => ({ followLive }),
startBuffer: true,
endBuffer: true,
startScrub: true,
@@ -1862,6 +1875,23 @@ export const sessionRecordingPlayerLogic = kea<sessionRecordingPlayerLogicType>(
initializePlayerFromStart: () => null,
},
],
+ followLiveRequested: [
+ false,
+ {
+ setFollowLive: (_, { followLive }) => followLive,
+ },
+ ],
+ // separate from endReached, which replayer re-init clears, so Live still resumes after a tab switch
+ liveWaitingForData: [
+ false,
+ {
+ setEndReached: (_, { reached }) => reached,
+ setFollowLive: () => false,
+ setPlay: () => false,
+ openExplorer: () => false,
+ setIsCommenting: (state, { isCommenting }) => (isCommenting ? false : state),
+ },
+ ],
endReached: [
false,
{
@@ -1919,6 +1949,11 @@ export const sessionRecordingPlayerLogic = kea<sessionRecordingPlayerLogicType>(
],
})),
selectors({
+ followLive: [
+ (s) => [s.followLiveRequested, s.featureFlags],
+ (requested: boolean, featureFlags: FeatureFlagsSet): boolean =>
+ requested && !!featureFlags[FEATURE_FLAGS.REPLAY_FOLLOW_LIVE],
+ ],
// Nothing resets this, because the frame's src stops changing once the retries run out.
playerFrameDocumentFailed: [
(s) => [s.playerFrameLoadFailures, s.playerFrameLoadStopped],
@@ -3321,6 +3356,20 @@ export const sessionRecordingPlayerLogic = kea<sessionRecordingPlayerLogicType>(
actions.syncPlayerSpeed() // hotfix: speed changes on player state change
values.player?.replayer?.pause()
},
+ setFollowLive: ({ followLive }) => {
+ if (!values.featureFlags[FEATURE_FLAGS.REPLAY_FOLLOW_LIVE]) {
+ return
+ }
+ posthog.capture('recording follow live toggled', { follow_live: followLive })
+ actions.setLivePolling(followLive)
+ const end = values.sessionPlayerData.end?.valueOf()
+ if (followLive && end) {
+ const start = values.sessionPlayerData.start?.valueOf() ?? end
+ actions.setCurrentTimestamp(Math.max(start, end - LIVE_EDGE_OFFSET_MS))
+ actions.setEndReached(false)
+ actions.setPlay()
+ }
+ },
setEndReached: ({ reached }) => {
if (reached) {
actions.endBuffer()
@@ -3948,6 +3997,13 @@ export const sessionRecordingPlayerLogic = kea<sessionRecordingPlayerLogicType>(
if (hasSnapshotChanges) {
actions.syncSnapshotsWithPlayer()
+
+ const endGrew = (value?.end?.valueOf() ?? 0) > (oldValue?.end?.valueOf() ?? 0)
+ if (values.followLive && values.liveWaitingForData && endGrew) {
+ // resume from the old end, not from the start as setPlay does after endReached
+ actions.setEndReached(false)
+ actions.setPlay()
+ }
}
},
timestampChangeTracking: (value) => {
diff --git a/frontend/src/scenes/session-recordings/player/snapshotDataLogic.test.ts b/frontend/src/scenes/session-recordings/player/snapshotDataLogic.test.ts
index 2b73fc971a29..f7d70d419973 100644
--- a/frontend/src/scenes/session-recordings/player/snapshotDataLogic.test.ts
+++ b/frontend/src/scenes/session-recordings/player/snapshotDataLogic.test.ts
@@ -4,6 +4,8 @@ import { EventType, IncrementalSource, NodeType, mutationData } from 'posthog-js
import { chunkMutationSnapshot, MUTATION_CHUNK_SIZE } from '@posthog/replay-shared'
import { ApiError, RecordingDeletedError } from 'lib/api'
+import { FEATURE_FLAGS } from 'lib/constants'
+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { encodedWebSnapshotData } from 'scenes/session-recordings/player/__mocks__/encoded-snapshot-data'
import { parseEncodedSnapshots } from 'scenes/session-recordings/player/snapshot-processing/process-all-snapshots'
@@ -39,6 +41,33 @@ describe('snapshotDataLogic', () => {
logic.mount()
})
+ describe('follow live flag gate', () => {
+ it.each([
+ { flagOn: false, polls: false },
+ { flagOn: true, polls: true },
+ ])(
+ 'with the flag on: $flagOn, a live request polls before all sources load: $polls',
+ async ({ flagOn, polls }) => {
+ featureFlagLogic.actions.setFeatureFlags([], { [FEATURE_FLAGS.REPLAY_FOLLOW_LIVE]: flagOn })
+ const pollingLogic = snapshotDataLogic({
+ sessionRecordingId: 'live-gate',
+ blobV2PollingDisabled: false,
+ })
+ pollingLogic.mount()
+
+ const expectation = expectLogic(pollingLogic, () => pollingLogic.actions.setLivePolling(true))
+ if (polls) {
+ await expectation.toDispatchActions(['startPolling'])
+ } else {
+ await expectation.toNotHaveDispatchedActions(['startPolling'])
+ }
+ expect(pollingLogic.values.livePolling).toBe(flagOn)
+
+ pollingLogic.unmount()
+ }
+ )
+ })
+
describe('recording deleted selectors', () => {
it('isRecordingDeleted is false when no error', () => {
expect(logic.values.isRecordingDeleted).toBe(false)
diff --git a/frontend/src/scenes/session-recordings/player/snapshotDataLogic.tsx b/frontend/src/scenes/session-recordings/player/snapshotDataLogic.tsx
index 4036edddb0b7..ea0469730204 100644
--- a/frontend/src/scenes/session-recordings/player/snapshotDataLogic.tsx
+++ b/frontend/src/scenes/session-recordings/player/snapshotDataLogic.tsx
@@ -21,7 +21,9 @@ import { keyForSource } from '@posthog/replay-shared'
import { SnapshotSourceType, SnapshotStore, SourceLoadingState } from '@posthog/replay-shared'
import api, { ApiError, RecordingDeletedError } from 'lib/api'
+import { FEATURE_FLAGS } from 'lib/constants'
import 'lib/dayjs'
+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { parseEncodedSnapshots } from 'scenes/session-recordings/player/snapshot-processing/process-all-snapshots'
import { windowIdRegistryLogic } from 'scenes/session-recordings/player/windowIdRegistryLogic'
@@ -33,11 +35,13 @@ import {
SessionRecordingSnapshotSourceResponse,
} from '~/types'
+import type { FeatureFlagsSet } from '../../../lib/logic/featureFlagLogic'
import { SeekTarget, planNextBatch } from './snapshot-store/planNextBatch'
const DEFAULT_V2_POLLING_INTERVAL_MS: number = 10000
const MAX_V2_POLLING_INTERVAL_MS = 60000
const POLLING_INACTIVITY_TIMEOUT_MS = 5 * MAX_V2_POLLING_INTERVAL_MS
+const LIVE_POLLING_INTERVAL_MS = 5000
export interface SnapshotLogicProps {
sessionRecordingId: SessionRecordingId
@@ -48,6 +52,7 @@ export interface SnapshotLogicProps {
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface snapshotDataLogicValues {
+ featureFlags: FeatureFlagsSet // featureFlagLogic
getWindowId: (uuid: string | undefined) => number | undefined // windowIdRegistryLogic
uuidToIndex: Record<string, number> // windowIdRegistryLogic
allSourcesLoaded: boolean
@@ -55,6 +60,8 @@ export interface snapshotDataLogicValues {
isPolling: boolean
isRecordingDeleted: boolean
isSnapshotUnauthorized: boolean
+ livePolling: boolean
+ livePollingRequested: boolean
loadAllMode: boolean
loadingSources: Pick<SessionRecordingSnapshotSource, 'blob_key' | 'end_timestamp' | 'source' | 'start_timestamp'>[]
pollingInterval: number
@@ -156,6 +163,9 @@ export interface snapshotDataLogicActions {
retrySnapshotLoading: () => {
value: true
}
+ setLivePolling: (enabled: boolean) => {
+ enabled: boolean
+ }
setPlayerActive: (active: boolean) => {
active: boolean
}
@@ -200,6 +210,7 @@ export interface snapshotDataLogicActions {
export interface snapshotDataLogicMeta {
key: string
__keaTypeGenInternalSelectorTypes: {
+ livePolling: (livePollingRequested: boolean, featureFlags: FeatureFlagsSet) => boolean
snapshotsLoading: (
snapshotSourcesLoading: boolean,
snapshotsForSourceLoading: boolean,
@@ -248,6 +259,8 @@ export const snapshotDataLogic = kea<snapshotDataLogicType>([
values: [
windowIdRegistryLogic({ sessionRecordingId: props.sessionRecordingId }),
['uuidToIndex', 'getWindowId'],
+ featureFlagLogic,
+ ['featureFlags'],
],
})),
actions({
@@ -268,6 +281,7 @@ export const snapshotDataLogic = kea<snapshotDataLogicType>([
maybeStartPolling: true,
startPolling: true,
stopPolling: true,
+ setLivePolling: (enabled: boolean) => ({ enabled }),
setPollingInterval: (intervalMs: number) => ({ intervalMs }),
resetPollingInterval: true,
setTargetTimestamp: (timestamp: number | null, windowId?: number) => ({ timestamp, windowId }),
@@ -319,6 +333,12 @@ export const snapshotDataLogic = kea<snapshotDataLogicType>([
resetPollingInterval: () => DEFAULT_V2_POLLING_INTERVAL_MS,
},
],
+ livePollingRequested: [
+ false,
+ {
+ setLivePolling: (_, { enabled }) => enabled,
+ },
+ ],
isPolling: [
false,
{
@@ -620,7 +640,9 @@ export const snapshotDataLogic = kea<snapshotDataLogicType>([
if (!props.sessionRecordingId) {
return
}
- if (props.blobV2PollingDisabled || !values.allSourcesLoaded || values.isPolling || document.hidden) {
+ // a live jump to the end leaves earlier sources unloaded, and new blocks must still arrive
+ const waitingOnSources = !values.allSourcesLoaded && !values.livePolling
+ if (props.blobV2PollingDisabled || waitingOnSources || values.isPolling || document.hidden) {
return
}
@@ -632,7 +654,16 @@ export const snapshotDataLogic = kea<snapshotDataLogicType>([
}
actions.startPolling()
- actions.loadSnapshotSources(values.pollingInterval)
+ actions.loadSnapshotSources(values.livePolling ? LIVE_POLLING_INTERVAL_MS : values.pollingInterval)
+ },
+
+ setLivePolling: () => {
+ if (values.livePolling) {
+ cache.lastSourcesChangeTime = Date.now()
+ // replaces a poll that may be waiting out a long backoff
+ actions.stopPolling()
+ actions.maybeStartPolling()
+ }
},
loadNextSnapshotSource: async (_, breakpoint) => {
@@ -671,6 +702,11 @@ export const snapshotDataLogic = kea<snapshotDataLogicType>([
},
})),
selectors(({ cache }) => ({
+ livePolling: [
+ (s) => [s.livePollingRequested, s.featureFlags],
+ (requested: boolean, featureFlags: FeatureFlagsSet): boolean =>
+ requested && !!featureFlags[FEATURE_FLAGS.REPLAY_FOLLOW_LIVE],
+ ],
snapshotsLoading: [
(s) => [s.snapshotSourcesLoading, s.snapshotsForSourceLoading, s.storeVersion],
(snapshotSourcesLoading: boolean, snapshotsForSourceLoading: boolean, _storeVersion: number): boolean => {