mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-19 08:12:52 +00:00
chore: remove the dashboard's pre-snapshot feed
NEXT_PUBLIC_DASHBOARD_SNAPSHOT=false built a dashboard that read its tiles from two analytics slices, the widget layout, the mood analytics and the thresholds instead of the one snapshot cell. It took a rebuilt image to reach, and the snapshot has been the only path the published image runs since it became the default. The flag, its readers, the legacy reads in the dashboard hook and tile context, the slim and thick merge helper, the build-time toggle notes in .env.production.example and the self-hosting guide, and the tests that pinned the legacy wiring go.
This commit is contained in:
1 parent
d99456138b
commit
9dc519dd85
26 files changed
+106
-729
No files matched your search
@@ -1,52 +0,0 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { dashboardSource } from "@/__tests__/helpers/dashboard-source";
|
||||
|
||||
/**
|
||||
* v1.4.39.2 — dashboard analytics slim/thick split.
|
||||
*
|
||||
* Pre-fix the dashboard fired a single `useAnalyticsQuery()` against the
|
||||
* thick `/api/analytics` envelope; every per-type tile waited on the
|
||||
* heavy fan-out before paint. Mood and medication tiles arrived first
|
||||
* (separate routes) and then every other tile arrived as one burst,
|
||||
* which the maintainer reported as "etwas nervig" in the v1.4.39.1 post-deploy
|
||||
* trace.
|
||||
*
|
||||
* Post-fix the dashboard mounts TWO `useAnalyticsQuery` calls in
|
||||
* parallel: one for `?slice=summaries` (per-type tile strip) and one
|
||||
* for the thick envelope (BD-Zielbereich + glucose tiles). The tile
|
||||
* strip paints from the slim slice as soon as it lands; thick fields
|
||||
* stream in afterwards. Without this dual-mount the cold-mount UX
|
||||
* waterfall regresses to the v1.4.39.1 behaviour, so the test pins the
|
||||
* two call shapes.
|
||||
*
|
||||
* v1.7.0 — both calls now carry an `enabled` gate so the unified
|
||||
* snapshot rollout flag can disable them in favour of a single
|
||||
* `/api/dashboard/snapshot` cell. With the flag OFF (default) the
|
||||
* slim/thick split still drives the page, so the protective intent
|
||||
* holds; the matchers only relaxed to tolerate the `enabled` arg.
|
||||
*/
|
||||
|
||||
describe("v1.4.39.2 — dashboard analytics slim/thick split", () => {
|
||||
it("mounts both the slim slice and the thick slice in parallel", () => {
|
||||
const src = dashboardSource();
|
||||
// Slim slice — `?slice=summaries` paints the per-type tile strip.
|
||||
expect(src).toMatch(/useAnalyticsQuery\(\{\s*\n?\s*slice:\s*"summaries"/);
|
||||
// Thick slice — the no-slice `useAnalyticsQuery` feeds the
|
||||
// BD-Zielbereich + glucose tiles. Both must coexist. The thick
|
||||
// call now opens with `{ enabled:` (no `slice` key).
|
||||
expect(src).toMatch(/useAnalyticsQuery\(\{\s*\n?\s*enabled:/);
|
||||
});
|
||||
|
||||
it("merges slim and thick results so call-sites stay shape-stable", () => {
|
||||
const src = dashboardSource();
|
||||
// The merge contract: slim wins on overlapping fields, thick fills
|
||||
// in `bpInTargetPct*` and `glucoseByContext`. The text anchors
|
||||
// protect against a future refactor accidentally dropping one of
|
||||
// the queries — the `data` object that downstream tile rendering
|
||||
// consumes must stay shape-stable across both query states.
|
||||
expect(src).toMatch(/analyticsSlimQuery/);
|
||||
expect(src).toMatch(/analyticsThickQuery/);
|
||||
expect(src).toMatch(/bpInTargetPct/);
|
||||
expect(src).toMatch(/glucoseByContext/);
|
||||
});
|
||||
});
|
||||
@@ -284,12 +284,9 @@ describe("the tile the user actually sees", () => {
|
||||
describe("the gate reaches every feed, not just the default one", () => {
|
||||
it("strips the recovery-owned series from a summaries slice", () => {
|
||||
// `gateSummariesByModules` moved out of the snapshot builder, where it
|
||||
// was private, so `/api/analytics` can apply the SAME filter. With
|
||||
// `NEXT_PUBLIC_DASHBOARD_SNAPSHOT=false` that route feeds the tiles, and
|
||||
// it filtered nothing at all — so recovery-off plus RMSSD-only still
|
||||
// painted the tile, on the exact path the helper's docblock promised it
|
||||
// could not. A gate that only holds on one feed is only as strong as a
|
||||
// rollout flag.
|
||||
// was private, so `/api/analytics` can apply the SAME filter: that route
|
||||
// filtered nothing at all, so recovery-off plus RMSSD-only still reached
|
||||
// every reader of the slice.
|
||||
const summaries = {
|
||||
HEART_RATE_VARIABILITY: summary(9, 55),
|
||||
HRV_RMSSD: summary(30, 42),
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { dashboardSource } from "@/__tests__/helpers/dashboard-source";
|
||||
import { readSource } from "@/__tests__/helpers/source-files";
|
||||
|
||||
/**
|
||||
* v1.4.40 — dashboard Suspense boundaries.
|
||||
@@ -57,19 +56,6 @@ describe("v1.4.40 — dashboard per-cell Suspense boundaries", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("hoists DASHBOARD_QUERY_OPTS to module scope (audit-M2)", () => {
|
||||
const src = readSource(
|
||||
"src/components/dashboard/tiles/use-dashboard-data.ts",
|
||||
"export function useDashboardData",
|
||||
);
|
||||
// Module-scope declaration — search outside the hook body. Declared
|
||||
// inside it, every render would create a fresh `{}` reference.
|
||||
const moduleSliceEnd = src.indexOf("export function useDashboardData");
|
||||
expect(moduleSliceEnd).toBeGreaterThan(0);
|
||||
const moduleSlice = src.slice(0, moduleSliceEnd);
|
||||
expect(moduleSlice).toMatch(/const\s+DASHBOARD_QUERY_OPTS\s*=\s*\{/);
|
||||
});
|
||||
|
||||
it("keeps the per-render Intl hour walk off the page (audit-H4 successor)", () => {
|
||||
const src = dashboardSource();
|
||||
// The audit-H4 `useMemo(getHourForTimeZone, [userTimezone])` pin
|
||||
|
||||
@@ -24,11 +24,9 @@ import {
|
||||
* strip's footprint immediately and swaps to the real tiles the moment
|
||||
* the query resolves.
|
||||
*
|
||||
* v1.7.0 — the gate now keys off `primaryLoading`, which resolves to
|
||||
* the snapshot cell under `NEXT_PUBLIC_DASHBOARD_SNAPSHOT=true` and the
|
||||
* slim analytics cell otherwise. A disabled TanStack query reports
|
||||
* `isLoading: false`, so keying off the slim query in snapshot mode
|
||||
* (where it is `enabled: false`) flashed the empty state for the whole
|
||||
* v1.7.0 — the gate keys off `primaryLoading`, which resolves to the
|
||||
* snapshot cell. A disabled TanStack query reports `isLoading: false`, so
|
||||
* keying off any other query flashed the empty state for the whole
|
||||
* snapshot fetch. The pure `resolveDashboardFirstPaintGate` carries the
|
||||
* behaviour; textual pins keep the wiring honest.
|
||||
*/
|
||||
@@ -198,13 +196,13 @@ describe("v1.4.43 W11 — dashboard tile-strip skeleton (wiring)", () => {
|
||||
expect(skeletonBlock?.[0]).toContain("<ChartSkeleton");
|
||||
});
|
||||
|
||||
it("derives `primaryLoading` from the snapshot vs slim query", () => {
|
||||
it("derives `primaryLoading` from the snapshot query", () => {
|
||||
const src = dashboardSource();
|
||||
// v1.16.4 — `!mounted` pins SSR + the hydration render to the
|
||||
// skeleton branch so a late-hydrating boundary can't disagree with
|
||||
// the server HTML (React #418); see `useMounted`.
|
||||
expect(src).toMatch(
|
||||
/const\s+primaryLoading\s*=\s*!mounted\s*\|\|\s*\(snapshotEnabled\s*\?\s*snapshotQuery\.isLoading\s*:\s*analyticsSlimQuery\.isLoading\);/,
|
||||
/const\s+primaryLoading\s*=\s*!mounted\s*\|\|\s*snapshotQuery\.isLoading;/,
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -64,9 +64,6 @@ vi.mock("@/lib/modules/gate", () => ({
|
||||
vi.mock("@/lib/dashboard/snapshot-read", () => ({
|
||||
readDashboardSnapshotCached: (u: unknown) => readDashboardSnapshotCached(u),
|
||||
}));
|
||||
vi.mock("@/lib/dashboard/snapshot-flag", () => ({
|
||||
isDashboardSnapshotEnabled: () => true,
|
||||
}));
|
||||
vi.mock("@/lib/dashboard/batch-chart-types", () => ({
|
||||
computeBatchWindow: () => ({
|
||||
from: "2026-07-01T00:00:00.000Z",
|
||||
|
||||
@@ -80,11 +80,8 @@ export const GET = apiHandler(async (request?: Request) => {
|
||||
const slim = await readSummariesSlice(user.id, { serveStale: true });
|
||||
// Drop the types whose module the user turned off, from the SAME map
|
||||
// the snapshot builder gates on (`SUMMARY_TYPE_MODULE`, via
|
||||
// `gateSummariesByModules`). With `NEXT_PUBLIC_DASHBOARD_SNAPSHOT=false`
|
||||
// this slice — not the snapshot — feeds the dashboard tile strip, and
|
||||
// it used to hand back every type regardless: recovery off plus an
|
||||
// RMSSD-only account still painted the HRV tile, because nothing on
|
||||
// this path had ever filtered.
|
||||
// `gateSummariesByModules`), so a switched-off module's series never
|
||||
// reaches a page that reads this slice.
|
||||
//
|
||||
// Gated AFTER the cache read on purpose. The cached cell stays
|
||||
// module-independent, so toggling a module takes effect on the next
|
||||
|
||||
@@ -21,7 +21,6 @@ import {
|
||||
} from "@/lib/api/api-fetch";
|
||||
import { MfaLoginStep, type MfaMethod } from "@/components/auth/mfa-login-step";
|
||||
import { OIDC_MFA_COOKIE, OIDC_MFA_COOKIE_PATH } from "@/lib/auth/oidc-cookie";
|
||||
import { isDashboardSnapshotEnabled } from "@/lib/dashboard/snapshot-flag";
|
||||
import { prefetchDashboardSnapshot } from "@/lib/queries/use-dashboard-snapshot";
|
||||
import { clearOfflineCachesForSessionEnd } from "@/lib/pwa/query-persister";
|
||||
import { sanitizeSameOriginPath } from "@/lib/url-safety";
|
||||
@@ -237,9 +236,7 @@ export default function LoginPage() {
|
||||
// ample headroom to land before the new snapshot is written.
|
||||
void clearOfflineCachesForSessionEnd();
|
||||
const target = getRedirectTarget();
|
||||
if (target === "/" && isDashboardSnapshotEnabled()) {
|
||||
prefetchDashboardSnapshot(queryClient);
|
||||
}
|
||||
if (target === "/") prefetchDashboardSnapshot(queryClient);
|
||||
router.push(target);
|
||||
}
|
||||
|
||||
|
||||
@@ -84,7 +84,6 @@ export default function DashboardPageClient({
|
||||
const dashboard = useDashboardData({
|
||||
isAuthenticated,
|
||||
mounted,
|
||||
user,
|
||||
batchWindowProp: batchWindow,
|
||||
});
|
||||
const { digestQuery, layout, primaryLoading } = dashboard;
|
||||
|
||||
+11
-23
@@ -6,7 +6,6 @@ import {
|
||||
|
||||
import { getUnswitchedSession } from "@/lib/auth/acting-carrier";
|
||||
import { readDashboardSnapshotCached } from "@/lib/dashboard/snapshot-read";
|
||||
import { isDashboardSnapshotEnabled } from "@/lib/dashboard/snapshot-flag";
|
||||
import {
|
||||
computeBatchWindow,
|
||||
deriveBatchChartTypes,
|
||||
@@ -116,29 +115,18 @@ export default async function DashboardPage() {
|
||||
});
|
||||
}
|
||||
|
||||
// Above-the-fold prefetch runs ONLY in snapshot mode: legacy mode derives
|
||||
// its chart-type list from analytics queries the RSC did not run, so there
|
||||
// is no byte-identical key to dehydrate the series under. In legacy mode
|
||||
// `batchWindow` stays undefined and the client falls back to its own
|
||||
// browser-local window exactly as before — no behaviour change off-flag.
|
||||
const snapshotMode = isDashboardSnapshotEnabled();
|
||||
// The profile-tz window is computed ONCE and threaded to the client so
|
||||
// the batched-series key matches byte-for-byte.
|
||||
batchWindow = computeBatchWindow(new Date(), user.timezone);
|
||||
|
||||
// The profile-tz window is computed ONCE (snapshot mode only) and threaded
|
||||
// to the client so the batched-series key matches byte-for-byte.
|
||||
if (snapshotMode) {
|
||||
batchWindow = computeBatchWindow(new Date(), user.timezone);
|
||||
}
|
||||
|
||||
const seriesTypes = snapshotMode
|
||||
? deriveBatchChartTypes(
|
||||
resolveDashboardLayout(wireBody.layout),
|
||||
(
|
||||
wireBody.tiles as {
|
||||
summaries?: Record<string, { count?: number }>;
|
||||
}
|
||||
)?.summaries,
|
||||
)
|
||||
: [];
|
||||
const seriesTypes = deriveBatchChartTypes(
|
||||
resolveDashboardLayout(wireBody.layout),
|
||||
(
|
||||
wireBody.tiles as {
|
||||
summaries?: Record<string, { count?: number }>;
|
||||
}
|
||||
)?.summaries,
|
||||
);
|
||||
|
||||
// Digest carries a soft budget (cold-day extras rebuild); series is a
|
||||
// warm rollup read (< 100 ms) with none. Both fail soft to `undefined`.
|
||||
|
||||
Reference in new issue
Block a user