mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-20 12:23:02 +00:00
docs(theme): wrap localStorage in try catch
So that the site still works in Safari with all cookies blocked.
This commit is contained in:
parent
1d667b63b7
commit
5c3c038a41
1 changed files with 9 additions and 3 deletions
|
@ -9,14 +9,20 @@
|
||||||
const isValidTheme = (value) => themes.includes(value);
|
const isValidTheme = (value) => themes.includes(value);
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
const persisted_theme = localStorage.getItem(persistKey);
|
try {
|
||||||
if (isValidTheme(persisted_theme)) theme.set(persisted_theme);
|
const persisted_theme = localStorage.getItem(persistKey);
|
||||||
|
if (isValidTheme(persisted_theme)) theme.set(persisted_theme);
|
||||||
|
} catch (e) {}
|
||||||
});
|
});
|
||||||
|
|
||||||
afterUpdate(() => {
|
afterUpdate(() => {
|
||||||
if (isValidTheme($theme)) {
|
if (isValidTheme($theme)) {
|
||||||
document.documentElement.setAttribute("theme", $theme);
|
document.documentElement.setAttribute("theme", $theme);
|
||||||
if (persist) localStorage.setItem(persistKey, $theme);
|
if (persist) {
|
||||||
|
try {
|
||||||
|
localStorage.setItem(persistKey, $theme);
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue