@djangocfg/layouts 2.1.381 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@djangocfg/layouts",
3
- "version": "2.1.381",
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.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",
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.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",
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",
@@ -1,56 +1,93 @@
1
1
  'use client';
2
2
 
3
3
  import { Boundary } from '@djangocfg/ui-core/components';
4
- import type { BoundaryProps } from '@djangocfg/ui-core/components';
4
+ import type {
5
+ BoundaryProps,
6
+ BoundaryResetDetails,
7
+ } from '@djangocfg/ui-core/components';
5
8
  import { EventLevel, EventType, FrontendMonitor } from '@djangocfg/monitor/client';
9
+ import { useCallback } from 'react';
6
10
  import type { ErrorInfo, ReactNode } from 'react';
7
11
 
8
- export interface MonitorBoundaryProps extends Omit<BoundaryProps, 'onError'> {
9
- /** Optional name forwarded to FrontendMonitor.extra.source for filtering. */
12
+ export interface MonitorBoundaryProps extends Omit<BoundaryProps, 'onError' | 'onReset'> {
13
+ /** Forwarded to FrontendMonitor as `extra.source` so you can filter events by boundary. */
10
14
  name?: string;
11
- /** Additional handler called alongside the monitor capture. */
15
+ /** Additional render-error handler called alongside the monitor capture. */
12
16
  onError?: (error: Error, info: ErrorInfo) => void;
17
+ /** Additional reset handler called alongside the monitor breadcrumb. */
18
+ onReset?: (details: BoundaryResetDetails) => void;
13
19
  /** Disable monitor reporting (still catches and renders fallback). */
14
20
  reportToMonitor?: boolean;
15
21
  children: ReactNode;
16
22
  }
17
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
+
18
63
  /**
19
- * Boundary + auto-reporting to @djangocfg/monitor.
20
- * Use at the page/layout level so unexpected render errors are captured in your backend.
64
+ * `Boundary` + automatic reporting to `@djangocfg/monitor`.
21
65
  *
66
+ * Use at page/layout level so unexpected render errors are captured in your backend.
22
67
  * For widgets you don't want to report (chat, embeds), use `Boundary` from ui-core directly.
23
68
  */
24
69
  export function MonitorBoundary({
25
70
  name,
26
71
  onError,
72
+ onReset,
27
73
  reportToMonitor = true,
28
74
  ...rest
29
75
  }: 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
- />
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],
55
90
  );
91
+
92
+ return <Boundary {...rest} name={name} onError={handleError} onReset={handleReset} />;
56
93
  }