Skip to content

Conversation

@antontranelis
Copy link
Member

@antontranelis antontranelis commented Aug 4, 2025

Summary

  • Fixed endless loading screen when localStorage/cookies are unavailable
  • Added comprehensive localStorage error handling across the entire codebase
  • Implemented graceful fallback to memory-only authentication storage
  • Created reusable safeLocalStorage utility for consistent error handling

Changes Made

  • ✅ Added try-catch blocks around localStorage access in authLocalStorage
  • ✅ Modified getToken() to return null instead of throwing errors
  • ✅ Updated auth context to handle missing tokens gracefully
  • NEW: Created safeLocalStorage utility for consistent error handling
  • NEW: Fixed localStorage errors in useTheme hook
  • NEW: Fixed localStorage errors in ThemeControl component
  • ✅ Added proper error logging with console.warn
  • ✅ Fixed ESLint issues (nullish coalescing, catch-all rules)

Test Plan

  • Code passes ESLint with zero warnings
  • Authentication flow gracefully handles localStorage unavailability
  • Theme functionality works without localStorage access
  • App initializes properly even when localStorage throws SecurityError
  • Library builds successfully with new utility
  • Manual testing in private browsing mode
  • Manual testing with strict privacy settings

Technical Details

The issue occurred because localStorage.getItem() throws a SecurityError in certain browser environments (private browsing, strict privacy settings, iframes with cross-origin restrictions). This affected multiple parts of the application:

  1. Authentication system: Caused endless loading when trying to retrieve auth tokens
  2. Theme system: Could break theme persistence and selection

The fix implements a comprehensive solution:

  • Centralized error handling via safeLocalStorage utility
  • Graceful degradation to memory-only mode when persistent storage is unavailable
  • Consistent error logging for debugging purposes
  • No functionality loss - all features work without localStorage

This ensures the app functions correctly across all browser environments and privacy settings.

Fixes #212

🤖 Generated with Claude Code

- Add try-catch blocks around localStorage access in authLocalStorage
- Return null instead of throwing when localStorage is unavailable
- Prevent endless loading screen in private browsing/strict privacy modes
- Add proper error logging with console.warn
- Fix nullish coalescing operator usage

Fixes #212

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@antontranelis antontranelis changed the title fix: handle localStorage SecurityError gracefully fix(app): handle localStorage SecurityError gracefully Aug 4, 2025
antontranelis and others added 6 commits August 5, 2025 09:19
- Create safeLocalStorage utility for graceful error handling
- Update useTheme hook to use safeLocalStorage
- Update ThemeControl component to use safeLocalStorage
- Prevents SecurityError when localStorage is unavailable in theme features

This extends the localStorage fix from issue #212 to cover all localStorage usage in the codebase.
- Fix prettier formatting for localStorage utility
- Add pre-PR lint check script to prevent CI failures
- Create Claude Code hook configuration for automatic linting
- Remove check-lint.sh script (belongs in claude branch)
- Remove CLAUDE.md and other infrastructure files
- Keep feature branch focused on localStorage fixes only
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 [Bug] When cookies cannot be set we end up with endless loading screen

2 participants