perf(dashboard,insights): reserve the cold-paint footprint and cache the slow overview reads

The dashboard reserves chart-row skeleton cells from the saved layout
before the snapshot resolves, so a cold load paints close to its final
footprint instead of growing by a screen when data lands; the tile
silhouettes count only tile-capable widgets with blood pressure as two,
the greeting line keeps its box through name personalisation, and the
getting-started checklist moves below the charts where its arrival
shifts nothing. On the insights overview the targets build runs its
eight reads in parallel with a one-year floor on the glucose scan
instead of strictly in sequence over an unbounded history, the derived
batch gains a server cache where it previously recomputed sixteen
metrics on every read, both serve stale-while-revalidate, and the
health-score column reserves its exact footprint while the analytics
payload is pending.
This commit is contained in:
Marc-André Bombeck committed 2026-06-11 21:52:36 +02:00
1 parent b5e799c2d6
commit 242d2514ee
13 files changed
+784 -159

No files matched your search

@@ -40,7 +40,14 @@ export function DashboardHeader({
<h1 className="text-2xl font-bold tracking-tight">
{t("dashboard.title")}
</h1>
<p className="text-muted-foreground mt-1 text-sm">{welcomeText}</p>
{/* v1.16.8 — `min-h-5` reserves the greeting's line box from the
SSR pass on: the text personalises (name appended) on the
first client re-render after hydration, and the reserved
line keeps the header from collapsing/growing around that
swap. */}
<p className="text-muted-foreground mt-1 min-h-5 text-sm">
{welcomeText}
</p>
</div>
<div className="flex items-center gap-2">
{/* Customize shortcut to the dashboard-customization settings
@@ -317,4 +317,61 @@ describe("<HeroStrip>", () => {
const html = render(<HeroStrip briefing={null} now={morningLocal} />);
expect(html).not.toContain("md:items-stretch");
});
// ── v1.16.8 — score-column reservation while analytics is pending ──
it("reserves the score column with a skeleton while the payload is pending", () => {
const html = render(
<HeroStrip briefing={null} now={morningLocal} healthScorePending />,
);
// The placeholder mirrors the card's column footprint so the band
// paints at its final geometry from the first frame.
expect(html).toContain('data-slot="health-score-card-skeleton"');
expect(html).toContain("md:basis-[22rem]");
expect(html).toContain('aria-hidden="true"');
// The real card stays absent until the payload lands.
expect(html).not.toContain('data-slot="health-score-card" ');
});
it("keeps the two-column split active while pending", () => {
const html = render(
<HeroStrip briefing={null} now={morningLocal} healthScorePending />,
);
expect(html).toContain("md:flex-row");
expect(html).toContain("md:items-stretch");
});
it("drops the skeleton once the payload resolves without a score", () => {
const html = render(
<HeroStrip
briefing={null}
now={morningLocal}
healthScorePending={false}
/>,
);
expect(html).not.toContain('data-slot="health-score-card-skeleton"');
expect(html).not.toContain("md:items-stretch");
});
it("renders the real card, never the skeleton, when a score is present", () => {
const html = render(
<HeroStrip
briefing={null}
now={morningLocal}
healthScorePending
healthScore={{
score: 86,
band: "green",
components: {
bp: { value: 80, weight: 0.3 },
weight: { value: 70, weight: 0.2 },
mood: { value: 90, weight: 0.2 },
compliance: { value: 100, weight: 0.3 },
},
delta: 5,
}}
/>,
);
expect(html).toContain('data-slot="health-score-card"');
expect(html).not.toContain('data-slot="health-score-card-skeleton"');
});
});
+47 -1
View File
@@ -2,6 +2,7 @@
import { Sparkles } from "lucide-react";
import { Button } from "@/components/ui/button";
import { Skeleton } from "@/components/ui/skeleton";
import { useTranslations } from "@/lib/i18n/context";
import { formatRelativeTime } from "@/lib/i18n/relative-time";
import { useFeatureFlags } from "@/hooks/use-feature-flags";
@@ -89,6 +90,18 @@ interface HeroStripProps {
components: HealthScoreCardProps["components"];
delta: HealthScoreCardProps["delta"];
} | null;
/**
* v1.16.8 — true while the analytics payload that carries
* `healthScore` is still in flight. The right column then reserves the
* score card's footprint with a skeleton, so the hero band paints at
* roughly its final size from the first frame and the card landing is
* a swap, not a push. Pre-fix the column collapsed while loading and
* the whole overview reflowed when the (slow, thick-slice) analytics
* response arrived — the "greeting first, score card later" stagger.
* When the payload resolves WITHOUT a score (no data yet) the column
* collapses once, which is the legacy no-score shape.
*/
healthScorePending?: boolean;
}
/**
@@ -118,6 +131,7 @@ export function HeroStrip({
onAskCoach,
now,
healthScore,
healthScorePending = false,
}: HeroStripProps) {
const { t } = useTranslations();
// v1.4.37 W5 — operator-level Coach gate. When the global Coach flag
@@ -180,10 +194,15 @@ export function HeroStrip({
* `h-full` + `mt-auto` on its disclaimer to redistribute the
* recovered space without visual jank.
*/}
{/* v1.16.8 — the split keys on `reserveScoreColumn`, not on the
resolved payload alone: while the analytics query is in flight
the right column already holds the score card's footprint (the
skeleton below), so the band's two-column geometry is stable
from first paint. */}
<div
className={cn(
"flex flex-col gap-5",
healthScore &&
(healthScore || healthScorePending) &&
"md:flex-row md:items-stretch md:gap-6 lg:flex-row lg:items-stretch lg:gap-6",
)}
>
@@ -287,6 +306,33 @@ export function HeroStrip({
)}
</div>
{!healthScore && healthScorePending && (
/* v1.16.8 — layout-stable placeholder mirroring the score
card's column footprint (same basis / stretch classes as
`<HealthScoreCard>`): label row, headline number, progress
bar, four component rows. Decorative — the card announces
nothing while loading. */
<div
data-slot="health-score-card-skeleton"
aria-hidden="true"
className={cn(
"bg-card/65 border-border/60 rounded-xl border px-4 py-4 shadow-sm backdrop-blur-sm",
"w-full md:basis-[22rem] md:shrink-0 md:grow-0 xl:basis-[26rem]",
"flex h-full min-h-64 flex-col gap-3.5",
)}
>
<Skeleton className="h-3 w-24" />
<Skeleton className="h-12 w-28" />
<Skeleton className="h-2 w-full rounded-full" />
<Skeleton className="h-3 w-32" />
<div className="space-y-2.5 border-t pt-3.5">
<Skeleton className="h-3 w-full" />
<Skeleton className="h-3 w-full" />
<Skeleton className="h-3 w-full" />
<Skeleton className="h-3 w-full" />
</div>
</div>
)}
{healthScore && (
<HealthScoreCard
score={healthScore.score}