Skip to content

Commit 87a946c

Browse files
authored
Merge pull request #2105 from appwrite/fix-language-persistency
Fix: only save and retrieve valid platforms
2 parents 1c287a8 + cd2c724 commit 87a946c

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/lib/utils/references.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export const Platform = {
6565

6666
type PlatformType = typeof Platform;
6767
export type Platform = (typeof Platform)[keyof typeof Platform];
68+
export const VALID_PLATFORMS = new Set(Object.values(Platform));
6869

6970
export const Framework = {
7071
NextJs: 'Next.js',
@@ -154,16 +155,27 @@ export const preferredVersion = writable<Version | null>(
154155
globalThis?.localStorage?.getItem('preferredVersion') as Version
155156
);
156157

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());
160169

161170
if (browser) {
162171
preferredVersion.subscribe((value) => {
163172
if (value) globalThis?.localStorage?.setItem('preferredVersion', value);
164173
});
165174

166175
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+
}
168180
});
169181
}

0 commit comments

Comments
 (0)