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!

Dashboard performance improvements

Blue Mouse3b6a07b5d98a
diff --git a/web/app/hooks/useSize.ts b/web/app/hooks/useSize.ts
index 8c77e2f2c..a68e097b8 100644
--- a/web/app/hooks/useSize.ts
+++ b/web/app/hooks/useSize.ts
@@ -2,7 +2,7 @@ import _get from 'lodash/get'
import type { MutableRefObject } from 'react'
import { useEffect, useRef, useState } from 'react'
-const useSize = (): [
+const useSize = ({ trackHeight = true }: { trackHeight?: boolean } = {}): [
MutableRefObject<null>,
{ width: number; height: number },
] => {
@@ -18,16 +18,20 @@ const useSize = (): [
return
}
const resizeObserver = new ResizeObserver((entries) => {
- setSize({
- width: _get(entries, '0.contentRect.width', 0),
- height: _get(entries, '0.contentRect.height', 0),
- })
+ const width = _get(entries, '0.contentRect.width', 0)
+ const height = trackHeight ? _get(entries, '0.contentRect.height', 0) : 0
+
+ setSize((current) =>
+ current.width === width && current.height === height
+ ? current
+ : { width, height },
+ )
})
resizeObserver.observe(DOMnode)
return () => {
resizeObserver.unobserve(DOMnode)
}
- }, [])
+ }, [trackHeight])
return [ref, size]
}
diff --git a/web/app/pages/Admin/OverviewTab.tsx b/web/app/pages/Admin/OverviewTab.tsx
index a15b13431..533e07e0d 100644
--- a/web/app/pages/Admin/OverviewTab.tsx
+++ b/web/app/pages/Admin/OverviewTab.tsx
@@ -1,11 +1,7 @@
import dayjs from 'dayjs'
-import { motion } from 'motion/react'
import { Link } from 'react-router'
-import {
- MetricCard,
- metricCardsContainerVariants,
-} from '~/pages/Project/tabs/Traffic/MetricCards'
+import { MetricCard } from '~/pages/Project/tabs/Traffic/MetricCards'
import { Badge } from '~/ui/Badge'
import Select from '~/ui/Select'
import { Text } from '~/ui/Text'
@@ -283,12 +279,7 @@ export const OverviewTab = ({
menuClassName='right-0 w-max min-w-full'
/>
</div>
- <motion.div
- initial='hidden'
- animate='visible'
- variants={metricCardsContainerVariants}
- className='mb-5 flex flex-wrap justify-center gap-5 lg:justify-start'
- >
+ <div className='mb-5 flex flex-wrap justify-center gap-5 lg:justify-start'>
<MetricCard
label='Signups'
value={totals.signups.current}
@@ -312,7 +303,7 @@ export const OverviewTab = ({
goodChangeDirection='down'
valueMapper={countMetricMapper}
/>
- </motion.div>
+ </div>
<AdminChart
className='h-72'
series={[
@@ -342,12 +333,7 @@ export const OverviewTab = ({
<Text as='h3' size='lg' weight='semibold' className='mb-4'>
Events processed
</Text>
- <motion.div
- initial='hidden'
- animate='visible'
- variants={metricCardsContainerVariants}
- className='mb-5 flex flex-wrap justify-center gap-5 lg:justify-start'
- >
+ <div className='mb-5 flex flex-wrap justify-center gap-5 lg:justify-start'>
<MetricCard
label={`Events (${chartDays}d)`}
value={totals.events.current}
@@ -355,7 +341,7 @@ export const OverviewTab = ({
goodChangeDirection='down'
valueMapper={countMetricMapper}
/>
- </motion.div>
+ </div>
<AdminChart
className='h-72'
series={[
diff --git a/web/app/pages/Project/View/Panels.tsx b/web/app/pages/Project/View/Panels.tsx
index 05866f0c3..2a7c00cd7 100644
--- a/web/app/pages/Project/View/Panels.tsx
+++ b/web/app/pages/Project/View/Panels.tsx
@@ -31,7 +31,6 @@ import {
ArrowLineLeftIcon,
MagnifyingGlassIcon,
} from '@phosphor-icons/react'
-import { motion } from 'motion/react'
import React, {
memo,
useState,
@@ -39,7 +38,6 @@ import React, {
useMemo,
useCallback,
Fragment,
- useId,
useRef,
} from 'react'
import { useTranslation } from 'react-i18next'
@@ -110,19 +108,13 @@ const getPercentage = (value: number, total: number, precision = 2) => {
}
const panelBarStyle = (pct: number) =>
- ({ '--panel-bar-width': `${pct}%` }) as React.CSSProperties
-
-/**
- * Active-tab underline shared between a panel's tab buttons: rendering it
- * with a common layoutId makes it glide from the old tab to the new one.
- * The layoutId must be unique per panel instance — multiple panels render
- * their tab bars simultaneously.
- */
-const PanelTabUnderline = ({ layoutId }: { layoutId: string }) => (
- <motion.span
+ ({
+ '--panel-bar-scale': Math.max(0, Math.min(100, pct)) / 100,
+ }) as React.CSSProperties
+
+const PanelTabUnderline = () => (
+ <span
aria-hidden
- layoutId={layoutId}
- transition={{ duration: 0.2, ease: [0.23, 1, 0.32, 1] }}
className='absolute inset-x-0 -bottom-0.5 h-0.5 bg-slate-900 dark:bg-gray-50'
/>
)
@@ -256,8 +248,6 @@ const PanelContainer = ({
isLoading,
}: PanelContainerProps) => {
const { t } = useTranslation('common')
- const underlineId = useId()
-
return (
<div
className={cx(
@@ -322,9 +312,7 @@ const PanelContainer = ({
headless
chevron='mini'
/>
- {activeDropdownTab ? (
- <PanelTabUnderline layoutId={underlineId} />
- ) : null}
+ {activeDropdownTab ? <PanelTabUnderline /> : null}
</div>
)
}
@@ -348,9 +336,7 @@ const PanelContainer = ({
)}
>
{tab.label}
- {activeTabId === tab.id ? (
- <PanelTabUnderline layoutId={underlineId} />
- ) : null}
+ {activeTabId === tab.id ? <PanelTabUnderline /> : null}
</button>
)
})}
@@ -363,7 +349,6 @@ const PanelContainer = ({
className={cx(
contentClassName ??
'relative flex h-[19.6rem] flex-col overflow-hidden',
- isRefetching && 'opacity-75 transition-opacity duration-200',
)}
>
{isLoading ? <PanelLoadingState /> : children}
@@ -1859,8 +1844,6 @@ const CombinedMetadataPanel = ({
const [canShowDetails, setCanShowDetails] = useState(false)
const [detailsTrigger, setDetailsTrigger] = useState(0)
- const underlineId = useId()
-
const activeDropdownTab = dropdownItems.find(
(item) => item.id === activeSection.activeKey,
)
@@ -1897,9 +1880,7 @@ const CombinedMetadataPanel = ({
)}
>
{tab.label}
- {activeMode === tab.id ? (
- <PanelTabUnderline layoutId={underlineId} />
- ) : null}
+ {activeMode === tab.id ? <PanelTabUnderline /> : null}
</button>
))}
{!_isEmpty(dropdownItems) ? (
diff --git a/web/app/pages/Project/View/ViewProject.helpers.tsx b/web/app/pages/Project/View/ViewProject.helpers.tsx
index 03d86dd97..2c149b277 100644
--- a/web/app/pages/Project/View/ViewProject.helpers.tsx
+++ b/web/app/pages/Project/View/ViewProject.helpers.tsx
@@ -80,6 +80,19 @@ dayjs.extend(timezonePlugin)
// Max length of annotation text displayed on chart (truncated with "...")
const ANNOTATION_CHART_TEXT_MAX_LENGTH = 25
+export const getAnnotationGridLines = (
+ annotations?: Annotation[],
+): GridLineOptions[] =>
+ _map(annotations || [], (annotation) => ({
+ value: dayjs(annotation.date).toDate(),
+ text:
+ annotation.text.length > ANNOTATION_CHART_TEXT_MAX_LENGTH
+ ? `${annotation.text.substring(0, ANNOTATION_CHART_TEXT_MAX_LENGTH)}...`
+ : annotation.text,
+ class: `annotation-line annotation-id-${annotation.id}`,
+ position: 'start',
+ }))
+
const getAvg = (arr: any) => {
const total = _reduce(arr, (acc, c) => acc + c, 0)
return total / _size(arr)
@@ -626,17 +639,7 @@ const getSettings = (
): ChartOptions => {
const xAxisSize = _size(chart.x)
- // Convert annotations to grid lines
- // Each annotation gets a unique class identifier for DOM-based lookup
- const lines: GridLineOptions[] = _map(annotations || [], (annotation) => ({
- value: dayjs(annotation.date).toDate(),
- text:
- annotation.text.length > ANNOTATION_CHART_TEXT_MAX_LENGTH
- ? `${annotation.text.substring(0, ANNOTATION_CHART_TEXT_MAX_LENGTH)}...`
- : annotation.text,
- class: `annotation-line annotation-id-${annotation.id}`,
- position: 'start',
- }))
+ const lines = getAnnotationGridLines(annotations)
const modifiedChart = { ...chart }
let regions
const customEventsToArray = customEvents
@@ -1521,20 +1524,7 @@ const getSettingsError = (
): ChartOptions => {
const xAxisSize = _size(chart.x)
- // Convert annotations to grid lines
- // Each annotation gets a unique class identifier for DOM-based lookup
- const annotationLines: GridLineOptions[] = _map(
- annotations || [],
- (annotation) => ({
- value: dayjs(annotation.date).toDate(),
- text:
- annotation.text.length > ANNOTATION_CHART_TEXT_MAX_LENGTH
- ? `${annotation.text.substring(0, ANNOTATION_CHART_TEXT_MAX_LENGTH)}...`
- : annotation.text,
- class: `annotation-line annotation-id-${annotation.id}`,
- position: 'start',
- }),
- )
+ const annotationLines = getAnnotationGridLines(annotations)
// Build columns with both occurrences and affectedUsers if available
const columns: any[] = [
@@ -2023,20 +2013,7 @@ const getSettingsPerf = (
const xAxisSize = _size(chart.x)
const columns = getColumnsPerf(chart, activeChartMetrics, compareChart)
- // Convert annotations to grid lines
- // Each annotation gets a unique class identifier for DOM-based lookup
- const annotationLines: GridLineOptions[] = _map(
- annotations || [],
- (annotation) => ({
- value: dayjs(annotation.date).toDate(),
- text:
- annotation.text.length > ANNOTATION_CHART_TEXT_MAX_LENGTH
- ? `${annotation.text.substring(0, ANNOTATION_CHART_TEXT_MAX_LENGTH)}...`
- : annotation.text,
- class: `annotation-line annotation-id-${annotation.id}`,
- position: 'start',
- }),
- )
+ const annotationLines = getAnnotationGridLines(annotations)
return {
data: {
diff --git a/web/app/pages/Project/View/ViewProject.tsx b/web/app/pages/Project/View/ViewProject.tsx
index 451d2c791..8b63a0357 100644
--- a/web/app/pages/Project/View/ViewProject.tsx
+++ b/web/app/pages/Project/View/ViewProject.tsx
@@ -1,7 +1,6 @@
import { useQueryClient } from '@tanstack/react-query'
import cx from 'clsx'
import dayjs from 'dayjs'
-import { AnimatePresence, motion } from 'motion/react'
import _filter from 'lodash/filter'
import _find from 'lodash/find'
import _includes from 'lodash/includes'
@@ -146,13 +145,8 @@ interface ViewProjectContextType {
dataLoading: boolean
activeTab: keyof typeof PROJECT_TABS
filters: V2Filter[]
- projectViews: ProjectView[]
- projectViewsLoading: boolean | null
- loadProjectViews: (forced?: boolean) => void
- setProjectViewToUpdate: (view: ProjectView | undefined) => void
- setIsAddAViewOpened: (value: boolean) => void
-
isActiveCompare: boolean
+
dateRangeCompare: Date[] | null
activePeriodCompare: string
setIsActiveCompare: (value: boolean) => void
@@ -191,6 +185,14 @@ interface ViewProjectContextType {
setIsMapFullscreen: (value: boolean) => void
}
+interface ProjectViewsContextType {
+ projectViews: ProjectView[]
+ projectViewsLoading: boolean | null
+ loadProjectViews: (forced?: boolean) => void
+ setProjectViewToUpdate: (view: ProjectView | undefined) => void
+ setIsAddAViewOpened: (value: boolean) => void
+}
+
interface RefreshTriggersContextType {
goalsRefreshTrigger: number
experimentsRefreshTrigger: number
@@ -212,13 +214,8 @@ const defaultViewProjectContext: ViewProjectContextType = {
dataLoading: false,
activeTab: PROJECT_TABS.traffic,
filters: [],
- projectViews: [],
- projectViewsLoading: null,
- loadProjectViews: () => {},
- setProjectViewToUpdate: () => {},
- setIsAddAViewOpened: () => {},
-
isActiveCompare: false,
+
dateRangeCompare: null,
activePeriodCompare: '',
setIsActiveCompare: () => {},
@@ -253,6 +250,14 @@ const defaultViewProjectContext: ViewProjectContextType = {
setIsMapFullscreen: () => {},
}
+const defaultProjectViewsContext: ProjectViewsContextType = {
+ projectViews: [],
+ projectViewsLoading: null,
+ loadProjectViews: () => {},
+ setProjectViewToUpdate: () => {},
+ setIsAddAViewOpened: () => {},
+}
+
const defaultRefreshTriggersContext: RefreshTriggersContextType = {
goalsRefreshTrigger: 0,
experimentsRefreshTrigger: 0,
@@ -264,15 +269,39 @@ const defaultRefreshTriggersContext: RefreshTriggersContextType = {
const ViewProjectContext = createContext<ViewProjectContextType>(
defaultViewProjectContext,
)
+const ProjectViewsContext = createContext<ProjectViewsContextType>(
+ defaultProjectViewsContext,
+)
const RefreshTriggersContext = createContext<RefreshTriggersContextType>(
defaultRefreshTriggersContext,
)
+const ProjectViewAuxiliaryProviders = ({
+ projectViewsContextValue,
+ refreshTriggersValue,
+ children,
+}: {
+ projectViewsContextValue: ProjectViewsContextType
+ refreshTriggersValue: RefreshTriggersContextType
+ children: React.ReactNode
+}) => (
+ <ProjectViewsContext.Provider value={projectViewsContextValue}>
+ <RefreshTriggersContext.Provider value={refreshTriggersValue}>
+ {children}
+ </RefreshTriggersContext.Provider>
+ </ProjectViewsContext.Provider>
+)
+
export const useViewProjectContext = () => {
const context = useContext(ViewProjectContext)
return context
}
+export const useProjectViewsContext = () => {
+ const context = useContext(ProjectViewsContext)
+ return context
+}
+
export const useRefreshTriggers = () => {
const context = useContext(RefreshTriggersContext)
return context
@@ -357,7 +386,7 @@ const ViewProjectContent = () => {
return parseFiltersFromUrl(searchParams)
}, [searchParams])
- const tnMapping = typeNameMapping(t)
+ const tnMapping = useMemo(() => typeNameMapping(t), [t])
const refCalendar = useRef(null)
const refCalendarCompare = useRef(null)
const activeTab = useMemo(() => {
@@ -557,7 +586,7 @@ const ViewProjectContent = () => {
() => user?.timeFormat || TimeFormat['12-hour'],
[user],
)
- const [ref, size] = useSize()
+ const [ref, size] = useSize({ trackHeight: false })
const rotateXAxis = useMemo(() => size.width > 0 && size.width < 500, [size])
const [chartType, setChartType] = useState<keyof typeof chartTypes>(
(getItem('chartType') as keyof typeof chartTypes) || chartTypes.line,
@@ -1176,11 +1205,6 @@ const ViewProjectContent = () => {
dataLoading,
activeTab,
filters,
- projectViews,
- projectViewsLoading,
- loadProjectViews,
- setProjectViewToUpdate,
- setIsAddAViewOpened,
isActiveCompare,
dateRangeCompare,
@@ -1228,9 +1252,6 @@ const ViewProjectContent = () => {
dataLoading,
activeTab,
filters,
- projectViews,
- projectViewsLoading,
- loadProjectViews,
isActiveCompare,
dateRangeCompare,
activePeriodCompare,
@@ -1261,6 +1282,17 @@ const ViewProjectContent = () => {
],
)
+ const projectViewsContextValue = useMemo(
+ () => ({
+ projectViews,
+ projectViewsLoading,
+ loadProjectViews,
+ setProjectViewToUpdate,
+ setIsAddAViewOpened,
+ }),
+ [projectViews, projectViewsLoading, loadProjectViews],
+ )
+
const refreshTriggersValue = useMemo(
() => ({
goalsRefreshTrigger,
@@ -1440,7 +1472,10 @@ const ViewProjectContent = () => {
<ClientOnly>
{() => (
<ViewProjectContext.Provider value={contextValue}>
- <RefreshTriggersContext.Provider value={refreshTriggersValue}>
+ <ProjectViewAuxiliaryProviders
+ projectViewsContextValue={projectViewsContextValue}
+ refreshTriggersValue={refreshTriggersValue}
+ >
<>
<div
className={cx(
@@ -1519,74 +1554,90 @@ const ViewProjectContent = () => {
/>
</div>
) : null}
- <AnimatePresence mode='wait'>
- <motion.div
- key={activeTab}
- initial={{ opacity: 0, y: 6 }}
- animate={{ opacity: 1, y: 0 }}
- exit={{
- opacity: 0,
- transition: { duration: 0.1 },
- }}
- transition={{
- duration: 0.15,
- ease: [0.23, 1, 0.32, 1],
- }}
- >
- {/* Reserve roughly a screenful while the tab chunk
+ <div key={activeTab}>
+ {/* 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}
- {activeTab === PROJECT_TABS.traffic ? (
- <TrafficView
- tnMapping={tnMapping}
- customMetrics={customMetrics}
- onRemoveCustomMetric={onRemoveCustomMetric}
- resetCustomMetrics={resetCustomMetrics}
- />
- ) : null}
- {activeTab === PROJECT_TABS.performance ? (
- <PerformanceView tnMapping={tnMapping} />
- ) : null}
- {activeTab === PROJECT_TABS.seo ? (
- <SEOView projectId={id} tnMapping={tnMapping} />
- ) : null}
- {activeTab === PROJECT_TABS.funnels ? (
- <FunnelsView tnMapping={tnMapping} />
- ) : null}
- {activeTab === PROJECT_TABS.journeys ? (
- <JourneysView tnMapping={tnMapping} />
- ) : null}
- {activeTab === PROJECT_TABS.profiles ? (
- <ProfilesView tnMapping={tnMapping} />
- ) : null}
- {activeTab === PROJECT_TABS.sessions ? (
- <SessionsView
- tnMapping={tnMapping}
- rotateXAxis={rotateXAxis}
+ <Suspense
+ fallback={
+ <Loader className='min-h-including-header items-start' />
+ }
+ >
+ {activeTab === PROJECT_TABS.ai ? (
+ <AskAIView projectId={id} />
+ ) : null}
+ {activeTab === PROJECT_TABS.traffic ? (
+ <TrafficView
+ tnMapping={tnMapping}
+ customMetrics={customMetrics}
+ onRemoveCustomMetric={onRemoveCustomMetric}
+ resetCustomMetrics={resetCustomMetrics}
+ />
+ ) : null}
+ {activeTab === PROJECT_TABS.performance ? (
+ <PerformanceView tnMapping={tnMapping} />
+ ) : null}
+ {activeTab === PROJECT_TABS.seo ? (
+ <SEOView projectId={id} tnMapping={tnMapping} />
+ ) : null}
+ {activeTab === PROJECT_TABS.funnels ? (
+ <FunnelsView tnMapping={tnMapping} />
+ ) : null}
+ {activeTab === PROJECT_TABS.journeys ? (
+ <JourneysView tnMapping={tnMapping} />
+ ) : null}
+ {activeTab === PROJECT_TABS.profiles ? (
+ <ProfilesView tnMapping={tnMapping} />
+ ) : null}
+ {activeTab === PROJECT_TABS.sessions ? (
+ <SessionsView
+ tnMapping={tnMapping}
+ rotateXAxis={rotateXAxis}
+ />
+ ) : null}
+ {activeTab === PROJECT_TABS.replays ? (
+ replaysAccess.hasAccess ? (
+ <ReplaysView tnMapping={tnMapping} />
+ ) : (
+ <PlanFeatureLocked feature='replays' />
+ )
+ ) : null}
+ {activeTab === PROJECT_TABS.errors ? (
+ <ErrorsView />
+ ) : null}
+ {activeTab === PROJECT_TABS.goals ? (
+ <GoalsView
+ tnMapping={tnMapping}
+ period={period}
+ from={
+ dateRange ? getFormatDate(dateRange[0]) : ''
+ }
+ to={
+ dateRange ? getFormatDate(dateRange[1]) : ''
+ }
+ timezone={timezone}
+ />
+ ) : null}
+ {activeTab === PROJECT_TABS.experiments ? (
+ experimentsAccess.hasAccess ? (
+ <ExperimentsView
+ period={period}
+ from={
+ dateRange ? getFormatDate(dateRange[0]) : ''
+ }
+ to={
+ dateRange ? getFormatDate(dateRange[1]) : ''
+ }
+ timezone={timezone}
/>
- ) : null}
- {activeTab === PROJECT_TABS.replays ? (
- replaysAccess.hasAccess ? (
- <ReplaysView tnMapping={tnMapping} />
- ) : (
- <PlanFeatureLocked feature='replays' />
- )
- ) : null}
- {activeTab === PROJECT_TABS.errors ? (
- <ErrorsView />
- ) : null}
- {activeTab === PROJECT_TABS.goals ? (
- <GoalsView
- tnMapping={tnMapping}
+ ) : (
+ <PlanFeatureLocked feature='experiments' />
+ )
+ ) : null}
+ {activeTab === PROJECT_TABS.featureFlags ? (
+ featureFlagsAccess.hasAccess ? (
+ <FeatureFlagsView
period={period}
from={
dateRange ? getFormatDate(dateRange[0]) : ''
@@ -1596,53 +1647,15 @@ const ViewProjectContent = () => {
}
timezone={timezone}
/>
- ) : null}
- {activeTab === PROJECT_TABS.experiments ? (
- experimentsAccess.hasAccess ? (
- <ExperimentsView
- period={period}
- from={
- dateRange
- ? getFormatDate(dateRange[0])
- : ''
- }
- to={
- dateRange
- ? getFormatDate(dateRange[1])
- : ''
- }
- timezone={timezone}
- />
- ) : (
- <PlanFeatureLocked feature='experiments' />
- )
- ) : null}
- {activeTab === PROJECT_TABS.featureFlags ? (
- featureFlagsAccess.hasAccess ? (
- <FeatureFlagsView
- period={period}
- from={
- dateRange
- ? getFormatDate(dateRange[0])
- : ''
- }
- to={
- dateRange
- ? getFormatDate(dateRange[1])
- : ''
- }
- timezone={timezone}
- />
- ) : (
- <PlanFeatureLocked feature='featureFlags' />
- )
- ) : null}
- {activeTab === PROJECT_TABS.captcha ? (
- <CaptchaView projectId={id} />
- ) : null}
- </Suspense>
- </motion.div>
- </AnimatePresence>
+ ) : (
+ <PlanFeatureLocked feature='featureFlags' />
+ )
+ ) : null}
+ {activeTab === PROJECT_TABS.captcha ? (
+ <CaptchaView projectId={id} />
+ ) : null}
+ </Suspense>
+ </div>
{isEmbedded || isMapFullscreen ? null : (
<>
@@ -1798,7 +1811,7 @@ const ViewProjectContent = () => {
viewType={projectViewCreateType}
/>
</>
- </RefreshTriggersContext.Provider>
+ </ProjectViewAuxiliaryProviders>
</ViewProjectContext.Provider>
)}
</ClientOnly>
diff --git a/web/app/pages/Project/View/components/Filters.tsx b/web/app/pages/Project/View/components/Filters.tsx
index a7ed71818..88f2bd140 100644
--- a/web/app/pages/Project/View/components/Filters.tsx
+++ b/web/app/pages/Project/View/components/Filters.tsx
@@ -2,7 +2,6 @@ import _isEmpty from 'lodash/isEmpty'
import _map from 'lodash/map'
import _truncate from 'lodash/truncate'
import { FunnelIcon, XIcon } from '@phosphor-icons/react'
-import { AnimatePresence, motion } from 'motion/react'
import { memo, MouseEvent, useMemo } from 'react'
import { useTranslation } from 'react-i18next'
import { Link } from '~/ui/Link'
@@ -306,39 +305,24 @@ const Filters = ({ tnMapping, className }: FiltersProps) => {
<div className='flex min-w-0 flex-1 items-center gap-1'>
<FunnelIcon className='size-5 shrink-0 text-gray-500 dark:text-gray-400' />
<div className='flex flex-wrap'>
- <AnimatePresence mode='popLayout' initial={false}>
- {_map(supported, (filter) => (
- <motion.span
- key={getFilterKey(filter)}
- layout
- initial={{ opacity: 0, scale: 0.92 }}
- animate={{ opacity: 1, scale: 1 }}
- exit={{ opacity: 0, scale: 0.92 }}
- transition={{ duration: 0.15, ease: [0.23, 1, 0.32, 1] }}
- className='inline-flex'
- >
- <Filter
- tnMapping={tnMapping}
- canChangeExclusive
- removable
- filter={filter}
- />
- </motion.span>
- ))}
- {_map(unsupported, (filter) => (
- <motion.span
- key={`unsupported-${getFilterKey(filter)}`}
- layout
- initial={{ opacity: 0, scale: 0.92 }}
- animate={{ opacity: 0.6, scale: 1 }}
- exit={{ opacity: 0, scale: 0.92 }}
- transition={{ duration: 0.15, ease: [0.23, 1, 0.32, 1] }}
- className='inline-flex'
- >
- <Filter tnMapping={tnMapping} removable filter={filter} />
- </motion.span>
- ))}
- </AnimatePresence>
+ {_map(supported, (filter) => (
+ <span key={getFilterKey(filter)} className='inline-flex'>
+ <Filter
+ tnMapping={tnMapping}
+ canChangeExclusive
+ removable
+ filter={filter}
+ />
+ </span>
+ ))}
+ {_map(unsupported, (filter) => (
+ <span
+ key={`unsupported-${getFilterKey(filter)}`}
+ className='inline-flex opacity-60'
+ >
+ <Filter tnMapping={tnMapping} removable filter={filter} />
+ </span>
+ ))}
</div>
{unsupported.length > 0 ? (
<span className='ml-1 shrink-0 rounded-md bg-amber-50 px-1.5 py-0.5 text-[11px] font-medium text-amber-700 ring-1 ring-amber-200 ring-inset dark:bg-amber-500/10 dark:text-amber-300 dark:ring-amber-400/20'>
diff --git a/web/app/pages/Project/View/components/LiveVisitorsDropdown.tsx b/web/app/pages/Project/View/components/LiveVisitorsDropdown.tsx
index 3fcafed16..c5e091812 100644
--- a/web/app/pages/Project/View/components/LiveVisitorsDropdown.tsx
+++ b/web/app/pages/Project/View/components/LiveVisitorsDropdown.tsx
@@ -1,4 +1,3 @@
-import NumberFlow from '@number-flow/react'
import { CaretDownIcon, XIcon } from '@phosphor-icons/react'
import _map from 'lodash/map'
import React, { useState } from 'react'
@@ -8,11 +7,6 @@ import { Link } from '~/ui/Link'
import { getLiveVisitors as getLiveVisitorsV2 } from '~/api/v2/endpoints'
import type { LiveVisitor } from '~/api/v2/types'
-import {
- FLOW_TIMING,
- FLOW_VALUE_CLASS,
- useFlowValue,
-} from '~/hooks/useFlowValue'
import { PROJECT_TABS } from '~/lib/constants'
import Flag from '~/ui/Flag'
import PulsatingCircle from '~/ui/icons/PulsatingCircle'
@@ -30,7 +24,6 @@ const LiveVisitorsDropdown = () => {
const [isDropdownVisible, setIsDropdownVisible] = useState(false)
const [isLoading, setIsLoading] = useState(true)
const [liveInfo, setLiveInfo] = useState<LiveVisitor[]>([])
- const flowLiveVisitors = useFlowValue(liveVisitors)
// The translation interpolates the amount into the sentence, so split it
// around the placeholder to render the number with NumberFlow.
@@ -81,12 +74,7 @@ const LiveVisitorsDropdown = () => {
<PulsatingCircle className='mr-1.5' type='small' />
<span>
{liveVisitorsLabelStart}
- <NumberFlow
- className={FLOW_VALUE_CLASS}
- {...FLOW_TIMING}
- value={flowLiveVisitors}
- willChange
- />
+ {liveVisitors}
{liveVisitorsLabelEnd}{' '}
</span>
<CaretDownIcon
@@ -102,7 +90,7 @@ const LiveVisitorsDropdown = () => {
<div
id='live-visitors-dropdown'
className={cn(
- 'absolute top-full right-0 z-40 mt-1 max-w-[calc(100vw-1rem)] origin-top-right transform cursor-auto scrollbar-thin overflow-hidden rounded-md border border-black/10 bg-white text-xs text-gray-900 shadow-md transition duration-150 ease-out outline-none max-sm:fixed max-sm:top-20 max-sm:right-2 max-sm:left-2 max-sm:w-auto max-sm:max-w-none sm:w-[250px] dark:border-slate-700/50 dark:bg-slate-950 dark:text-gray-50',
+ 'absolute top-full right-0 z-40 mt-1 max-w-[calc(100vw-1rem)] origin-top-right transform cursor-auto scrollbar-thin overflow-hidden rounded-md border border-black/10 bg-white text-xs text-gray-900 shadow-md transition-[opacity,transform] duration-150 ease-out-quint outline-none motion-reduce:transition-none max-sm:fixed max-sm:top-20 max-sm:right-2 max-sm:left-2 max-sm:w-auto max-sm:max-w-none sm:w-[250px] dark:border-slate-700/50 dark:bg-slate-950 dark:text-gray-50',
liveInfo.length === 0 || isLoading ? 'min-w-[200px]' : 'min-w-0',
isDropdownVisible
? 'pointer-events-auto translate-y-0 scale-100 opacity-100'
diff --git a/web/app/pages/Project/View/components/MainChart.tsx b/web/app/pages/Project/View/components/MainChart.tsx
index 86c423891..36db23e25 100644
--- a/web/app/pages/Project/View/components/MainChart.tsx
+++ b/web/app/pages/Project/View/components/MainChart.tsx
@@ -1,4 +1,4 @@
-import { ChartOptions } from 'billboard.js'
+import { Chart, ChartOptions, GridLineOptions } from 'billboard.js'
import React, { useEffect, useRef, useMemo } from 'react'
import BillboardChart from '~/ui/BillboardChart'
@@ -11,6 +11,7 @@ interface MainChartProps {
dataNames?: Record<string, string>
className?: string
deps?: any[]
+ xGridLines?: GridLineOptions[]
}
export const MainChart = ({
@@ -19,20 +20,33 @@ export const MainChart = ({
dataNames,
className,
deps,
+ xGridLines,
}: MainChartProps) => {
const { registerChart, unregisterChart } = useChartManager()
- const chartRef = useRef<any>(null)
+ const chartRef = useRef<Chart | null>(null)
const mergedDeps = useMemo(
() => deps || [options, dataNames],
[deps, options, dataNames],
)
- const handleChartReady = (chart: any) => {
+ const handleChartReady = (chart: Chart | null) => {
chartRef.current = chart
registerChart(chartId, chart)
+
+ if (chart && xGridLines) {
+ chart.xgrids(xGridLines)
+ }
}
+ useEffect(() => {
+ if (!chartRef.current || !xGridLines) {
+ return
+ }
+
+ chartRef.current.xgrids(xGridLines)
+ }, [xGridLines])
+
useEffect(() => {
return () => {
unregisterChart(chartId)
diff --git a/web/app/pages/Project/View/components/ProjectSidebar.tsx b/web/app/pages/Project/View/components/ProjectSidebar.tsx
index fb726ed1c..70cafa83f 100644
--- a/web/app/pages/Project/View/components/ProjectSidebar.tsx
+++ b/web/app/pages/Project/View/components/ProjectSidebar.tsx
@@ -245,7 +245,7 @@ const CollapsibleGroup: React.FC<{
<div
className={cn(
- 'overflow-hidden transition-all duration-200 ease-in-out',
+ 'overflow-hidden transition-[max-height,opacity] duration-150 ease-out-quint motion-reduce:transition-none',
{
'max-h-96 opacity-100': isExpanded,
'max-h-0 opacity-0': !isExpanded,
@@ -480,11 +480,9 @@ const ProjectSidebar: React.FC<ProjectSidebarProps> = ({
isMobileOpen
? 'h-screen w-64 border-r border-gray-200 bg-white dark:border-slate-800/60 dark:bg-slate-950'
: cn(
- 'duration-300 ease-in-out',
isEmbedded
- ? 'h-[calc(100vh-1rem)] transition-[width]'
+ ? 'h-[calc(100vh-1rem)]'
: cn(
- 'transition-[width,height]',
isScrolled
? 'h-[calc(100vh-var(--banner-height)-1.5rem)]'
: 'h-[calc(100vh-var(--header-total-height)-1rem)]',
@@ -724,11 +722,11 @@ const ProjectSidebar: React.FC<ProjectSidebarProps> = ({
return (
<div className='pointer-events-auto fixed inset-0 z-50 md:hidden'>
<div
- className='animate-fade-in absolute inset-0 bg-black/50'
+ className='animate-fade-in absolute inset-0 bg-black/50 motion-reduce:animate-none'
onClick={onMobileClose}
aria-hidden='true'
/>
- <div className='animate-slide-in-left relative h-full w-fit'>
+ <div className='animate-slide-in-left relative h-full w-fit motion-reduce:animate-none'>
{sidebarContent}
</div>
</div>
@@ -754,7 +752,7 @@ export const MobileSidebarTrigger: React.FC<MobileSidebarTriggerProps> = ({
<button
type='button'
onClick={onClick}
- className='flex items-center justify-center rounded-md border border-gray-300 p-2 text-gray-700 transition-all ring-inset hover:bg-white focus:z-10 focus:ring-1 focus:ring-slate-900 focus:outline-hidden dark:border-slate-700/80 dark:text-gray-200 dark:hover:bg-slate-900 dark:focus:ring-slate-300'
+ className='flex items-center justify-center rounded-md border border-gray-300 p-2 text-gray-700 transition-[background-color,color,box-shadow,transform] duration-150 ease-out-quint ring-inset hover:bg-white focus:z-10 focus:ring-1 focus:ring-slate-900 focus:outline-hidden active:scale-[0.97] motion-reduce:active:scale-100 dark:border-slate-700/80 dark:text-gray-200 dark:hover:bg-slate-900 dark:focus:ring-slate-300'
aria-label={t('common.openMenu')}
>
<ListIcon className='h-5 w-5' />
diff --git a/web/app/pages/Project/View/components/ProjectViewHeaderActions.tsx b/web/app/pages/Project/View/components/ProjectViewHeaderActions.tsx
index 8e657e069..6a7d32999 100644
--- a/web/app/pages/Project/View/components/ProjectViewHeaderActions.tsx
+++ b/web/app/pages/Project/View/components/ProjectViewHeaderActions.tsx
@@ -24,7 +24,7 @@ import {
splitProjectViewFiltersByTab,
supportsProjectViewSegments,
} from '../utils/projectViewSegments'
-import { useViewProjectContext } from '../ViewProject'
+import { useProjectViewsContext, useViewProjectContext } from '../ViewProject'
import { getFiltersUrlParams } from './SearchFilters'
@@ -71,16 +71,14 @@ const ProjectViewHeaderActions = ({
extraActions,
}: ProjectViewHeaderActionsProps) => {
const { allowedToManage } = useCurrentProject()
+ const { activeTab, dataLoading, filters } = useViewProjectContext()
const {
- activeTab,
- dataLoading,
- filters,
projectViews,
projectViewsLoading,
loadProjectViews,
setProjectViewToUpdate,
setIsAddAViewOpened,
- } = useViewProjectContext()
+ } = useProjectViewsContext()
const { t } = useTranslation('common')
const [searchParams, setSearchParams] = useSearchParams()
const deleteFetcher = useFetcher<ProjectViewActionData>()
diff --git a/web/app/pages/Project/View/components/RefreshStatsButton.tsx b/web/app/pages/Project/View/components/RefreshStatsButton.tsx
index 082a37d3f..6f9f40743 100644
--- a/web/app/pages/Project/View/components/RefreshStatsButton.tsx
+++ b/web/app/pages/Project/View/components/RefreshStatsButton.tsx
@@ -5,7 +5,6 @@ import { useTranslation } from 'react-i18next'
import { useAuth } from '~/providers/AuthProvider'
import Button from '~/ui/Button'
import Tooltip from '~/ui/Tooltip'
-import { cn } from '~/utils/generic'
import { useViewProjectContext } from '../ViewProject'
@@ -27,10 +26,9 @@ export const RefreshStatsButton = ({ onRefresh }: RefreshStatsButtonProps) => {
const hasTriggeredRefresh = useRef(false)
useEffect(() => {
- let animationFrameId: number
let lastRenderedProgress = 0
- const animate = () => {
+ const updateProgress = () => {
const elapsed = Date.now() - startTimeRef.current
const newProgress = Math.min((elapsed / REFRESH_INTERVAL_MS) * 100, 100)
@@ -66,13 +64,12 @@ export const RefreshStatsButton = ({ onRefresh }: RefreshStatsButtonProps) => {
}
})()
}
-
- animationFrameId = requestAnimationFrame(animate)
}
- animationFrameId = requestAnimationFrame(animate)
+ updateProgress()
+ const intervalId = window.setInterval(updateProgress, 250)
- return () => cancelAnimationFrame(animationFrameId)
+ return () => window.clearInterval(intervalId)
}, [onRefresh, isRefreshing, authLoading, dataLoading])
const handleManualRefresh = async () => {
@@ -113,28 +110,22 @@ export const RefreshStatsButton = ({ onRefresh }: RefreshStatsButtonProps) => {
disabled={authLoading || dataLoading || isRefreshing}
>
<span className='relative size-5'>
- <ArrowClockwiseIcon
- className={cn(
- 'absolute inset-0 size-5 text-gray-400/80 dark:text-slate-600',
- {
- 'animate-spin': showSpinner,
- },
- )}
- />
- {!showSpinner ? (
- <span
- className='absolute inset-0'
- style={{
- maskImage: `conic-gradient(from 100deg, black ${progress}%, transparent ${progress}%)`,
- WebkitMaskImage: `conic-gradient(from 100deg, black ${progress}%, transparent ${progress}%)`,
- }}
- >
- <ArrowClockwiseIcon className='size-5 text-gray-700 dark:text-gray-50' />
- </span>
- ) : null}
{showSpinner ? (
- <ArrowClockwiseIcon className='absolute inset-0 size-5 animate-spin text-gray-700 dark:text-gray-50' />
- ) : null}
+ <ArrowClockwiseIcon className='absolute inset-0 size-5 animate-spin text-gray-700 motion-reduce:animate-none dark:text-gray-50' />
+ ) : (
+ <>
+ <ArrowClockwiseIcon className='absolute inset-0 size-5 text-gray-400/80 dark:text-slate-600' />
+ <span
+ className='absolute inset-0'
+ style={{
+ maskImage: `conic-gradient(from 100deg, black ${progress}%, transparent ${progress}%)`,
+ WebkitMaskImage: `conic-gradient(from 100deg, black ${progress}%, transparent ${progress}%)`,
+ }}
+ >
+ <ArrowClockwiseIcon className='size-5 text-gray-700 dark:text-gray-50' />
+ </span>
+ </>
+ )}
</span>
</Button>
}
diff --git a/web/app/pages/Project/View/components/TBPeriodSelector.tsx b/web/app/pages/Project/View/components/TBPeriodSelector.tsx
index 44f458598..184d4b1a6 100644
--- a/web/app/pages/Project/View/components/TBPeriodSelector.tsx
+++ b/web/app/pages/Project/View/components/TBPeriodSelector.tsx
@@ -65,7 +65,7 @@ const TBPeriodSelector = ({
<span>{title}</span>
<CaretDownIcon
className={cx(
- 'ml-2 h-5 w-5 transform-gpu text-gray-700 transition ease-in-out dark:text-gray-50',
+ 'ml-2 h-5 w-5 transform-gpu text-gray-700 transition-transform duration-150 ease-out-quint motion-reduce:transition-none dark:text-gray-50',
{
'rotate-180': open,
},
diff --git a/web/app/pages/Project/View/v2/loading.tsx b/web/app/pages/Project/View/v2/loading.tsx
index 4ba496957..e6076441b 100644
--- a/web/app/pages/Project/View/v2/loading.tsx
+++ b/web/app/pages/Project/View/v2/loading.tsx
@@ -4,24 +4,10 @@ export const RefetchIndicator = ({ className }: { className?: string }) => (
<div
aria-hidden
className={cx(
- 'absolute inset-x-0 top-0 z-10 h-0.5 overflow-hidden',
+ 'absolute inset-x-0 top-0 z-10 h-0.5 overflow-hidden rounded-full bg-slate-200/70 dark:bg-slate-700/70',
className,
)}
>
- <div
- className='absolute h-full rounded-full bg-linear-to-r from-slate-400 via-slate-700 to-slate-900 dark:from-slate-500 dark:via-slate-200 dark:to-white'
- style={{
- animation:
- 'indeterminate1 1.8s cubic-bezier(0.65, 0.815, 0.735, 0.395) infinite',
- }}
- />
- <div
- className='absolute h-full rounded-full bg-linear-to-r from-slate-700 to-slate-900 opacity-70 dark:from-slate-300 dark:to-white'
- style={{
- animation:
- 'indeterminate2 1.8s cubic-bezier(0.165, 0.84, 0.44, 1) infinite',
- animationDelay: '1s',
- }}
- />
+ <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>
)
diff --git a/web/app/pages/Project/tabs/Performance/PerformanceChart.tsx b/web/app/pages/Project/tabs/Performance/PerformanceChart.tsx
index afe8df779..7be0990a5 100644
--- a/web/app/pages/Project/tabs/Performance/PerformanceChart.tsx
+++ b/web/app/pages/Project/tabs/Performance/PerformanceChart.tsx
@@ -6,7 +6,10 @@ import { Annotation } from '~/lib/models/Project'
import type { ChartDataPointClick } from '~/pages/Project/View/utils/chartPoint'
import { MainChart } from '../../View/components/MainChart'
-import { getSettingsPerf } from '../../View/ViewProject.helpers'
+import {
+ getAnnotationGridLines,
+ getSettingsPerf,
+} from '../../View/ViewProject.helpers'
interface PerformanceChartProps {
chart: Record<string, string[]>
@@ -46,6 +49,11 @@ export const PerformanceChart = ({
[onDataPointClick, t],
)
+ const annotationLines = useMemo(
+ () => getAnnotationGridLines(annotations),
+ [annotations],
+ )
+
const options: ChartOptions = useMemo(() => {
return getSettingsPerf(
chart,
@@ -57,7 +65,7 @@ export const PerformanceChart = ({
compareChart,
onZoom,
enableZoom,
- annotations,
+ undefined,
onDataPointClick,
dataPointClickLabel,
)
@@ -71,7 +79,6 @@ export const PerformanceChart = ({
compareChart,
onZoom,
enableZoom,
- annotations,
onDataPointClick,
dataPointClickLabel,
])
@@ -87,7 +94,6 @@ export const PerformanceChart = ({
compareChart,
onZoom,
enableZoom,
- annotations,
onDataPointClick,
dataPointClickLabel,
],
@@ -101,7 +107,6 @@ export const PerformanceChart = ({
compareChart,
onZoom,
enableZoom,
- annotations,
onDataPointClick,
dataPointClickLabel,
],
@@ -114,6 +119,7 @@ export const PerformanceChart = ({
dataNames={dataNames}
className={className}
deps={deps}
+ xGridLines={annotationLines}
/>
)
}
diff --git a/web/app/pages/Project/tabs/Performance/PerformanceView.tsx b/web/app/pages/Project/tabs/Performance/PerformanceView.tsx
index c0972cd6c..bb086c36f 100644
--- a/web/app/pages/Project/tabs/Performance/PerformanceView.tsx
+++ b/web/app/pages/Project/tabs/Performance/PerformanceView.tsx
@@ -707,6 +707,6 @@ const PerformanceViewInner = ({ tnMapping }: PerformanceViewProps) => {
)
}
-const PerformanceView = PerformanceViewWrapper
+const PerformanceView = React.memo(PerformanceViewWrapper)
export default PerformanceView
diff --git a/web/app/pages/Project/tabs/Traffic/CustomEventsSubmenu.tsx b/web/app/pages/Project/tabs/Traffic/CustomEventsSubmenu.tsx
index c65556501..94921929b 100644
--- a/web/app/pages/Project/tabs/Traffic/CustomEventsSubmenu.tsx
+++ b/web/app/pages/Project/tabs/Traffic/CustomEventsSubmenu.tsx
@@ -150,7 +150,7 @@ const CustomEventsSubmenu: React.FC<CustomEventsSubmenuProps> = ({
enter='transition ease-out duration-100'
enterFrom='transform opacity-0 scale-95'
enterTo='transform opacity-100 scale-100'
- leave='transition ease-in duration-75'
+ leave='transition ease-out duration-75'
leaveFrom='transform opacity-100 scale-100'
leaveTo='transform opacity-0 scale-95'
>
diff --git a/web/app/pages/Project/tabs/Traffic/MetricCards.tsx b/web/app/pages/Project/tabs/Traffic/MetricCards.tsx
index c8e5fadc6..4cf7f3f0d 100644
--- a/web/app/pages/Project/tabs/Traffic/MetricCards.tsx
+++ b/web/app/pages/Project/tabs/Traffic/MetricCards.tsx
@@ -3,7 +3,6 @@ import _isEmpty from 'lodash/isEmpty'
import _isNumber from 'lodash/isNumber'
import _map from 'lodash/map'
import _round from 'lodash/round'
-import { motion, type Variants } from 'motion/react'
import React, { memo } from 'react'
import { useTranslation } from 'react-i18next'
@@ -17,23 +16,6 @@ import {
getTimeFromSeconds,
} from '~/utils/generic'
-// Entrance animation: parent containers set initial='hidden' animate='visible'
-// to stagger the cards in. Standalone usage (no motion parent) stays static.
-export const metricCardsContainerVariants: Variants = {
- visible: {
- transition: { staggerChildren: 0.04 },
- },
-}
-
-const metricCardVariants: Variants = {
- hidden: { opacity: 0, y: 8 },
- visible: {
- opacity: 1,
- y: 0,
- transition: { duration: 0.2, ease: [0.23, 1, 0.32, 1] },
- },
-}
-
interface MetricCardProps {
label: string
value: React.ReactNode
@@ -108,10 +90,7 @@ export const MetricCard: React.FC<MetricCardProps> = ({
valueMapper,
classes,
}) => (
- <motion.div
- variants={metricCardVariants}
- className={cx('flex flex-col', classes?.container)}
- >
+ <div className={cx('flex flex-col', classes?.container)}>
<Text
size='4xl'
weight='bold'
@@ -140,7 +119,7 @@ export const MetricCard: React.FC<MetricCardProps> = ({
valueMapper={valueMapper}
/>
</div>
- </motion.div>
+ </div>
)
interface MetricCardsProps {
@@ -299,12 +278,7 @@ export const PerformanceMetricCards = memo(
}
return (
- <motion.div
- initial='hidden'
- animate='visible'
- variants={metricCardsContainerVariants}
- className='mb-5 flex flex-wrap justify-center gap-5 lg:justify-start'
- >
+ <div className='mb-5 flex flex-wrap justify-center gap-5 lg:justify-start'>
<MetricCard
label={t('dashboard.frontend')}
value={overall.current?.frontend}
@@ -344,7 +318,7 @@ export const PerformanceMetricCards = memo(
)
}
/>
- </motion.div>
+ </div>
)
},
)
diff --git a/web/app/pages/Project/tabs/Traffic/TrafficChart.tsx b/web/app/pages/Project/tabs/Traffic/TrafficChart.tsx
index aaef310b1..86cd68b37 100644
--- a/web/app/pages/Project/tabs/Traffic/TrafficChart.tsx
+++ b/web/app/pages/Project/tabs/Traffic/TrafficChart.tsx
@@ -6,7 +6,10 @@ import { Annotation } from '~/lib/models/Project'
import type { ChartDataPointClick } from '~/pages/Project/View/utils/chartPoint'
import { MainChart } from '../../View/components/MainChart'
-import { getSettings } from '../../View/ViewProject.helpers'
+import {
+ getAnnotationGridLines,
+ getSettings,
+} from '../../View/ViewProject.helpers'
interface TrafficChartProps {
chartData: any
@@ -54,6 +57,11 @@ export const TrafficChart = ({
[onDataPointClick, t],
)
+ const annotationLines = useMemo(
+ () => getAnnotationGridLines(annotations),
+ [annotations],
+ )
+
const options: ChartOptions = useMemo(() => {
return getSettings(
chartData,
@@ -67,7 +75,7 @@ export const TrafficChart = ({
dataChartCompare,
onZoom,
enableZoom,
- annotations,
+ undefined,
period,
timezone,
onDataPointClick,
@@ -85,7 +93,6 @@ export const TrafficChart = ({
dataChartCompare,
onZoom,
enableZoom,
- annotations,
period,
timezone,
onDataPointClick,
@@ -105,7 +112,6 @@ export const TrafficChart = ({
dataChartCompare,
onZoom,
enableZoom,
- annotations,
period,
timezone,
onDataPointClick,
@@ -123,7 +129,6 @@ export const TrafficChart = ({
dataChartCompare,
onZoom,
enableZoom,
- annotations,
period,
timezone,
onDataPointClick,
@@ -138,6 +143,7 @@ export const TrafficChart = ({
dataNames={dataNames}
className={className}
deps={deps}
+ xGridLines={annotationLines}
/>
)
}
diff --git a/web/app/pages/Project/tabs/Traffic/TrafficView.tsx b/web/app/pages/Project/tabs/Traffic/TrafficView.tsx
index 7b1f805fc..4120323e9 100644
--- a/web/app/pages/Project/tabs/Traffic/TrafficView.tsx
+++ b/web/app/pages/Project/tabs/Traffic/TrafficView.tsx
@@ -19,7 +19,6 @@ import React, {
Suspense,
} from 'react'
import { createPortal } from 'react-dom'
-import { motion } from 'motion/react'
import { useTranslation } from 'react-i18next'
import { useSearchParams, useLoaderData } from 'react-router'
import { toast } from 'sonner'
@@ -46,7 +45,6 @@ import CustomMetrics from '~/pages/Project/tabs/Traffic/CustomMetrics'
import {
MetricCard,
MetricCards,
- metricCardsContainerVariants,
} from '~/pages/Project/tabs/Traffic/MetricCards'
import PageLinkRow from '~/pages/Project/tabs/Traffic/PageLinkRow'
import RefRow from '~/pages/Project/tabs/Traffic/RefRow'
@@ -1166,15 +1164,8 @@ const TrafficViewInner = ({
<HasImportedIndicator />
</Suspense>
</div>
- {/* Always rendered: the cards read zero until the summary lands and
- then roll up to it, so the row holds its height instead of
- appearing late and shoving the chart and panels down. */}
- <motion.div
- initial='hidden'
- animate='visible'
- variants={metricCardsContainerVariants}
- className='mb-5 flex flex-wrap justify-center gap-5 lg:justify-start'
- >
+ {/* Always rendered so the row holds its height while data loads. */}
+ <div className='mb-5 flex flex-wrap justify-center gap-5 lg:justify-start'>
<MetricCards
overall={overallForCards}
overallCompare={overallCompare}
@@ -1207,7 +1198,7 @@ const TrafficViewInner = ({
),
)
: null}
- </motion.div>
+ </div>
{isChartLoading ? (
// Same box as TrafficChart below (incl. its mobile mt-5) so the
// chart drops straight into the spinner's place.
@@ -1395,6 +1386,6 @@ const TrafficViewInner = ({
)
}
-const TrafficView = TrafficViewWrapper
+const TrafficView = React.memo(TrafficViewWrapper)
export default TrafficView
diff --git a/web/app/styles/index.css b/web/app/styles/index.css
index 87358f299..274b31496 100644
--- a/web/app/styles/index.css
+++ b/web/app/styles/index.css
@@ -1,30 +1,22 @@
-@keyframes indeterminate1 {
+@keyframes indeterminate-bar {
0% {
- left: -35%;
- right: 100%;
- }
- 60% {
- left: 100%;
- right: -90%;
+ transform: translate3d(-60%, 0, 0);
}
100% {
- left: 100%;
- right: -90%;
+ transform: translate3d(340%, 0, 0);
}
}
-@keyframes indeterminate2 {
- 0% {
- left: -200%;
- right: 100%;
- }
- 60% {
- left: 107%;
- right: -8%;
- }
- 100% {
- left: 107%;
- right: -8%;
+.indeterminate-bar {
+ animation: indeterminate-bar 1s linear infinite;
+}
+
+@media (prefers-reduced-motion: reduce) {
+ .indeterminate-bar {
+ width: 100%;
+ animation: none;
+ transform: none;
+ opacity: 0.55;
}
}
diff --git a/web/app/styles/tailwind.css b/web/app/styles/tailwind.css
index e4740fcc2..94ff561c2 100644
--- a/web/app/styles/tailwind.css
+++ b/web/app/styles/tailwind.css
@@ -151,16 +151,18 @@
}
}
- /* Panel row background bars: animate width retargets, and sweep in from
- zero when rows first mount (entering rows / panel tab switches). */
+ /* Panel row background bars stay full-width and animate their scale so
+ loading a dashboard does not trigger layout on every animation frame. */
.panel-bar {
- width: var(--panel-bar-width, 0%);
+ width: 100%;
+ transform: scaleX(var(--panel-bar-scale, 0));
+ transform-origin: left center;
@media (prefers-reduced-motion: no-preference) {
- transition: width 400ms var(--ease-out-quint);
+ transition: transform 220ms var(--ease-out-quint);
@starting-style {
- width: 0%;
+ transform: scaleX(0);
}
}
}
diff --git a/web/app/ui/LoadingBar.tsx b/web/app/ui/LoadingBar.tsx
index 861864958..d7a3206e8 100644
--- a/web/app/ui/LoadingBar.tsx
+++ b/web/app/ui/LoadingBar.tsx
@@ -12,27 +12,12 @@ const LoadingBar: React.FC<LoadingBarProps> = ({ className }) => {
return (
<div
className={cx(
- 'fixed top-0 right-0 left-0 z-50 h-0.5 w-full overflow-hidden bg-transparent',
+ 'fixed top-0 right-0 left-0 z-50 h-0.5 w-full overflow-hidden rounded-full bg-slate-200/70 dark:bg-slate-700/70',
className,
)}
>
<progress className='sr-only' aria-label={t('common.loading')} />
- <div
- className='absolute h-full rounded-full bg-linear-to-r from-slate-400 via-slate-700 to-slate-900 dark:from-slate-500 dark:via-slate-200 dark:to-white'
- style={{
- animation:
- 'indeterminate1 1.8s cubic-bezier(0.65, 0.815, 0.735, 0.395) infinite',
- }}
- />
-
- <div
- className='absolute h-full rounded-full bg-linear-to-r from-slate-700 to-slate-900 opacity-70 dark:from-slate-300 dark:to-white'
- style={{
- animation:
- 'indeterminate2 1.8s cubic-bezier(0.165, 0.84, 0.44, 1) infinite',
- animationDelay: '1s',
- }}
- />
+ <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>
)
}
diff --git a/web/app/ui/NumberFlow.tsx b/web/app/ui/NumberFlow.tsx
index 8ad529225..479d96ddc 100644
--- a/web/app/ui/NumberFlow.tsx
+++ b/web/app/ui/NumberFlow.tsx
@@ -1,30 +1,10 @@
-import NumberFlow, { NumberFlowGroup } from '@number-flow/react'
import _round from 'lodash/round'
-import { useEffect, useState } from 'react'
-
-import {
- FLOW_TIMING,
- FLOW_VALUE_CLASS,
- useFlowValue,
-} from '~/hooks/useFlowValue'
import {
getStringFromTime,
getTimeFromSeconds,
nFormatterSeparated,
} from '~/utils/generic'
-// NumberFlow renders nothing meaningful server-side, so every flow falls back to
-// plain text until hydration and only then starts animating.
-const useIsHydrated = () => {
- const [isHydrated, setIsHydrated] = useState(false)
-
- useEffect(() => {
- setIsHydrated(true)
- }, [])
-
- return isHydrated
-}
-
const StaticCompactNumber = ({ value }: { value?: number }) => {
const [num, symbol] = nFormatterSeparated(value, 1) as [number, string | null]
@@ -36,61 +16,16 @@ const StaticCompactNumber = ({ value }: { value?: number }) => {
)
}
-const AnimatedCompactNumber = ({ value }: { value?: number }) => {
- const flowValue = useFlowValue(value)
- const [num, symbol] = nFormatterSeparated(flowValue, 1) as [
- number,
- string | null,
- ]
-
- return (
- <NumberFlow
- className={FLOW_VALUE_CLASS}
- {...FLOW_TIMING}
- value={num}
- suffix={symbol ?? undefined}
- format={{ maximumFractionDigits: 1 }}
- willChange
- />
- )
-}
-
/** Counts, abbreviated past a thousand (1.2k, 3.4M). */
-export const CompactNumberFlow = ({ value }: { value?: number }) => {
- const isHydrated = useIsHydrated()
-
- return isHydrated ? (
- <AnimatedCompactNumber value={value} />
- ) : (
- <StaticCompactNumber value={value} />
- )
-}
-
-const AnimatedPercent = ({ value }: { value: number }) => {
- const flowValue = useFlowValue(value)
-
- return (
- <NumberFlow
- className={FLOW_VALUE_CLASS}
- {...FLOW_TIMING}
- value={flowValue}
- suffix='%'
- format={{ maximumFractionDigits: 1 }}
- willChange
- />
- )
-}
+export const CompactNumberFlow = ({ value }: { value?: number }) => (
+ <StaticCompactNumber value={value} />
+)
/** Percentages, rounded to a single decimal. */
export const PercentFlow = ({ value }: { value?: number }) => {
- const isHydrated = useIsHydrated()
const sanitizedValue = Number.isFinite(value) ? _round(value as number, 1) : 0
- return isHydrated ? (
- <AnimatedPercent value={sanitizedValue} />
- ) : (
- <>{sanitizedValue}%</>
- )
+ return <>{sanitizedValue}%</>
}
const StaticDuration = ({
@@ -108,66 +43,6 @@ const StaticDuration = ({
</>
)
-const AnimatedDuration = ({
- value,
- showMs,
-}: {
- value?: number
- showMs?: boolean
-}) => {
- const flowValue = useFlowValue(value)
- const time = getTimeFromSeconds(flowValue)
- const s = showMs ? _round(time.s + time.ms / 1000, 2) : time.s
-
- // Decide which units to render from the target value so the NumberFlow
- // elements mount once and roll from zero, instead of remounting mid-flight
- const target = getTimeFromSeconds(
- Number.isFinite(value) ? (value as number) : 0,
- )
- const targetS = showMs ? _round(target.s + target.ms / 1000, 2) : target.s
- const showH = target.h > 0
- const showM = target.m > 0
- const showS = targetS > 0 || (!showH && !showM)
-
- return (
- <NumberFlowGroup>
- <>
- {target.negative ? '-' : null}
- {showH ? (
- <NumberFlow
- className={FLOW_VALUE_CLASS}
- {...FLOW_TIMING}
- value={time.h}
- suffix='h'
- willChange
- />
- ) : null}
- {showH && (showM || showS) ? ' ' : null}
- {showM ? (
- <NumberFlow
- className={FLOW_VALUE_CLASS}
- {...FLOW_TIMING}
- value={time.m}
- suffix='m'
- willChange
- />
- ) : null}
- {showM && showS ? ' ' : null}
- {showS ? (
- <NumberFlow
- className={FLOW_VALUE_CLASS}
- {...FLOW_TIMING}
- value={s}
- suffix='s'
- format={{ maximumFractionDigits: 2 }}
- willChange
- />
- ) : null}
- </>
- </NumberFlowGroup>
- )
-}
-
/** Durations given in seconds, rendered as h/m/s. */
export const DurationFlow = ({
value,
@@ -175,12 +50,4 @@ export const DurationFlow = ({
}: {
value?: number
showMs?: boolean
-}) => {
- const isHydrated = useIsHydrated()
-
- return isHydrated ? (
- <AnimatedDuration value={value} showMs={showMs} />
- ) : (
- <StaticDuration value={value} showMs={showMs} />
- )
-}
+}) => <StaticDuration value={value} showMs={showMs} />