Skip to content

Commit 84bea84

Browse files
committed
Create FALLBACK_SETTINGS on demand so we don't call createThemeStore() eagerly and thus set <html class="dark"> unintentional
1 parent 5730122 commit 84bea84

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

Diff for: .changeset/giant-camels-lie.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"svelte-ux": patch
3+
---
4+
5+
Create `FALLBACK_SETTINGS` on demand so we don't call `createThemeStore()` eagerly and thus set `<html class="dark">` unintentional

Diff for: packages/svelte-ux/src/lib/components/settings.ts

+12-8
Original file line numberDiff line numberDiff line change
@@ -118,19 +118,23 @@ export function settings(settings: SettingsInput): Settings {
118118
});
119119
}
120120

121-
const FALLBACK_CONTEXT: Settings = {
122-
currentTheme: createThemeStore({ light: ['light'], dark: ['dark'] }),
123-
componentSettingsCache: {},
124-
...createLocaleStores({}),
125-
};
121+
let FALLBACK_SETTINGS: Settings | null = null;
122+
123+
function getFallbackSettings() {
124+
FALLBACK_SETTINGS = FALLBACK_SETTINGS ?? {
125+
currentTheme: createThemeStore({ light: ['light'], dark: ['dark'] }),
126+
componentSettingsCache: {},
127+
...createLocaleStores({}),
128+
};
129+
return FALLBACK_SETTINGS;
130+
}
126131

127132
export function getSettings(): Settings {
128133
// in a try/catch to be able to test w/o svelte components
129-
130134
try {
131-
return getContext<Settings>(settingsKey) ?? FALLBACK_CONTEXT;
135+
return getContext<Settings>(settingsKey) ?? getFallbackSettings();
132136
} catch (error) {
133-
return FALLBACK_CONTEXT;
137+
return getFallbackSettings();
134138
}
135139
}
136140

0 commit comments

Comments
 (0)