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!

Remove connection banner

Blue Mouse340dc8fd331e
diff --git a/web/app/components/OfflineBanner.tsx b/web/app/components/OfflineBanner.tsx
deleted file mode 100644
index 41f65f463..000000000
--- a/web/app/components/OfflineBanner.tsx
+++ /dev/null
@@ -1,67 +0,0 @@
-import { WifiSlashIcon, ArrowClockwiseIcon } from '@phosphor-icons/react'
-import { AnimatePresence, motion } from 'framer-motion'
-import { memo } from 'react'
-import { useTranslation } from 'react-i18next'
-
-import { useNetworkStatus } from '~/hooks/useNetworkStatus'
-import { cn } from '~/utils/generic'
-
-interface OfflineBannerProps {
- onRetry?: () => void
- className?: string
-}
-
-const OfflineBanner = ({ onRetry, className }: OfflineBannerProps) => {
- const { t } = useTranslation('common')
- const { isOnline, lastSyncedAt } = useNetworkStatus()
-
- const formattedTime = lastSyncedAt
- ? lastSyncedAt.toLocaleTimeString(undefined, {
- hour: '2-digit',
- minute: '2-digit',
- })
- : null
-
- return (
- <AnimatePresence>
- {!isOnline ? (
- <motion.div
- initial={{ height: 0, opacity: 0 }}
- animate={{ height: 'auto', opacity: 1 }}
- exit={{ height: 0, opacity: 0 }}
- transition={{ duration: 0.2, ease: 'easeOut' }}
- className={cn('overflow-hidden', className)}
- >
- <div className='flex items-center justify-between gap-3 rounded-lg border border-amber-200 bg-amber-50 px-4 py-2.5 dark:border-amber-900/50 dark:bg-amber-950/40'>
- <div className='flex items-center gap-2.5'>
- <WifiSlashIcon
- weight='duotone'
- className='size-4 shrink-0 text-amber-600 dark:text-amber-400'
- />
- <p className='text-sm font-medium text-amber-800 dark:text-amber-200'>
- {t('project.offline')}
- {formattedTime ? (
- <span className='ml-1 font-normal text-amber-600 dark:text-amber-400'>
- {t('project.lastSynced', { time: formattedTime })}
- </span>
- ) : null}
- </p>
- </div>
- {onRetry ? (
- <button
- type='button'
- onClick={onRetry}
- className='inline-flex shrink-0 items-center gap-1.5 rounded-md px-2.5 py-1 text-xs font-medium text-amber-700 transition-colors hover:bg-amber-100 dark:text-amber-300 dark:hover:bg-amber-900/40'
- >
- <ArrowClockwiseIcon className='size-3.5' />
- {t('project.retry')}
- </button>
- ) : null}
- </div>
- </motion.div>
- ) : null}
- </AnimatePresence>
- )
-}
-
-export default memo(OfflineBanner)
diff --git a/web/app/entry.client.tsx b/web/app/entry.client.tsx
index b88b724a9..bd0a87b4c 100644
--- a/web/app/entry.client.tsx
+++ b/web/app/entry.client.tsx
@@ -45,33 +45,15 @@ const handleChunkError = (error: unknown): boolean => {
return false
}
-const isNetworkError = (error: unknown): boolean => {
- if (!error) return false
- const message = error instanceof Error ? error.message : String(error)
- return (
- !navigator.onLine ||
- /NetworkError/i.test(message) ||
- /Failed to fetch/i.test(message) ||
- /Load failed/i.test(message) ||
- (/fetch/i.test(message) && error instanceof TypeError)
- )
-}
-
// Global error handler for uncaught chunk loading errors
window.addEventListener('error', (event) => {
handleChunkError(event.error)
})
-// Handle unhandled promise rejections (dynamic imports + network errors)
+// Handle unhandled promise rejections (dynamic imports)
window.addEventListener('unhandledrejection', (event) => {
if (handleChunkError(event.reason)) {
event.preventDefault()
- return
- }
-
- if (isNetworkError(event.reason)) {
- event.preventDefault()
- console.warn('[Swetrix] Network request failed (offline?)', event.reason)
}
})
diff --git a/web/app/hooks/useAnalyticsProxy.ts b/web/app/hooks/useAnalyticsProxy.ts
index 65a3bbba0..a1f0a85be 100644
--- a/web/app/hooks/useAnalyticsProxy.ts
+++ b/web/app/hooks/useAnalyticsProxy.ts
@@ -47,10 +47,6 @@ interface ProxyResponse<T> {
}
async function postAnalytics<T>(payload: unknown): Promise<ProxyResponse<T>> {
- if (typeof navigator !== 'undefined' && !navigator.onLine) {
- throw new Error('No internet connection')
- }
-
const response = await fetch('/api/analytics', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
diff --git a/web/app/hooks/useNetworkStatus.ts b/web/app/hooks/useNetworkStatus.ts
deleted file mode 100644
index d10e48908..000000000
--- a/web/app/hooks/useNetworkStatus.ts
+++ /dev/null
@@ -1,71 +0,0 @@
-import { useCallback, useEffect, useRef, useSyncExternalStore } from 'react'
-
-function subscribe(callback: () => void) {
- window.addEventListener('online', callback)
- window.addEventListener('offline', callback)
- return () => {
- window.removeEventListener('online', callback)
- window.removeEventListener('offline', callback)
- }
-}
-
-function getSnapshot() {
- return navigator.onLine
-}
-
-function getServerSnapshot() {
- return true
-}
-
-let lastSyncedAt: Date | null = null
-const listeners = new Set<() => void>()
-
-function notifySyncListeners() {
- for (const listener of listeners) {
- listener()
- }
-}
-
-export function markSynced() {
- lastSyncedAt = new Date()
- notifySyncListeners()
-}
-
-function subscribeSynced(callback: () => void) {
- listeners.add(callback)
- return () => {
- listeners.delete(callback)
- }
-}
-
-function getSyncedSnapshot() {
- return lastSyncedAt
-}
-
-export function useNetworkStatus() {
- const isOnline = useSyncExternalStore(
- subscribe,
- getSnapshot,
- getServerSnapshot,
- )
- const syncedAt = useSyncExternalStore(
- subscribeSynced,
- getSyncedSnapshot,
- () => null,
- )
- const wasOfflineRef = useRef(false)
-
- useEffect(() => {
- if (!isOnline) {
- wasOfflineRef.current = true
- }
- }, [isOnline])
-
- const justReconnected = isOnline && wasOfflineRef.current
-
- const clearReconnected = useCallback(() => {
- wasOfflineRef.current = false
- }, [])
-
- return { isOnline, lastSyncedAt: syncedAt, justReconnected, clearReconnected }
-}
diff --git a/web/app/pages/Project/View/ViewProject.tsx b/web/app/pages/Project/View/ViewProject.tsx
index 780b74af7..f07b92747 100644
--- a/web/app/pages/Project/View/ViewProject.tsx
+++ b/web/app/pages/Project/View/ViewProject.tsx
@@ -47,8 +47,6 @@ import { toast } from 'sonner'
import EventsRunningOutBanner from '~/components/EventsRunningOutBanner'
import Footer from '~/components/Footer'
import Header from '~/components/Header'
-import OfflineBanner from '~/components/OfflineBanner'
-import { useNetworkStatus, markSynced } from '~/hooks/useNetworkStatus'
import useSize from '~/hooks/useSize'
import { changeLanguage } from '~/i18n'
import {
@@ -694,14 +692,6 @@ const ViewProjectContent = () => {
setItem(LS_IS_ACTIVE_COMPARE_KEY, isActiveCompare ? 'true' : 'false')
}, [isActiveCompare])
- const { isOnline, justReconnected, clearReconnected } = useNetworkStatus()
-
- useEffect(() => {
- if (project && !authLoading) {
- markSynced()
- }
- }, [project, authLoading])
-
const [showFiltersSearch, setShowFiltersSearch] = useState(false)
const [isMobileSidebarOpen, setIsMobileSidebarOpen] = useState(false)
@@ -921,15 +911,6 @@ const ViewProjectContent = () => {
[authLoading, dataLoading, activeTab],
)
- useEffect(() => {
- if (justReconnected && isOnline) {
- refreshStats(false).finally(() => {
- clearReconnected()
- markSynced()
- })
- }
- }, [justReconnected, isOnline, refreshStats, clearReconnected])
-
useEffect(() => {
setPeriodPairsCompare(tbPeriodPairsCompare(t, undefined, language))
}, [t, language])
@@ -1503,10 +1484,6 @@ const ViewProjectContent = () => {
ref={dashboardRef}
>
<EventsRunningOutBanner />
- <OfflineBanner
- onRetry={() => refreshStats(true)}
- className='mb-2'
- />
{!isMapFullscreen ? (
<div className='pointer-events-auto'>
<MobileSidebarTrigger
diff --git a/web/app/routes/projects.$id.tsx b/web/app/routes/projects.$id.tsx
index 6d347da50..2a156f2a1 100644
--- a/web/app/routes/projects.$id.tsx
+++ b/web/app/routes/projects.$id.tsx
@@ -8,7 +8,6 @@ import {
type LinksFunction,
type LoaderFunctionArgs,
type MetaFunction,
- type ShouldRevalidateFunctionArgs,
} from 'react-router'
import { data, redirect } from 'react-router'
@@ -100,16 +99,6 @@ export const links: LinksFunction = () => [
{ rel: 'stylesheet', href: ProjectViewStyle },
]
-export function shouldRevalidate({
- defaultShouldRevalidate,
-}: ShouldRevalidateFunctionArgs) {
- if (typeof navigator !== 'undefined' && !navigator.onLine) {
- return false
- }
-
- return defaultShouldRevalidate
-}
-
export const meta: MetaFunction<typeof loader> = ({ data, location }) => {
// eslint-disable-next-line react-hooks/rules-of-hooks
const { t } = useTranslation('common')
diff --git a/web/public/locales/en.json b/web/public/locales/en.json
index f0124b174..7a31b3687 100644
--- a/web/public/locales/en.json
+++ b/web/public/locales/en.json
@@ -1411,9 +1411,6 @@
"lookingForMore": "Looking for more?",
"overrideCurrentlyFilters": "Override currently applied filters",
"noExist": "The selected project does not exist",
- "offline": "No internet connection",
- "lastSynced": "· Last synced at {{time}}",
- "retry": "Retry",
"geo": "Geolocation",
"browserInfo": "Browser information",
"urlInfo": "URL information",