π 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
Improve panel loading UI
Blue Moused162e2234e38
diff --git a/web/app/pages/Project/View/Panels.tsx b/web/app/pages/Project/View/Panels.tsxindex aafb0538b..8c73d5199 100644--- a/web/app/pages/Project/View/Panels.tsx+++ b/web/app/pages/Project/View/Panels.tsx@@ -54,6 +54,7 @@ import Dropdown from '~/ui/Dropdown'import Input from '~/ui/Input'import Sort from '~/ui/icons/Sort'import Spin from '~/ui/icons/Spin'+import Loader from '~/ui/Loader'import Modal from '~/ui/Modal'import { Text } from '~/ui/Text'import {@@ -159,6 +160,14 @@ const PanelEmptyState = ({</div>)+// Mirrors PanelEmptyState's box model so a panel is the same height whether it+// is loading, empty or full.+const PanelLoadingState = () => (+ <div className='flex h-full flex-1 items-center justify-center px-4 py-8'>+ <Loader className='pt-0!' />+ </div>+)+const PanelDocsEmptyState = ({variant,}: {@@ -220,8 +229,12 @@ interface PanelContainerProps {onTabChange?: (tab: string) => voidactiveTabId?: stringonDetailsClick?: () => void+ /** Renders the details button in a disabled state, keeping the panel height stable while there is nothing to drill into. */+ detailsDisabled?: booleandropdownPlaceholder?: stringisRefetching?: boolean+ /** Replaces the panel body with a centered spinner, keeping the panel at its usual height. */+ isLoading?: boolean}const PanelContainer = ({@@ -236,8 +249,10 @@ const PanelContainer = ({onTabChange,activeTabId,onDetailsClick,+ detailsDisabled,dropdownPlaceholder,isRefetching,+ isLoading,}: PanelContainerProps) => {const { t } = useTranslation('common')const underlineId = useId()@@ -350,7 +365,7 @@ const PanelContainer = ({isRefetching && 'opacity-75 transition-opacity duration-200',)}>- {children}+ {isLoading ? <PanelLoadingState /> : children}</div>{onDetailsClick ? (<div className='mt-2 flex items-center justify-center'>@@ -359,6 +374,7 @@ const PanelContainer = ({className='gap-1.5 px-3 py-2'type='button'onClick={onDetailsClick}+ disabled={detailsDisabled}aria-label={t('common.details')}><ScanIcon className='size-4' />@@ -1355,14 +1371,9 @@ const MetadataKeyBody = ({const hasExistingData =mode === 'customEvent' ? !_isEmpty(rawMetadata) : !_isEmpty(valuesData)- const hasOverflowData =- mode === 'customEvent'- ? _size(rawMetadata) > ENTRIES_PER_PANEL- : _size(valuesData) > ENTRIES_PER_PANEL-useEffect(() => {- onShowDetailsChange?.(hasOverflowData)- }, [hasOverflowData, onShowDetailsChange])+ onShowDetailsChange?.(hasExistingData)+ }, [hasExistingData, onShowDetailsChange])useEffect(() => {if (detailsTrigger && detailsTrigger > 0) {@@ -1387,11 +1398,7 @@ const MetadataKeyBody = ({// Only show loader on initial load when there's no existing dataif (loading && !hasExistingData) {- return (- <div className='flex items-center justify-center py-8'>- <Spin />- </div>- )+ return <PanelLoadingState />}if (@@ -1742,20 +1749,19 @@ const CombinedMetadataPanel = ({detailsTrigger={detailsTrigger}/></div>- {canShowDetails ? (- <div className='mt-2 flex items-center justify-center'>- <Button- variant='icon'- className='gap-1.5 px-3 py-2'- type='button'- onClick={() => setDetailsTrigger((n) => n + 1)}- aria-label={t('common.details')}- >- <ScanIcon className='size-4' />- <span>{t('common.details')}</span>- </Button>- </div>- ) : null}+ <div className='mt-2 flex items-center justify-center'>+ <Button+ variant='icon'+ className='gap-1.5 px-3 py-2'+ type='button'+ onClick={() => setDetailsTrigger((n) => n + 1)}+ disabled={!canShowDetails}+ aria-label={t('common.details')}+ >+ <ScanIcon className='size-4' />+ <span>{t('common.details')}</span>+ </Button>+ </div></div>)}@@ -1826,6 +1832,8 @@ interface PanelProps {/** When true with rowTooltipRenderer, tooltip is fixed to the cursor (chart-style) instead of Radix anchor positioning. */rowTooltipFollowCursor?: booleanisRefetching?: boolean+ /** Shows a centered spinner in place of the rows while the first page is being fetched. */+ isLoading?: booleanserverTotal?: numberonLoadMore?: () => voidloadingMore?: boolean@@ -2256,6 +2264,7 @@ const Panel = ({rowTooltipRenderer,rowTooltipFollowCursor = false,isRefetching,+ isLoading,serverTotal,onLoadMore,loadingMore,@@ -2308,11 +2317,11 @@ const Panel = ({return (<PanelContainer- onDetailsClick={- _size(data) > ENTRIES_PER_PANEL- ? () => setDetailsOpened(true)- : undefined- }+ // A custom body (a map, an error state) has no rows to drill into, so it+ // gets no details button at all. Row panels always keep theirs β disabled+ // rather than absent β so the panel is the same height while loading.+ onDetailsClick={customRenderer ? undefined : () => setDetailsOpened(true)}+ detailsDisabled={isLoading || _isEmpty(data)}name={name}icon={icon}type={id}@@ -2320,6 +2329,7 @@ const Panel = ({onTabChange={onTabChange}activeTabId={activeTabId}isRefetching={isRefetching}+ isLoading={isLoading}>{customRenderer ? (customRenderer()@@ -2964,6 +2974,7 @@ const MetadataPanelMemo = memo(MetadataPanel) as typeof MetadataPanelexport {PanelContainer,PanelEmptyState,+ PanelLoadingState,PanelMemo as Panel,CustomEventsMemo as CustomEvents,CombinedMetadataPanelMemo as CombinedMetadataPanel,diff --git a/web/app/pages/Project/View/ViewProject.tsx b/web/app/pages/Project/View/ViewProject.tsxindex 049e24320..b7ebf609b 100644--- a/web/app/pages/Project/View/ViewProject.tsx+++ b/web/app/pages/Project/View/ViewProject.tsx@@ -1543,7 +1543,15 @@ const ViewProjectContent = () => {ease: [0.23, 1, 0.32, 1],}}>- <Suspense fallback={<Loader />}>+ {/* Reserve roughly a screenful while the tab chunk+ downloads, otherwise the page is briefly short+ enough to pull the footer into view and then+ jumps once the tab renders. */}+ <Suspense+ fallback={+ <Loader className='min-h-including-header items-start' />+ }+ >{activeTab === PROJECT_TABS.ai ? (<AskAIView projectId={id} />) : null}diff --git a/web/app/pages/Project/View/v2/BreakdownPanel.tsx b/web/app/pages/Project/View/v2/BreakdownPanel.tsxindex b5086bd39..4b94cdbc1 100644--- a/web/app/pages/Project/View/v2/BreakdownPanel.tsx+++ b/web/app/pages/Project/View/v2/BreakdownPanel.tsx@@ -163,53 +163,29 @@ export const BreakdownPanel = ({)}- if (query.isLoading || (!hasBeenInView && !query.data)) {- return (- <div ref={ref}>- <PanelContainer- name={name}- icon={icon}- type={activeSubTabId}- tabs={containerTabs}- onTabChange={onSubTabChange}- activeTabId={activeSubTabId}- />- </div>- )- }-- if (query.isError) {- return (- <div ref={ref}>- <PanelContainer- name={name}- icon={icon}- type={activeSubTabId}- tabs={containerTabs}- onTabChange={onSubTabChange}- activeTabId={activeSubTabId}- >- <div className='flex h-full flex-1 flex-col items-center justify-center px-4 py-8 text-center'>- <div className='mb-3 flex size-10 items-center justify-center rounded-lg bg-gray-100 dark:bg-slate-900'>- <WarningOctagonIcon className='size-5 text-gray-400 dark:text-slate-500' />- </div>- <Text as='p' size='sm' colour='secondary'>- {t('apiNotifications.somethingWentWrong')}- </Text>- <Button- className='mt-3 gap-1.5'- onClick={() => query.refetch()}- variant='secondary'- size='sm'- >- <ArrowsClockwiseIcon className='size-4' />- {t('project.refreshStats')}- </Button>- </div>- </PanelContainer>+ // Panels below the fold only start fetching once scrolled into view, which+ // leaves the query pending rather than loading β both mean "no rows yet".+ const isLoading = query.isLoading || (!hasBeenInView && !query.data)++ const renderError = () => (+ <div className='flex h-full flex-1 flex-col items-center justify-center px-4 py-8 text-center'>+ <div className='mb-3 flex size-10 items-center justify-center rounded-lg bg-gray-100 dark:bg-slate-900'>+ <WarningOctagonIcon className='size-5 text-gray-400 dark:text-slate-500' /></div>- )- }+ <Text as='p' size='sm' colour='secondary'>+ {t('apiNotifications.somethingWentWrong')}+ </Text>+ <Button+ className='mt-3 gap-1.5'+ onClick={() => query.refetch()}+ variant='secondary'+ size='sm'+ >+ <ArrowsClockwiseIcon className='size-4' />+ {t('project.refreshStats')}+ </Button>+ </div>+ )return (<div ref={ref}>@@ -220,6 +196,8 @@ export const BreakdownPanel = ({name={name}data={entries}serverTotal={total}+ isLoading={isLoading}+ customRenderer={query.isError ? renderError : undefined}tabs={containerTabs}onTabChange={onSubTabChange}activeTabId={activeSubTabId}diff --git a/web/app/pages/Project/tabs/Captcha/CaptchaView.tsx b/web/app/pages/Project/tabs/Captcha/CaptchaView.tsxindex bb35a0706..8f8e643e5 100644--- a/web/app/pages/Project/tabs/Captcha/CaptchaView.tsx+++ b/web/app/pages/Project/tabs/Captcha/CaptchaView.tsx@@ -129,9 +129,9 @@ const CaptchaView = (_props: CaptchaViewProps) => {const isPanelsDataEmpty = isPanelsDataEmptyRaw && !hasShownContentRef.current- const isInitialLoading =- (summaryQuery.isLoading || timeseriesQuery.isLoading) &&- !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.isLoadingconst panels = useMemo(() =>@@ -297,18 +297,6 @@ const CaptchaView = (_props: CaptchaViewProps) => {const headerRightContent = <ProjectViewHeaderActions tnMapping={tnMapping} />- if (isInitialLoading) {- return (- <>- <DashboardHeader- showLiveVisitors={false}- rightContent={headerRightContent}- />- <Loader />- </>- )- }-if (isPanelsDataEmpty) {return (<>@@ -329,6 +317,11 @@ const CaptchaView = (_props: CaptchaViewProps) => {/><div><Filters className='mb-3' tnMapping={tnMapping} />+ {isChartLoading ? (+ <div className='flex h-80 items-center justify-center overflow-hidden rounded-lg border border-gray-200 bg-white p-4 dark:border-slate-800/60 dark:bg-slate-900/25'>+ <Loader className='pt-0!' />+ </div>+ ) : null}{!_isEmpty(chartData.x) ? (<CaptchaChartchart={chartData}diff --git a/web/app/pages/Project/tabs/Errors/ErrorsView.tsx b/web/app/pages/Project/tabs/Errors/ErrorsView.tsxindex 32de554f7..be821ad1b 100644--- a/web/app/pages/Project/tabs/Errors/ErrorsView.tsx+++ b/web/app/pages/Project/tabs/Errors/ErrorsView.tsx@@ -1100,7 +1100,9 @@ const ErrorsViewInner = () => {<Filters className='mb-3' tnMapping={tnMapping} />- {detailsLoading ? <Loader /> : null}+ {detailsLoading ? (+ <Loader className='min-h-including-header items-start' />+ ) : null}{activeError?.details ? (<div className='relative'>@@ -1234,7 +1236,7 @@ const ErrorsViewInner = () => {/>}/>- <Loader />+ <Loader className='min-h-including-header items-start' /></div>)}diff --git a/web/app/pages/Project/tabs/Performance/PerformanceView.tsx b/web/app/pages/Project/tabs/Performance/PerformanceView.tsxindex f9e26a784..dd3455330 100644--- a/web/app/pages/Project/tabs/Performance/PerformanceView.tsx+++ b/web/app/pages/Project/tabs/Performance/PerformanceView.tsx@@ -203,9 +203,9 @@ const PerformanceViewInner = ({ tnMapping }: PerformanceViewProps) => {const isPanelsDataEmpty = isPanelsDataEmptyRaw && !hasShownContentRef.current- const isInitialLoading =- (summaryQuery.isLoading || timeseriesQuery.isLoading) &&- !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.isLoadingconst handleDataPointClick = useCallback((d: { x: Date; index: number; xValue?: string }) => {@@ -472,15 +472,6 @@ const PerformanceViewInner = ({ tnMapping }: PerformanceViewProps) => {const headerRightContent = <ProjectViewHeaderActions tnMapping={tnMapping} />- if (isInitialLoading) {- return (- <>- <DashboardHeader rightContent={headerRightContent} />- <Loader />- </>- )- }-if (isPanelsDataEmpty) {return (<>@@ -556,6 +547,11 @@ const PerformanceViewInner = ({ tnMapping }: PerformanceViewProps) => {/></div>+ {isChartLoading ? (+ <div className='flex h-80 items-center justify-center'>+ <Loader className='pt-0!' />+ </div>+ ) : null}{!_isEmpty(overall) ? (<PerformanceMetricCardsoverall={overall}diff --git a/web/app/pages/Project/tabs/SEO/CompactReferralPanel.tsx b/web/app/pages/Project/tabs/SEO/CompactReferralPanel.tsxindex d7565d1ac..d77568328 100644--- a/web/app/pages/Project/tabs/SEO/CompactReferralPanel.tsx+++ b/web/app/pages/Project/tabs/SEO/CompactReferralPanel.tsx@@ -4,7 +4,7 @@ import React, { useMemo } from 'react'import { useTranslation } from 'react-i18next'import type { Entry } from '~/lib/models/Entry'-import { PanelEmptyState } from '~/pages/Project/View/Panels'+import { PanelEmptyState, PanelLoadingState } from '~/pages/Project/View/Panels'import { Text } from '~/ui/Text'import { nFormatter } from '~/utils/generic'@@ -16,6 +16,7 @@ interface CompactReferralPanelProps {data: Entry[]icon: React.ReactNoderowMapper: (entry: any) => React.ReactNode+ isLoading?: boolean}const CompactReferralPanel = ({@@ -23,6 +24,7 @@ const CompactReferralPanel = ({data,icon,rowMapper,+ isLoading,}: CompactReferralPanelProps) => {const { t } = useTranslation('common')const total = useMemo(() => data.reduce((sum, e) => sum + e.count, 0), [data])@@ -53,7 +55,7 @@ const CompactReferralPanel = ({const col1 = allRows.slice(0, COMPACT_ENTRIES_PER_COL)const col2 = allRows.slice(COMPACT_ENTRIES_PER_COL)- if (_isEmpty(data)) {+ if (isLoading || _isEmpty(data)) {return (<div className='overflow-hidden rounded-lg border border-gray-200 bg-white px-4 py-3 dark:border-slate-800/60 dark:bg-slate-900/25'><div className='flex items-center gap-1 text-gray-900 dark:text-gray-50'>@@ -62,7 +64,11 @@ const CompactReferralPanel = ({{title}</Text></div>- <PanelEmptyState message={t('project.noParamData')} />+ {isLoading ? (+ <PanelLoadingState />+ ) : (+ <PanelEmptyState message={t('project.noParamData')} />+ )}</div>)}diff --git a/web/app/pages/Project/tabs/SEO/SEOView.tsx b/web/app/pages/Project/tabs/SEO/SEOView.tsxindex ecfb0087e..5ad0f1e07 100644--- a/web/app/pages/Project/tabs/SEO/SEOView.tsx+++ b/web/app/pages/Project/tabs/SEO/SEOView.tsx@@ -38,6 +38,7 @@ import {Panel,PanelContainer,PanelEmptyState,+ PanelLoadingState,} from '~/pages/Project/View/Panels'import {useViewProjectContext,@@ -256,6 +257,10 @@ const SEOViewInner = ({ projectId, tnMapping }: SEOViewProps) => {const gscLoading = isLoading || isCompareLoadingconst gscError = error || compareError+ // No cached response to fall back on β panels show spinners rather than+ // claiming they have no data.+ const isSEOLoading = gscLoading && !data+const [isManualRefreshing, setIsManualRefreshing] = useState(false)const prevTrigger = useRef(seoRefreshTrigger)@@ -700,27 +705,6 @@ const SEOViewInner = ({ projectId, tnMapping }: SEOViewProps) => {[t],)- if (gscLoading && !data) {- return (- <>- <DashboardHeader- showSearchButton={false}- showRefreshButton={false}- rightContent={- <ProjectViewHeaderActions- tnMapping={tnMapping}- extraActions={manualRefreshButton}- />- }- timeBucketSelectorItems={seoPeriodPairs}- />- <div className='flex min-h-[400px] items-center justify-center'>- <Loader />- </div>- </>- )- }-if (gscError && !data) {return (<>@@ -927,6 +911,11 @@ const SEOViewInner = ({ projectId, tnMapping }: SEOViewProps) => {}/></div>+ {isSEOLoading ? (+ <div className='flex h-80 items-center justify-center'>+ <Loader className='pt-0!' />+ </div>+ ) : null}{anyMetricActive && !_isEmpty(aggregatedSeries) ? (<divonContextMenu={(event) =>@@ -958,12 +947,14 @@ const SEOViewInner = ({ projectId, tnMapping }: SEOViewProps) => {data={searchEngineEntries}icon={panelIconMapping.referrer}rowMapper={refRowMapper}+ isLoading={isSEOLoading}/><CompactReferralPaneltitle={t('project.seo.aiReferrals')}data={aiReferralEntries}icon={<RobotIcon className='h-5 w-5' />}rowMapper={refRowMapper}+ isLoading={isSEOLoading}/><div className='overflow-hidden rounded-lg border border-gray-200 bg-white px-4 py-3 dark:border-slate-800/60 dark:bg-slate-900/25'><div className='mb-1 flex items-center gap-1 text-gray-900 dark:text-gray-50'>@@ -972,7 +963,9 @@ const SEOViewInner = ({ projectId, tnMapping }: SEOViewProps) => {{t('project.seo.brandedTraffic')}</Text></div>- {isBrandedTrafficSkipped ? (+ {isSEOLoading ? (+ <PanelLoadingState />+ ) : isBrandedTrafficSkipped ? (<PanelEmptyState message={t('project.seo.analyticsSkipped')} />) : brandedTraffic.branded + brandedTraffic.nonBranded > 0 ? (<BillboardChart@@ -992,6 +985,7 @@ const SEOViewInner = ({ projectId, tnMapping }: SEOViewProps) => {icon={<ChartBarIcon className='size-5' />}type='impressionsByPosition'contentClassName='relative flex min-h-[21rem] flex-col overflow-hidden'+ isLoading={isSEOLoading}>{isPositionAnalyticsSkipped ? (<PanelEmptyState message={t('project.seo.analyticsSkipped')} />@@ -1011,6 +1005,7 @@ const SEOViewInner = ({ projectId, tnMapping }: SEOViewProps) => {icon={<TrendUpIcon className='size-5' />}type='organicPositions'contentClassName='relative flex min-h-[21rem] flex-col overflow-hidden'+ isLoading={isSEOLoading}>{isPositionAnalyticsSkipped ? (<PanelEmptyState message={t('project.seo.analyticsSkipped')} />@@ -1039,6 +1034,7 @@ const SEOViewInner = ({ projectId, tnMapping }: SEOViewProps) => {detailsExtraColumns={detailsExtraColumns}hidePercentageInDetailsdataLoading={gscLoading}+ isLoading={isSEOLoading}rowTooltipRenderer={seoGscRowTooltip}rowTooltipFollowCursor/>@@ -1054,6 +1050,7 @@ const SEOViewInner = ({ projectId, tnMapping }: SEOViewProps) => {detailsExtraColumns={detailsExtraColumns}hidePercentageInDetailsdataLoading={gscLoading}+ isLoading={isSEOLoading}rowTooltipRenderer={seoGscRowTooltip}rowTooltipFollowCursor/>@@ -1083,7 +1080,11 @@ const SEOViewInner = ({ projectId, tnMapping }: SEOViewProps) => {}contentClassName=''>- {quadrantData ? (+ {isSEOLoading ? (+ <div className='flex h-[400px] items-center justify-center'>+ <Loader className='pt-0!' />+ </div>+ ) : quadrantData ? (<BillboardChartoptions={quadrantChartOptions}className='h-[400px] [&_.bb-circle]:fill-indigo-500/60 [&_.bb-circle]:stroke-indigo-600 [&_.bb-circle]:stroke-1 dark:[&_.bb-circle]:fill-indigo-400/60 dark:[&_.bb-circle]:stroke-indigo-300'@@ -1109,6 +1110,7 @@ const SEOViewInner = ({ projectId, tnMapping }: SEOViewProps) => {detailsExtraColumns={detailsExtraColumns}hidePercentageInDetailsdataLoading={gscLoading}+ isLoading={isSEOLoading}/><Panelname={t('project.devices')}@@ -1124,6 +1126,7 @@ const SEOViewInner = ({ projectId, tnMapping }: SEOViewProps) => {detailsExtraColumns={detailsExtraColumns}hidePercentageInDetailsdataLoading={gscLoading}+ isLoading={isSEOLoading}/></div>diff --git a/web/app/pages/Project/tabs/Traffic/TrafficView.tsx b/web/app/pages/Project/tabs/Traffic/TrafficView.tsxindex 0dfda7109..d54bbd97f 100644--- a/web/app/pages/Project/tabs/Traffic/TrafficView.tsx+++ b/web/app/pages/Project/tabs/Traffic/TrafficView.tsx@@ -367,9 +367,9 @@ const TrafficViewInner = ({const isPanelsDataEmpty = isPanelsDataEmptyRaw && !hasShownContentRef.current- const isInitialLoading =- (summaryQuery.isLoading || customEventsQuery.isLoading) &&- !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.isLoadingconst isMountedRef = useRef(true)@@ -1020,15 +1020,6 @@ const TrafficViewInner = ({<ProjectViewHeaderActions tnMapping={tnMapping} exportTypes={exportTypes} />)- if (isInitialLoading) {- return (- <>- <DashboardHeader rightContent={headerRightContent} />- <Loader />- </>- )- }-if (isPanelsDataEmpty) {return (<>@@ -1160,6 +1151,11 @@ const TrafficViewInner = ({<HasImportedIndicator /></Suspense></div>+ {isChartLoading ? (+ <div className='flex h-80 items-center justify-center'>+ <Loader className='pt-0!' />+ </div>+ ) : null}{!_isEmpty(overall) ? (<motion.divinitial='hidden'