@djangocfg/layouts 2.1.659 → 2.1.660

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.659",
3
+ "version": "2.1.660",
4
4
  "description": "Simple, straightforward layout components for Next.js - import and use with props",
5
5
  "keywords": [
6
6
  "layouts",
@@ -91,11 +91,11 @@
91
91
  "test": "vitest run"
92
92
  },
93
93
  "peerDependencies": {
94
- "@djangocfg/analytics": "^2.1.659",
95
- "@djangocfg/api": "^2.1.659",
96
- "@djangocfg/devtools": "^2.1.659",
97
- "@djangocfg/i18n": "^2.1.659",
98
- "@djangocfg/ui-core": "^2.1.659",
94
+ "@djangocfg/analytics": "^2.1.660",
95
+ "@djangocfg/api": "^2.1.660",
96
+ "@djangocfg/devtools": "^2.1.660",
97
+ "@djangocfg/i18n": "^2.1.660",
98
+ "@djangocfg/ui-core": "^2.1.660",
99
99
  "@hookform/resolvers": "^5.2.2 || ^7.0.2",
100
100
  "consola": "^3.4.2",
101
101
  "lucide-react": "^1.68.0",
@@ -123,12 +123,12 @@
123
123
  "qrcode.react": "^4.2.0"
124
124
  },
125
125
  "devDependencies": {
126
- "@djangocfg/analytics": "^2.1.659",
127
- "@djangocfg/api": "^2.1.659",
128
- "@djangocfg/devtools": "^2.1.659",
129
- "@djangocfg/i18n": "^2.1.659",
130
- "@djangocfg/typescript-config": "^2.1.659",
131
- "@djangocfg/ui-core": "^2.1.659",
126
+ "@djangocfg/analytics": "^2.1.660",
127
+ "@djangocfg/api": "^2.1.660",
128
+ "@djangocfg/devtools": "^2.1.660",
129
+ "@djangocfg/i18n": "^2.1.660",
130
+ "@djangocfg/typescript-config": "^2.1.660",
131
+ "@djangocfg/ui-core": "^2.1.660",
132
132
  "@storybook/react-vite": "^10.6.5",
133
133
  "@types/node": "^25.9.5",
134
134
  "@types/react": "19.3.0",
@@ -7,6 +7,8 @@ import type {
7
7
  } from '@djangocfg/ui-core/components';
8
8
  import { EventLevel, EventType, devtools } from '@djangocfg/devtools';
9
9
  import { useCallback } from 'react';
10
+
11
+ import { reportRenderError } from './reportRenderError';
10
12
  import type { ErrorInfo, ReactNode } from 'react';
11
13
 
12
14
  export interface MonitorBoundaryProps extends Omit<BoundaryProps, 'onError' | 'onReset'> {
@@ -26,21 +28,7 @@ function currentUrl(): string | undefined {
26
28
  }
27
29
 
28
30
  function reportError(name: string | undefined, error: Error, info: ErrorInfo): void {
29
- try {
30
- devtools.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
- }
31
+ reportRenderError(name ?? 'boundary', error, info);
44
32
  }
45
33
 
46
34
  function reportReset(name: string | undefined, details: BoundaryResetDetails): void {
@@ -0,0 +1,36 @@
1
+ import { beforeEach, describe, expect, it, vi } from 'vitest';
2
+
3
+ const capture = vi.fn();
4
+ const flush = vi.fn();
5
+ vi.mock('@djangocfg/devtools', () => ({
6
+ EventLevel: { ERROR: 'error' },
7
+ EventType: { ERROR: 'ERROR' },
8
+ devtools: { capture: (...a: unknown[]) => capture(...a), flush: () => flush() },
9
+ }));
10
+
11
+ import { reportRenderError } from './reportRenderError';
12
+
13
+ describe('reportRenderError', () => {
14
+ beforeEach(() => {
15
+ capture.mockReset();
16
+ flush.mockReset();
17
+ });
18
+
19
+ it('captures a render TypeError with its stack and component stack, then flushes', () => {
20
+ const err = new TypeError("Cannot read properties of undefined (reading 'x')");
21
+ reportRenderError('app', err, { componentStack: '\n in Page' } as never);
22
+ expect(capture).toHaveBeenCalledTimes(1);
23
+ const event = capture.mock.calls[0][0];
24
+ expect(event.message).toContain('Cannot read properties');
25
+ expect(event.stack_trace).toBe(err.stack);
26
+ expect(event.extra).toMatchObject({ source: 'app', errorName: 'TypeError', componentStack: '\n in Page' });
27
+ expect(flush).toHaveBeenCalledTimes(1);
28
+ });
29
+
30
+ it('never throws when devtools does', () => {
31
+ capture.mockImplementation(() => {
32
+ throw new Error('devtools down');
33
+ });
34
+ expect(() => reportRenderError('app', new Error('x'))).not.toThrow();
35
+ });
36
+ });
@@ -0,0 +1,34 @@
1
+ import type { ErrorInfo } from 'react';
2
+
3
+ import { EventLevel, EventType, devtools } from '@djangocfg/devtools';
4
+
5
+ /**
6
+ * Send a render error caught by an error boundary to the backend monitor.
7
+ *
8
+ * A boundary swallows the error: React renders the fallback and the exception
9
+ * never reaches `window.onerror`, so devtools' global capture cannot see it. This
10
+ * is the one place that reports it. It queues the event and flushes at once (the
11
+ * fallback's "Reload" can unload the page before the 5 s timer fires); the flush
12
+ * on `visibilitychange: hidden` still goes out with keepalive.
13
+ *
14
+ * Never throws: monitoring must not crash the boundary.
15
+ */
16
+ export function reportRenderError(source: string, error: Error, info?: ErrorInfo): void {
17
+ try {
18
+ devtools.capture({
19
+ event_type: EventType.ERROR,
20
+ level: EventLevel.ERROR,
21
+ message: error.message || 'Unhandled React render error',
22
+ stack_trace: error.stack,
23
+ url: typeof window !== 'undefined' ? window.location.href : undefined,
24
+ extra: {
25
+ source,
26
+ componentStack: info?.componentStack,
27
+ errorName: error.name,
28
+ },
29
+ });
30
+ devtools.flush();
31
+ } catch {
32
+ // ignore
33
+ }
34
+ }
@@ -56,6 +56,7 @@ import { RouteProgressProvider } from '@djangocfg/ui-core/route-progress';
56
56
  import { NextIntlLinkBridge } from './NextIntlLinkBridge';
57
57
  import { ThemeProvider } from '@djangocfg/ui-core/theme';
58
58
  import { AppErrorFallback } from '../../components/errors/AppErrorFallback';
59
+ import { reportRenderError } from '../../components/errors/reportRenderError';
59
60
  import { ErrorTrackingProvider } from '../../components/errors/ErrorsTracker';
60
61
  import { AnalyticsProvider } from '../../snippets/Analytics';
61
62
  import { AuthDialog } from '../../snippets/AuthDialog';
@@ -158,7 +159,12 @@ export function BaseApp({
158
159
  <UiProviders
159
160
  debug={debug}
160
161
  errorBoundary={enableErrorBoundary ? undefined : false}
161
- onError={errorBoundary?.onError}
162
+ onError={(error, info) => {
163
+ // The boundary swallows the error, so devtools' window.onerror never sees it:
164
+ // report it here, then let the host's own handler run.
165
+ reportRenderError('app-boundary', error, info);
166
+ errorBoundary?.onError?.(error, info);
167
+ }}
162
168
  errorFallback={
163
169
  enableErrorBoundary
164
170
  ? () => <AppErrorFallback supportEmail={errorBoundary?.supportEmail} />