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 loading indicator issues

Blue Mouse7ad2ae01a145
diff --git a/web/app/pages/Project/Goals/View/GoalsView.tsx b/web/app/pages/Project/Goals/View/GoalsView.tsx
index 62e7936d3..5e8438085 100644
--- a/web/app/pages/Project/Goals/View/GoalsView.tsx
+++ b/web/app/pages/Project/Goals/View/GoalsView.tsx
@@ -10,7 +10,7 @@ import {
FileTextIcon,
MousePointerClickIcon,
} from 'lucide-react'
-import { useState, useEffect, useMemo } from 'react'
+import { useState, useEffect, useMemo, useRef } from 'react'
import { useTranslation } from 'react-i18next'
import { Link } from 'react-router'
import { toast } from 'sonner'
@@ -26,7 +26,9 @@ import {
import { useViewProjectContext } from '~/pages/Project/View/ViewProject'
import { useCurrentProject } from '~/providers/CurrentProjectProvider'
import Button from '~/ui/Button'
+import Spin from '~/ui/icons/Spin'
import Loader from '~/ui/Loader'
+import LoadingBar from '~/ui/LoadingBar'
import Modal from '~/ui/Modal'
import Pagination from '~/ui/Pagination'
import ProgressRing from '~/ui/ProgressRing'
@@ -77,9 +79,11 @@ const GoalRow = ({ goal, stats, statsLoading, onDelete, onEdit, onClick }: GoalR
</Text>
) : null}
{/* Mobile stats */}
- <div className='mt-2 flex items-center gap-x-3 text-xs leading-5 text-gray-500 sm:hidden dark:text-gray-300'>
+ <div className='mt-2 flex h-9 items-center gap-x-3 text-xs leading-5 text-gray-500 sm:hidden dark:text-gray-300'>
{statsLoading ? (
- <Loader />
+ <div className='flex size-9 items-center justify-center'>
+ <Spin className='m-0 size-5' />
+ </div>
) : stats ? (
<>
<span>
@@ -101,9 +105,11 @@ const GoalRow = ({ goal, stats, statsLoading, onDelete, onEdit, onClick }: GoalR
</div>
</div>
<div className='flex shrink-0 items-center gap-x-4'>
- <div className='hidden sm:flex sm:items-center sm:gap-x-3'>
+ <div className='hidden h-11 sm:flex sm:items-center sm:gap-x-3'>
{statsLoading ? (
- <Loader />
+ <div className='flex size-11 items-center justify-center'>
+ <Spin className='m-0 size-5' />
+ </div>
) : stats ? (
<>
<p className='text-sm leading-6'>
@@ -182,6 +188,7 @@ const GoalsView = ({ period, from = '', to = '', timezone }: GoalsViewProps) =>
const { t } = useTranslation()
const [isLoading, setIsLoading] = useState<boolean | null>(null)
+ const isLoadingRef = useRef(false) // Use ref to avoid stale closure issues in loadGoals
const [total, setTotal] = useState(0)
const [goals, setGoals] = useState<Goal[]>([])
const [goalStats, setGoalStats] = useState<Record<string, GoalStats | null>>({})
@@ -205,9 +212,10 @@ const GoalsView = ({ period, from = '', to = '', timezone }: GoalsViewProps) =>
}, [goals, filterQuery])
const loadGoals = async (take: number, skip: number) => {
- if (isLoading) {
+ if (isLoadingRef.current) {
return
}
+ isLoadingRef.current = true
setIsLoading(true)
try {
@@ -217,6 +225,7 @@ const GoalsView = ({ period, from = '', to = '', timezone }: GoalsViewProps) =>
} catch (reason: any) {
setError(reason)
} finally {
+ isLoadingRef.current = false
setIsLoading(false)
}
}
@@ -322,7 +331,8 @@ const GoalsView = ({ period, from = '', to = '', timezone }: GoalsViewProps) =>
)
}
- if (isLoading || isLoading === null) {
+ // Show Loader only on initial load (no existing data)
+ if ((isLoading || isLoading === null) && _isEmpty(goals)) {
return (
<div className='mt-4'>
<Loader />
@@ -332,6 +342,7 @@ const GoalsView = ({ period, from = '', to = '', timezone }: GoalsViewProps) =>
return (
<div className='mt-4'>
+ {isLoading && !_isEmpty(goals) ? <LoadingBar /> : null}
{_isEmpty(goals) ? (
<div className='mt-5 rounded-xl bg-gray-700 p-5'>
<div className='flex items-center text-gray-50'>
diff --git a/web/app/pages/Project/View/ViewProject.tsx b/web/app/pages/Project/View/ViewProject.tsx
index 805fd9037..f412a191a 100644
--- a/web/app/pages/Project/View/ViewProject.tsx
+++ b/web/app/pages/Project/View/ViewProject.tsx
@@ -1577,17 +1577,9 @@ const ViewProjectContent = () => {
})
}
- const resetErrors = () => {
- errorsRequestIdRef.current += 1
- setErrorsSkip(0)
- setErrors([])
- setErrorsLoading(null)
- setCanLoadMoreErrors(false)
- }
-
const switchActiveErrorFilter = _debounce((pairID: string) => {
setErrorOptions((prev) => ({ ...prev, [pairID]: !prev[pairID] }))
- resetErrors()
+ setErrorsSkip(0)
}, 0)
const updateStatusInErrors = (status: 'active' | 'resolved') => {
@@ -2037,8 +2029,8 @@ const ViewProjectContent = () => {
// Coming back from a session detail to the list: reset pagination and reload first page
if (prevActivePSIDRef.current) {
skipNextSessionsAutoLoadRef.current = true
- resetSessions()
- loadSessions(0)
+ setSessionsSkip(0)
+ loadSessions(0, true)
}
prevActivePSIDRef.current = null
return
@@ -2055,7 +2047,7 @@ const ViewProjectContent = () => {
// Coming back from an error detail to the list: reset pagination and reload first page
if (prevActiveEIDRef.current) {
skipNextErrorsAutoLoadRef.current = true
- resetErrors()
+ setErrorsSkip(0)
loadErrors(0, true)
}
prevActiveEIDRef.current = null
@@ -2067,7 +2059,7 @@ const ViewProjectContent = () => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [period, dateRange, timeBucket, activeEID, filters])
- const loadSessions = async (forcedSkip?: number) => {
+ const loadSessions = async (forcedSkip?: number, override?: boolean) => {
if (sessionsLoading) {
return
}
@@ -2093,7 +2085,11 @@ const ViewProjectContent = () => {
}
if (requestId === sessionsRequestIdRef.current) {
- setSessions((prev) => [...prev, ...(dataSessions?.sessions || [])])
+ if (override) {
+ setSessions(dataSessions?.sessions || [])
+ } else {
+ setSessions((prev) => [...prev, ...(dataSessions?.sessions || [])])
+ }
setSessionsSkip((prev) => {
if (typeof forcedSkip === 'number') {
return SESSIONS_TAKE + forcedSkip
@@ -2117,7 +2113,7 @@ const ViewProjectContent = () => {
}
}
- const loadProfiles = async (forcedSkip?: number) => {
+ const loadProfiles = async (forcedSkip?: number, override?: boolean) => {
if (profilesLoading) {
return
}
@@ -2165,7 +2161,11 @@ const ViewProjectContent = () => {
}
if (requestId === profilesRequestIdRef.current) {
- setProfiles((prev) => [...prev, ...(dataProfiles?.profiles || [])])
+ if (override) {
+ setProfiles(dataProfiles?.profiles || [])
+ } else {
+ setProfiles((prev) => [...prev, ...(dataProfiles?.profiles || [])])
+ }
setProfilesSkip((prev) => {
if (typeof forcedSkip === 'number') {
return SESSIONS_TAKE + forcedSkip
@@ -2289,13 +2289,6 @@ const ViewProjectContent = () => {
}
}
- const resetProfiles = () => {
- profilesRequestIdRef.current += 1
- setProfilesSkip(0)
- setProfiles([])
- setCanLoadMoreProfiles(false)
- }
-
const loadErrors = async (forcedSkip?: number, override?: boolean) => {
if (errorsLoading) {
return
@@ -2641,8 +2634,8 @@ const ViewProjectContent = () => {
return
}
- resetSessions()
- loadSessions(0)
+ setSessionsSkip(0)
+ loadSessions(0, true)
return
}
@@ -2652,8 +2645,8 @@ const ViewProjectContent = () => {
return
}
- resetErrors()
- loadErrors(0)
+ setErrorsSkip(0)
+ loadErrors(0, true)
return
}
@@ -2663,8 +2656,8 @@ const ViewProjectContent = () => {
return
}
- resetProfiles()
- loadProfiles(0)
+ setProfilesSkip(0)
+ loadProfiles(0, true)
return
}
@@ -2809,8 +2802,8 @@ const ViewProjectContent = () => {
}
// Reset pagination and load the first page whenever the query context changes
- resetProfiles()
- loadProfiles(0)
+ setProfilesSkip(0)
+ loadProfiles(0, true)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [
activeTab,
@@ -2843,9 +2836,9 @@ const ViewProjectContent = () => {
if (prevProfileId && !activeProfileId) {
// We just closed a profile detail, reset to first page
- resetProfiles()
+ setProfilesSkip(0)
skipNextProfilesAutoLoadRef.current = true
- loadProfiles(0)
+ loadProfiles(0, true)
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [activeProfileId])
@@ -3016,14 +3009,6 @@ const ViewProjectContent = () => {
}
}, [dataLoading])
- const resetSessions = () => {
- sessionsRequestIdRef.current += 1
- 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
const updatePeriod = ({ period: newPeriod }: { period: Period }) => {
if (period === newPeriod) {
@@ -3035,8 +3020,8 @@ const ViewProjectContent = () => {
newSearchParams.delete('to')
newSearchParams.set('period', newPeriod)
- resetSessions()
- resetErrors()
+ setSessionsSkip(0)
+ setErrorsSkip(0)
updatePreferences({
period: newPeriod,
@@ -3438,7 +3423,12 @@ const ViewProjectContent = () => {
}}
>
<>
- {dataLoading && !isAutoRefreshing ? <LoadingBar /> : null}
+ {(dataLoading && !isAutoRefreshing) ||
+ (sessionsLoading && !_isEmpty(sessions)) ||
+ (errorsLoading && !_isEmpty(errors)) ||
+ (profilesLoading && !_isEmpty(profiles)) ? (
+ <LoadingBar />
+ ) : null}
{!isEmbedded ? <Header /> : null}
<EventsRunningOutBanner />
<div
@@ -3908,7 +3898,7 @@ const ViewProjectContent = () => {
profileType={profileTypeFilter}
onProfileTypeChange={(type) => {
setProfileTypeFilter(type)
- resetProfiles()
+ setProfilesSkip(0)
}}
/>
{(profilesLoading === null || profilesLoading) && _isEmpty(profiles) ? <Loader /> : null}
diff --git a/web/app/pages/Project/View/components/CaptchaView.tsx b/web/app/pages/Project/View/components/CaptchaView.tsx
index 03da8a609..cfb3ca5c4 100644
--- a/web/app/pages/Project/View/components/CaptchaView.tsx
+++ b/web/app/pages/Project/View/components/CaptchaView.tsx
@@ -12,6 +12,7 @@ import useSize from '~/hooks/useSize'
import { chartTypes, BROWSER_LOGO_MAP, OS_LOGO_MAP, OS_LOGO_MAP_DARK } from '~/lib/constants'
import { useTheme } from '~/providers/ThemeProvider'
import Loader from '~/ui/Loader'
+import LoadingBar from '~/ui/LoadingBar'
import { Filter } from '../interfaces/traffic'
import { Panel } from '../Panels'
@@ -168,26 +169,23 @@ const CaptchaView = ({ projectId }: CaptchaViewProps) => {
return { search: newSearchParams.toString() }
}
- if (analyticsLoading) {
+ // Check if we have existing data
+ const hasExistingData = chartData !== null || !_isEmpty(panelsData.types)
+
+ // Show Loader only on initial load (no existing data)
+ if (analyticsLoading && !hasExistingData) {
return <Loader />
}
- if (isPanelsDataEmpty) {
+ if (isPanelsDataEmpty && !dataLoading) {
return <NoEvents filters={filters} />
}
return (
<div ref={ref}>
+ {dataLoading && hasExistingData ? <LoadingBar /> : null}
<div className='mt-5'>
<Filters tnMapping={tnMapping} />
- {dataLoading ? (
- <div className='static mt-4 !bg-transparent' id='loader'>
- <div className='loader-head dark:!bg-slate-800'>
- <div className='first dark:!bg-slate-600' />
- <div className='second dark:!bg-slate-600' />
- </div>
- </div>
- ) : null}
{chartData ? (
<div className='mt-4'>
<CaptchaChart