Skip to content

refactor: prevent TTL extension on mount, add SSR guardrail, fix null/undefined round-trip#22

Merged
woozyking merged 1 commit into
mainfrom
ssr-safety
May 15, 2026
Merged

refactor: prevent TTL extension on mount, add SSR guardrail, fix null/undefined round-trip#22
woozyking merged 1 commit into
mainfrom
ssr-safety

Conversation

@woozyking

Copy link
Copy Markdown
Owner
  • Skip the initial post-hydration write via a firstRun ref; previously every mount re-serialized the hydrated value and reset expiry, silently extending TTL indefinitely for any component that remounted before expiration
  • Guard all storage access behind an SSR-safe isBrowser check
  • Wrap cached payloads in { value } so null/undefined survive round-trip (previously indistinguishable from a cache miss)
  • Move TTL unit + argument validation out of the write path; compute once at configuration time and tighten type checks (reject NaN, Infinity, non-numbers)
  • Replace SUPPORTED_HOOKS array with a Set for O(1) lookup and clearer intent
  • Gate console.warn behind NODE_ENV !== "production" to silence prod noise
  • Extract dropCache helper and reuse it from the memoized remove()

…/undefined round-trip

- Skip the initial post-hydration write via a `firstRun` ref; previously every
  mount re-serialized the hydrated value and reset `expiry`, silently extending
  TTL indefinitely for any component that remounted before expiration
- Guard all storage access behind an SSR-safe `isBrowser` check
- Wrap cached payloads in `{ value }` so `null`/`undefined` survive round-trip
  (previously indistinguishable from a cache miss)
- Move TTL unit + argument validation out of the write path; compute once at
  configuration time and tighten type checks (reject NaN, Infinity, non-numbers)
- Replace `SUPPORTED_HOOKS` array with a `Set` for O(1) lookup and clearer intent
- Gate `console.warn` behind `NODE_ENV !== "production"` to silence prod noise
- Extract `dropCache` helper and reuse it from the memoized `remove()`
@woozyking woozyking merged commit 21eb9b1 into main May 15, 2026
5 checks passed
@woozyking woozyking deleted the ssr-safety branch May 15, 2026 01:58
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.

1 participant