Fix branding page 500 on hard refresh: guard document access during SSR
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -42,6 +42,7 @@ function hexToRgba(hex: string, opacity: number): string {
|
|||||||
* so theme changes take effect immediately without a full page reload.
|
* so theme changes take effect immediately without a full page reload.
|
||||||
*/
|
*/
|
||||||
export function persistThemeCSS(theme: TenantThemeData) {
|
export function persistThemeCSS(theme: TenantThemeData) {
|
||||||
|
if (typeof document === 'undefined') return;
|
||||||
const lightVars: string[] = [];
|
const lightVars: string[] = [];
|
||||||
const darkVars: string[] = [];
|
const darkVars: string[] = [];
|
||||||
|
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ const appliedElements: { el: HTMLElement; prop: string }[] = [];
|
|||||||
* Only applies fields for the given mode (light or dark).
|
* Only applies fields for the given mode (light or dark).
|
||||||
*/
|
*/
|
||||||
export function applyThemePreview(draft: TenantThemeData, mode: 'light' | 'dark') {
|
export function applyThemePreview(draft: TenantThemeData, mode: 'light' | 'dark') {
|
||||||
|
if (typeof document === 'undefined') return;
|
||||||
clearThemePreview();
|
clearThemePreview();
|
||||||
|
|
||||||
const fieldMap = mode === 'light' ? LIGHT_FIELD_MAP : DARK_FIELD_MAP;
|
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.
|
* Removes all inline CSS var overrides applied by applyThemePreview.
|
||||||
*/
|
*/
|
||||||
export function clearThemePreview() {
|
export function clearThemePreview() {
|
||||||
|
if (typeof document === 'undefined') return;
|
||||||
const el = document.documentElement;
|
const el = document.documentElement;
|
||||||
for (const v of appliedVars) {
|
for (const v of appliedVars) {
|
||||||
el.style.removeProperty(v);
|
el.style.removeProperty(v);
|
||||||
|
|||||||
Reference in New Issue
Block a user