File tree Expand file tree Collapse file tree 6 files changed +55
-14
lines changed
playground-web/src/app/connect/sign-in/button
portal/src/components/others
packages/thirdweb/src/utils/storage Expand file tree Collapse file tree 6 files changed +55
-14
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " thirdweb " : patch
3+ ---
4+
5+ Catch localStorage getItem and setItem unhandled errors
Original file line number Diff line number Diff line change @@ -13,15 +13,22 @@ export function useLocalStorage<TType>(
1313 // FIXME: ideally we do not need localstorage like this, alernatively we move this into use-query and use-mutation to invalidate etc
1414 // eslint-disable-next-line no-restricted-syntax
1515 useEffect ( ( ) => {
16- const item = window . localStorage . getItem ( key ) ;
17-
18- _setValue ( item ? JSON . parse ( item ) : initialValue ) ;
16+ try {
17+ const item = window . localStorage . getItem ( key ) ;
18+ _setValue ( item ? JSON . parse ( item ) : initialValue ) ;
19+ } catch {
20+ // ignore
21+ }
1922 } , [ key , initialValue ] ) ;
2023
2124 const setValue = ( value_ : TType ) => {
2225 _setValue ( value_ ) ;
2326 if ( isBrowser ( ) ) {
24- window . localStorage . setItem ( key , JSON . stringify ( value_ ) ) ;
27+ try {
28+ window . localStorage . setItem ( key , JSON . stringify ( value_ ) ) ;
29+ } catch {
30+ // ignore
31+ }
2532 }
2633 } ;
2734
Original file line number Diff line number Diff line change @@ -41,7 +41,11 @@ export function RightSection(props: {
4141 // fake login for playground
4242 const playgroundAuth : ConnectButtonProps [ "auth" ] = {
4343 async doLogin ( ) {
44- localStorage . setItem ( "playground-loggedin" , "true" ) ;
44+ try {
45+ localStorage . setItem ( "playground-loggedin" , "true" ) ;
46+ } catch {
47+ // ignore
48+ }
4549 } ,
4650 async doLogout ( ) {
4751 localStorage . removeItem ( "playground-loggedin" ) ;
@@ -59,7 +63,11 @@ export function RightSection(props: {
5963 } ;
6064 } ,
6165 async isLoggedIn ( ) {
62- return ! ! localStorage . getItem ( "playground-loggedin" ) ;
66+ try {
67+ return ! ! localStorage . getItem ( "playground-loggedin" ) ;
68+ } catch {
69+ return false ;
70+ }
6371 } ,
6472 } ;
6573
Original file line number Diff line number Diff line change @@ -10,8 +10,12 @@ export function Banner(props: { text: string; href: string; id: string }) {
1010 const bannerCancelledKey = `banner-cancelled${ props . href } ` ;
1111
1212 useEffect ( ( ) => {
13- if ( localStorage . getItem ( bannerCancelledKey ) !== "true" ) {
14- setShowBanner ( true ) ;
13+ try {
14+ if ( localStorage . getItem ( bannerCancelledKey ) !== "true" ) {
15+ setShowBanner ( true ) ;
16+ }
17+ } catch {
18+ // ignore
1519 }
1620 } , [ bannerCancelledKey ] ) ;
1721
@@ -41,7 +45,11 @@ export function Banner(props: { text: string; href: string; id: string }) {
4145 className = "absolute right-4 shrink-0 bg-none bg-transparent p-1"
4246 onClick = { ( ) => {
4347 setShowBanner ( false ) ;
44- localStorage . setItem ( bannerCancelledKey , "true" ) ;
48+ try {
49+ localStorage . setItem ( bannerCancelledKey , "true" ) ;
50+ } catch {
51+ // ignore
52+ }
4553 } }
4654 >
4755 < XIcon
Original file line number Diff line number Diff line change @@ -26,7 +26,11 @@ export function ThemeSwitcher(props: { className?: string }) {
2626 const newTheme = theme === "light" ? "dark" : "light" ;
2727 setTheme ( newTheme ) ;
2828 document . body . dataset . theme = newTheme ;
29- localStorage . setItem ( "website-theme" , newTheme ) ;
29+ try {
30+ localStorage . setItem ( "website-theme" , newTheme ) ;
31+ } catch {
32+ // ignore
33+ }
3034 } }
3135 variant = "outline"
3236 className = { cn ( "p-2" , props . className ) }
Original file line number Diff line number Diff line change @@ -2,14 +2,23 @@ import type { AsyncStorage } from "./AsyncStorage.js";
22
33export const webLocalStorage : AsyncStorage = {
44 async getItem ( key : string ) {
5- if ( typeof window !== "undefined" && window . localStorage ) {
6- return localStorage . getItem ( key ) ;
5+ try {
6+ if ( typeof window !== "undefined" && window . localStorage ) {
7+ return localStorage . getItem ( key ) ;
8+ }
9+ } catch {
10+ // ignore
711 }
12+
813 return null ;
914 } ,
1015 async setItem ( key : string , value : string ) {
11- if ( typeof window !== "undefined" && window . localStorage ) {
12- localStorage . setItem ( key , value ) ;
16+ try {
17+ if ( typeof window !== "undefined" && window . localStorage ) {
18+ localStorage . setItem ( key , value ) ;
19+ }
20+ } catch {
21+ // ignore
1322 }
1423 } ,
1524 async removeItem ( key : string ) {
You can’t perform that action at this time.
0 commit comments