Skip to content

refactor(hooks): dedupe useCookieConsent storage - #504

Open
chiptus wants to merge 2 commits into
mainfrom
claude/focused-hopper-ajtlht
Open

chiptus wants to merge 2 commits into
mainfrom
claude/focused-hopper-ajtlht

Conversation

@chiptus

@chiptus chiptus commented Sep 17, 2026

Copy link
Copy Markdown
Owner

Migrates useCookieConsent off its hand-rolled JSON-parse/version-check onto the shared useLocalStorageState hook (UPL-48), adding an optional storage-adapter parameter so it can keep reading/writing through CrossDomainStorage instead of localStorage directly. consent stays ConsentPreferences | null; a stale-version or malformed stored record still falls back to "no consent" (banner shown), matching prior behavior.

Verification

  • pnpm testuseCookieConsent.test.ts (16 tests, unmodified) and useLocalStorageState.test.ts (7 tests, +1 new for the storage adapter) all pass.
  • pnpm run typecheck, pnpm run lint, pnpm run build all pass.
  • Open the app without a saved consent cookie: banner appears; accept/customize/reject still persist via CrossDomainStorage as before.
  • Manually revoke consent (or clear the gdpr-consent cookie/localStorage key): banner reappears, consent resolves to null.

Co-Authored-By: Claude Sonnet 5 noreply@anthropic.com

🤖 Generated with Claude Code

https://claude.ai/code/session_017T38pa7BfP2YJZMsw5qWgr


Generated by Claude Code

Drops useCookieConsent's hand-rolled parse/version-check boilerplate in
favor of the shared Zod-validated useLocalStorageState hook (UPL-48),
matching the useLinkWizardSkipped migration in ADR-0007. Adds an
optional storage-adapter parameter to useLocalStorageState so
useCookieConsent can keep reading/writing through CrossDomainStorage
instead of localStorage directly.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017T38pa7BfP2YJZMsw5qWgr
setStoredConsent(null) writes the literal string "null" back to
storage; calling CrossDomainStorage.removeItem before that silently
undid the removal. Self-review catch, no behavior change to consent
state (still resolves to null either way).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017T38pa7BfP2YJZMsw5qWgr
Copilot AI lite review requested due to automatic review settings September 17, 2026 05:15
@vercel

vercel Bot commented Sep 17, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
upline Ready Ready Preview Sep 17, 2026 5:16am UTC

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The new storage-adapter path calls getItem/setItem without guarding against adapter/storage runtime errors, which can crash render or event handlers when adapters (or storage availability) throw.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

This PR refactors useCookieConsent to use the shared useLocalStorageState hook for persisted consent state, and extends useLocalStorageState to support pluggable storage backends (so consent can continue to be stored via CrossDomainStorage).

Changes:

  • Add an optional StorageLike adapter parameter to useLocalStorageState and route reads/writes through it.
  • Migrate useCookieConsent persistence/validation to useLocalStorageState + Zod schema, keeping the “stale/malformed => no consent” behavior.
  • Add a unit test covering the custom storage adapter behavior.
File summaries
File Description
src/hooks/useLocalStorageState.ts Adds a StorageLike adapter parameter and uses it for getItem/setItem.
src/hooks/useLocalStorageState.test.ts Adds coverage to ensure a custom adapter is used instead of localStorage.
src/hooks/useCookieConsent.ts Switches consent storage/rehydration to useLocalStorageState with CrossDomainStorage.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines 19 to 21
function readValue(): Value {
const raw = localStorage.getItem(key);
const raw = storage.getItem(key);
if (raw) {
@github-actions

Copy link
Copy Markdown

Playwright test results

passed  65 passed

Details

stats  65 tests across 21 suites
duration  1 minute, 17 seconds
commit  5a058da

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.

3 participants