cloudflare-next-intl 0.5.1 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/cookie_consent/client/components/cookie_consent_dialog.js +2 -2
- package/dist/src/cookie_consent/client/cookie_consent_provider.js +7 -7
- package/dist/src/cookie_consent/types.d.ts +8 -0
- package/package.json +1 -1
- package/dist/src/general/get_layout_states.d.ts +0 -0
- package/dist/src/general/get_layout_states.js +0 -39
|
@@ -12,8 +12,8 @@ import { defaultCookieDialogClassNames } from './default_dialog_styles';
|
|
|
12
12
|
* particular design system.
|
|
13
13
|
*/
|
|
14
14
|
export default function CookieConsentDialog({ message, link, privacyPolicyLinkText, acceptText, declineText, hideDecline = false, id = 'cookie-consent-dialog', classNames, styles, render, }) {
|
|
15
|
-
const { consent, setConsent, privacyPolicyPath } = useCookieConsent();
|
|
16
|
-
if (consent !== null)
|
|
15
|
+
const { consent, isMounted, setConsent, privacyPolicyPath } = useCookieConsent();
|
|
16
|
+
if (!isMounted || consent !== null)
|
|
17
17
|
return null;
|
|
18
18
|
if (render)
|
|
19
19
|
return _jsx(_Fragment, { children: render({ setConsent }) });
|
|
@@ -58,14 +58,14 @@ export default function CookieConsentProvider({ requiresConsent = true, children
|
|
|
58
58
|
}, []);
|
|
59
59
|
const [consent, setConsentState] = useState(null);
|
|
60
60
|
const [privacyPolicyUpdated, setPrivacyPolicyUpdated] = useState(false);
|
|
61
|
+
const [isMounted, setIsMounted] = useState(false);
|
|
61
62
|
useEffect(() => {
|
|
62
63
|
const storedConsent = parseConsent(getCookie(consentCookieName));
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
if (storedConsent === null || !policyDate)
|
|
64
|
+
const autoAccepted = storedConsent === null && !requiresConsent;
|
|
65
|
+
setConsentState(autoAccepted ? true : storedConsent);
|
|
66
|
+
setIsMounted(true);
|
|
67
|
+
const isFirstVisit = storedConsent === null && !autoAccepted;
|
|
68
|
+
if (isFirstVisit || !policyDate)
|
|
69
69
|
return;
|
|
70
70
|
const storedDateRaw = getCookie(dateCookieName);
|
|
71
71
|
if (!storedDateRaw) {
|
|
@@ -90,6 +90,6 @@ export default function CookieConsentProvider({ requiresConsent = true, children
|
|
|
90
90
|
setPrivacyPolicyUpdated(false);
|
|
91
91
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
92
92
|
}, []);
|
|
93
|
-
const contextValue = useMemo(() => ({ consent, privacyPolicyUpdated, setConsent, acknowledgePrivacyPolicyUpdate, privacyPolicyPath }), [consent, privacyPolicyUpdated, setConsent, acknowledgePrivacyPolicyUpdate, privacyPolicyPath]);
|
|
93
|
+
const contextValue = useMemo(() => ({ consent, privacyPolicyUpdated, isMounted, setConsent, acknowledgePrivacyPolicyUpdate, privacyPolicyPath }), [consent, privacyPolicyUpdated, isMounted, setConsent, acknowledgePrivacyPolicyUpdate, privacyPolicyPath]);
|
|
94
94
|
return (_jsx(CookieConsentContext.Provider, { value: contextValue, children: children }));
|
|
95
95
|
}
|
|
@@ -4,6 +4,14 @@ export type ConsentValue = boolean | null;
|
|
|
4
4
|
export interface CookieConsentContextType {
|
|
5
5
|
/** Current consent value; `null` until the visitor decides. */
|
|
6
6
|
consent: ConsentValue;
|
|
7
|
+
/**
|
|
8
|
+
* `false` until the client has read the stored consent/date cookies once
|
|
9
|
+
* (always `false` during SSR and the first client render, to avoid a
|
|
10
|
+
* hydration mismatch). The default dialog components render nothing
|
|
11
|
+
* until this is `true`, so a returning visitor's decided consent never
|
|
12
|
+
* flashes the banner before disappearing.
|
|
13
|
+
*/
|
|
14
|
+
isMounted: boolean;
|
|
7
15
|
/**
|
|
8
16
|
* `true` once a privacy-policy update has been detected (stored consent
|
|
9
17
|
* predates `cookieConsent.privacyPolicyDate`) and hasn't been
|
package/package.json
CHANGED
|
File without changes
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// NOTE: currently disabled — this file exports nothing at runtime, even
|
|
3
|
-
// though "./getLayoutStates" is listed in package.json's exports map.
|
|
4
|
-
// Do not rely on `cloudflare-next-intl/getLayoutStates` until this is
|
|
5
|
-
// re-enabled; use `getLocale()` + read the theme cookie manually instead.
|
|
6
|
-
// "use server";
|
|
7
|
-
// import { cookies } from "next/headers";
|
|
8
|
-
// import { localeCookieName, isDarkCookieKey } from "../config/cookie_key";
|
|
9
|
-
// import config from "../config/intl_config";
|
|
10
|
-
// interface HtmlParamProps {
|
|
11
|
-
// className?: string;
|
|
12
|
-
// suppressHydrationWarning?: boolean;
|
|
13
|
-
// lang: string;
|
|
14
|
-
// }
|
|
15
|
-
// export default async function getLayoutStates(): Promise<{
|
|
16
|
-
// isDark: boolean | null;
|
|
17
|
-
// locale: string;
|
|
18
|
-
// htmlParam?: HtmlParamProps;
|
|
19
|
-
// }> {
|
|
20
|
-
// const cookie = await cookies();
|
|
21
|
-
// const isDarkMode = cookie.get(isDarkCookieKey)?.value;
|
|
22
|
-
// const isDark = getCookieBooleanValue(isDarkMode);
|
|
23
|
-
// const cookieLocale = (cookie.get(localeCookieName)?.value as string) ?? config.defaultLocale;
|
|
24
|
-
// const htmlParam: HtmlParamProps = { suppressHydrationWarning: !isDarkMode, lang: cookieLocale };
|
|
25
|
-
// if (isDark === true) {
|
|
26
|
-
// htmlParam.className = 'dark';
|
|
27
|
-
// }
|
|
28
|
-
// return { isDark, locale: cookieLocale, htmlParam };
|
|
29
|
-
// }
|
|
30
|
-
// function getCookieBooleanValue(cookieValue: string | undefined): boolean | null {
|
|
31
|
-
// switch (cookieValue) {
|
|
32
|
-
// case "true":
|
|
33
|
-
// return true;
|
|
34
|
-
// case "false":
|
|
35
|
-
// return false;
|
|
36
|
-
// default:
|
|
37
|
-
// return null;
|
|
38
|
-
// }
|
|
39
|
-
// }
|