Conversation
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
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
🟡 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
StorageLikeadapter parameter touseLocalStorageStateand route reads/writes through it. - Migrate
useCookieConsentpersistence/validation touseLocalStorageState+ 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.
| function readValue(): Value { | ||
| const raw = localStorage.getItem(key); | ||
| const raw = storage.getItem(key); | ||
| if (raw) { |
Playwright test resultsDetails
|
Migrates
useCookieConsentoff its hand-rolled JSON-parse/version-check onto the shareduseLocalStorageStatehook (UPL-48), adding an optional storage-adapter parameter so it can keep reading/writing throughCrossDomainStorageinstead oflocalStoragedirectly.consentstaysConsentPreferences | null; a stale-version or malformed stored record still falls back to "no consent" (banner shown), matching prior behavior.Verification
pnpm test—useCookieConsent.test.ts(16 tests, unmodified) anduseLocalStorageState.test.ts(7 tests, +1 new for the storage adapter) all pass.pnpm run typecheck,pnpm run lint,pnpm run buildall pass.CrossDomainStorageas before.gdpr-consentcookie/localStorage key): banner reappears,consentresolves tonull.Co-Authored-By: Claude Sonnet 5 noreply@anthropic.com
🤖 Generated with Claude Code
https://claude.ai/code/session_017T38pa7BfP2YJZMsw5qWgr
Generated by Claude Code