cloudflare-next-intl 0.10.25 → 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.
- package/dist/src/client/components/client_provider.js +4 -8
- package/dist/src/client/components/client_provider_static.js +2 -4
- package/dist/src/cookie_consent/client/components/cookie_consent_analytics.js +15 -2
- package/dist/src/cookie_consent/client/components/cookie_consent_dialog.js +4 -1
- package/dist/src/cookie_consent/client/components/privacy_policy_update_dialog.js +4 -1
- package/package.json +1 -1
- package/dist/src/client/components/use_lazy_wrapping_provider.d.ts +0 -12
- package/dist/src/client/components/use_lazy_wrapping_provider.js +0 -34
- package/dist/src/firebase_auth/client/auth_user_pending_provider.d.ts +0 -5
- package/dist/src/firebase_auth/client/auth_user_pending_provider.js +0 -17
|
@@ -3,16 +3,14 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
3
3
|
import { setLocaleCache, setMessageForLocaleCache } from "../../general/cache_variables.js";
|
|
4
4
|
import { useEffect, useMemo, Suspense } from "react";
|
|
5
5
|
import dynamic from "next/dynamic.js";
|
|
6
|
-
import
|
|
6
|
+
import CookieConsentProvider from "../../cookie_consent/client/cookie_consent_provider.js";
|
|
7
|
+
import AuthUserProvider from "../../firebase_auth/client/auth_user_provider.js";
|
|
7
8
|
import config from "@intl-config";
|
|
8
9
|
import installConsoleErrorOverride from "../../error_handling/install_console_error_override.js";
|
|
9
10
|
import installGlobalErrorOverride from "../../error_handling/install_global_error_override.js";
|
|
10
|
-
import AuthUserPendingProvider from "../../firebase_auth/client/auth_user_pending_provider.js";
|
|
11
11
|
import { LocaleContext } from "./locale_provider.js";
|
|
12
12
|
export { LocaleContext };
|
|
13
|
-
const loadAuthUserProvider = () => import("../../firebase_auth/client/auth_user_provider.js");
|
|
14
13
|
const AutoFirebasePerformanceEvents = dynamic(() => import("../../firebase_auth/client/components/auto_firebase_performance_events.js"));
|
|
15
|
-
const loadCookieConsentProvider = () => import("../../cookie_consent/client/cookie_consent_provider.js");
|
|
16
14
|
const CookieConsentAnalytics = dynamic(() => import("../../cookie_consent/client/components/cookie_consent_analytics.js"));
|
|
17
15
|
const AutoAnalyticsEvents = dynamic(() => import("../../cookie_consent/client/components/auto_analytics_events.js"));
|
|
18
16
|
const loadCookieConsentDialog = () => import("../../cookie_consent/client/components/cookie_consent_dialog.js");
|
|
@@ -23,8 +21,6 @@ export default function LocationzationClientProvider({ language, messages, initi
|
|
|
23
21
|
setMessageForLocaleCache(language, messages);
|
|
24
22
|
installConsoleErrorOverride(config, true);
|
|
25
23
|
installGlobalErrorOverride(config);
|
|
26
|
-
const { Provider: AuthUserProvider } = useLazyWrappingProvider(loadAuthUserProvider);
|
|
27
|
-
const { Provider: CookieConsentProvider, isReady: cookieConsentReady } = useLazyWrappingProvider(loadCookieConsentProvider);
|
|
28
24
|
useEffect(() => {
|
|
29
25
|
if (!config.cookieConsent || !autoWireDialogs)
|
|
30
26
|
return;
|
|
@@ -32,10 +28,10 @@ export default function LocationzationClientProvider({ language, messages, initi
|
|
|
32
28
|
}, [autoWireDialogs]);
|
|
33
29
|
let providedChildren = children;
|
|
34
30
|
if (config.firebaseAuth && !skipAuthProvider) {
|
|
35
|
-
providedChildren =
|
|
31
|
+
providedChildren = _jsxs(AuthUserProvider, { initialUser: initialAuthUser, children: [children, config.firebaseAuth.performance !== false && (_jsx(Suspense, { fallback: null, children: _jsx(AutoFirebasePerformanceEvents, {}) }))] });
|
|
36
32
|
}
|
|
37
33
|
if (config.cookieConsent) {
|
|
38
|
-
providedChildren = _jsxs(CookieConsentProvider, { requiresConsent: requiresConsent, children: [providedChildren,
|
|
34
|
+
providedChildren = _jsxs(CookieConsentProvider, { requiresConsent: requiresConsent, children: [providedChildren, analyticsConfig && (_jsx(Suspense, { fallback: null, children: _jsx(CookieConsentAnalytics, { config: analyticsConfig }) })), analyticsConfig && (analyticsConfig.googleAnalyticsId || analyticsConfig.googleAdsId) && (_jsx(Suspense, { fallback: null, children: _jsx(AutoAnalyticsEvents, { config: autoAnalyticsEventsConfig }) })), autoWireDialogs && (_jsx(Suspense, { fallback: null, children: _jsx(CookieConsentDialog, { ...dialogProps }) })), autoWireDialogs && (_jsx(Suspense, { fallback: null, children: _jsx(PrivacyPolicyUpdateDialog, { ...updateDialogProps }) }))] });
|
|
39
35
|
}
|
|
40
36
|
const contextValue = useMemo(() => ({ language, messages }), [language, messages]);
|
|
41
37
|
return _jsx(LocaleContext.Provider, { value: contextValue, children: providedChildren });
|
|
@@ -3,12 +3,11 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
3
3
|
import { setLocaleCache, setMessageForLocaleCache } from "../../general/cache_variables.js";
|
|
4
4
|
import { createContext, useMemo, Suspense } from "react";
|
|
5
5
|
import dynamic from "next/dynamic.js";
|
|
6
|
-
import
|
|
6
|
+
import CookieConsentProvider from "../../cookie_consent/client/cookie_consent_provider.js";
|
|
7
7
|
import config from "@intl-config";
|
|
8
8
|
import installConsoleErrorOverride from "../../error_handling/install_console_error_override.js";
|
|
9
9
|
import installGlobalErrorOverride from "../../error_handling/install_global_error_override.js";
|
|
10
10
|
export const LocaleContext = createContext(undefined);
|
|
11
|
-
const loadCookieConsentProvider = () => import("../../cookie_consent/client/cookie_consent_provider.js");
|
|
12
11
|
const CookieConsentAnalytics = dynamic(() => import("../../cookie_consent/client/components/cookie_consent_analytics.js"));
|
|
13
12
|
const AutoAnalyticsEvents = dynamic(() => import("../../cookie_consent/client/components/auto_analytics_events.js"));
|
|
14
13
|
const CookieConsentDialog = dynamic(() => import("../../cookie_consent/client/components/cookie_consent_dialog.js"));
|
|
@@ -18,10 +17,9 @@ export default function LocationzationClientProvider({ language, messages, analy
|
|
|
18
17
|
setMessageForLocaleCache(language, messages);
|
|
19
18
|
installConsoleErrorOverride(config, true);
|
|
20
19
|
installGlobalErrorOverride(config);
|
|
21
|
-
const { Provider: CookieConsentProvider, isReady: cookieConsentReady } = useLazyWrappingProvider(loadCookieConsentProvider);
|
|
22
20
|
let providedChildren = children;
|
|
23
21
|
if (config.cookieConsent) {
|
|
24
|
-
providedChildren = _jsxs(CookieConsentProvider, { requiresConsent: requiresConsent, children: [providedChildren,
|
|
22
|
+
providedChildren = _jsxs(CookieConsentProvider, { requiresConsent: requiresConsent, children: [providedChildren, analyticsConfig && (_jsx(Suspense, { fallback: null, children: _jsx(CookieConsentAnalytics, { config: analyticsConfig }) })), analyticsConfig && (analyticsConfig.googleAnalyticsId || analyticsConfig.googleAdsId) && (_jsx(Suspense, { fallback: null, children: _jsx(AutoAnalyticsEvents, { config: autoAnalyticsEventsConfig }) })), autoWireDialogs && (_jsx(Suspense, { fallback: null, children: _jsx(CookieConsentDialog, { ...dialogProps }) })), autoWireDialogs && (_jsx(Suspense, { fallback: null, children: _jsx(PrivacyPolicyUpdateDialog, { ...updateDialogProps }) }))] });
|
|
25
23
|
}
|
|
26
24
|
const contextValue = useMemo(() => ({ language, messages }), [language, messages]);
|
|
27
25
|
return _jsx(LocaleContext.Provider, { value: contextValue, children: providedChildren });
|
|
@@ -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) } })),
|
|
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
|
-
|
|
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
|
-
|
|
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,12 +0,0 @@
|
|
|
1
|
-
import { type ComponentType } from "react";
|
|
2
|
-
type ModuleLoader<P> = () => Promise<{
|
|
3
|
-
default: ComponentType<P>;
|
|
4
|
-
}>;
|
|
5
|
-
export interface LazyWrappingProviderResult<P extends Record<string, unknown>> {
|
|
6
|
-
Provider: ComponentType<P & {
|
|
7
|
-
children?: React.ReactNode;
|
|
8
|
-
}>;
|
|
9
|
-
isReady: boolean;
|
|
10
|
-
}
|
|
11
|
-
export default function useLazyWrappingProvider<P extends Record<string, unknown>>(loader: ModuleLoader<P>): LazyWrappingProviderResult<P>;
|
|
12
|
-
export {};
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { useEffect, useRef, useState } from "react";
|
|
4
|
-
const settledCache = new Map();
|
|
5
|
-
export default function useLazyWrappingProvider(loader) {
|
|
6
|
-
const opaqueLoader = loader;
|
|
7
|
-
const resolvedRef = useRef(settledCache.get(opaqueLoader) ?? null);
|
|
8
|
-
const [isReady, setIsReady] = useState(resolvedRef.current !== null);
|
|
9
|
-
useEffect(() => {
|
|
10
|
-
if (resolvedRef.current)
|
|
11
|
-
return;
|
|
12
|
-
let cancelled = false;
|
|
13
|
-
loader().then((mod) => {
|
|
14
|
-
if (cancelled)
|
|
15
|
-
return;
|
|
16
|
-
settledCache.set(opaqueLoader, mod.default);
|
|
17
|
-
resolvedRef.current = mod.default;
|
|
18
|
-
setIsReady(true);
|
|
19
|
-
});
|
|
20
|
-
return () => {
|
|
21
|
-
cancelled = true;
|
|
22
|
-
};
|
|
23
|
-
}, []);
|
|
24
|
-
const wrapperRef = useRef(null);
|
|
25
|
-
if (!wrapperRef.current) {
|
|
26
|
-
wrapperRef.current = function LazyWrappingProvider({ children, ...props }) {
|
|
27
|
-
const Resolved = resolvedRef.current;
|
|
28
|
-
if (!Resolved)
|
|
29
|
-
return children;
|
|
30
|
-
return _jsx(Resolved, { ...props, children: children });
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
return { Provider: wrapperRef.current, isReady };
|
|
34
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { useMemo } from 'react';
|
|
4
|
-
import { AuthUserContext } from './auth_user_context.js';
|
|
5
|
-
function notReady() {
|
|
6
|
-
return Promise.reject(new Error('AuthUserProvider is still loading'));
|
|
7
|
-
}
|
|
8
|
-
export default function AuthUserPendingProvider({ initialUser = null, children }) {
|
|
9
|
-
const value = useMemo(() => ({
|
|
10
|
-
user: initialUser,
|
|
11
|
-
loading: initialUser === null,
|
|
12
|
-
reloadUser: notReady,
|
|
13
|
-
sendVerificationEmail: notReady,
|
|
14
|
-
logout: notReady,
|
|
15
|
-
}), [initialUser]);
|
|
16
|
-
return _jsx(AuthUserContext.Provider, { value: value, children: children });
|
|
17
|
-
}
|