cloudflare-next-intl 0.8.42 → 0.8.44
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/README.md +33 -0
- package/dist/src/client/hooks/use_path_name.js +3 -0
- package/dist/src/config/init_config.js +4 -0
- package/dist/src/cookie_consent/client/cookie_consent_provider.js +1 -1
- package/dist/src/error_handling/clear_client_cache.d.ts +1 -0
- package/dist/src/error_handling/clear_client_cache.js +18 -0
- package/dist/src/error_handling/index.d.ts +2 -0
- package/dist/src/error_handling/index.js +2 -0
- package/dist/src/error_handling/is_stale_deploy_error.d.ts +4 -0
- package/dist/src/error_handling/is_stale_deploy_error.js +31 -0
- package/dist/src/types/types.d.ts +7 -0
- package/llms.txt +4 -0
- package/package.json +9 -1
package/README.md
CHANGED
|
@@ -468,6 +468,8 @@ export default setIntlConfig({
|
|
|
468
468
|
// formattedMessage is a ready-to-print "[classOrMethodName] Error: ..." string
|
|
469
469
|
myErrorTracker.capture(formattedMessage);
|
|
470
470
|
},
|
|
471
|
+
// staleDeployPatterns: [...], // customize substrings matched by isStaleDeployError;
|
|
472
|
+
// // defaults to defaultStaleDeployPatterns (chunk, failed to fetch, etc)
|
|
471
473
|
// overrideConsoleError: true, // route every console.error(...) call through onError too
|
|
472
474
|
// ignoreConsoleErrors: [...], // defaults to defaultIgnoredConsoleErrors (this package's
|
|
473
475
|
// // own Firebase Auth codes for expected user-input failures);
|
|
@@ -499,6 +501,37 @@ server-side resolution) on `ErrorHandlingParams` — reporting is skipped
|
|
|
499
501
|
whenever `consent` is set and not `true`, since sending error reports to a
|
|
500
502
|
third party without consent can itself be GDPR-relevant.
|
|
501
503
|
|
|
504
|
+
#### Stale Deploy & Chunk Load Error Recovery
|
|
505
|
+
|
|
506
|
+
When a new version of your application is deployed to Cloudflare Workers, users on older client sessions may encounter `ChunkLoadError` or failed dynamic imports when requesting outdated chunks. Use `isStaleDeployError` and `clearClientCache` in error boundaries or global error handlers to automatically recover:
|
|
507
|
+
|
|
508
|
+
```typescript
|
|
509
|
+
import { isStaleDeployError, clearClientCache } from "cloudflare-next-intl/errorHandling";
|
|
510
|
+
|
|
511
|
+
export default function GlobalError({
|
|
512
|
+
error,
|
|
513
|
+
reset,
|
|
514
|
+
}: {
|
|
515
|
+
error: Error & { digest?: string };
|
|
516
|
+
reset: () => void;
|
|
517
|
+
}) {
|
|
518
|
+
useEffect(() => {
|
|
519
|
+
if (isStaleDeployError(error)) {
|
|
520
|
+
clearClientCache().then(() => {
|
|
521
|
+
window.location.reload();
|
|
522
|
+
});
|
|
523
|
+
}
|
|
524
|
+
}, [error]);
|
|
525
|
+
|
|
526
|
+
// ... render fallback UI
|
|
527
|
+
}
|
|
528
|
+
```
|
|
529
|
+
|
|
530
|
+
- `isStaleDeployError(error: Error, patterns?: readonly string[]): boolean`: Returns `true` if the error indicates a missing chunk, failed fetch, CSS chunk failure, closed connection, corrupted RSC payload, or hydration error #412 from a stale deployment. Defaults to `defaultStaleDeployPatterns` (or patterns configured in `intl-config.ts` via `errorHandling.staleDeployPatterns`).
|
|
531
|
+
- `setStaleDeployPatterns(patterns: readonly string[]): void`: Setter to update the active pattern list and pre-compute lowercased substrings for maximum runtime performance.
|
|
532
|
+
- `getStaleDeployPatterns(): readonly string[]`: Returns the currently active pattern list.
|
|
533
|
+
- `clearClientCache(): Promise<void>`: Best-effort cleanup that deletes all CacheStorage caches (`window.caches`), unregisters active Service Workers, and clears `sessionStorage`.
|
|
534
|
+
|
|
502
535
|
### Database (`db`)
|
|
503
536
|
|
|
504
537
|
Thin Postgres/Drizzle data-access layer over a Postgres connection string
|
|
@@ -13,6 +13,9 @@ import { useLocale } from "./client_hooks";
|
|
|
13
13
|
export default function usePathname() {
|
|
14
14
|
const pathname = nextUsePathname();
|
|
15
15
|
const locale = useLocale();
|
|
16
|
+
if (!pathname) {
|
|
17
|
+
return '/';
|
|
18
|
+
}
|
|
16
19
|
const path = pathname.replace(`/${locale}`, '');
|
|
17
20
|
if (path) {
|
|
18
21
|
return path;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { setStaleDeployPatterns } from '../error_handling/is_stale_deploy_error';
|
|
1
2
|
// Every path this package compares against `request.nextUrl.pathname`
|
|
2
3
|
// (always `/`-prefixed) must itself start with `/` — a missing leading
|
|
3
4
|
// slash means `path === fa.verifyEmailPath` (and the same check for
|
|
@@ -58,5 +59,8 @@ function normalizeFirebaseAuthPaths(config) {
|
|
|
58
59
|
* ```
|
|
59
60
|
*/
|
|
60
61
|
export function setIntlConfig(config) {
|
|
62
|
+
if (config.errorHandling?.staleDeployPatterns) {
|
|
63
|
+
setStaleDeployPatterns(config.errorHandling.staleDeployPatterns);
|
|
64
|
+
}
|
|
61
65
|
return normalizeFirebaseAuthPaths(config);
|
|
62
66
|
}
|
|
@@ -116,7 +116,7 @@ export default function CookieConsentProvider({ requiresConsent = true, children
|
|
|
116
116
|
// `pathname` still carries the locale prefix (e.g. `/de/privacy-policy`),
|
|
117
117
|
// so match on a trailing segment rather than strict equality.
|
|
118
118
|
useEffect(() => {
|
|
119
|
-
if (privacyPolicyUpdated && privacyPolicyPath !== false && pathname
|
|
119
|
+
if (privacyPolicyUpdated && privacyPolicyPath !== false && pathname?.endsWith(privacyPolicyPath)) {
|
|
120
120
|
acknowledgePrivacyPolicyUpdate();
|
|
121
121
|
}
|
|
122
122
|
}, [pathname, privacyPolicyUpdated, privacyPolicyPath, acknowledgePrivacyPolicyUpdate]);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function clearClientCache(): Promise<void>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export default async function clearClientCache() {
|
|
2
|
+
try {
|
|
3
|
+
if (typeof window !== 'undefined' && 'caches' in window && window.caches) {
|
|
4
|
+
const keys = await caches.keys();
|
|
5
|
+
await Promise.all(keys.map((key) => caches.delete(key)));
|
|
6
|
+
}
|
|
7
|
+
if (typeof navigator !== 'undefined' && 'serviceWorker' in navigator && navigator.serviceWorker) {
|
|
8
|
+
const registrations = await navigator.serviceWorker.getRegistrations();
|
|
9
|
+
await Promise.all(registrations.map((registration) => registration.unregister()));
|
|
10
|
+
}
|
|
11
|
+
if (typeof sessionStorage !== 'undefined') {
|
|
12
|
+
sessionStorage.clear();
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
// best-effort cleanup, ignore failures
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -7,4 +7,6 @@ export { default as installGlobalErrorOverride } from './install_global_error_ov
|
|
|
7
7
|
export { default as stringifyUnknown } from './stringify_unknown';
|
|
8
8
|
export { default as formatErrorMessage } from './format_error_message';
|
|
9
9
|
export { defaultIgnoredConsoleErrors } from './default_ignored_console_errors';
|
|
10
|
+
export { default as isStaleDeployError, defaultStaleDeployPatterns, setStaleDeployPatterns, getStaleDeployPatterns, } from './is_stale_deploy_error';
|
|
11
|
+
export { default as clearClientCache } from './clear_client_cache';
|
|
10
12
|
export type { ErrorHandlingParams, ErrorHandlingRoutingConfig } from '../types/types';
|
|
@@ -5,3 +5,5 @@ export { default as installGlobalErrorOverride } from './install_global_error_ov
|
|
|
5
5
|
export { default as stringifyUnknown } from './stringify_unknown';
|
|
6
6
|
export { default as formatErrorMessage } from './format_error_message';
|
|
7
7
|
export { defaultIgnoredConsoleErrors } from './default_ignored_console_errors';
|
|
8
|
+
export { default as isStaleDeployError, defaultStaleDeployPatterns, setStaleDeployPatterns, getStaleDeployPatterns, } from './is_stale_deploy_error';
|
|
9
|
+
export { default as clearClientCache } from './clear_client_cache';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const defaultStaleDeployPatterns: readonly string[];
|
|
2
|
+
export declare function setStaleDeployPatterns(patterns: readonly string[]): void;
|
|
3
|
+
export declare function getStaleDeployPatterns(): readonly string[];
|
|
4
|
+
export default function isStaleDeployError(error: Error, patterns?: readonly string[]): boolean;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export const defaultStaleDeployPatterns = [
|
|
2
|
+
'chunk',
|
|
3
|
+
'failed to fetch',
|
|
4
|
+
'loading css chunk',
|
|
5
|
+
'connection closed',
|
|
6
|
+
'rsc payload',
|
|
7
|
+
'minified react error #412',
|
|
8
|
+
];
|
|
9
|
+
let activePatterns = defaultStaleDeployPatterns;
|
|
10
|
+
let activeLowercasedPatterns = defaultStaleDeployPatterns.map((p) => p.toLowerCase());
|
|
11
|
+
export function setStaleDeployPatterns(patterns) {
|
|
12
|
+
activePatterns = patterns;
|
|
13
|
+
activeLowercasedPatterns = patterns.map((p) => p.toLowerCase());
|
|
14
|
+
}
|
|
15
|
+
export function getStaleDeployPatterns() {
|
|
16
|
+
return activePatterns;
|
|
17
|
+
}
|
|
18
|
+
export default function isStaleDeployError(error, patterns) {
|
|
19
|
+
if (!error)
|
|
20
|
+
return false;
|
|
21
|
+
if (error.name === 'ChunkLoadError')
|
|
22
|
+
return true;
|
|
23
|
+
const message = (error.message || '').toLowerCase();
|
|
24
|
+
const list = patterns ? patterns.map((p) => p.toLowerCase()) : activeLowercasedPatterns;
|
|
25
|
+
for (let i = 0; i < list.length; i++) {
|
|
26
|
+
if (message.includes(list[i])) {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
@@ -264,6 +264,13 @@ export interface ErrorHandlingRoutingConfig {
|
|
|
264
264
|
* default entirely; pass `[]` to report everything.
|
|
265
265
|
*/
|
|
266
266
|
ignoreConsoleErrors?: readonly string[];
|
|
267
|
+
/**
|
|
268
|
+
* Error message patterns matched by `isStaleDeployError(error)` to detect
|
|
269
|
+
* stale deploy / chunk load errors (e.g. `'chunk'`, `'failed to fetch'`,
|
|
270
|
+
* `'loading css chunk'`, `'connection closed'`, `'rsc payload'`,
|
|
271
|
+
* `'minified react error #412'`). Defaults to `defaultStaleDeployPatterns`.
|
|
272
|
+
*/
|
|
273
|
+
staleDeployPatterns?: readonly string[];
|
|
267
274
|
/**
|
|
268
275
|
* Called with the stringified message of each `console.error(...)` call
|
|
269
276
|
* (only consulted when `overrideConsoleError` is `true`), in addition to
|
package/llms.txt
CHANGED
|
@@ -28,6 +28,10 @@ other subpath can be used.
|
|
|
28
28
|
- `./dbEslint` — flat-config ESLint fragment banning direct `@supabase/supabase-js`, `pg`, `postgres`, and deep `dist/` imports in application code.
|
|
29
29
|
- `./dbHelpers` — generic Drizzle SQL helper functions (`excluded`, `onConflictSet`, `ago`, `currentDate`, `windowCount`, `unnestLateral`, `ascNullsLast`, `alwaysTrue`, `lateral`, `aliasColumn`, `minOf`, `maxOf`, `roundReal`, `multiply`, `scalarFromCte`) for use with `./db`.
|
|
30
30
|
- `./vite` — `buildIdAsset(fileName?)`: Vite plugin to emit the client `BUILD_ID` asset (from `__VINEXT_SHARED_BUILD_ID` or `__VINEXT_BUILD_ID`) during build in Vinext/Vite environments.
|
|
31
|
+
- `./errorHandling` — error reporting & stale deploy recovery barrel: `reportError`, `withErrorHandling`, `installConsoleErrorOverride`, `installGlobalErrorOverride`, `stringifyUnknown`, `formatErrorMessage`, `defaultIgnoredConsoleErrors`, `createServerErrorAction`, `isStaleDeployError`, `defaultStaleDeployPatterns`, `setStaleDeployPatterns`, `getStaleDeployPatterns`, `clearClientCache`.
|
|
32
|
+
- `./isStaleDeployError` — `isStaleDeployError(error, patterns?)`, `setStaleDeployPatterns(patterns)`, `getStaleDeployPatterns()`: detector returning `true` for version skew / chunk load / hydration errors (ChunkLoadError, failed to fetch, loading CSS chunk, connection closed, RSC payload failure, minified error #412) with fast pre-lowercased pattern cache and intl-config integration (`errorHandling.staleDeployPatterns`).
|
|
33
|
+
- `./clearClientCache` — `clearClientCache()`: async helper wiping `window.caches`, unregistering service workers, and clearing `sessionStorage` for recovering from stale deployments.
|
|
34
|
+
- `./createServerErrorAction` — `createServerErrorAction(action, config)`: wrapper for server actions with standardized error reporting.
|
|
31
35
|
|
|
32
36
|
## `firebaseAuth*` subpaths (require `firebaseAuth` set on your `RoutingConfig`)
|
|
33
37
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cloudflare-next-intl",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.44",
|
|
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",
|
|
@@ -190,6 +190,14 @@
|
|
|
190
190
|
"types": "./dist/src/error_handling/create_server_error_action.d.ts",
|
|
191
191
|
"import": "./dist/src/error_handling/create_server_error_action.js"
|
|
192
192
|
},
|
|
193
|
+
"./isStaleDeployError": {
|
|
194
|
+
"types": "./dist/src/error_handling/is_stale_deploy_error.d.ts",
|
|
195
|
+
"import": "./dist/src/error_handling/is_stale_deploy_error.js"
|
|
196
|
+
},
|
|
197
|
+
"./clearClientCache": {
|
|
198
|
+
"types": "./dist/src/error_handling/clear_client_cache.d.ts",
|
|
199
|
+
"import": "./dist/src/error_handling/clear_client_cache.js"
|
|
200
|
+
},
|
|
193
201
|
"./db": {
|
|
194
202
|
"types": "./dist/src/db/index.d.ts",
|
|
195
203
|
"import": "./dist/src/db/index.js"
|