mirror of
https://github.com/utopia-os/utopia-ui.git
synced 2025-12-13 07:46:10 +00:00
- Fix prettier formatting for localStorage utility - Add pre-PR lint check script to prevent CI failures - Create Claude Code hook configuration for automatic linting
36 lines
976 B
TypeScript
36 lines
976 B
TypeScript
/* eslint-disable no-catch-all/no-catch-all */
|
|
/* eslint-disable no-console */
|
|
|
|
/**
|
|
* Safe localStorage utility that handles SecurityError gracefully
|
|
* when localStorage is not available (e.g., private browsing mode)
|
|
*/
|
|
export const safeLocalStorage = {
|
|
getItem: (key: string): string | null => {
|
|
try {
|
|
return localStorage.getItem(key)
|
|
} catch (error) {
|
|
console.warn(`localStorage.getItem failed for key "${key}":`, error)
|
|
return null
|
|
}
|
|
},
|
|
|
|
setItem: (key: string, value: string): void => {
|
|
try {
|
|
localStorage.setItem(key, value)
|
|
} catch (error) {
|
|
console.warn(`localStorage.setItem failed for key "${key}":`, error)
|
|
// Silently fail - functionality will work in memory-only mode
|
|
}
|
|
},
|
|
|
|
removeItem: (key: string): void => {
|
|
try {
|
|
localStorage.removeItem(key)
|
|
} catch (error) {
|
|
console.warn(`localStorage.removeItem failed for key "${key}":`, error)
|
|
// Silently fail
|
|
}
|
|
},
|
|
}
|