@djangocfg/layouts 2.1.380 → 2.1.382
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 +30 -0
- package/package.json +17 -17
- package/src/components/errors/MonitorBoundary.tsx +93 -0
- package/src/components/errors/index.ts +2 -0
package/README.md
CHANGED
|
@@ -126,6 +126,36 @@ When `routing` is set, `BaseApp` mounts a locale-aware `<Link>` adapter so every
|
|
|
126
126
|
|
|
127
127
|
`baseApp.project` enables `window.monitor`. Debug panel: `Cmd+D` or `?debug=1`.
|
|
128
128
|
|
|
129
|
+
### `MonitorBoundary`
|
|
130
|
+
|
|
131
|
+
Error boundary that automatically reports caught errors to `@djangocfg/monitor`. Use at page/layout level so unexpected render errors land in your backend dashboard.
|
|
132
|
+
|
|
133
|
+
```tsx
|
|
134
|
+
import { MonitorBoundary } from '@djangocfg/layouts';
|
|
135
|
+
|
|
136
|
+
export default function Layout({ children }) {
|
|
137
|
+
return (
|
|
138
|
+
<MonitorBoundary variant="fullscreen" name="root-layout">
|
|
139
|
+
{children}
|
|
140
|
+
</MonitorBoundary>
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Per-section, non-fatal:
|
|
145
|
+
<MonitorBoundary variant="card" name="dashboard-stats" resetKeys={[pathname]}>
|
|
146
|
+
<StatsPanel />
|
|
147
|
+
</MonitorBoundary>
|
|
148
|
+
|
|
149
|
+
// Opt out of reporting (e.g. third-party iframe noise):
|
|
150
|
+
<MonitorBoundary reportToMonitor={false} variant="silent">
|
|
151
|
+
<EmbeddedWidget />
|
|
152
|
+
</MonitorBoundary>
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Wraps `Boundary` from `@djangocfg/ui-core` — same `variant`/`fallback`/`resetKeys` API, plus auto `FrontendMonitor.capture(...)`.
|
|
156
|
+
|
|
157
|
+
For local UI widgets that should not report to backend, use `Boundary` from `@djangocfg/ui-core` directly.
|
|
158
|
+
|
|
129
159
|
---
|
|
130
160
|
|
|
131
161
|
## Package exports
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@djangocfg/layouts",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.382",
|
|
4
4
|
"description": "Simple, straightforward layout components for Next.js - import and use with props",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"layouts",
|
|
@@ -84,13 +84,13 @@
|
|
|
84
84
|
"check": "tsc --noEmit"
|
|
85
85
|
},
|
|
86
86
|
"peerDependencies": {
|
|
87
|
-
"@djangocfg/api": "^2.1.
|
|
88
|
-
"@djangocfg/centrifugo": "^2.1.
|
|
89
|
-
"@djangocfg/debuger": "^2.1.
|
|
90
|
-
"@djangocfg/i18n": "^2.1.
|
|
91
|
-
"@djangocfg/monitor": "^2.1.
|
|
92
|
-
"@djangocfg/ui-core": "^2.1.
|
|
93
|
-
"@djangocfg/ui-nextjs": "^2.1.
|
|
87
|
+
"@djangocfg/api": "^2.1.382",
|
|
88
|
+
"@djangocfg/centrifugo": "^2.1.382",
|
|
89
|
+
"@djangocfg/debuger": "^2.1.382",
|
|
90
|
+
"@djangocfg/i18n": "^2.1.382",
|
|
91
|
+
"@djangocfg/monitor": "^2.1.382",
|
|
92
|
+
"@djangocfg/ui-core": "^2.1.382",
|
|
93
|
+
"@djangocfg/ui-nextjs": "^2.1.382",
|
|
94
94
|
"@hookform/resolvers": "^5.2.2",
|
|
95
95
|
"consola": "^3.4.2",
|
|
96
96
|
"lucide-react": "^0.545.0",
|
|
@@ -121,15 +121,15 @@
|
|
|
121
121
|
"uuid": "^11.1.0"
|
|
122
122
|
},
|
|
123
123
|
"devDependencies": {
|
|
124
|
-
"@djangocfg/api": "^2.1.
|
|
125
|
-
"@djangocfg/centrifugo": "^2.1.
|
|
126
|
-
"@djangocfg/debuger": "^2.1.
|
|
127
|
-
"@djangocfg/i18n": "^2.1.
|
|
128
|
-
"@djangocfg/monitor": "^2.1.
|
|
129
|
-
"@djangocfg/typescript-config": "^2.1.
|
|
130
|
-
"@djangocfg/ui-core": "^2.1.
|
|
131
|
-
"@djangocfg/ui-nextjs": "^2.1.
|
|
132
|
-
"@djangocfg/ui-tools": "^2.1.
|
|
124
|
+
"@djangocfg/api": "^2.1.382",
|
|
125
|
+
"@djangocfg/centrifugo": "^2.1.382",
|
|
126
|
+
"@djangocfg/debuger": "^2.1.382",
|
|
127
|
+
"@djangocfg/i18n": "^2.1.382",
|
|
128
|
+
"@djangocfg/monitor": "^2.1.382",
|
|
129
|
+
"@djangocfg/typescript-config": "^2.1.382",
|
|
130
|
+
"@djangocfg/ui-core": "^2.1.382",
|
|
131
|
+
"@djangocfg/ui-nextjs": "^2.1.382",
|
|
132
|
+
"@djangocfg/ui-tools": "^2.1.382",
|
|
133
133
|
"@types/node": "^24.7.2",
|
|
134
134
|
"@types/react": "^19.1.0",
|
|
135
135
|
"@types/react-dom": "^19.1.0",
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { Boundary } from '@djangocfg/ui-core/components';
|
|
4
|
+
import type {
|
|
5
|
+
BoundaryProps,
|
|
6
|
+
BoundaryResetDetails,
|
|
7
|
+
} from '@djangocfg/ui-core/components';
|
|
8
|
+
import { EventLevel, EventType, FrontendMonitor } from '@djangocfg/monitor/client';
|
|
9
|
+
import { useCallback } from 'react';
|
|
10
|
+
import type { ErrorInfo, ReactNode } from 'react';
|
|
11
|
+
|
|
12
|
+
export interface MonitorBoundaryProps extends Omit<BoundaryProps, 'onError' | 'onReset'> {
|
|
13
|
+
/** Forwarded to FrontendMonitor as `extra.source` so you can filter events by boundary. */
|
|
14
|
+
name?: string;
|
|
15
|
+
/** Additional render-error handler called alongside the monitor capture. */
|
|
16
|
+
onError?: (error: Error, info: ErrorInfo) => void;
|
|
17
|
+
/** Additional reset handler called alongside the monitor breadcrumb. */
|
|
18
|
+
onReset?: (details: BoundaryResetDetails) => void;
|
|
19
|
+
/** Disable monitor reporting (still catches and renders fallback). */
|
|
20
|
+
reportToMonitor?: boolean;
|
|
21
|
+
children: ReactNode;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function currentUrl(): string | undefined {
|
|
25
|
+
return typeof window !== 'undefined' ? window.location.href : undefined;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function reportError(name: string | undefined, error: Error, info: ErrorInfo): void {
|
|
29
|
+
try {
|
|
30
|
+
FrontendMonitor.capture({
|
|
31
|
+
event_type: EventType.ERROR,
|
|
32
|
+
level: EventLevel.ERROR,
|
|
33
|
+
message: error.message || 'Unhandled React render error',
|
|
34
|
+
stack_trace: error.stack,
|
|
35
|
+
url: currentUrl(),
|
|
36
|
+
extra: {
|
|
37
|
+
source: name ?? 'boundary',
|
|
38
|
+
componentStack: info.componentStack,
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
} catch {
|
|
42
|
+
// Never let monitor failures crash the boundary itself.
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function reportReset(name: string | undefined, details: BoundaryResetDetails): void {
|
|
47
|
+
try {
|
|
48
|
+
FrontendMonitor.capture({
|
|
49
|
+
event_type: EventType.ERROR,
|
|
50
|
+
level: EventLevel.INFO,
|
|
51
|
+
message: `Boundary recovered (${details.reason})`,
|
|
52
|
+
url: currentUrl(),
|
|
53
|
+
extra: {
|
|
54
|
+
source: name ?? 'boundary',
|
|
55
|
+
reason: details.reason,
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
} catch {
|
|
59
|
+
// ignore
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* `Boundary` + automatic reporting to `@djangocfg/monitor`.
|
|
65
|
+
*
|
|
66
|
+
* Use at page/layout level so unexpected render errors are captured in your backend.
|
|
67
|
+
* For widgets you don't want to report (chat, embeds), use `Boundary` from ui-core directly.
|
|
68
|
+
*/
|
|
69
|
+
export function MonitorBoundary({
|
|
70
|
+
name,
|
|
71
|
+
onError,
|
|
72
|
+
onReset,
|
|
73
|
+
reportToMonitor = true,
|
|
74
|
+
...rest
|
|
75
|
+
}: MonitorBoundaryProps) {
|
|
76
|
+
const handleError = useCallback(
|
|
77
|
+
(error: Error, info: ErrorInfo) => {
|
|
78
|
+
if (reportToMonitor) reportError(name, error, info);
|
|
79
|
+
onError?.(error, info);
|
|
80
|
+
},
|
|
81
|
+
[name, onError, reportToMonitor],
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
const handleReset = useCallback(
|
|
85
|
+
(details: BoundaryResetDetails) => {
|
|
86
|
+
if (reportToMonitor) reportReset(name, details);
|
|
87
|
+
onReset?.(details);
|
|
88
|
+
},
|
|
89
|
+
[name, onReset, reportToMonitor],
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
return <Boundary {...rest} name={name} onError={handleError} onReset={handleReset} />;
|
|
93
|
+
}
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
export { ErrorBoundary } from './ErrorBoundary';
|
|
6
|
+
export { MonitorBoundary } from './MonitorBoundary';
|
|
7
|
+
export type { MonitorBoundaryProps } from './MonitorBoundary';
|
|
6
8
|
export { ErrorLayout } from './ErrorLayout';
|
|
7
9
|
export type { ErrorLayoutProps } from './ErrorLayout';
|
|
8
10
|
export { getErrorContent, ERROR_CODES } from './errorConfig';
|