@@ -65,6 +65,7 @@ export const Platform = {
65
65
66
66
type PlatformType = typeof Platform ;
67
67
export type Platform = ( typeof Platform ) [ keyof typeof Platform ] ;
68
+ export const VALID_PLATFORMS = new Set ( Object . values ( Platform ) ) ;
68
69
69
70
export const Framework = {
70
71
NextJs : 'Next.js' ,
@@ -154,16 +155,27 @@ export const preferredVersion = writable<Version | null>(
154
155
globalThis ?. localStorage ?. getItem ( 'preferredVersion' ) as Version
155
156
) ;
156
157
157
- export const preferredPlatform = writable < Platform > (
158
- ( globalThis ?. localStorage ?. getItem ( 'preferredPlatform' ) ?? 'client-web' ) as Platform
159
- ) ;
158
+ function getInitialPlatform ( ) : Platform {
159
+ const stored = globalThis ?. localStorage ?. getItem ( 'preferredPlatform' ) ?? Platform . ClientWeb ;
160
+ // return if this platform is valid
161
+ if ( VALID_PLATFORMS . has ( stored as Platform ) ) {
162
+ return stored as Platform ;
163
+ } else {
164
+ return Platform . ClientWeb ;
165
+ }
166
+ }
167
+
168
+ export const preferredPlatform = writable < Platform > ( getInitialPlatform ( ) ) ;
160
169
161
170
if ( browser ) {
162
171
preferredVersion . subscribe ( ( value ) => {
163
172
if ( value ) globalThis ?. localStorage ?. setItem ( 'preferredVersion' , value ) ;
164
173
} ) ;
165
174
166
175
preferredPlatform . subscribe ( ( value ) => {
167
- if ( value ) globalThis ?. localStorage ?. setItem ( 'preferredPlatform' , value ) ;
176
+ // only save the ones for which we have api references.
177
+ if ( value && VALID_PLATFORMS . has ( value ) ) {
178
+ globalThis ?. localStorage ?. setItem ( 'preferredPlatform' , value ) ;
179
+ }
168
180
} ) ;
169
181
}
0 commit comments