From e5be8f2e4902b37ad3554690a08581c23cc5547a Mon Sep 17 00:00:00 2001 From: yongwee Date: Sat, 21 Oct 2023 12:11:50 +0800 Subject: [PATCH] [@mantine/hooks]: Fix storage access error in create-storage --- .../src/use-local-storage/create-storage.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/mantine-hooks/src/use-local-storage/create-storage.ts b/src/mantine-hooks/src/use-local-storage/create-storage.ts index 69f05e15477..45ed0b5b77f 100644 --- a/src/mantine-hooks/src/use-local-storage/create-storage.ts +++ b/src/mantine-hooks/src/use-local-storage/create-storage.ts @@ -81,12 +81,19 @@ export function createStorage(type: StorageType, hookName: string) { }: StorageProperties) { const readStorageValue = useCallback( (skipStorage?: boolean): T => { - if ( - typeof window === 'undefined' || - !(type in window) || - window[type] === null || - skipStorage - ) { + let storageBlockedOrSkipped; + + try { + storageBlockedOrSkipped = + typeof window === 'undefined' || + !(type in window) || + window[type] === null || + !!skipStorage; + } catch (_e) { + storageBlockedOrSkipped = true; + } + + if (storageBlockedOrSkipped) { return defaultValue as T; }