Skip to content

📈 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!

fix: session & errors back to list does not load properly

Blue Mousef93682708086
diff --git a/web/app/pages/Project/View/ViewProject.tsx b/web/app/pages/Project/View/ViewProject.tsx
index 4c4359a59..91eda516b 100644
--- a/web/app/pages/Project/View/ViewProject.tsx
+++ b/web/app/pages/Project/View/ViewProject.tsx
@@ -512,6 +512,7 @@ const ViewProject = () => {
const activePSID = useMemo(() => {
return searchParams.get('psid')
}, [searchParams])
+ const prevActivePSIDRef = useRef<string | null>(activePSID)
const [zoomedTimeRange, setZoomedTimeRange] = useState<[Date, Date] | null>(null)
const [sessionChartInstance, setSessionChartInstance] = useState<Chart | null>(null)
@@ -526,6 +527,7 @@ const ViewProject = () => {
const activeEID = useMemo(() => {
return searchParams.get('eid')
}, [searchParams])
+ const prevActiveEIDRef = useRef<string | null>(activeEID)
const [funnelToEdit, setFunnelToEdit] = useState<Funnel | undefined>(undefined)
const [funnelActionLoading, setFunnelActionLoading] = useState(false)
@@ -1168,6 +1170,7 @@ const ViewProject = () => {
setErrorsSkip(0)
setErrors([])
setErrorsLoading(null)
+ setCanLoadMoreErrors(false)
}
const switchActiveErrorFilter = _debounce((pairID: string) => {
@@ -1692,20 +1695,34 @@ const ViewProject = () => {
useEffect(() => {
if (!activePSID) {
setActiveSession(null)
+ // Coming back from a session detail to the list: reset pagination and reload first page
+ if (prevActivePSIDRef.current) {
+ resetSessions()
+ loadSessions(0)
+ }
+ prevActivePSIDRef.current = null
return
}
loadSession(activePSID)
+ prevActivePSIDRef.current = activePSID
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [period, dateRange, timeBucket, activePSID])
useEffect(() => {
if (!activeEID) {
setActiveError(null)
+ // Coming back from an error detail to the list: reset pagination and reload first page
+ if (prevActiveEIDRef.current) {
+ resetErrors()
+ loadErrors(0, true)
+ }
+ prevActiveEIDRef.current = null
return
}
loadError(activeEID)
+ prevActiveEIDRef.current = activeEID
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [period, dateRange, timeBucket, activeEID, filters])
@@ -2487,6 +2504,7 @@ const ViewProject = () => {
setSessionsSkip(0)
setSessions([])
setSessionsLoading(null)
+ setCanLoadMoreSessions(false)
}
// We can assume period provided is never custom, as it's handled separately in the Datepicker callback function
diff --git a/web/app/pages/Project/View/components/Errors.tsx b/web/app/pages/Project/View/components/Errors.tsx
index c31f636bb..cc5b33cc5 100644
--- a/web/app/pages/Project/View/components/Errors.tsx
+++ b/web/app/pages/Project/View/components/Errors.tsx
@@ -3,7 +3,7 @@ import cx from 'clsx'
import _map from 'lodash/map'
import React, { useMemo } from 'react'
import { useTranslation } from 'react-i18next'
-import { Link } from 'react-router'
+import { Link, useLocation } from 'react-router'
import { ClientOnly } from 'remix-utils/client-only'
import { SwetrixError } from '~/lib/models/Project'
@@ -34,6 +34,7 @@ const ErrorItem = ({ error }: ErrorItemProps) => {
t,
i18n: { language },
} = useTranslation('common')
+ const location = useLocation()
const lastSeen = useMemo(() => {
return getRelativeDateIfPossible(error.last_seen, language)
}, [error.last_seen, language])
@@ -61,12 +62,11 @@ const ErrorItem = ({ error }: ErrorItemProps) => {
}
}, [error.status, t])
- const eidUrl = new URL(window.location.href)
- eidUrl.searchParams.set('eid', error.eid)
- const stringifiedUrl = eidUrl.toString()
+ const params = new URLSearchParams(location.search)
+ params.set('eid', error.eid)
return (
- <Link to={stringifiedUrl}>
+ <Link to={{ search: params.toString() }}>
<li className='relative mb-3 flex cursor-pointer justify-between gap-x-6 overflow-hidden rounded-xl border border-gray-200 bg-gray-50 px-4 py-4 transition-colors hover:bg-gray-200/70 sm:px-6 dark:border-slate-800/25 dark:bg-slate-800/70 dark:hover:bg-slate-700/60'>
<div className='flex min-w-0 gap-x-4'>
<div className='min-w-0 flex-auto'>
diff --git a/web/app/pages/Project/View/components/Sessions.tsx b/web/app/pages/Project/View/components/Sessions.tsx
index c6387fdd6..6cd6ac2e8 100644
--- a/web/app/pages/Project/View/components/Sessions.tsx
+++ b/web/app/pages/Project/View/components/Sessions.tsx
@@ -5,7 +5,7 @@ import _map from 'lodash/map'
import { FileTextIcon, BugIcon, MousePointerClickIcon } from 'lucide-react'
import React, { useMemo } from 'react'
import { useTranslation } from 'react-i18next'
-import { Link } from 'react-router'
+import { Link, useLocation } from 'react-router'
import { ClientOnly } from 'remix-utils/client-only'
import { Session as SessionType } from '~/lib/models/Project'
@@ -37,6 +37,7 @@ const Session = ({ session, timeFormat }: SessionProps) => {
t,
i18n: { language },
} = useTranslation('common')
+ const location = useLocation()
const sessionStartTime = dayjs(session.sessionStart)
@@ -91,12 +92,11 @@ const Session = ({ session, timeFormat }: SessionProps) => {
return `${startDateTimeStr} - ${endTimeStr}${durationDisplay}`
}, [session, language, timeFormat, sessionDurationString, sessionStartTime])
- const psidUrl = new URL(window.location.href)
- psidUrl.searchParams.set('psid', session.psid)
- const stringifiedUrl = psidUrl.toString()
+ const params = new URLSearchParams(location.search)
+ params.set('psid', session.psid)
return (
- <Link to={stringifiedUrl}>
+ <Link to={{ search: params.toString() }}>
<li className='relative mb-3 flex cursor-pointer justify-between gap-x-6 overflow-hidden rounded-xl border border-gray-200 bg-gray-50 px-4 py-4 transition-colors hover:bg-gray-200/70 sm:px-6 dark:border-slate-800/25 dark:bg-slate-800/70 dark:hover:bg-slate-700/60'>
<div className='flex min-w-0 gap-x-4'>
<div className='min-w-0 flex-auto'>