:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
perf(homepage): load the today sparklines after the home renders (#122611)
Paul D'Ambra201e98857cd2
diff --git a/frontend/bin/check-eager-graph.mjs b/frontend/bin/check-eager-graph.mjsindex 63dfa01ee22a..6343e0d40d66 100644--- a/frontend/bin/check-eager-graph.mjs+++ b/frontend/bin/check-eager-graph.mjs@@ -172,6 +172,9 @@ const ROOTS = ['src/scenes/project-homepage/ai-first/AiFirstHomepage.tsx','src/scenes/project-homepage/today/TodayReportPage.tsx','src/queries/Query/Query.tsx',+ // esbuild splits chunks by what can reach a file, so one static import through the quill-charts+ // barrel puts every chart type on the home load. The home sparklines load lazily instead.+ 'packages/quill/packages/charts/',],},{diff --git a/frontend/src/layout/today/TodayObjectHoverCard.tsx b/frontend/src/layout/today/TodayObjectHoverCard.tsxindex 480623836c34..685bee8a016c 100644--- a/frontend/src/layout/today/TodayObjectHoverCard.tsx+++ b/frontend/src/layout/today/TodayObjectHoverCard.tsx@@ -1,18 +1,25 @@import { useActions, useValues } from 'kea'-import { Fragment, useEffect, useMemo } from 'react'+import { Fragment, Suspense, lazy, useEffect, useMemo } from 'react'import { IconArrowRight, IconChevronRight, IconExternal } from '@posthog/icons'import { Badge, Item, ItemContent, ItemSeparator, ItemTitle, Skeleton } from '@posthog/quill'import { newInternalTab } from 'lib/utils/newInternalTab'+import { retryImport } from 'lib/utils/retryImport'import { capitalizeFirstLetter } from 'lib/utils/strings'import { baseObjectType } from 'scenes/library/libraryUtils'import { todayNumber } from 'scenes/project-homepage/today/todayNumbers'-import { TodaySparkline } from 'scenes/project-homepage/today/TodaySparkline'import { TodayHoverCardFact } from './TodayHoverCardFact'import { cardMenuParts } from './todayMenuParts'import { todayObjectGlanceLogic } from './todayObjectGlanceLogic'++// The charts are most of the code the home page adds, and this card opens only on hover.+const TodaySparkline = lazy(() =>+ retryImport(() =>+ import('scenes/project-homepage/today/TodaySparkline').then((m) => ({ default: m.TodaySparkline }))+ )+)import { GLANCE_TYPES, TodayObjectGlance } from './todayObjectGlances'import { TodayObjectIcon } from './TodayObjectIcon'import { TodayObjectPreview } from './todayPreviewCards'@@ -30,13 +37,15 @@ function Glance({ glance }: { glance: TodayObjectGlance }): JSX.Element {</div>{headline.series.length > 1 && (<div className="h-10">- <TodaySparkline- values={headline.series}- labels={headline.labels}- tone="neutral"- emphasizeLast={1}- formatValue={headline.formatValue ?? todayNumber}- />+ <Suspense fallback={null}>+ <TodaySparkline+ values={headline.series}+ labels={headline.labels}+ tone="neutral"+ emphasizeLast={1}+ formatValue={headline.formatValue ?? todayNumber}+ />+ </Suspense></div>)}</div>diff --git a/frontend/src/scenes/project-homepage/today/TodayChange.tsx b/frontend/src/scenes/project-homepage/today/TodayChange.tsxindex 63095d8dfa53..c055bf1ad4d5 100644--- a/frontend/src/scenes/project-homepage/today/TodayChange.tsx+++ b/frontend/src/scenes/project-homepage/today/TodayChange.tsx@@ -1,4 +1,4 @@-import { type TodayTone, useTodayTonePalette } from './TodaySparkline'+import { type TodayTone, useTodayTonePalette } from './todayTone'export function TodayChange({ change, tone }: { change: number | null; tone: TodayTone }): JSX.Element | null {const palette = useTodayTonePalette()diff --git a/frontend/src/scenes/project-homepage/today/TodayPulse.tsx b/frontend/src/scenes/project-homepage/today/TodayPulse.tsxindex c2d0addef5ee..78f8881af9dc 100644--- a/frontend/src/scenes/project-homepage/today/TodayPulse.tsx+++ b/frontend/src/scenes/project-homepage/today/TodayPulse.tsx@@ -1,11 +1,12 @@import { useActions, useValues } from 'kea'-import { type RefObject, useLayoutEffect, useRef } from 'react'+import { type RefObject, Suspense, lazy, useLayoutEffect, useRef } from 'react'import { Skeleton } from '@posthog/quill'import { dayjs } from 'lib/dayjs'import { LinkPrimitive } from 'lib/lemon-ui/Link'import { humanFriendlyNumber } from 'lib/utils/numbers'+import { retryImport } from 'lib/utils/retryImport'import { formatAggregationAxisValue } from 'scenes/insights/aggregationAxisFormat'import { teamLogic } from 'scenes/teamLogic'import { urls } from 'scenes/urls'@@ -27,7 +28,12 @@ import { todayNumber } from './todayNumbers'import { TodayPulseCard } from './TodayPulseCard'import { TodayPulseHoverCard } from './TodayPulseHoverCard'import { pulseOpenHandlers } from './todayPulseOpenHandlers'-import { TodaySparkline, type TodayTone } from './TodaySparkline'+import type { TodayTone } from './todayTone'++// The charts are most of the code the home page adds, so the numbers render first and the sparklines follow.+const TodaySparkline = lazy(() =>+ retryImport(() => import('./TodaySparkline').then((m) => ({ default: m.TodaySparkline })))+)const CHANGE_THRESHOLD = 3const MIN_ABSOLUTE_CHANGE = 5@@ -167,12 +173,14 @@ export function TodayPulse({ metrics }: { metrics: TodayPulseTile[] }): JSX.Elem<TodayChange change={metric.change_pct} tone={tone} /></span><span className="TodayPulse__spark">- <TodaySparkline- values={metric.series}- labels={seriesLabels(metric)}- emphasizeLast={metric.interval === 'day' ? 7 : 1}- tone={tone}- />+ <Suspense fallback={null}>+ <TodaySparkline+ values={metric.series}+ labels={seriesLabels(metric)}+ emphasizeLast={metric.interval === 'day' ? 7 : 1}+ tone={tone}+ />+ </Suspense></span></>)diff --git a/frontend/src/scenes/project-homepage/today/TodayPulseCard.tsx b/frontend/src/scenes/project-homepage/today/TodayPulseCard.tsxindex 66da93706d98..a3e64efcf12b 100644--- a/frontend/src/scenes/project-homepage/today/TodayPulseCard.tsx+++ b/frontend/src/scenes/project-homepage/today/TodayPulseCard.tsx@@ -1,4 +1,4 @@-import { useState } from 'react'+import { Suspense, lazy, useState } from 'react'import { IconArrowRight, IconInfo, IconPin, IconPinFilled } from '@posthog/icons'import {@@ -15,6 +15,7 @@ import {import { dayjs } from 'lib/dayjs'import { LinkPrimitive } from 'lib/lemon-ui/Link'+import { retryImport } from 'lib/utils/retryImport'import { TodayHoverCardFact } from '~/layout/today/TodayHoverCardFact'@@ -22,9 +23,13 @@ import type { HighlightMetricApi } from 'products/today/frontend/generated/api.simport { TodayChange } from './TodayChange'import { pulsePeak, pulsePeriodCaption, pulseWhy } from './todayPulseFacts'-import { TodayPulseMovers } from './TodayPulseMovers'import { pulseOpenHandlers } from './todayPulseOpenHandlers'-import type { TodayTone } from './TodaySparkline'+import type { TodayTone } from './todayTone'++// The charts are most of the code the home page adds, and this card opens only on hover.+const TodayPulseMovers = lazy(() =>+ retryImport(() => import('./TodayPulseMovers').then((m) => ({ default: m.TodayPulseMovers })))+)const PERIOD_FORMATS: Record<HighlightMetricApi['interval'], string> = {day: 'ddd, D MMM',@@ -103,7 +108,9 @@ export function TodayPulseCard({<Text size="xs" variant="muted" render={<span />}>What changed most</Text>- <TodayPulseMovers movers={metric.movers} formatValue={formatValue} />+ <Suspense fallback={null}>+ <TodayPulseMovers movers={metric.movers} formatValue={formatValue} />+ </Suspense></div>)}<Collapsiblediff --git a/frontend/src/scenes/project-homepage/today/TodayPulseMovers.tsx b/frontend/src/scenes/project-homepage/today/TodayPulseMovers.tsxindex f6ce5dd38f0f..36798f5f2905 100644--- a/frontend/src/scenes/project-homepage/today/TodayPulseMovers.tsx+++ b/frontend/src/scenes/project-homepage/today/TodayPulseMovers.tsx@@ -7,7 +7,7 @@ import { useChartTheme } from 'lib/charts/hooks'import type { HighlightMoverApi } from 'products/today/frontend/generated/api.schemas'import { TodayChange } from './TodayChange'-import { useTodayTonePalette } from './TodaySparkline'+import { useTodayTonePalette } from './todayTone'export function TodayPulseMovers({movers,diff --git a/frontend/src/scenes/project-homepage/today/TodaySparkline.tsx b/frontend/src/scenes/project-homepage/today/TodaySparkline.tsxindex aa013bbc90c6..5caeff33fd95 100644--- a/frontend/src/scenes/project-homepage/today/TodaySparkline.tsx+++ b/frontend/src/scenes/project-homepage/today/TodaySparkline.tsx@@ -1,4 +1,3 @@-import { useValues } from 'kea'import { useCallback, useMemo } from 'react'import {@@ -12,26 +11,7 @@ import {import { useChartConfig, useChartTheme } from 'lib/charts/hooks'-import { themeLogic } from '~/layout/navigation-3000/themeLogic'--export type TodayTone = 'risk' | 'good' | 'neutral'--interface TodayTonePalette {- risk: string- good: string- neutral: string- line: string-}--const PALETTE: Record<'light' | 'dark', TodayTonePalette> = {- light: { risk: '#d6453a', good: '#1f9d55', neutral: '#55554f', line: '#c4c4bc' },- dark: { risk: '#ff7b6e', good: '#5fd38d', neutral: '#c9c9c2', line: '#55554f' },-}--export function useTodayTonePalette(): TodayTonePalette {- const { isDarkModeOn } = useValues(themeLogic)- return isDarkModeOn ? PALETTE.dark : PALETTE.light-}+import { type TodayTone, useTodayTonePalette } from './todayTone'export function TodaySparkline({values,diff --git a/frontend/src/scenes/project-homepage/today/todayTone.ts b/frontend/src/scenes/project-homepage/today/todayTone.tsnew file mode 100644index 000000000000..1df31ea9db35--- /dev/null+++ b/frontend/src/scenes/project-homepage/today/todayTone.ts@@ -0,0 +1,22 @@+import { useValues } from 'kea'++import { themeLogic } from '~/layout/navigation-3000/themeLogic'++export type TodayTone = 'risk' | 'good' | 'neutral'++interface TodayTonePalette {+ risk: string+ good: string+ neutral: string+ line: string+}++const PALETTE: Record<'light' | 'dark', TodayTonePalette> = {+ light: { risk: '#d6453a', good: '#1f9d55', neutral: '#55554f', line: '#c4c4bc' },+ dark: { risk: '#ff7b6e', good: '#5fd38d', neutral: '#c9c9c2', line: '#55554f' },+}++export function useTodayTonePalette(): TodayTonePalette {+ const { isDarkModeOn } = useValues(themeLogic)+ return isDarkModeOn ? PALETTE.dark : PALETTE.light+}