@djangocfg/layouts 2.1.380 → 2.1.381

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 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.380",
3
+ "version": "2.1.381",
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.380",
88
- "@djangocfg/centrifugo": "^2.1.380",
89
- "@djangocfg/debuger": "^2.1.380",
90
- "@djangocfg/i18n": "^2.1.380",
91
- "@djangocfg/monitor": "^2.1.380",
92
- "@djangocfg/ui-core": "^2.1.380",
93
- "@djangocfg/ui-nextjs": "^2.1.380",
87
+ "@djangocfg/api": "^2.1.381",
88
+ "@djangocfg/centrifugo": "^2.1.381",
89
+ "@djangocfg/debuger": "^2.1.381",
90
+ "@djangocfg/i18n": "^2.1.381",
91
+ "@djangocfg/monitor": "^2.1.381",
92
+ "@djangocfg/ui-core": "^2.1.381",
93
+ "@djangocfg/ui-nextjs": "^2.1.381",
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.380",
125
- "@djangocfg/centrifugo": "^2.1.380",
126
- "@djangocfg/debuger": "^2.1.380",
127
- "@djangocfg/i18n": "^2.1.380",
128
- "@djangocfg/monitor": "^2.1.380",
129
- "@djangocfg/typescript-config": "^2.1.380",
130
- "@djangocfg/ui-core": "^2.1.380",
131
- "@djangocfg/ui-nextjs": "^2.1.380",
132
- "@djangocfg/ui-tools": "^2.1.380",
124
+ "@djangocfg/api": "^2.1.381",
125
+ "@djangocfg/centrifugo": "^2.1.381",
126
+ "@djangocfg/debuger": "^2.1.381",
127
+ "@djangocfg/i18n": "^2.1.381",
128
+ "@djangocfg/monitor": "^2.1.381",
129
+ "@djangocfg/typescript-config": "^2.1.381",
130
+ "@djangocfg/ui-core": "^2.1.381",
131
+ "@djangocfg/ui-nextjs": "^2.1.381",
132
+ "@djangocfg/ui-tools": "^2.1.381",
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,56 @@
1
+ 'use client';
2
+
3
+ import { Boundary } from '@djangocfg/ui-core/components';
4
+ import type { BoundaryProps } from '@djangocfg/ui-core/components';
5
+ import { EventLevel, EventType, FrontendMonitor } from '@djangocfg/monitor/client';
6
+ import type { ErrorInfo, ReactNode } from 'react';
7
+
8
+ export interface MonitorBoundaryProps extends Omit<BoundaryProps, 'onError'> {
9
+ /** Optional name forwarded to FrontendMonitor.extra.source for filtering. */
10
+ name?: string;
11
+ /** Additional handler called alongside the monitor capture. */
12
+ onError?: (error: Error, info: ErrorInfo) => void;
13
+ /** Disable monitor reporting (still catches and renders fallback). */
14
+ reportToMonitor?: boolean;
15
+ children: ReactNode;
16
+ }
17
+
18
+ /**
19
+ * Boundary + auto-reporting to @djangocfg/monitor.
20
+ * Use at the page/layout level so unexpected render errors are captured in your backend.
21
+ *
22
+ * For widgets you don't want to report (chat, embeds), use `Boundary` from ui-core directly.
23
+ */
24
+ export function MonitorBoundary({
25
+ name,
26
+ onError,
27
+ reportToMonitor = true,
28
+ ...rest
29
+ }: MonitorBoundaryProps) {
30
+ return (
31
+ <Boundary
32
+ {...rest}
33
+ name={name}
34
+ onError={(error, info) => {
35
+ if (reportToMonitor) {
36
+ try {
37
+ FrontendMonitor.capture({
38
+ event_type: EventType.ERROR,
39
+ level: EventLevel.ERROR,
40
+ message: error.message || 'Unhandled React render error',
41
+ stack_trace: error.stack,
42
+ url: typeof window !== 'undefined' ? window.location.href : undefined,
43
+ extra: {
44
+ source: name ?? 'boundary',
45
+ componentStack: info.componentStack,
46
+ },
47
+ });
48
+ } catch {
49
+ // Never let monitor failures crash the boundary itself.
50
+ }
51
+ }
52
+ onError?.(error, info);
53
+ }}
54
+ />
55
+ );
56
+ }
@@ -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';