@djangocfg/layouts 2.1.665 → 2.1.667
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 +14 -14
- package/src/components/errors/ErrorsTracker/providers/ErrorTrackingProvider.test.tsx +51 -0
- package/src/components/errors/ErrorsTracker/providers/ErrorTrackingProvider.tsx +1 -1
- package/src/components/errors/ErrorsTracker/types.ts +2 -0
- package/src/components/errors/ErrorsTracker/utils/formatters.ts +6 -0
- package/src/layouts/AppLayout/BaseApp.tsx +5 -1
- package/src/snippets/Analytics/AnalyticsProvider.tsx +4 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@djangocfg/layouts",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.667",
|
|
4
4
|
"description": "Simple, straightforward layout components for Next.js - import and use with props",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"layouts",
|
|
@@ -91,12 +91,12 @@
|
|
|
91
91
|
"test": "vitest run"
|
|
92
92
|
},
|
|
93
93
|
"peerDependencies": {
|
|
94
|
-
"@djangocfg/analytics": "^2.1.
|
|
95
|
-
"@djangocfg/api": "^2.1.
|
|
96
|
-
"@djangocfg/devtools": "^2.1.
|
|
97
|
-
"@djangocfg/i18n": "^2.1.
|
|
98
|
-
"@djangocfg/realtime": "^2.1.
|
|
99
|
-
"@djangocfg/ui-core": "^2.1.
|
|
94
|
+
"@djangocfg/analytics": "^2.1.667",
|
|
95
|
+
"@djangocfg/api": "^2.1.667",
|
|
96
|
+
"@djangocfg/devtools": "^2.1.667",
|
|
97
|
+
"@djangocfg/i18n": "^2.1.667",
|
|
98
|
+
"@djangocfg/realtime": "^2.1.667",
|
|
99
|
+
"@djangocfg/ui-core": "^2.1.667",
|
|
100
100
|
"@hookform/resolvers": "^5.2.2 || ^7.0.2",
|
|
101
101
|
"@tanstack/react-query": "^5.108.2",
|
|
102
102
|
"consola": "^3.4.2",
|
|
@@ -123,13 +123,13 @@
|
|
|
123
123
|
"qrcode.react": "^4.2.0"
|
|
124
124
|
},
|
|
125
125
|
"devDependencies": {
|
|
126
|
-
"@djangocfg/analytics": "^2.1.
|
|
127
|
-
"@djangocfg/api": "^2.1.
|
|
128
|
-
"@djangocfg/devtools": "^2.1.
|
|
129
|
-
"@djangocfg/i18n": "^2.1.
|
|
130
|
-
"@djangocfg/realtime": "^2.1.
|
|
131
|
-
"@djangocfg/typescript-config": "^2.1.
|
|
132
|
-
"@djangocfg/ui-core": "^2.1.
|
|
126
|
+
"@djangocfg/analytics": "^2.1.667",
|
|
127
|
+
"@djangocfg/api": "^2.1.667",
|
|
128
|
+
"@djangocfg/devtools": "^2.1.667",
|
|
129
|
+
"@djangocfg/i18n": "^2.1.667",
|
|
130
|
+
"@djangocfg/realtime": "^2.1.667",
|
|
131
|
+
"@djangocfg/typescript-config": "^2.1.667",
|
|
132
|
+
"@djangocfg/ui-core": "^2.1.667",
|
|
133
133
|
"@storybook/react-vite": "^10.6.5",
|
|
134
134
|
"@tanstack/react-query": "5.108.2",
|
|
135
135
|
"@types/node": "^25.9.5",
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import React, { act } from 'react';
|
|
3
|
+
import { createRoot } from 'react-dom/client';
|
|
4
|
+
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
5
|
+
|
|
6
|
+
const { showError } = vi.hoisted(() => ({ showError: vi.fn() }));
|
|
7
|
+
vi.mock('@djangocfg/ui-core/hooks', () => ({ toast: { error: showError } }));
|
|
8
|
+
vi.mock('@djangocfg/devtools', () => ({
|
|
9
|
+
useDebugMode: () => false,
|
|
10
|
+
isProduction: true,
|
|
11
|
+
EventType: { ERROR: 'error', NETWORK_ERROR: 'network_error', JS_ERROR: 'js_error' },
|
|
12
|
+
EventLevel: { WARNING: 'warning', ERROR: 'error' },
|
|
13
|
+
}));
|
|
14
|
+
vi.mock('../components/ErrorToast', () => ({ createErrorToast: vi.fn() }));
|
|
15
|
+
|
|
16
|
+
import { ErrorTrackingProvider } from './ErrorTrackingProvider';
|
|
17
|
+
|
|
18
|
+
(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
|
|
19
|
+
|
|
20
|
+
describe('production diagnostic references', () => {
|
|
21
|
+
afterEach(() => showError.mockClear());
|
|
22
|
+
|
|
23
|
+
it('uses the exact runtime reference in the safe validation and network toasts', () => {
|
|
24
|
+
const host = document.createElement('div');
|
|
25
|
+
const root = createRoot(host);
|
|
26
|
+
act(() => root.render(<ErrorTrackingProvider><div /></ErrorTrackingProvider>));
|
|
27
|
+
try {
|
|
28
|
+
act(() => window.dispatchEvent(new CustomEvent('zod-validation-error', {
|
|
29
|
+
detail: {
|
|
30
|
+
operation: 'GET /test/', method: 'GET', path: '/test/',
|
|
31
|
+
reference: 'ERR-VALIDATION', error: { issues: [{ code: 'invalid_type', path: ['ok'], message: 'private' }] },
|
|
32
|
+
response: { ok: 'private' }, timestamp: new Date(),
|
|
33
|
+
},
|
|
34
|
+
})));
|
|
35
|
+
expect(showError).toHaveBeenCalledWith('Invalid data received', expect.objectContaining({
|
|
36
|
+
description: 'Please try again. Reference: ERR-VALIDATION',
|
|
37
|
+
}));
|
|
38
|
+
|
|
39
|
+
act(() => window.dispatchEvent(new CustomEvent('network-error', {
|
|
40
|
+
detail: { method: 'POST', url: '/test/', reference: 'ERR-NETWORK',
|
|
41
|
+
statusCode: 503, error: 'HTTP 503', timestamp: new Date() },
|
|
42
|
+
})));
|
|
43
|
+
expect(showError).toHaveBeenCalledWith('Server error', expect.objectContaining({
|
|
44
|
+
description: "We're working on it. Reference: ERR-NETWORK",
|
|
45
|
+
}));
|
|
46
|
+
expect(showError).toHaveBeenCalledTimes(2);
|
|
47
|
+
} finally {
|
|
48
|
+
act(() => root.unmount());
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
});
|
|
@@ -173,7 +173,7 @@ export function ErrorTrackingProvider({
|
|
|
173
173
|
duration: toastOptions.duration,
|
|
174
174
|
});
|
|
175
175
|
} else if (!shouldThrottleProdToast(detail.type)) {
|
|
176
|
-
const errorId = generateShortErrorId();
|
|
176
|
+
const errorId = detail.reference || generateShortErrorId();
|
|
177
177
|
const { title, description } = getProductionToast(detail, errorId);
|
|
178
178
|
toast.error(title, { description, duration: config.duration });
|
|
179
179
|
}
|
|
@@ -197,6 +197,12 @@ export function getProductionToast(detail: ErrorDetail, errorId: string): { titl
|
|
|
197
197
|
};
|
|
198
198
|
case 'network': {
|
|
199
199
|
const status = detail.statusCode;
|
|
200
|
+
if (status && status >= 200 && status < 300) {
|
|
201
|
+
return {
|
|
202
|
+
title: 'Invalid server response',
|
|
203
|
+
description: `Please try again. Reference: ${errorId}`,
|
|
204
|
+
};
|
|
205
|
+
}
|
|
200
206
|
if (status && status >= 500) {
|
|
201
207
|
return {
|
|
202
208
|
title: 'Server error',
|
|
@@ -205,7 +205,11 @@ export function BaseApp({
|
|
|
205
205
|
cors={errorTracking?.cors}
|
|
206
206
|
network={errorTracking?.network}
|
|
207
207
|
onError={errorTracking?.onError}
|
|
208
|
-
onMonitorCapture={(d) =>
|
|
208
|
+
onMonitorCapture={(d) => {
|
|
209
|
+
// Devtools owns the generated-client validation and network events.
|
|
210
|
+
// Do not create a second monitoring row.
|
|
211
|
+
if (d.type !== 'validation' && d.type !== 'network') devtools.capture(errorDetailToDevtoolsEvent(d));
|
|
212
|
+
}}
|
|
209
213
|
>
|
|
210
214
|
<ScrollToTop />
|
|
211
215
|
<Devtools {...devtoolsProps} />
|
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
useAnalyticsClient,
|
|
28
28
|
type AnalyticsTransport,
|
|
29
29
|
} from '@djangocfg/analytics';
|
|
30
|
+
import { auth as authStore } from '@djangocfg/api';
|
|
30
31
|
import { setAnalyticsSink, useAuth } from '@djangocfg/api/auth';
|
|
31
32
|
import { useLocaleOptional } from '@djangocfg/i18n';
|
|
32
33
|
|
|
@@ -69,7 +70,9 @@ export function AnalyticsProvider({
|
|
|
69
70
|
const strippedPath = usePathnameWithoutLocale(locale);
|
|
70
71
|
|
|
71
72
|
const transports = useMemo<AnalyticsTransport[]>(() => {
|
|
72
|
-
const list: AnalyticsTransport[] = [
|
|
73
|
+
const list: AnalyticsTransport[] = [
|
|
74
|
+
djangocfg({ getAuthToken: () => authStore.getToken() }),
|
|
75
|
+
];
|
|
73
76
|
if (trackingId) list.push(ga4({ trackingId }));
|
|
74
77
|
return list;
|
|
75
78
|
}, [trackingId]);
|