{"record":{"id":"4524fef3b8240fe5","repo":"mantinedev/mantine","slug":"use-local-storage-failed-to-remove-value-from-sto","errorCode":null,"errorMessage":"use-local-storage: Failed to remove value from storage, localStorage is blocked","messagePattern":"use-local-storage: Failed to remove 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":65,"sourceCode":"    } 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'\n      );\n    }\n  };\n\n  return { getItem, setItem, removeItem };\n}\n\nexport type UseStorageReturnValue<T> = [\n  T, // current value\n  (val: T | ((prevState: T) => T)) => void, // callback to set value in storage\n  () => void, // callback to remove value from storage\n];\n\nexport function createStorage<T>(type: StorageType, hookName: string) {\n  const eventName = type === 'localStorage' ? 'mantine-local-storage' : 'mantine-session-storage';\n  const { getItem, setItem, removeItem } = createStorageHandler(type);\n","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/mantinedev/mantine/blob/8a284e2c2c53a9cb6f39f5dc389bf41b7a2073f8/packages/@mantine/hooks/src/use-local-storage/create-storage.ts#L47-L83","documentation":"A console.warn (not a thrown error) emitted by use-local-storage's removeItem path when window.localStorage.removeItem throws. Removal of the persisted key fails, typically because storage access is blocked entirely. The in-memory state still updates, so the app continues to work.","triggerScenarios":"Calling the setter with a function returning undefined (useLocalStorage's convention for removing the key), or window.dispatchEvent(new Event('storage')) paths, ends in removeItem which throws when localStorage is blocked. Also triggered on unmount cleanup or clear-value flows in privacy-restricted browsers or SSR.","commonSituations":"Same class of issues as getItem/setItem warnings: blocked third-party storage in iframes, Safari private mode, 'block all cookies' settings, privacy extensions, SSR or JSDOM tests where localStorage throws. Surfaces when users clear/reset a stored value.","solutions":["Recognize it as a companion warning to the getItem/setItem ones — fix the storage access issue and all three disappear","Verify your test environment's localStorage mock implements removeItem if you see this in Jest/Vitest","For embedded apps, use Storage Access API or accept non-persistent fallback","Ignore in production if persistence is optional for your feature"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"function isStorageRemovable(): boolean {\n  try {\n    const k = '__r__';\n    window.localStorage.setItem(k, '1');\n    window.localStorage.removeItem(k);\n    return true;\n  } catch {\n    return false;\n  }\n}","typeGuard":null,"tryCatchPattern":"// Library handles the catch; if removing stale keys yourself:\ntry {\n  localStorage.removeItem(key);\n} catch {\n  // storage blocked — nothing to clean up","preventionTips":["Ensure test localStorage mocks implement removeItem, not just getItem/setItem","Use the setter-to-undefined removal convention only when persistence actually works","Accept that in blocked-storage contexts removal is a no-op","Address the root cause (blocked storage) rather than each warning individually"],"tags":["local-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"}