react-doctor/js-cache-storage
Cache repeated `localStorage`/`sessionStorage` reads in a local variable — each access serializes/deserializes
- Category: Performance
- Severity: warn
- Source:
oxlint-plugin-react-doctor - Framework: global
- Enabled when: always
Validation prompt
Use this to decide whether a fired diagnostic is real or a false positive.
The rule fires when localStorage.getItem or sessionStorage.getItem is called 2 or more times with the same string-literal key anywhere in the file. False positive when calls live in mutually exclusive code paths that don't both run in one pass, or you intentionally re-read because another tab / extension may have mutated the storage between reads.
Fix prompt
Use this once validation confirms the diagnostic is real.
Read once into a local const and reuse the variable. Each getItem is a synchronous main-thread call that may block on disk I/O and JSON parsing. If you need cross-tab freshness, register window.addEventListener('storage', ...) once and update the cached value only when the storage event fires. https://developer.mozilla.org/en-US/docs/Web/API/Window/storage_event
Related rules
More Performance rules from the rules reference:
react-doctor/js-combine-iterations: Combine `.map().filter()` (or similar chains) into a single pass with `.reduce()` or a `for...of` loop to avoid iterating the array twicereact-doctor/js-early-exit: Add an early `return` / `continue` to flatten deep nesting and short-circuit when the predicate is already knownreact-doctor/js-flatmap-filter: Use `.flatMap(item => condition ? [value] : [])` — transforms and filters in a single pass instead of creating an intermediate arrayreact-doctor/js-hoist-intl: Hoist `new Intl.NumberFormat(...)` to module scope or wrap in `useMemo` — Intl constructors allocate dozens of objects per locale lookupreact-doctor/js-hoist-regexp: Hoist `new RegExp(...)` (or large regex literals) to a module-level constant so it isn't recompiled on every loop iteration