diff --git a/.changeset/small-shoes-live.md b/.changeset/small-shoes-live.md new file mode 100644 index 00000000..175bfe3d --- /dev/null +++ b/.changeset/small-shoes-live.md @@ -0,0 +1,7 @@ +--- +"@quiltt/core": patch +"@quiltt/react": patch +"@quiltt/react-test-nextjs": patch +--- + +Skip browser code when in expo app diff --git a/ECMAScript/core/src/Storage/Local.ts b/ECMAScript/core/src/Storage/Local.ts index 617cb35f..dc83f86c 100644 --- a/ECMAScript/core/src/Storage/Local.ts +++ b/ECMAScript/core/src/Storage/Local.ts @@ -11,7 +11,7 @@ export class LocalStorage { private observers: { [key: string]: Observer[] } = {} constructor() { - if (typeof window !== 'undefined') { + if (typeof window !== 'undefined' && !window?.expo) { window.addEventListener('storage', this.handleStorageEvent.bind(this)) } } @@ -29,7 +29,7 @@ export class LocalStorage { isDisabled = (): boolean => !this.isEnabled() get = (key: string): Maybe | undefined => { - if (typeof window === 'undefined') return undefined + if (typeof window === 'undefined' || !!window.expo) return undefined try { const state = window.localStorage.getItem(`quiltt.${key}`) @@ -41,7 +41,7 @@ export class LocalStorage { } set = (key: string, state: Maybe | undefined): void => { - if (typeof window === 'undefined') return + if (typeof window === 'undefined' || !!window.expo) return try { if (state) { diff --git a/ECMAScript/core/src/types.ts b/ECMAScript/core/src/types.ts index c36bed05..6d16121f 100644 --- a/ECMAScript/core/src/types.ts +++ b/ECMAScript/core/src/types.ts @@ -8,3 +8,8 @@ export type Nullable = { [K in keyof T]: T[K] | null } export type Mutable = { -readonly [Key in keyof Type]: Type[Key] } export type DeepPartial = T extends object ? { [P in keyof T]?: DeepPartial } : T export type DeepReadonly = T extends object ? { [P in keyof T]: DeepReadonly } : T +declare global { + interface Window { + expo: any + } +}