mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-14 06:40:50 +00:00
perf(insights): keep Zod off the first load of the metric pages
The value domain read the plausibility band out of the measurement validation module, so every metric sub-page that asks whether a metric can be negative or is integer-valued loaded the measurement schemas and Zod with them. The band and its check live in a Zod-free module now, re-exported by the validation module for the server writers, and the values list checks its segment against the exhaustive type label map instead of the Zod enum. About fifty metric routes drop roughly 88 KB gzip from their first load. The client-route guard walks a metric page and the values list too.
This commit is contained in:
1 parent
41c906e862
commit
ebdb63f0d8
6 files changed
+284
-258
No files matched your search
@@ -8,8 +8,8 @@ import {
|
||||
INSIGHTS_OVERVIEW,
|
||||
resolveValuesBackHref,
|
||||
} from "@/lib/insights/values-back-link";
|
||||
import { measurementTypeEnum } from "@/lib/validations/measurement";
|
||||
import { MEASUREMENT_TYPE_LABEL_KEYS } from "@/components/measurements/measurement-list-meta";
|
||||
import { MEASUREMENT_TYPE_LABEL_KEYS as EVERY_MEASUREMENT_TYPE } from "@/lib/measurements/type-label-keys";
|
||||
import { BackLink } from "@/components/ui/back-link";
|
||||
import { MeasurementList } from "@/components/measurements/measurement-list";
|
||||
import { SubPageShell } from "@/components/insights/sub-page-shell";
|
||||
@@ -38,8 +38,11 @@ export default function InsightsMetricValuesPage({
|
||||
const searchParams = useSearchParams();
|
||||
|
||||
// Reject any segment that is not a real MeasurementType so a typo'd
|
||||
// deep-link 404s instead of mounting a blank list.
|
||||
if (!measurementTypeEnum.options.includes(type as never)) {
|
||||
// deep-link 404s instead of mounting a blank list. The leaf label map is
|
||||
// typed `Record<MeasurementType, string>`, so the compiler holds it to
|
||||
// exactly the enum, and it answers the question without pulling the
|
||||
// measurement schemas, and Zod, into the page.
|
||||
if (!Object.hasOwn(EVERY_MEASUREMENT_TYPE, type)) {
|
||||
notFound();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user