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: billboard.js rendering issues after load

Blue Mouse7c076a1ef4c5
diff --git a/web/app/pages/Project/View/v2/loading.tsx b/web/app/pages/Project/View/v2/loading.tsx
index e6076441b..a2a41afb0 100644
--- a/web/app/pages/Project/View/v2/loading.tsx
+++ b/web/app/pages/Project/View/v2/loading.tsx
@@ -1,4 +1,9 @@
+import { ArrowsClockwiseIcon } from '@phosphor-icons/react'
import cx from 'clsx'
+import { useTranslation } from 'react-i18next'
+
+import Button from '~/ui/Button'
+import { Text } from '~/ui/Text'
export const RefetchIndicator = ({ className }: { className?: string }) => (
<div
@@ -11,3 +16,24 @@ export const RefetchIndicator = ({ className }: { className?: string }) => (
<div className='indeterminate-bar absolute inset-y-0 left-0 w-[42%] rounded-full bg-linear-to-r from-slate-400 via-slate-900 to-slate-400 will-change-transform dark:from-slate-500 dark:via-white dark:to-slate-500' />
</div>
)
+
+export const ChartErrorState = ({ onRetry }: { onRetry: () => void }) => {
+ const { t } = useTranslation('common')
+
+ return (
+ <div className='flex h-80 flex-col items-center justify-center text-center'>
+ <Text as='p' size='sm' colour='secondary'>
+ {t('apiNotifications.somethingWentWrong')}
+ </Text>
+ <Button
+ className='mt-3 gap-1.5'
+ onClick={onRetry}
+ variant='secondary'
+ size='sm'
+ >
+ <ArrowsClockwiseIcon className='size-4' />
+ {t('project.refreshStats')}
+ </Button>
+ </div>
+ )
+}
diff --git a/web/app/pages/Project/tabs/Performance/PerformanceView.tsx b/web/app/pages/Project/tabs/Performance/PerformanceView.tsx
index bb086c36f..df98de45b 100644
--- a/web/app/pages/Project/tabs/Performance/PerformanceView.tsx
+++ b/web/app/pages/Project/tabs/Performance/PerformanceView.tsx
@@ -36,7 +36,10 @@ import {
BreakdownPanel,
BreakdownSubTab,
} from '~/pages/Project/View/v2/BreakdownPanel'
-import { RefetchIndicator } from '~/pages/Project/View/v2/loading'
+import {
+ ChartErrorState,
+ RefetchIndicator,
+} from '~/pages/Project/View/v2/loading'
import { useViewProjectContext } from '~/pages/Project/View/ViewProject'
import {
panelIconMapping,
@@ -204,15 +207,15 @@ const PerformanceViewInner = ({ tnMapping }: PerformanceViewProps) => {
const isPanelsDataEmpty = isPanelsDataEmptyRaw && !hasShownContentRef.current
- // Queries keep previous data across period/filter changes, so `isLoading` only
- // ever means "nothing cached to show yet" β€” exactly when a spinner is wanted.
- const isChartLoading = summaryQuery.isLoading || timeseriesQuery.isLoading
+ // Keep the chart slot occupied through initial loading and retry delays.
+ const isChartLoading = summaryQuery.isPending || timeseriesQuery.isPending
+ const isChartError = summaryQuery.isError || timeseriesQuery.isError
// The counterpart: stale data is on screen while a refresh is in flight, so
// the panel gets the same progress bar the breakdown panels use.
const isChartRefetching =
- (summaryQuery.isFetching && !summaryQuery.isLoading) ||
- (timeseriesQuery.isFetching && !timeseriesQuery.isLoading)
+ (summaryQuery.isFetching && !summaryQuery.isPending) ||
+ (timeseriesQuery.isFetching && !timeseriesQuery.isPending)
const handleDataPointClick = useCallback(
(d: { x: Date; index: number; xValue?: string }) => {
@@ -562,7 +565,14 @@ const PerformanceViewInner = ({ tnMapping }: PerformanceViewProps) => {
overall={overall}
overallCompare={overallCompare}
/>
- {isChartLoading ? (
+ {isChartError ? (
+ <ChartErrorState
+ onRetry={() => {
+ summaryQuery.refetch()
+ timeseriesQuery.refetch()
+ }}
+ />
+ ) : isChartLoading ? (
// Same box as PerformanceChart below (incl. its mobile mt-5) so the
// chart drops straight into the spinner's place.
<div className='mt-5 flex h-80 items-center justify-center md:mt-0'>
diff --git a/web/app/pages/Project/tabs/Traffic/TrafficView.tsx b/web/app/pages/Project/tabs/Traffic/TrafficView.tsx
index 4120323e9..dcc66c7ce 100644
--- a/web/app/pages/Project/tabs/Traffic/TrafficView.tsx
+++ b/web/app/pages/Project/tabs/Traffic/TrafficView.tsx
@@ -77,7 +77,10 @@ import {
pivotTrafficTimeseries,
summaryToOverall,
} from '~/pages/Project/View/v2/adapters'
-import { RefetchIndicator } from '~/pages/Project/View/v2/loading'
+import {
+ ChartErrorState,
+ RefetchIndicator,
+} from '~/pages/Project/View/v2/loading'
import { TrafficMap } from '~/pages/Project/View/v2/TrafficMap'
import { useViewProjectContext } from '~/pages/Project/View/ViewProject'
import {
@@ -373,15 +376,15 @@ const TrafficViewInner = ({
const isPanelsDataEmpty = isPanelsDataEmptyRaw && !hasShownContentRef.current
- // Queries keep previous data across period/filter changes, so `isLoading` only
- // ever means "nothing cached to show yet" β€” exactly when a spinner is wanted.
- const isChartLoading = summaryQuery.isLoading || timeseriesQuery.isLoading
+ // Keep the chart slot occupied through initial loading and retry delays.
+ const isChartLoading = summaryQuery.isPending || timeseriesQuery.isPending
+ const isChartError = summaryQuery.isError || timeseriesQuery.isError
// The counterpart: stale data is on screen while a refresh is in flight, so
// the panel gets the same progress bar the breakdown panels use.
const isChartRefetching =
- (summaryQuery.isFetching && !summaryQuery.isLoading) ||
- (timeseriesQuery.isFetching && !timeseriesQuery.isLoading)
+ (summaryQuery.isFetching && !summaryQuery.isPending) ||
+ (timeseriesQuery.isFetching && !timeseriesQuery.isPending)
const isMountedRef = useRef(true)
@@ -1199,7 +1202,14 @@ const TrafficViewInner = ({
)
: null}
</div>
- {isChartLoading ? (
+ {isChartError ? (
+ <ChartErrorState
+ onRetry={() => {
+ summaryQuery.refetch()
+ timeseriesQuery.refetch()
+ }}
+ />
+ ) : isChartLoading ? (
// Same box as TrafficChart below (incl. its mobile mt-5) so the
// chart drops straight into the spinner's place.
<div className='mt-5 flex h-80 items-center justify-center md:mt-0'>