From df602ab559283c94b0d661fe24b1e188c7becfa5 Mon Sep 17 00:00:00 2001 From: Catherine Renelle <32781029+catrenelle@users.noreply.github.com> Date: Fri, 27 Feb 2026 22:20:04 -0500 Subject: [PATCH] Fix branding page 500 on hard refresh: guard document access during SSR Co-Authored-By: Claude Opus 4.6 --- src/lib/utils/theme-persist.ts | 1 + src/lib/utils/theme-preview.ts | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/lib/utils/theme-persist.ts b/src/lib/utils/theme-persist.ts index 28b4183..f5cb6e4 100644 --- a/src/lib/utils/theme-persist.ts +++ b/src/lib/utils/theme-persist.ts @@ -42,6 +42,7 @@ function hexToRgba(hex: string, opacity: number): string { * so theme changes take effect immediately without a full page reload. */ export function persistThemeCSS(theme: TenantThemeData) { + if (typeof document === 'undefined') return; const lightVars: string[] = []; const darkVars: string[] = []; diff --git a/src/lib/utils/theme-preview.ts b/src/lib/utils/theme-preview.ts index 646159e..538a5f6 100644 --- a/src/lib/utils/theme-preview.ts +++ b/src/lib/utils/theme-preview.ts @@ -52,6 +52,7 @@ const appliedElements: { el: HTMLElement; prop: string }[] = []; * Only applies fields for the given mode (light or dark). */ export function applyThemePreview(draft: TenantThemeData, mode: 'light' | 'dark') { + if (typeof document === 'undefined') return; clearThemePreview(); const fieldMap = mode === 'light' ? LIGHT_FIELD_MAP : DARK_FIELD_MAP; @@ -118,6 +119,7 @@ export function applyThemePreview(draft: TenantThemeData, mode: 'light' | 'dark' * Removes all inline CSS var overrides applied by applyThemePreview. */ export function clearThemePreview() { + if (typeof document === 'undefined') return; const el = document.documentElement; for (const v of appliedVars) { el.style.removeProperty(v);