Files
HealthLog/next.config.ts
T
Marc-André Bombeck d254e9cd98 perf(insights): defer below-fold mother-page blocks behind next/dynamic + bundle config hygiene
Lighthouse v1.4.33 flagged ~463 KiB of unused JS on first /insights
paint plus ~211 KiB of bundled JS as unminified. Two coordinated
moves close the gap without touching the Coach panel internals or
the dashboard tree.

next.config.ts
- `compiler.removeConsole` with `exclude: ["error", "warn"]` strips
  the chart-wiring + Coach SSE breadcrumb literals from the prod
  bundle. Error + warn paths still flow through to GlitchTip.
- `headers()` advertises `Permissions-Policy: unload=()` so Chromium
  admits the page to the back/forward cache when navigating away. We
  carry no `beforeunload` / `unload` listeners in-tree so the hint is
  honest.

src/app/insights/page.tsx
- `<DailyBriefing>`, `<CorrelationRow>`, `<TrendsRow>` move behind
  `next/dynamic({ ssr: false, loading: <Skeleton /> })`. All three
  paint below the hero on every viewport and were eagerly imported
  before. Each loader skeleton matches the dimensions of the resolved
  block so layout doesn't shift.
- `<HeroStrip>` stays an eager import — the greeting + health-score
  badge are the visible-first-paint surface.
2026-05-16 17:57:03 +02:00

74 lines
2.7 KiB
TypeScript

import type { NextConfig } from "next";
import bundleAnalyzer from "@next/bundle-analyzer";
const nextConfig: NextConfig = {
output: "standalone",
poweredByHeader: false,
// v1.4.33 IW2 — strip `console.*` calls from the production bundle
// (keep `console.error` + `console.warn` so the GlitchTip reporter
// and prod-side debug rails still surface). The Lighthouse audit
// flagged ~211 KiB of bundled JS as "unminified" — Turbopack already
// mangles + minifies the chunks, but the in-tree `console.log`
// breadcrumbs from the chart wiring + Coach SSE handlers carried
// hundreds of preserved string literals through to the client. The
// SWC compiler drops the calls + their literal-only arguments
// entirely in production.
compiler: {
removeConsole:
process.env.NODE_ENV === "production"
? { exclude: ["error", "warn"] }
: false,
},
// v1.4.33 IW2 — bfcache hygiene. `Permissions-Policy: unload=()`
// tells the browser the page does not need the `unload` event,
// which Chromium uses as a hint to admit the page to the
// back/forward cache on navigation away. Pair with the absence of
// any `beforeunload` / `unload` listener in our own code so the
// bfcache restore path stays clear. The other CSP-style security
// headers already live on the response via the standalone runtime;
// we add only the bfcache hint here.
async headers() {
return [
{
source: "/:path*",
headers: [
{ key: "Permissions-Policy", value: "unload=()" },
],
},
];
},
serverExternalPackages: [
"@prisma/client",
"pg-boss",
"@prisma/adapter-pg",
"pg",
],
// v1.4.25 Fix-G — `src/lib/ai/prompts/safety-contracts.ts` reads its
// sibling YAML files at runtime via `__dirname + readFileSync`. The
// standalone bundler ships the JS but not the YAML, so the build
// crashed during page-data collection with ENOENT once the Turbopack
// chunking-error layer was cleared. Telling Next to trace the YAML
// files explicitly keeps them in the runtime image alongside the
// bundled module.
outputFileTracingIncludes: {
"*": ["./src/lib/ai/prompts/safety-contracts.*.yaml"],
},
experimental: {
optimizePackageImports: ["recharts", "lucide-react"],
},
};
/**
* v1.4.28 R3d — opt-in bundle analyzer behind `ANALYZE=1`.
*
* `pnpm analyze` (defined in `package.json`) sets the env var and
* runs `next build`; the analyzer writes static HTML reports to
* `.next/analyze/*.html`. The wrapper is a no-op when the env var is
* unset so the regular `pnpm build` pipeline pays nothing.
*/
const withBundleAnalyzer = bundleAnalyzer({
enabled: process.env.ANALYZE === "1",
});
export default withBundleAnalyzer(nextConfig);