cloudflare-next-intl 0.9.36 → 0.9.38
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 +28 -0
- package/dist/src/error_handling/create_server_error_action.js +2 -29
- package/dist/src/error_handling/report_client_error_action.d.ts +2 -0
- package/dist/src/error_handling/report_client_error_action.js +6 -0
- package/dist/src/error_handling/report_client_error_core.d.ts +3 -0
- package/dist/src/error_handling/report_client_error_core.js +31 -0
- package/llms.txt +1 -0
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -627,6 +627,34 @@ server-side resolution) on `ErrorHandlingParams` — reporting is skipped
|
|
|
627
627
|
whenever `consent` is set and not `true`, since sending error reports to a
|
|
628
628
|
third party without consent can itself be GDPR-relevant.
|
|
629
629
|
|
|
630
|
+
#### Reporting client-side errors
|
|
631
|
+
|
|
632
|
+
`reportClientError` is a ready-made server action for a client component's
|
|
633
|
+
own `catch`/error boundary — it resolves your `errorHandling`/`generate`
|
|
634
|
+
config through `@intl-config` (the alias `db`/`clearSessionAction` already
|
|
635
|
+
use — see "Setup" above), so there's no wrapper file or setup call beyond
|
|
636
|
+
that alias:
|
|
637
|
+
|
|
638
|
+
```typescript
|
|
639
|
+
// some_client_component.tsx
|
|
640
|
+
"use client";
|
|
641
|
+
import reportClientError from "cloudflare-next-intl/reportClientError";
|
|
642
|
+
|
|
643
|
+
try {
|
|
644
|
+
await riskyClientThing();
|
|
645
|
+
} catch (error) {
|
|
646
|
+
void reportClientError(error, "riskyClientThing");
|
|
647
|
+
}
|
|
648
|
+
```
|
|
649
|
+
|
|
650
|
+
The error is stringified before it crosses the action boundary — no need to
|
|
651
|
+
normalize it into an `Error` yourself first, even a non-`Error` throw or an
|
|
652
|
+
unresolved React reference stub comes through safely — and `isClient: true`
|
|
653
|
+
plus a best-effort `requestContext: { path, userAgent, referer }` (via
|
|
654
|
+
`next/headers`) are attached automatically. Prefer `createServerErrorAction`
|
|
655
|
+
instead if you want config bound explicitly per call rather than resolved
|
|
656
|
+
through `@intl-config`.
|
|
657
|
+
|
|
630
658
|
#### Stale Deploy & Chunk Load Error Recovery
|
|
631
659
|
|
|
632
660
|
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.
|
|
@@ -1,33 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import stringifyUnknown from './stringify_unknown.js';
|
|
3
|
-
async function resolveRequestContext() {
|
|
4
|
-
try {
|
|
5
|
-
const { headers } = await import('next/headers.js');
|
|
6
|
-
const headerList = await headers();
|
|
7
|
-
return {
|
|
8
|
-
path: headerList.get('x-pathname') ?? undefined,
|
|
9
|
-
userAgent: headerList.get('user-agent') ?? undefined,
|
|
10
|
-
referer: headerList.get('referer') ?? undefined,
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
catch {
|
|
14
|
-
return {};
|
|
15
|
-
}
|
|
16
|
-
}
|
|
1
|
+
import { reportClientErrorCore } from './report_client_error_core.js';
|
|
17
2
|
export default function createServerErrorAction(config) {
|
|
18
3
|
return async function reportClientError(error, classOrMethodName, params) {
|
|
19
|
-
|
|
20
|
-
const isPlainParamsObject = typeof params === 'object' && params !== null && !Array.isArray(params);
|
|
21
|
-
const mergedParams = params === undefined
|
|
22
|
-
? { requestContext }
|
|
23
|
-
: isPlainParamsObject
|
|
24
|
-
? { ...params, requestContext }
|
|
25
|
-
: { params, requestContext };
|
|
26
|
-
await reportError(config, {
|
|
27
|
-
error: stringifyUnknown(error, true),
|
|
28
|
-
classOrMethodName,
|
|
29
|
-
params: mergedParams,
|
|
30
|
-
isClient: true,
|
|
31
|
-
});
|
|
4
|
+
await reportClientErrorCore(config, error, classOrMethodName, params);
|
|
32
5
|
};
|
|
33
6
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
'use server';
|
|
2
|
+
import config from '@intl-config';
|
|
3
|
+
import { reportClientErrorCore } from './report_client_error_core.js';
|
|
4
|
+
export default async function reportClientError(error, classOrMethodName, params) {
|
|
5
|
+
await reportClientErrorCore(config, error, classOrMethodName, params);
|
|
6
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ErrorHandlingParams } from '../types/types.js';
|
|
2
|
+
import { type ReportErrorConfig } from './report_error.js';
|
|
3
|
+
export declare function reportClientErrorCore(config: ReportErrorConfig | undefined, error: unknown, classOrMethodName: string, params?: ErrorHandlingParams['params']): Promise<void>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import reportError from './report_error.js';
|
|
2
|
+
import stringifyUnknown from './stringify_unknown.js';
|
|
3
|
+
async function resolveRequestContext() {
|
|
4
|
+
try {
|
|
5
|
+
const { headers } = await import('next/headers.js');
|
|
6
|
+
const headerList = await headers();
|
|
7
|
+
return {
|
|
8
|
+
path: headerList.get('x-pathname') ?? undefined,
|
|
9
|
+
userAgent: headerList.get('user-agent') ?? undefined,
|
|
10
|
+
referer: headerList.get('referer') ?? undefined,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return {};
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export async function reportClientErrorCore(config, error, classOrMethodName, params) {
|
|
18
|
+
const requestContext = await resolveRequestContext();
|
|
19
|
+
const isPlainParamsObject = typeof params === 'object' && params !== null && !Array.isArray(params);
|
|
20
|
+
const mergedParams = params === undefined
|
|
21
|
+
? { requestContext }
|
|
22
|
+
: isPlainParamsObject
|
|
23
|
+
? { ...params, requestContext }
|
|
24
|
+
: { params, requestContext };
|
|
25
|
+
await reportError(config, {
|
|
26
|
+
error: stringifyUnknown(error, true),
|
|
27
|
+
classOrMethodName,
|
|
28
|
+
params: mergedParams,
|
|
29
|
+
isClient: true,
|
|
30
|
+
});
|
|
31
|
+
}
|
package/llms.txt
CHANGED
|
@@ -34,6 +34,7 @@ other subpath can be used.
|
|
|
34
34
|
- `./clearClientCache` — `clearClientCache()`: async helper wiping `window.caches`, unregistering service workers, and clearing `sessionStorage` for recovering from stale deployments.
|
|
35
35
|
- `useStaleDeployRecovery(error, onRecover?, delayMs?)` (client hook, in `./errorHandling`) — once per build id (`localStorage['buildId']`, `sessionStorage` marker), waits `delayMs` (default 5000ms), runs optional `onRecover()` + `clearClientCache()` in parallel, then `window.location.reload()`. Returns whether a reload is pending, so caller renders a loading state instead of error UI. Recovers even past the one-reload cap when `localStorage['buildIdSetAt']` is <60s old (new deploy still settling). `shouldRecoverFromStaleDeploy(error, buildId, marker, recentBuild?)` and `isRecentBuild(setAt, now, windowMs?)` are the pure predicates.
|
|
36
36
|
- `./createServerErrorAction` — `createServerErrorAction(action, config)`: wrapper for server actions with standardized error reporting.
|
|
37
|
+
- `./reportClientError` — `reportClientError(error, classOrMethodName, params?)`: ready-made `"use server"` action reporting a client-originated error, config resolved via `@intl-config` (no per-app wrapper file or setup call needed, unlike `createServerErrorAction`).
|
|
37
38
|
|
|
38
39
|
## `firebaseAuth*` subpaths (require `firebaseAuth` set on your `RoutingConfig`)
|
|
39
40
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cloudflare-next-intl",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.38",
|
|
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",
|
|
@@ -206,6 +206,10 @@
|
|
|
206
206
|
"types": "./dist/src/error_handling/create_server_error_action.d.ts",
|
|
207
207
|
"import": "./dist/src/error_handling/create_server_error_action.js"
|
|
208
208
|
},
|
|
209
|
+
"./reportClientError": {
|
|
210
|
+
"types": "./dist/src/error_handling/report_client_error_action.d.ts",
|
|
211
|
+
"import": "./dist/src/error_handling/report_client_error_action.js"
|
|
212
|
+
},
|
|
209
213
|
"./isStaleDeployError": {
|
|
210
214
|
"types": "./dist/src/error_handling/is_stale_deploy_error.d.ts",
|
|
211
215
|
"import": "./dist/src/error_handling/is_stale_deploy_error.js"
|