Hold data-shaped page bodies until their reads settle

Several pages stacked cards whose final height is the data's: the
illness day timeline, the measurement list, the insights arrange list,
the system status cards, the score notices that land with the slower
report. Each resolving on its own pushed the rest down the page, for a
CLS of 0.11 to 0.18 at desktop width. RevealWhenSettled mounts the body
at once but keeps it out of layout until no query is in flight (two
frames running, two seconds at most), with a placeholder in its place.

The chart loading shells were also ~100 px shorter than the card they
became: they now reserve the day-dot row, its caption and the collapsed
data-table disclosure, and the range-tab row at its 44 px height.
This commit is contained in:
Marc-André Bombeck committed 2026-10-08 18:34:11 +02:00
1 parent 1a52384a1d
commit a0c5ab6591
10 files changed
+464 -240

No files matched your search

+44 -2
View File
@@ -48,11 +48,51 @@ import { useTranslations } from "@/lib/i18n/context";
const SLOW_HINT_DELAY_MS = 3_000;
/**
* The footer a loaded `<HealthChart>` paints under its plot: the row of day
* dots and its caption on a day-linked chart, and the collapsed "show as
* table" disclosure. A loading shell without it was ~100 px shorter than the
* card it turned into (CLS on every metric page, the BMI page most visibly),
* so the shells reserve the same boxes: `h-3` rug, `mt-1` caption (two lines
* on a phone, one from `sm`), and the disclosure's `mt-3 border-t pt-3` frame
* around its `min-h-11` button.
*/
export function ChartFooterReserve({
dayLinks = false,
dataTable = false,
}: {
dayLinks?: boolean;
dataTable?: boolean;
}) {
if (!dayLinks && !dataTable) return null;
return (
<div aria-hidden="true" data-slot="chart-footer-reserve">
{dayLinks ? (
<>
<div className="h-3" />
<div className="mt-1 h-9 sm:h-4" />
</>
) : null}
{dataTable ? (
<div className="border-border mt-3 border-t pt-3">
<div className="h-11" />
</div>
) : null}
</div>
);
}
export function ChartSkeleton({
className,
mini = false,
dayLinks = false,
dataTable = false,
}: {
className?: string;
/** Reserve the day-dot row + caption a day-linked chart paints. */
dayLinks?: boolean;
/** Reserve the collapsed data-table disclosure. */
dataTable?: boolean;
/**
* When true, render the compact variant used inside the trends-row
* chart slot (140 px band, lighter chrome). Defaults to false for
@@ -106,8 +146,9 @@ export function ChartSkeleton({
{/* Header row — title + range tabs match the real chart's
`mb-4 flex flex-col gap-2 sm:flex-row` chrome. */}
<div className="mb-4 flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between">
<Skeleton className="h-4 w-32" />
<div className="flex items-center gap-2">
<Skeleton className="h-5 w-32" />
{/* The range tabs are 44 px tap targets, so the row is too. */}
<div className="flex h-11 items-center gap-2">
<Skeleton className="h-6 w-12" />
<Skeleton className="h-6 w-12" />
<Skeleton className="h-6 w-12" />
@@ -118,6 +159,7 @@ export function ChartSkeleton({
{/* Chart band — mirrors the same `h-[var(--chart-height,…)]`
contract `health-chart.tsx` paints at line 1087-1089. */}
<Skeleton className="h-[var(--chart-height,240px)] w-full md:h-[var(--chart-height-md,280px)]" />
<ChartFooterReserve dayLinks={dayLinks} dataTable={dataTable} />
{showSlowHint && (
<p
+34 -8
View File
@@ -29,20 +29,46 @@ import { importWithRetry } from "@/lib/retry-import";
* to ONE error card with a reload affordance instead of bubbling to the
* route-level `error.tsx`.
*/
const HealthChartLazy = dynamic(
() =>
importWithRetry(() => import("@/components/charts/chart-runtime")).then(
(mod) => ({ default: mod.HealthChart }),
),
{ ssr: false, loading: () => <ChartSkeleton /> },
);
const loadHealthChart = () =>
importWithRetry(() => import("@/components/charts/chart-runtime")).then(
(mod) => ({ default: mod.HealthChart }),
);
// One lazy boundary per footer shape: `next/dynamic`'s loading slot gets no
// props, so the shell that must match a day-linked chart with its data table
// is its own boundary. All four resolve the same chunk.
const HealthChartLazy = dynamic(loadHealthChart, {
ssr: false,
loading: () => <ChartSkeleton />,
});
const HealthChartLazyDay = dynamic(loadHealthChart, {
ssr: false,
loading: () => <ChartSkeleton dayLinks />,
});
const HealthChartLazyTable = dynamic(loadHealthChart, {
ssr: false,
loading: () => <ChartSkeleton dataTable />,
});
const HealthChartLazyDayTable = dynamic(loadHealthChart, {
ssr: false,
loading: () => <ChartSkeleton dayLinks dataTable />,
});
export function HealthChartDynamic(
props: ComponentProps<typeof HealthChartLazy>,
): ReactElement {
const Lazy = props.mini
? HealthChartLazy
: props.dayLinks
? props.showDataTable
? HealthChartLazyDayTable
: HealthChartLazyDay
: props.showDataTable
? HealthChartLazyTable
: HealthChartLazy;
return (
<ChartErrorBoundary>
<HealthChartLazy {...props} />
<Lazy {...props} />
</ChartErrorBoundary>
);
}
+10 -1
View File
@@ -68,6 +68,7 @@ import { bucketCaptionKey } from "@/lib/charts/bucket-caption";
import type { MeasurementType } from "@/generated/prisma/client";
import { ChartOverlayControls } from "./chart-overlay-controls";
import { ChartDataTable, type ChartDataTableColumn } from "./chart-data-table";
import { ChartFooterReserve } from "./chart-skeleton";
import { useChartOverlayPrefs } from "@/hooks/use-chart-overlay-prefs";
import { useViewportWidth } from "@/hooks/use-viewport-width";
import { computeTickPositions } from "@/lib/charts/x-axis-density";
@@ -1945,7 +1946,15 @@ export function HealthChart({
// card height never jumps when the data lands — the dashboard's
// shared-reveal overlay and every insights mount stay
// layout-shift-free.
<Skeleton className={`w-full ${chartHeightClass}`} />
<>
<Skeleton className={`w-full ${chartHeightClass}`} />
{mini ? null : (
<ChartFooterReserve
dayLinks={dayLinksActive}
dataTable={showDataTable}
/>
)}
</>
) : isError ? (
// v1.16.8 — a failed query paints as an ERROR with a retry
// affordance, not as the "no data in this range" empty state.