perf(monitoring): read the monitoring switches in the root layout

Every document load, the sign-in page included, mounted a client
effect that asked `/api/monitoring/settings` for three instance-wide
values (false, null, false on a default install) before it mounted the
analytics script or the error reporter. The root layout is a server
component and now reads them while it renders and passes them in, so
the request and the effect go. The key-mismatch page reads nothing, as
before. The route stays for other callers.
This commit is contained in:
Marc-André Bombeck committed 2026-11-11 22:05:48 +01:00
1 parent d2ac3b91bd
commit ea6e94adcf
3 files changed
+80 -39

No files matched your search

+16 -2
View File
@@ -8,6 +8,7 @@ import "./globals.css";
import { Providers } from "@/components/providers";
import { AuthShell } from "@/components/layout/auth-shell";
import { MonitoringBootstrap } from "@/components/monitoring/bootstrap";
import { getPublicMonitoringSettings } from "@/lib/monitoring-settings";
import { WebVitalsReporter } from "@/components/monitoring/web-vitals-reporter";
import { resolveInitialLocale } from "@/lib/i18n/resolve-initial-locale";
import { isKeyMismatch } from "@/lib/boot/key-mismatch-state";
@@ -86,7 +87,12 @@ export default async function RootLayout({
? ((await headers()).get("x-nonce") ?? undefined)
: undefined;
const initialLocale = await resolveInitialLocale();
// The monitoring switches ride the document render instead of a request
// from every page load; the key-mismatch page reads no data.
const [initialLocale, monitoring] = await Promise.all([
resolveInitialLocale(),
isKeyMismatch() ? null : getPublicMonitoringSettings(),
]);
return (
<html lang={initialLocale} suppressHydrationWarning>
@@ -139,7 +145,15 @@ export default async function RootLayout({
<KeyMismatchPage locale={initialLocale} />
) : (
<Providers initialLocale={initialLocale}>
<MonitoringBootstrap />
<MonitoringBootstrap
settings={
monitoring && {
umamiEnabled: monitoring.umamiEnabled,
umamiWebsiteId: monitoring.umamiWebsiteId,
glitchtipEnabled: monitoring.glitchtipEnabled,
}
}
/>
<WebVitalsReporter />
{/* `DEMO_MODE` is a server-only env var; the proxy uses it to
block mutations. Resolve it here (server component) and