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);
|
||||
|
||||
onMount(() => {
|
||||
const persisted_theme = localStorage.getItem(persistKey);
|
||||
if (isValidTheme(persisted_theme)) theme.set(persisted_theme);
|
||||
try {
|
||||
const persisted_theme = localStorage.getItem(persistKey);
|
||||
if (isValidTheme(persisted_theme)) theme.set(persisted_theme);
|
||||
} catch (e) {}
|
||||
});
|
||||
|
||||
afterUpdate(() => {
|
||||
if (isValidTheme($theme)) {
|
||||
document.documentElement.setAttribute("theme", $theme);
|
||||
if (persist) localStorage.setItem(persistKey, $theme);
|
||||
if (persist) {
|
||||
try {
|
||||
localStorage.setItem(persistKey, $theme);
|
||||
} catch (e) {}
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue