@appscode/design-system 2.17.86 → 2.17.87

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appscode/design-system",
3
- "version": "2.17.86",
3
+ "version": "2.17.87",
4
4
  "description": "A design system for Appscode websites and dashboards made using Bulma",
5
5
  "main": "main.scss",
6
6
  "scripts": {
@@ -29,9 +29,30 @@ const themeModes = ref<ThemeModes>({
29
29
 
30
30
  const emit = defineEmits(["set:theme"]);
31
31
 
32
+ // localStorage throws when the origin's quota is full, and when storage is
33
+ // unreachable altogether (private browsing, sandboxed iframe, blocked site
34
+ // data, server-side render). Remembering the theme is a convenience, so a
35
+ // failure must never stop the theme from being read or applied.
36
+ const readThemeMode = (): string | null => {
37
+ try {
38
+ return localStorage.getItem("themeMode");
39
+ } catch {
40
+ // no stored preference available
41
+ return null;
42
+ }
43
+ };
44
+
45
+ const persistThemeMode = (mode: string) => {
46
+ try {
47
+ localStorage.setItem("themeMode", mode);
48
+ } catch {
49
+ // not remembered across reloads, but it still applies for this session
50
+ }
51
+ };
52
+
32
53
  onMounted(() => {
33
54
  // get theme mode from localStorage or set default one
34
- themeMode.value = localStorage.getItem("themeMode") || "light";
55
+ themeMode.value = readThemeMode() || "light";
35
56
  });
36
57
 
37
58
  onUnmounted(() => {
@@ -39,7 +60,7 @@ onUnmounted(() => {
39
60
  });
40
61
 
41
62
  const onThemeModeChange = (n: string) => {
42
- localStorage.setItem("themeMode", n);
63
+ persistThemeMode(n);
43
64
 
44
65
  let theme = n;
45
66
  if (n === "system") {