cloudflare-next-intl 0.10.26 → 0.10.27

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.
@@ -1,12 +1,14 @@
1
1
  'use client';
2
2
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { useEffect, Suspense } from 'react';
3
+ import { useEffect, useSyncExternalStore, Suspense } from 'react';
4
4
  import dynamic from 'next/dynamic.js';
5
5
  import useCookieConsent from '../use_cookie_consent.js';
6
6
  const ClarityScript = dynamic(() => import('./clarity_script.js'));
7
+ const noopSubscribe = () => () => undefined;
7
8
  export default function CookieConsentAnalytics({ config }) {
8
9
  const { consent, requiresConsent } = useCookieConsent();
9
10
  const granted = consent === true || !requiresConsent;
11
+ const hydrated = useSyncExternalStore(noopSubscribe, () => true, () => false);
10
12
  useEffect(() => {
11
13
  if (consent === null && requiresConsent)
12
14
  return;
@@ -21,8 +23,19 @@ export default function CookieConsentAnalytics({ config }) {
21
23
  analytics_storage: state,
22
24
  });
23
25
  }, [consent, requiresConsent, granted]);
26
+ useEffect(() => {
27
+ if (!granted || !config.cloudflareBeaconToken)
28
+ return;
29
+ if (document.querySelector('script[data-cf-beacon]'))
30
+ return;
31
+ const script = document.createElement('script');
32
+ script.defer = true;
33
+ script.src = 'https://static.cloudflareinsights.com/beacon.min.js';
34
+ script.setAttribute('data-cf-beacon', config.cloudflareBeaconToken);
35
+ document.head.appendChild(script);
36
+ }, [granted, config.cloudflareBeaconToken]);
24
37
  const hasGoogle = Boolean(config.googleAnalyticsId || config.googleAdsId || config.googleAdSenseId);
25
- return (_jsxs(_Fragment, { children: [hasGoogle && (_jsx("script", { id: "cookie-consent-google-consent-mode", dangerouslySetInnerHTML: { __html: googleConsentModeBootstrapScript(config) } })), granted && config.cloudflareBeaconToken && (_jsx("script", { defer: true, src: "https://static.cloudflareinsights.com/beacon.min.js", "data-cf-beacon": config.cloudflareBeaconToken })), granted && config.clarityProjectId && (_jsx(Suspense, { fallback: null, children: _jsx(ClarityScript, { projectId: config.clarityProjectId }) }))] }));
38
+ return (_jsxs(_Fragment, { children: [hasGoogle && (_jsx("script", { id: "cookie-consent-google-consent-mode", dangerouslySetInnerHTML: { __html: googleConsentModeBootstrapScript(config) } })), hydrated && granted && config.clarityProjectId && (_jsx(Suspense, { fallback: null, children: _jsx(ClarityScript, { projectId: config.clarityProjectId }) }))] }));
26
39
  }
27
40
  export function googleConsentModeBootstrapScript(config) {
28
41
  const configCalls = [config.googleAnalyticsId, config.googleAdsId]
@@ -1,14 +1,17 @@
1
1
  'use client';
2
2
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useSyncExternalStore } from 'react';
3
4
  import useCookieConsent from '../use_cookie_consent.js';
4
5
  import DefaultPrivacyPolicyLink from './default_privacy_policy_link.js';
5
6
  import DialogPortal from './dialog_portal.js';
6
7
  import { getLocaleCache } from '../../../general/cache_variables.js';
7
8
  import { defaultCookieConsentText } from './default_dialog_text.js';
8
9
  import { defaultCookieDialogClassNames } from './default_dialog_styles.js';
10
+ const noopSubscribe = () => () => undefined;
9
11
  export default function CookieConsentDialog({ message, link, privacyPolicyLinkText, showPrivacyPolicy, acceptText, declineText, hideDecline = false, id = 'cookie-consent-dialog', classNames, styles, render, }) {
10
12
  const { consent, requiresConsent, isMounted, setConsent, privacyPolicyPath, showPrivacyPolicy: showPrivacyPolicyCtx } = useCookieConsent();
11
- if (!isMounted || !requiresConsent || consent !== null)
13
+ const hydrated = useSyncExternalStore(noopSubscribe, () => true, () => false);
14
+ if (!hydrated || !isMounted || !requiresConsent || consent !== null)
12
15
  return null;
13
16
  if (render)
14
17
  return _jsx(_Fragment, { children: render({ setConsent }) });
@@ -1,14 +1,17 @@
1
1
  'use client';
2
2
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useSyncExternalStore } from 'react';
3
4
  import useCookieConsent from '../use_cookie_consent.js';
4
5
  import DefaultPrivacyPolicyLink from './default_privacy_policy_link.js';
5
6
  import DialogPortal from './dialog_portal.js';
6
7
  import { getLocaleCache } from '../../../general/cache_variables.js';
7
8
  import { defaultPrivacyPolicyUpdateText } from './default_dialog_text.js';
8
9
  import { defaultCookieDialogClassNames } from './default_dialog_styles.js';
10
+ const noopSubscribe = () => () => undefined;
9
11
  export default function PrivacyPolicyUpdateDialog({ message, link, privacyPolicyLinkText, showPrivacyPolicy, closeText, id = 'privacy-policy-update-dialog', classNames, styles, render, }) {
10
12
  const { privacyPolicyUpdated, acknowledgePrivacyPolicyUpdate, privacyPolicyPath, showPrivacyPolicy: showPrivacyPolicyCtx } = useCookieConsent();
11
- if (!privacyPolicyUpdated)
13
+ const hydrated = useSyncExternalStore(noopSubscribe, () => true, () => false);
14
+ if (!hydrated || !privacyPolicyUpdated)
12
15
  return null;
13
16
  if (render)
14
17
  return _jsx(_Fragment, { children: render({ acknowledge: acknowledgePrivacyPolicyUpdate }) });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cloudflare-next-intl",
3
- "version": "0.10.26",
3
+ "version": "0.10.27",
4
4
  "description": "Optimized Next Intl Package Special for App Router and Cloudflare",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",