: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
feat(experiments): use a skeleton for the metric loading state instead of a spinner (#65565)
Rodrigo Iloro5b9eb3ff2e9b
diff --git a/frontend/src/scenes/experiments/MetricsView/new/MetricRowGroup.tsx b/frontend/src/scenes/experiments/MetricsView/new/MetricRowGroup.tsxindex dedead819c5f..6d32ffa2e41b 100644--- a/frontend/src/scenes/experiments/MetricsView/new/MetricRowGroup.tsx+++ b/frontend/src/scenes/experiments/MetricsView/new/MetricRowGroup.tsx@@ -1,5 +1,6 @@import './MetricRowGroup.scss'+import clsx from 'clsx'import { useActions, useValues } from 'kea'import React, { useEffect, useRef, useState } from 'react'import { createPortal } from 'react-dom'@@ -9,6 +10,7 @@ import { IconTrending } from '@posthog/icons'import { FEATURE_FLAGS } from 'lib/constants'import { IconTrendingDown } from 'lib/lemon-ui/icons'import { LemonCollapse } from 'lib/lemon-ui/LemonCollapse'+import { LemonSkeleton } from 'lib/lemon-ui/LemonSkeleton'import { featureFlagLogic } from 'lib/logic/featureFlagLogic'import { humanFriendlyLargeNumber } from 'lib/utils/numbers'import { VariantTag } from 'scenes/experiments/ExperimentView/VariantTag'@@ -27,9 +29,15 @@ import { experimentMetricsLogic } from '~/scenes/experiments/experimentMetricsLoimport { isLaunched } from '~/scenes/experiments/experimentsLogic'import { useColumnWidthSync } from '~/scenes/experiments/MetricsView/hooks/useColumnWidthSync'import { ChartEmptyState } from '~/scenes/experiments/MetricsView/shared/ChartEmptyState'+import { SkeletonResultCells } from '~/scenes/experiments/MetricsView/shared/ChartLoadingSkeleton'import { ChartLoadingState } from '~/scenes/experiments/MetricsView/shared/ChartLoadingState'import { useChartColors } from '~/scenes/experiments/MetricsView/shared/colors'import { MetricHeader } from '~/scenes/experiments/MetricsView/shared/MetricHeader'+import {+ FIXED_HEIGHT_STYLE,+ getMinHeightStyle,+ getScaledHeightStyle,+} from '~/scenes/experiments/MetricsView/shared/rowHeights'import {type ExperimentVariantResult,formatChanceToWinForGoal,@@ -62,22 +70,6 @@ import { renderTooltipContent } from './MetricRowGroupTooltip'import { TimeseriesModal } from './TimeseriesModal'import { useAxisScale } from './useAxisScale'-const FIXED_HEIGHT_STYLE: React.CSSProperties = {- height: `${CELL_HEIGHT}px`,- maxHeight: `${CELL_HEIGHT}px`,-}--const getScaledHeightStyle = (rowCount: number): React.CSSProperties => {- const scaledHeight = `${CELL_HEIGHT * rowCount}px`-- return {- height: scaledHeight,- maxHeight: scaledHeight,- }-}--const getMinHeightStyle = (height: number): React.CSSProperties => ({ minHeight: `${height}px` })-interface BreakdownErrorStateProps {metric: ExperimentMetricisAlternatingRow: boolean@@ -597,6 +589,7 @@ export function MetricRowGroup({const { reportExperimentTimeseriesViewed, retryPrimaryMetric, retrySecondaryMetric, refreshExperimentResults } =useActions(experimentLogic)+ const { variants } = useValues(experimentLogic)const { featureFlags } = useValues(featureFlagLogic)const { isRecalculating } = useValues(experimentMetricsLogic({ experiment }))const { triggerRecalculation } = useActions(experimentMetricsLogic({ experiment }))@@ -720,9 +713,76 @@ export function MetricRowGroup({})}- if (isLoading || error || !result) {- const hasError = !!error- const noResultHeight = hasError ? CELL_HEIGHT : Math.max(CELL_HEIGHT, EMPTY_STATE_ROW_MIN_HEIGHT)+ // Skeleton-with-variants while results compute: keeps the final row layout so data fills in place+ if (!error && (isLoading || exposuresLoading)) {+ const skeletonVariantKeys = variants.length > 0 ? variants.map((variant) => variant.key) : ['control']+ const bg = isAlternatingRow ? 'bg-bg-table' : 'bg-bg-light'++ return (+ <>+ <tr className="hover:bg-bg-hover group [&:last-child>td]:border-b-0" style={FIXED_HEIGHT_STYLE}>+ {/* Metric column: real header spanning every variant row, stays interactive while loading */}+ <td+ className={`w-1/5 border-r p-3 align-top text-left relative overflow-hidden ${+ !isLastMetric ? 'border-b' : ''+ } ${bg}`}+ rowSpan={skeletonVariantKeys.length}+ style={getScaledHeightStyle(skeletonVariantKeys.length)}+ >+ <MetricHeader+ displayOrder={displayOrder}+ metric={metric}+ metricType={metricType}+ isPrimaryMetric={!isSecondary}+ experiment={experiment}+ onDuplicateMetricClick={() => onDuplicateMetric?.()}+ onDeleteMetricClick={onDeleteMetric ? () => onDeleteMetric() : undefined}+ onBreakdownChange={onBreakdownChange}+ />+ </td>++ <SkeletonResultCells+ variantKey={skeletonVariantKeys[0]}+ className={clsx(bg, skeletonVariantKeys.length === 1 && 'border-b')}+ detailsCell={+ <td+ className={clsx(+ 'w-20 pt-3 align-top relative overflow-hidden',+ !isLastMetric && 'border-b',+ bg+ )}+ rowSpan={skeletonVariantKeys.length}+ style={getScaledHeightStyle(skeletonVariantKeys.length)}+ >+ {/* Reserve the Details button's footprint so the chart column doesn't shift when results land */}+ {showDetailsModal && (+ <div className="flex justify-end">+ <LemonSkeleton className="h-6 w-[74px]" />+ </div>+ )}+ </td>+ }+ />+ </tr>++ {skeletonVariantKeys.slice(1).map((variantKey, index) => (+ <tr+ key={variantKey}+ className="hover:bg-bg-hover group [&:last-child>td]:border-b-0"+ style={FIXED_HEIGHT_STYLE}+ >+ <SkeletonResultCells+ variantKey={variantKey}+ className={clsx(bg, index === skeletonVariantKeys.length - 2 && 'border-b')}+ />+ </tr>+ ))}+ </>+ )+ }++ if (error || !result) {+ const noResultHeight = error ? CELL_HEIGHT : Math.max(CELL_HEIGHT, EMPTY_STATE_ROW_MIN_HEIGHT)const noResultStateStyle = getMinHeightStyle(noResultHeight)return (@@ -747,7 +807,7 @@ export function MetricRowGroup({/></td>- {/* Combined columns for loading/error state */}+ {/* Combined columns for error/empty state */}<tdcolSpan={6}className={`p-3 text-center ${isAlternatingRow ? 'bg-bg-table' : 'bg-bg-light'} ${@@ -755,18 +815,14 @@ export function MetricRowGroup({}`}style={noResultStateStyle}>- {!hasError && (isLoading || exposuresLoading) ? (- <ChartLoadingState height={noResultHeight} />- ) : (- <ChartEmptyState- height={noResultHeight}- experimentStarted={isLaunched(experiment)}- metric={metric}- error={error}- query={debugQuery}- onRetry={handleRetry}- />- )}+ <ChartEmptyState+ height={noResultHeight}+ experimentStarted={isLaunched(experiment)}+ metric={metric}+ error={error}+ query={debugQuery}+ onRetry={handleRetry}+ /></td></tr>{metric.breakdownFilter?.breakdowns && metric.breakdownFilter.breakdowns.length > 0 && (diff --git a/frontend/src/scenes/experiments/MetricsView/shared/ChartLoadingSkeleton.tsx b/frontend/src/scenes/experiments/MetricsView/shared/ChartLoadingSkeleton.tsxnew file mode 100644index 000000000000..1db3f5bc4f34--- /dev/null+++ b/frontend/src/scenes/experiments/MetricsView/shared/ChartLoadingSkeleton.tsx@@ -0,0 +1,65 @@+import clsx from 'clsx'++import { LemonSkeleton } from 'lib/lemon-ui/LemonSkeleton'+import { VariantTag } from 'scenes/experiments/ExperimentView/VariantTag'++import { FIXED_HEIGHT_STYLE } from '~/scenes/experiments/MetricsView/shared/rowHeights'++export function SkeletonResultCells({+ variantKey,+ className,+ detailsCell,+}: {+ variantKey: string+ className: string+ // Rendered between P-value and Chart, with rowSpan, on the baseline row only; matches the real layout+ detailsCell?: JSX.Element+}): JSX.Element {+ return (+ <>+ {/* Variant tag is real; we know the variants before any result lands */}+ <td+ className={clsx('w-20 pt-1 pl-3 pr-3 pb-1 text-left whitespace-nowrap overflow-hidden', className)}+ style={FIXED_HEIGHT_STYLE}+ >+ <VariantTag variantKey={variantKey} />+ </td>++ {/* Value */}+ <td+ className={clsx('w-24 pt-1 pl-3 pr-3 pb-1 text-left whitespace-nowrap overflow-hidden', className)}+ style={FIXED_HEIGHT_STYLE}+ >+ <LemonSkeleton className="h-4 w-12" />+ </td>++ {/* Delta */}+ <td+ className={clsx('w-20 pt-1 pl-3 pr-3 pb-1 text-left whitespace-nowrap overflow-hidden', className)}+ style={FIXED_HEIGHT_STYLE}+ >+ <LemonSkeleton className="h-4 w-10" />+ </td>++ {/* P-value / Win probability */}+ <td+ className={clsx('w-20 pt-1 pl-3 pr-3 pb-1 text-center whitespace-nowrap overflow-hidden', className)}+ style={FIXED_HEIGHT_STYLE}+ >+ <LemonSkeleton className="h-4 w-10 mx-auto" />+ </td>++ {detailsCell}++ {/* Chart: mirrors ChartCell's wrapper so the bar lands where the real chart will */}+ <td+ className={clsx('p-0 align-middle text-center relative overflow-hidden', className)}+ style={FIXED_HEIGHT_STYLE}+ >+ <div className="px-3">+ <LemonSkeleton className="h-3 w-full" />+ </div>+ </td>+ </>+ )+}diff --git a/frontend/src/scenes/experiments/MetricsView/shared/rowHeights.ts b/frontend/src/scenes/experiments/MetricsView/shared/rowHeights.tsnew file mode 100644index 000000000000..7cf0e6d63674--- /dev/null+++ b/frontend/src/scenes/experiments/MetricsView/shared/rowHeights.ts@@ -0,0 +1,13 @@+import { CELL_HEIGHT } from '~/scenes/experiments/MetricsView/new/constants'++export const FIXED_HEIGHT_STYLE: React.CSSProperties = {+ height: `${CELL_HEIGHT}px`,+ maxHeight: `${CELL_HEIGHT}px`,+}++export const getScaledHeightStyle = (rowCount: number): React.CSSProperties => {+ const scaledHeight = `${CELL_HEIGHT * rowCount}px`+ return { height: scaledHeight, maxHeight: scaledHeight }+}++export const getMinHeightStyle = (height: number): React.CSSProperties => ({ minHeight: `${height}px` })