File tree Expand file tree Collapse file tree 2 files changed +20
-6
lines changed Expand file tree Collapse file tree 2 files changed +20
-6
lines changed Original file line number Diff line number Diff line change @@ -129,11 +129,25 @@ export class BrowserClient extends BaseClient<BrowserClientOptions> {
129
129
}
130
130
131
131
return {
132
- get ( key : string ) {
133
- return localStorage . getItem ( getKey ( key ) ) ;
132
+ get ( key : string ) : unknown {
133
+ const value = WINDOW . localStorage . getItem ( getKey ( key ) ) ;
134
+
135
+ if ( value === null ) {
136
+ return value ;
137
+ }
138
+
139
+ try {
140
+ return JSON . parse ( value ) ;
141
+ } catch {
142
+ return null ;
143
+ }
134
144
} ,
135
- set ( key : string , value : string ) {
136
- return localStorage . setItem ( getKey ( key ) , value ) ;
145
+ set ( key : string , value : any ) : void {
146
+ try {
147
+ WINDOW . localStorage . setItem ( getKey ( key ) , JSON . stringify ( value ) ) ;
148
+ } catch {
149
+ DEBUG_BUILD && logger . error ( 'Unable to serialize configuration and save to localStorage' ) ;
150
+ }
137
151
} ,
138
152
} ;
139
153
}
Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ export function remoteConfig({
30
30
// Use cached configuration if it exists
31
31
const cachedValue = storage . get ( defaultConfigName ) ;
32
32
if ( cachedValue ) {
33
- _activeConfig = JSON . parse ( cachedValue ) ;
33
+ _activeConfig = cachedValue ;
34
34
_source = 'CACHED' ;
35
35
_state = 'INITIALIZED' ;
36
36
}
@@ -67,7 +67,7 @@ export function remoteConfig({
67
67
_pendingConfig = data ;
68
68
_hasUpdate = true ;
69
69
70
- storage . set ( defaultConfigName , JSON . stringify ( data ) ) ;
70
+ storage . set ( defaultConfigName , data ) ;
71
71
storage . set ( `${ defaultConfigName } _lastFetch` , + _lastFetch ) ;
72
72
// _state = "SUCCESS";
73
73
resolve ( ) ;
You can’t perform that action at this time.
0 commit comments