mantinedev/mantine · warning
use-local-storage: Failed to remove value from storage, loca
Error message
use-local-storage: Failed to remove value from storage, localStorage is blocked
What it means
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.
Source
Thrown at packages/@mantine/hooks/src/use-local-storage/create-storage.ts:65
} catch (error) {
console.warn('use-local-storage: Failed to get value from storage, localStorage is blocked');
return null;
}
};
const setItem = (key: string, value: string) => {
try {
window[type].setItem(key, value);
} catch (error) {
console.warn('use-local-storage: Failed to set value to storage, localStorage is blocked');
}
};
const removeItem = (key: string) => {
try {
window[type].removeItem(key);
} catch (error) {
console.warn(
'use-local-storage: Failed to remove value from storage, localStorage is blocked'
);
}
};
return { getItem, setItem, removeItem };
}
export type UseStorageReturnValue<T> = [
T, // current value
(val: T | ((prevState: T) => T)) => void, // callback to set value in storage
() => void, // callback to remove value from storage
];
export function createStorage<T>(type: StorageType, hookName: string) {
const eventName = type === 'localStorage' ? 'mantine-local-storage' : 'mantine-session-storage';
const { getItem, setItem, removeItem } = createStorageHandler(type);
View on GitHub (pinned to 8a284e2c2c)
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
Defensive patterns
Strategy: fallback
Validate before calling
function isStorageRemovable(): boolean {
try {
const k = '__r__';
window.localStorage.setItem(k, '1');
window.localStorage.removeItem(k);
return true;
} catch {
return false;
}
} Try / catch
// Library handles the catch; if removing stale keys yourself:
try {
localStorage.removeItem(key);
} catch {
// storage blocked — nothing to clean up Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- use-local-storage: Failed to get value from storage, localSt
- use-local-storage: Failed to set value to storage, localStor
- @mantine/hooks ${hookName}: Failed to serialize the value
- [@mantine/core] Local storage color scheme manager was unabl
- [@mantine/code-highlight] Language `${language}` ${reason},
AI-assisted analysis of mantinedev/mantine@8a284e2c2c (2026-08-28).
Data as JSON: /api/errors/4524fef3b8240fe5.
Report an issue: GitHub.