From 72131b345c7daa3d7dc691d4eb63b25915134238 Mon Sep 17 00:00:00 2001 From: Joe Attardi Date: Sat, 4 Mar 2023 16:54:00 -0500 Subject: [PATCH] Check for window object before assigning property --- packages/picmo/src/data/emojiData.ts | 2 +- packages/picmo/src/options.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/picmo/src/data/emojiData.ts b/packages/picmo/src/data/emojiData.ts index 9ff59e9e..c47e6bbc 100644 --- a/packages/picmo/src/data/emojiData.ts +++ b/packages/picmo/src/data/emojiData.ts @@ -5,7 +5,7 @@ import { computeHash, isSessionStorageAvailable } from '../util'; import { createStorage } from '../webStorageShim'; import { InMemoryStoreFactory } from './InMemoryStore'; -if (!isSessionStorageAvailable()) { +if (!isSessionStorageAvailable() && typeof window !== 'undefined') { // emojibase relies on session storage being available for caching data. // No way to disable this so we'll make a fake implementation. Caching won't work as expected // but at least the picker will run. diff --git a/packages/picmo/src/options.ts b/packages/picmo/src/options.ts index 4bf86d17..9d68ca56 100644 --- a/packages/picmo/src/options.ts +++ b/packages/picmo/src/options.ts @@ -31,7 +31,7 @@ const defaultOptions: Partial = { custom: [] }; -if (!isLocalStorageAvailable()) { +if (!isLocalStorageAvailable() && typeof window !== 'undefined') { console.warn('[picmo] localStorage not available, falling back to simple in-memory storage'); Object.defineProperty(window, 'localStorage', { value: createStorage()