Chakra UI v2: Unresolved fallback strategy when localStorage and sessionStorage are blocked
24.5K reputation · 06 Apr 2021, 08:12 UTC
Goal
We want to understand how Chakra UI’s color‑mode hook behaves when both primary and secondary storage mechanisms are unavailable, such as in strict privacy or incognito modes.
Constraints
The library uses localStorage by default, with an optional sessionStorage fallback introduced in v2. Neither storage is guaranteed to be accessible. The documentation does not specify what happens when both are blocked.
Unresolved Decision
Should the hook revert to the system preference, silently fallback to a default mode, or throw an error? The current implementation appears to default to the system preference but this is not explicitly documented.
Questions
- What is the exact fallback logic executed by useColorMode when both localStorage and sessionStorage are inaccessible?
- Does Chakra UI provide a configurable option to override this default fallback behavior?
- What are the implications for user experience if the fallback defaults to system preference on every reload?