Skip to content

Commit ca12d6d

Browse files
Slashgearphilibea
andauthored
fix(cookie-consent): use conditional access to document (#2041)
Co-authored-by: philibeaux <[email protected]>
1 parent 577e753 commit ca12d6d

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

.changeset/sharp-buckets-unite.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@scaleway/cookie-consent": patch
3+
---
4+
5+
Cookie consent provider now work on client and server side

packages/cookie-consent/src/CookieConsentProvider/CookieConsentProvider.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { useSegmentIntegrations } from './useSegmentIntegrations'
1717

1818
const COOKIE_PREFIX = '_scw_rgpd'
1919
const HASH_COOKIE = `${COOKIE_PREFIX}_hash`
20+
const IS_CLIENT = typeof document !== 'undefined'
2021

2122
// Appx 13 Months
2223
const CONSENT_MAX_AGE = 13 * 30 * 24 * 60 * 60
@@ -72,7 +73,7 @@ export const CookieConsentProvider = ({
7273
}>) => {
7374
const [needConsent, setNeedsConsent] = useState(false)
7475
const [cookies, setCookies] = useState<Record<string, string>>(
75-
cookie.parse(document.cookie),
76+
IS_CLIENT ? cookie.parse(document.cookie) : {},
7677
)
7778

7879
const {

0 commit comments

Comments
 (0)