Skip to content

Commit 68f886e

Browse files
committed
Add full fallback settings when setting() is not defined (context)
1 parent 7190af0 commit 68f886e

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

.changeset/fifty-seals-hang.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"svelte-ux": patch
3+
---
4+
5+
Do not require `settings()` to be defined

packages/svelte-ux/src/lib/components/settings.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,19 @@ 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+
};
126+
121127
export function getSettings(): Settings {
122-
// in a try/catch to be able to test wo svelte components
128+
// in a try/catch to be able to test w/o svelte components
129+
123130
try {
124-
return getContext<Settings>(settingsKey) ?? {};
131+
return getContext<Settings>(settingsKey) ?? FALLBACK_CONTEXT;
125132
} catch (error) {
126-
return {
127-
currentTheme: createThemeStore({ light: ['light'], dark: ['dark'] }),
128-
componentSettingsCache: {},
129-
};
133+
return FALLBACK_CONTEXT;
130134
}
131135
}
132136

0 commit comments

Comments
 (0)