The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
prevent SecurityError crash when localStorage access is blocked
Pedro Ladeirae3b6e88e8f86
diff --git a/packages/ui/src/hooks/use-local-storage.ts b/packages/ui/src/hooks/use-local-storage.tsindex 0afda7c4d8..8fb4d59cc4 100644--- a/packages/ui/src/hooks/use-local-storage.ts+++ b/packages/ui/src/hooks/use-local-storage.ts@@ -3,8 +3,12 @@ import { useEffect, useState } from "react";function getItemFromLocalStorage(key: string) {if (typeof window === "undefined") return null;- const item = window.localStorage.getItem(key);- if (item) return JSON.parse(item);+ try {+ const item = window.localStorage.getItem(key);+ if (item) return JSON.parse(item);+ } catch {+ return null;+ }return null;}@@ -25,8 +29,11 @@ export function useLocalStorage<T>(const setValue = (value: T) => {setStoredValue(value);- if (typeof window !== "undefined") {+ if (typeof window === "undefined") return;+ try {window.localStorage.setItem(key, JSON.stringify(value));+ } catch {+ // Ignore write failures (storage blocked or quota exceeded).}};