File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed
packages/swr-devtools-panel/src/components Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -5,8 +5,13 @@ const THEME_KEY = "$swr-devtools:theme";
55
66const initialTheme = ( ) : Theme => {
77 if ( typeof window === "undefined" ) return "system" ;
8- // @ts -expect-error
9- return localStorage . getItem ( THEME_KEY ) || "system" ;
8+ let theme : Theme = "system" ;
9+ try {
10+ theme = localStorage . getItem ( THEME_KEY ) as Theme ;
11+ } catch {
12+ // noop
13+ }
14+ return theme ;
1015} ;
1116
1217const getThemeByPreference = ( ) =>
@@ -42,7 +47,11 @@ export const ThemeProvider = ({ children }: { children: React.ReactNode }) => {
4247 setTheme ( initialTheme ( ) ) ;
4348 } , [ ] ) ;
4449 useEffect ( ( ) => {
45- localStorage . setItem ( THEME_KEY , theme ) ;
50+ try {
51+ localStorage . setItem ( THEME_KEY , theme ) ;
52+ } catch {
53+ // noop
54+ }
4655 } , [ theme ] ) ;
4756 return (
4857 < ThemeContext . Provider value = { { theme, setTheme } } >
You can’t perform that action at this time.
0 commit comments