cloudflare-next-intl 0.9.23 → 0.9.24
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.
|
@@ -46,7 +46,8 @@ export function googleConsentModeBootstrapScript(config) {
|
|
|
46
46
|
document.head.appendChild(a);
|
|
47
47
|
})();`
|
|
48
48
|
: '';
|
|
49
|
-
return `
|
|
49
|
+
return `try {
|
|
50
|
+
window.dataLayer = window.dataLayer || [];
|
|
50
51
|
function gtag(){dataLayer.push(arguments);}
|
|
51
52
|
gtag('consent', 'default', {
|
|
52
53
|
'ad_storage': 'denied',
|
|
@@ -58,5 +59,6 @@ gtag('consent', 'default', {
|
|
|
58
59
|
gtag('js', new Date());
|
|
59
60
|
${configCalls}
|
|
60
61
|
${gtagLoader}
|
|
61
|
-
${adSenseLoader}
|
|
62
|
+
${adSenseLoader}
|
|
63
|
+
} catch (e) { try { console.error('Cookie Consent Analytics Script Error:', e); } catch (e2) {} }`;
|
|
62
64
|
}
|
|
@@ -12,6 +12,7 @@ export default function HelperScript() {
|
|
|
12
12
|
_jsx("script", { src: "https://www.google.com/recaptcha/api.js?render=explicit", async: true, defer: true }), !isDev &&
|
|
13
13
|
_jsx("script", { id: "stale-deploy-early-catch", dangerouslySetInnerHTML: {
|
|
14
14
|
__html: `(function() {
|
|
15
|
+
try {
|
|
15
16
|
var patterns = ${JSON.stringify(defaultStaleDeployPatterns)};
|
|
16
17
|
var key = 'stale-deploy-recovery-reloaded';
|
|
17
18
|
var attemptedThisLoad = false;
|
|
@@ -38,6 +39,11 @@ export default function HelperScript() {
|
|
|
38
39
|
attemptedThisLoad = true;
|
|
39
40
|
sessionStorage.setItem(key, buildId);
|
|
40
41
|
console.warn('[StaleDeploy early-catch] Reloading for buildId:', buildId);
|
|
42
|
+
try {
|
|
43
|
+
if (document.documentElement) {
|
|
44
|
+
document.documentElement.style.opacity = '0';
|
|
45
|
+
}
|
|
46
|
+
} catch (e) {}
|
|
41
47
|
try {
|
|
42
48
|
var u = new URL(window.location.href);
|
|
43
49
|
u.searchParams.set('_stale_reload', String(Date.now()));
|
|
@@ -53,28 +59,41 @@ export default function HelperScript() {
|
|
|
53
59
|
window.addEventListener('unhandledrejection', function(e) {
|
|
54
60
|
recover(e.reason && (e.reason.message || e.reason), 'unhandledrejection');
|
|
55
61
|
});
|
|
62
|
+
} catch (e) { try { console.error('Stale Deploy Early Catch Script Error:', e); } catch (e2) {} }
|
|
56
63
|
})();`
|
|
57
64
|
} }), !isDev &&
|
|
58
65
|
_jsx("script", { id: "build-id-script", children: `(async function() {
|
|
59
66
|
try {
|
|
60
67
|
const resp = await fetch('/BUILD_ID', { method: 'HEAD', cache: 'no-store' });
|
|
61
68
|
if (resp.ok) {
|
|
62
|
-
|
|
69
|
+
let BUILD_ID;
|
|
70
|
+
try {
|
|
71
|
+
BUILD_ID = resp.headers.get('ETag')?.replace(/W\\/|"/g, '');
|
|
72
|
+
} catch (e) { BUILD_ID = undefined; }
|
|
63
73
|
if(!BUILD_ID) return;
|
|
64
|
-
console.log('Build ID:', BUILD_ID);
|
|
74
|
+
try { console.log('Build ID:', BUILD_ID); } catch (e) {}
|
|
65
75
|
|
|
66
|
-
|
|
76
|
+
let prevBuild;
|
|
77
|
+
try {
|
|
78
|
+
prevBuild = localStorage.getItem('buildId');
|
|
79
|
+
} catch (e) { prevBuild = null; }
|
|
67
80
|
|
|
68
81
|
if (prevBuild !== BUILD_ID) {
|
|
69
|
-
|
|
70
|
-
|
|
82
|
+
try {
|
|
83
|
+
localStorage.setItem('buildId', BUILD_ID);
|
|
84
|
+
localStorage.setItem('buildIdSetAt', String(Date.now()));
|
|
85
|
+
} catch (e) {}
|
|
71
86
|
if(prevBuild){
|
|
72
|
-
|
|
87
|
+
try {
|
|
88
|
+
window.location.reload(true);
|
|
89
|
+
} catch (e) {
|
|
90
|
+
try { window.location.reload(); } catch (e2) {}
|
|
91
|
+
}
|
|
73
92
|
}
|
|
74
93
|
}
|
|
75
94
|
}
|
|
76
95
|
} catch (e) {
|
|
77
|
-
console.error('Check Build ID Script Error:', e);
|
|
96
|
+
try { console.error('Check Build ID Script Error:', e); } catch (e2) {}
|
|
78
97
|
}
|
|
79
98
|
})();` }), _jsx("script", { id: "intl-app-state-checker", children: `(function() {
|
|
80
99
|
try {
|
|
@@ -87,16 +106,22 @@ export default function HelperScript() {
|
|
|
87
106
|
// Use a regex to find the cookie directly, avoiding splits and loops.
|
|
88
107
|
// The non-capturing group (?:^|; ) matches the start of the string or a '; '
|
|
89
108
|
// to ensure we're not matching a substring of another cookie's name.
|
|
90
|
-
|
|
91
|
-
|
|
109
|
+
try {
|
|
110
|
+
const match = document.cookie.match(new RegExp(\`(?:^|; )\${name}=([^;]*)\`));
|
|
111
|
+
return match ? decodeURIComponent(match[1]) : null;
|
|
112
|
+
} catch (e) {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
92
115
|
};
|
|
93
116
|
|
|
94
117
|
function setTheme(isDark){
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
classList.
|
|
99
|
-
|
|
118
|
+
try {
|
|
119
|
+
const classList=document.documentElement.classList;
|
|
120
|
+
// This check is efficient as it only touches the DOM when a change is needed.
|
|
121
|
+
if (classList.contains('dark') !== isDark) {
|
|
122
|
+
classList.toggle('dark', isDark);
|
|
123
|
+
}
|
|
124
|
+
} catch (e) {}
|
|
100
125
|
}
|
|
101
126
|
|
|
102
127
|
function syncTheme(){
|
|
@@ -124,37 +149,45 @@ export default function HelperScript() {
|
|
|
124
149
|
if (locale && locale !== '${config.defaultLocale}' && !pathname.startsWith(\`/\${locale}\`)) {
|
|
125
150
|
const newPath = \`/\${locale}\${pathname === '/' ? '' : pathname}\${search}\${hash}\`;
|
|
126
151
|
// Redirecting will stop further script execution on this page.
|
|
127
|
-
|
|
152
|
+
try {
|
|
153
|
+
window.location.href = newPath;
|
|
154
|
+
} catch (e) {}
|
|
128
155
|
} else {
|
|
129
156
|
const isDark = getCookie('${isDarkCookieKey}');
|
|
130
157
|
if(isDark===null){
|
|
131
|
-
|
|
158
|
+
let prefersDark = false;
|
|
159
|
+
try {
|
|
160
|
+
prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
|
|
161
|
+
} catch (e) {}
|
|
132
162
|
setTheme(prefersDark);
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
163
|
+
try {
|
|
164
|
+
document.cookie = '${isDarkCookieKey}=' +
|
|
165
|
+
prefersDark +
|
|
166
|
+
'; path=/; max-age=31536000; SameSite=Lax;'
|
|
167
|
+
${secureCookieAttribute};
|
|
168
|
+
} catch (e) {}
|
|
137
169
|
}else{
|
|
138
170
|
setTheme(isDark==='true');
|
|
139
171
|
}
|
|
140
172
|
// 3. Set up listeners for client-side navigation (only if not redirecting).
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
173
|
+
try {
|
|
174
|
+
// Store original history methods.
|
|
175
|
+
const pushState = history.pushState;
|
|
176
|
+
const replaceState = history.replaceState;
|
|
177
|
+
const back = history.back;
|
|
146
178
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
179
|
+
history.back = function (...args) {
|
|
180
|
+
try { back.apply(history, args); } catch (e) {}
|
|
181
|
+
};
|
|
182
|
+
history.pushState = function (...args) {
|
|
183
|
+
try { pushState.apply(history, args); } catch (e) {}
|
|
184
|
+
try { syncTheme(); } catch (e) {} // Re-sync theme after navigation.
|
|
185
|
+
};
|
|
186
|
+
history.replaceState = function (...args) {
|
|
187
|
+
try { replaceState.apply(history, args); } catch (e) {}
|
|
188
|
+
try { syncTheme(); } catch (e) {} // Re-sync theme after state replacement.
|
|
189
|
+
};
|
|
190
|
+
} catch (e) {}
|
|
158
191
|
}
|
|
159
192
|
} catch (e) {
|
|
160
193
|
console.error('App State check Script Error:', e);
|