cloudflare-next-intl 0.9.54 → 0.9.55
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.
|
@@ -3,13 +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 { createContext, useMemo } from "react";
|
|
5
5
|
import dynamic from "next/dynamic.js";
|
|
6
|
+
import useLazyWrappingProvider from "./use_lazy_wrapping_provider.js";
|
|
6
7
|
import config from "@intl-config";
|
|
7
8
|
import installConsoleErrorOverride from "../../error_handling/install_console_error_override.js";
|
|
8
9
|
import installGlobalErrorOverride from "../../error_handling/install_global_error_override.js";
|
|
9
10
|
export const LocaleContext = createContext(undefined);
|
|
10
|
-
const
|
|
11
|
+
const loadAuthUserProvider = () => import("../../firebase_auth/client/auth_user_provider.js");
|
|
11
12
|
const AutoFirebasePerformanceEvents = dynamic(() => import("../../firebase_auth/client/components/auto_firebase_performance_events.js"));
|
|
12
|
-
const
|
|
13
|
+
const loadCookieConsentProvider = () => import("../../cookie_consent/client/cookie_consent_provider.js");
|
|
13
14
|
const CookieConsentAnalytics = dynamic(() => import("../../cookie_consent/client/components/cookie_consent_analytics.js"));
|
|
14
15
|
const AutoAnalyticsEvents = dynamic(() => import("../../cookie_consent/client/components/auto_analytics_events.js"));
|
|
15
16
|
const CookieConsentDialog = dynamic(() => import("../../cookie_consent/client/components/cookie_consent_dialog.js"));
|
|
@@ -19,12 +20,14 @@ export default function LocationzationClientProvider({ language, messages, initi
|
|
|
19
20
|
setMessageForLocaleCache(language, messages);
|
|
20
21
|
installConsoleErrorOverride(config, true);
|
|
21
22
|
installGlobalErrorOverride(config);
|
|
23
|
+
const { Provider: AuthUserProvider } = useLazyWrappingProvider(loadAuthUserProvider);
|
|
24
|
+
const { Provider: CookieConsentProvider, isReady: cookieConsentReady } = useLazyWrappingProvider(loadCookieConsentProvider);
|
|
22
25
|
let providedChildren = children;
|
|
23
26
|
if (config.firebaseAuth && !skipAuthProvider) {
|
|
24
27
|
providedChildren = _jsxs(AuthUserProvider, { initialUser: initialAuthUser, children: [children, config.firebaseAuth.performance !== false && _jsx(AutoFirebasePerformanceEvents, {})] });
|
|
25
28
|
}
|
|
26
29
|
if (config.cookieConsent) {
|
|
27
|
-
providedChildren = _jsxs(CookieConsentProvider, { requiresConsent: requiresConsent, children: [providedChildren, analyticsConfig && _jsx(CookieConsentAnalytics, { config: analyticsConfig }), analyticsConfig && (analyticsConfig.googleAnalyticsId || analyticsConfig.googleAdsId) && _jsx(AutoAnalyticsEvents, { config: autoAnalyticsEventsConfig }), autoWireDialogs && _jsx(CookieConsentDialog, { ...dialogProps }), autoWireDialogs && _jsx(PrivacyPolicyUpdateDialog, { ...updateDialogProps })] });
|
|
30
|
+
providedChildren = _jsxs(CookieConsentProvider, { requiresConsent: requiresConsent, children: [providedChildren, cookieConsentReady && analyticsConfig && _jsx(CookieConsentAnalytics, { config: analyticsConfig }), cookieConsentReady && analyticsConfig && (analyticsConfig.googleAnalyticsId || analyticsConfig.googleAdsId) && _jsx(AutoAnalyticsEvents, { config: autoAnalyticsEventsConfig }), cookieConsentReady && autoWireDialogs && _jsx(CookieConsentDialog, { ...dialogProps }), cookieConsentReady && autoWireDialogs && _jsx(PrivacyPolicyUpdateDialog, { ...updateDialogProps })] });
|
|
28
31
|
}
|
|
29
32
|
const contextValue = useMemo(() => ({ language, messages }), [language, messages]);
|
|
30
33
|
return _jsx(LocaleContext.Provider, { value: contextValue, children: providedChildren });
|
|
@@ -3,11 +3,12 @@ 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 } from "react";
|
|
5
5
|
import dynamic from "next/dynamic.js";
|
|
6
|
+
import useLazyWrappingProvider from "./use_lazy_wrapping_provider.js";
|
|
6
7
|
import config from "@intl-config";
|
|
7
8
|
import installConsoleErrorOverride from "../../error_handling/install_console_error_override.js";
|
|
8
9
|
import installGlobalErrorOverride from "../../error_handling/install_global_error_override.js";
|
|
9
10
|
export const LocaleContext = createContext(undefined);
|
|
10
|
-
const
|
|
11
|
+
const loadCookieConsentProvider = () => import("../../cookie_consent/client/cookie_consent_provider.js");
|
|
11
12
|
const CookieConsentAnalytics = dynamic(() => import("../../cookie_consent/client/components/cookie_consent_analytics.js"));
|
|
12
13
|
const AutoAnalyticsEvents = dynamic(() => import("../../cookie_consent/client/components/auto_analytics_events.js"));
|
|
13
14
|
const CookieConsentDialog = dynamic(() => import("../../cookie_consent/client/components/cookie_consent_dialog.js"));
|
|
@@ -17,9 +18,10 @@ export default function LocationzationClientProvider({ language, messages, analy
|
|
|
17
18
|
setMessageForLocaleCache(language, messages);
|
|
18
19
|
installConsoleErrorOverride(config, true);
|
|
19
20
|
installGlobalErrorOverride(config);
|
|
21
|
+
const { Provider: CookieConsentProvider, isReady: cookieConsentReady } = useLazyWrappingProvider(loadCookieConsentProvider);
|
|
20
22
|
let providedChildren = children;
|
|
21
23
|
if (config.cookieConsent) {
|
|
22
|
-
providedChildren = _jsxs(CookieConsentProvider, { requiresConsent: requiresConsent, children: [providedChildren, analyticsConfig && _jsx(CookieConsentAnalytics, { config: analyticsConfig }), analyticsConfig && (analyticsConfig.googleAnalyticsId || analyticsConfig.googleAdsId) && _jsx(AutoAnalyticsEvents, { config: autoAnalyticsEventsConfig }), autoWireDialogs && _jsx(CookieConsentDialog, { ...dialogProps }), autoWireDialogs && _jsx(PrivacyPolicyUpdateDialog, { ...updateDialogProps })] });
|
|
24
|
+
providedChildren = _jsxs(CookieConsentProvider, { requiresConsent: requiresConsent, children: [providedChildren, cookieConsentReady && analyticsConfig && _jsx(CookieConsentAnalytics, { config: analyticsConfig }), cookieConsentReady && analyticsConfig && (analyticsConfig.googleAnalyticsId || analyticsConfig.googleAdsId) && _jsx(AutoAnalyticsEvents, { config: autoAnalyticsEventsConfig }), cookieConsentReady && autoWireDialogs && _jsx(CookieConsentDialog, { ...dialogProps }), cookieConsentReady && autoWireDialogs && _jsx(PrivacyPolicyUpdateDialog, { ...updateDialogProps })] });
|
|
23
25
|
}
|
|
24
26
|
const contextValue = useMemo(() => ({ language, messages }), [language, messages]);
|
|
25
27
|
return _jsx(LocaleContext.Provider, { value: contextValue, children: providedChildren });
|
|
@@ -0,0 +1,12 @@
|
|
|
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 {};
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
}
|