Skip to content

Conversation

@nieblara
Copy link
Contributor

@nieblara nieblara commented Dec 18, 2025

Description

What does this PR do?

Introduces a useLocalStorage hook to provide a useState-like API for persistent localStorage storage, replacing manual localStorage read/write patterns across multiple providers.

Changes:

  • New useLocalStorage hook with:

    • Type-safe generics
    • SSR safety (typeof window checks)
    • Optional cross-tab synchronization via StorageEvent
    • Custom serializers/deserializers for non-JSON values
    • Smart persistence (doesn't write defaults until explicitly set)
    • Returns [value, setValue, remove] tuple
  • Refactored providers to use the hook:

    • useToolbarVisibility - Reduced from 77 lines to ~30 lines, removed duplicate cross-tab sync logic
    • StarredFlagsProvider - Now uses hook instead of loadStarredFlags/saveStarredFlags
  • Cleanup:

    • Used refs for serializers to prevent unnecessary effect re-runs when inline functions are passed

Backward Compatibility

Data formats in localStorage are identical to the previous implementation:

Key Format
ld-toolbar-starred-flags JSON array ["flag1", "flag2"]
ld-toolbar-environment Raw string staging
ld-toolbar-project Raw string my-project
ld-toolbar-disabled String "true" or item removed

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📚 Documentation (changes to documentation only)
  • 🔧 Refactor (code change that neither fixes a bug nor adds a feature)
  • 🎨 Style (formatting, missing semicolons, etc; no production code change)
  • Performance (code change that improves performance)
  • Test (adding missing tests, refactoring tests; no production code change)
  • 🔨 Chore (updating grunt tasks, build process, etc; no production code change)

@nieblara nieblara requested review from a team and pranjal-jately-ld as code owners December 18, 2025 08:44
@nieblara nieblara requested a review from cspath1 December 18, 2025 08:45
Copy link
Contributor

@cspath1 cspath1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for helping clean this up!

@nieblara nieblara merged commit 738357a into main Jan 6, 2026
4 checks passed
@nieblara nieblara deleted the add-localstorage-hook-1 branch January 6, 2026 11:26
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.

4 participants