📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
Add replay loading indicator
Blue Mouse5dbaf80c61bc
diff --git a/web/app/pages/Project/tabs/Sessions/SessionReplayModal.tsx b/web/app/pages/Project/tabs/Sessions/SessionReplayModal.tsxindex 2f17fa679..821246333 100644--- a/web/app/pages/Project/tabs/Sessions/SessionReplayModal.tsx+++ b/web/app/pages/Project/tabs/Sessions/SessionReplayModal.tsx@@ -37,7 +37,7 @@ import {useState,} from 'react'import { useTranslation } from 'react-i18next'-import { Replayer } from 'dom-player'+import { Replayer, ReplayerEvents } from 'dom-player'import type { eventWithTime } from 'dom-player'import './replayPlayer.css'import { toast } from 'sonner'@@ -87,6 +87,7 @@ const DEFAULT_REPLAY_VIEWPORT = { width: 1280, height: 720 }const XHTML_XMLNS = 'http://www.w3.org/1999/xhtml'const SCREENSHOT_ASSET_WAIT_MS = 1000const EXPORT_POLL_INTERVAL_MS = 2000+const PLAYER_READY_FALLBACK_MS = 8000type ReplayEvent = Omit<eventWithTime, 'data'> & {data?: Record<string, any>@@ -1043,6 +1044,7 @@ const SessionReplayModal = ({const [duration, setDuration] = useState(0)const [currentTime, setCurrentTime] = useState(0)const [isPlaying, setIsPlaying] = useState(false)+ const [isPlayerReady, setIsPlayerReady] = useState(false)const [speed, setSpeed] = useState(1)const [showTimeline, setShowTimeline] = useState(false)const [isFullscreen, setIsFullscreen] = useState(false)@@ -1150,7 +1152,9 @@ const SessionReplayModal = ({}, [language, replayStartDateTimestamp, timeFormat, timezone])const shouldShowPreview =Boolean(hoverPreview) && hasEvents && !error && duration > 0- const canControlReplay = hasEvents && !error && duration > 0+ const shouldShowReplayLoading =+ isPreparing || isLoading || (hasEvents && !error && !isPlayerReady)+ const canControlReplay = hasEvents && !error && duration > 0 && isPlayerReadyconst isReplayExporting =isExportStarting ||exportStatus?.status === 'queued' ||@@ -1160,11 +1164,12 @@ const SessionReplayModal = ({Math.min(100, Math.round(exportStatus?.progress || 0)),)const shouldShowControls =- !isPlaying ||- isPlayerHovered ||- isControlsFocused ||- settingsOpen ||- !canControlReplay+ !shouldShowReplayLoading &&+ (!isPlaying ||+ isPlayerHovered ||+ isControlsFocused ||+ settingsOpen ||+ !canControlReplay)const speedLabel =speed === 1 ? t('project.sessionReplay.normalSpeed') : `${speed}×`const selectedReplayId = replayId || replay?.replayId@@ -1225,6 +1230,7 @@ const SessionReplayModal = ({setDuration(0)setCurrentTime(0)setIsPlaying(false)+ setIsPlayerReady(false)setHoverPreview(null)setIsPlayerHovered(false)setIsControlsFocused(false)@@ -1262,14 +1268,32 @@ const SessionReplayModal = ({const root = playerRoot.currentroot.innerHTML = ''setIsPlaying(false)+ setIsPlayerReady(false)setCurrentTime(0)+ let instance: Replayer | null = null+ let readyFallback: number | null = null+ let readyRaf: number | null = null++ const markPlayerReady = () => {+ if (readyFallback) {+ window.clearTimeout(readyFallback)+ readyFallback = null+ }++ if (readyRaf) return+ readyRaf = window.requestAnimationFrame(() => {+ readyRaf = null+ setIsPlayerReady(true)+ })+ }try {- const instance = new Replayer(events as eventWithTime[], {+ instance = new Replayer(events as eventWithTime[], {root,speed: speedRef.current,insertStyleRules: ['html, body { background-color: #fff; }'],})+ instance.on(ReplayerEvents.FullsnapshotRebuilded, markPlayerReady)replayer.current = instanceconst metadata = instance.getMetaData()const fallbackDuration =@@ -1277,6 +1301,15 @@ const SessionReplayModal = ({? getTimestamp(events[events.length - 1]) - getTimestamp(events[0]): 0setDuration(Math.max(0, metadata.totalTime || fallbackDuration))++ if (events.some((event) => event.type === EVENT_FULL_SNAPSHOT)) {+ readyFallback = window.setTimeout(+ markPlayerReady,+ PLAYER_READY_FALLBACK_MS,+ )+ } else {+ markPlayerReady()+ }} catch (reason) {setError(reason instanceof Error@@ -1286,8 +1319,11 @@ const SessionReplayModal = ({}return () => {- replayer.current?.pause()- replayer.current = null+ if (readyFallback) window.clearTimeout(readyFallback)+ if (readyRaf) window.cancelAnimationFrame(readyRaf)+ instance?.off(ReplayerEvents.FullsnapshotRebuilded, markPlayerReady)+ instance?.pause()+ if (replayer.current === instance) replayer.current = nullroot.innerHTML = ''}}, [events, hasEvents, isOpen, t])@@ -1911,9 +1947,16 @@ const SessionReplayModal = ({setHoverPreview(null)}}>- {isPreparing || isLoading ? (- <div className='absolute inset-0 z-30 flex items-center justify-center bg-black/70'>- <Loader />+ {shouldShowReplayLoading ? (+ <div className='absolute inset-0 z-40 flex items-center justify-center bg-black/80 px-6 text-center'>+ <Loader+ className='flex-col gap-3 pt-0! text-slate-100'+ label={t('project.sessionReplay.loading')}+ labelClassName='text-sm font-medium text-slate-100'+ showLabel+ spinnerAlwaysLight+ spinnerClassName='size-5'+ /></div>) : null}{!isPreparing && error ? (diff --git a/web/app/ui/Loader.tsx b/web/app/ui/Loader.tsxindex 88764ec26..1d5d63ed3 100644--- a/web/app/ui/Loader.tsx+++ b/web/app/ui/Loader.tsx@@ -6,18 +6,40 @@ import { cn } from '~/utils/generic'interface LoaderProps {className?: stringlabel?: string+ labelClassName?: string+ showLabel?: boolean+ spinnerAlwaysLight?: boolean+ spinnerClassName?: string}-const Loader = ({ className, label }: LoaderProps) => {+const Loader = ({+ className,+ label,+ labelClassName,+ showLabel,+ spinnerAlwaysLight,+ spinnerClassName,+}: LoaderProps) => {const { t } = useTranslation('common')+ const resolvedLabel = label ?? t('common.loading')return (<outputclassName={cn('flex items-center justify-center pt-10', className)}aria-live='polite'>- <Spin className='mr-0! ml-0!' />- <span className='sr-only'>{label ?? t('common.loading')}</span>+ <Spin+ alwaysLight={spinnerAlwaysLight}+ className={cn('mr-0! ml-0!', spinnerClassName)}+ />+ <span+ className={cn(+ showLabel ? 'text-sm font-medium' : 'sr-only',+ labelClassName,+ )}+ >+ {resolvedLabel}+ </span></output>)}diff --git a/web/public/locales/en.json b/web/public/locales/en.jsonindex 94cc70f0c..bd7793751 100644--- a/web/public/locales/en.json+++ b/web/public/locales/en.json@@ -1985,6 +1985,7 @@"expiresAt": "Expires {{date}}","eventsCount": "{{count}} replay events","title": "Session replay",+ "loading": "Preparing replay...","loadError": "Could not load replay","delete": "Delete replay","deleted": "Replay deleted",