{"record":{"id":"09a32d0269314160","repo":"mantinedev/mantine","slug":"use-local-storage-failed-to-get-value-from-storag","errorCode":null,"errorMessage":"use-local-storage: Failed to get value from storage, localStorage is blocked","messagePattern":"use-local-storage: Failed to get value from storage, localStorage is blocked","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/@mantine/hooks/src/use-local-storage/create-storage.ts","lineNumber":48,"sourceCode":"  } catch (error) {\n    throw new Error(`@mantine/hooks ${hookName}: Failed to serialize the value`);\n  }\n}\n\nfunction deserializeJSON(value: string | undefined) {\n  try {\n    return value && JSON.parse(value);\n  } catch {\n    return value;\n  }\n}\n\nfunction createStorageHandler(type: StorageType) {\n  const getItem = (key: string) => {\n    try {\n      return window[type].getItem(key);\n    } catch (error) {\n      console.warn('use-local-storage: Failed to get value from storage, localStorage is blocked');\n      return null;\n    }\n  };\n\n  const setItem = (key: string, value: string) => {\n    try {\n      window[type].setItem(key, value);\n    } catch (error) {\n      console.warn('use-local-storage: Failed to set value to storage, localStorage is blocked');\n    }\n  };\n\n  const removeItem = (key: string) => {\n    try {\n      window[type].removeItem(key);\n    } catch (error) {\n      console.warn(\n        'use-local-storage: Failed to remove value from storage, localStorage is blocked'","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/mantinedev/mantine/blob/8a284e2c2c53a9cb6f39f5dc389bf41b7a2073f8/packages/@mantine/hooks/src/use-local-storage/create-storage.ts#L30-L66","documentation":"This is a console.warn (not a thrown error) emitted by use-local-storage (and use-local-storage-shared) when reading from window.localStorage throws. It means browser storage access is blocked, so the hook cannot retrieve the persisted value and returns null. The hook degrades gracefully and keeps working with in-memory state only.","triggerScenarios":"window.localStorage.getItem(key) throws — typically when cookies/site data are blocked (Chrome 'Block third-party cookies' + iframe/embed contexts), Safari ITP private mode, browser privacy settings, or SSR environments where localStorage is unavailable. Emitted on mount and on any read triggered by the 'storage' event handler.","commonSituations":"App embedded in an iframe (widgets, embedded dashboards) with third-party cookies blocked; Safari private browsing; users with strict privacy extensions or 'block all cookies' enabled; corporate browser policies; headless test environments mocking window without localStorage.","solutions":["Verify it is only a warning: the hook still works, values just won't persist — often safe to ignore in production","Reproduce the user's browser state: enable 'Block third-party cookies' in Chrome or use Safari private mode to confirm storage is blocked","If in an iframe, request storage access via Storage Access API (document.requestStorageAccess()) or serve the embed first-party","Provide a fallback storage (e.g. cookie-based or in-memory manager) when localStorage access throws"],"exampleFix":"// Detect blocked storage before relying on persistence\nfunction storageAvailable() {\n  try {\n    const k = '__t';\n    window.localStorage.setItem(k, '1');\n    window.localStorage.removeItem(k);\n    return true;\n  } catch {\n    return false;\n  }\n}\nconst value = useLocalStorage({ key: 'k', defaultValue: '' }); // still safe if blocked","handlingStrategy":"fallback","validationCode":"function isLocalStorageReadable(): boolean {\n  try {\n    const k = '__probe__';\n    window.localStorage.setItem(k, '1');\n    window.localStorage.removeItem(k);\n    return true;\n  } catch {\n    return false;\n  }\n}","typeGuard":"const isLocalStorageAvailable = (): boolean => {\n  try {\n    return typeof window !== 'undefined' && window.localStorage !== null;\n  } catch {\n    return false;\n  }\n};","tryCatchPattern":"// Library already catches internally; only warn suppression is relevant.\n// To silence in tests:\nconst warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});","preventionTips":["Treat use-local-storage as best-effort persistence; design features to work without stored values","Mock localStorage fully (getItem/setItem/removeItem) in Jest/Vitest setups","For iframes, request storage access before loading the app","Watch for these warnings in QA on Safari private mode and cookie-blocked Chrome"],"tags":["local-storage","browser-storage","privacy","use-local-storage","warning"],"backgroundTag":"local-storage-blocked","analyzedSha":"8a284e2c2c53a9cb6f39f5dc389bf41b7a2073f8","analyzedAt":"2026-08-28T10:25:51.087Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}