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

  1. Recognize it as a companion warning to the getItem/setItem ones — fix the storage access issue and all three disappear
  2. Verify your test environment's localStorage mock implements removeItem if you see this in Jest/Vitest
  3. For embedded apps, use Storage Access API or accept non-persistent fallback
  4. 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

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


AI-assisted analysis of mantinedev/mantine@8a284e2c2c (2026-08-28). Data as JSON: /api/errors/4524fef3b8240fe5. Report an issue: GitHub.