xertica-ui 2.3.0 → 2.4.1
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/CHANGELOG.md +22 -2
- package/README.md +33 -22
- package/bin/cli.ts +136 -47
- package/bin/language-config.ts +5 -8
- package/components/assistant/modern-chat-input/ModernChatInput.tsx +17 -7
- package/components/assistant/xertica-assistant/parts/AssistantConversationList.tsx +1 -3
- package/components/assistant/xertica-assistant/parts/AssistantFeedbackDialog.tsx +13 -3
- package/components/assistant/xertica-assistant/parts/AssistantMessageBubble.tsx +10 -6
- package/components/assistant/xertica-assistant/xertica-assistant.tsx +1 -3
- package/components/blocks/card-patterns/FeatureCardSkeleton.tsx +1 -6
- package/components/blocks/card-patterns/ProfileCard.tsx +1 -3
- package/components/blocks/card-patterns/ProjectCardSkeleton.tsx +1 -6
- package/components/brand/language-selector/language-selector.stories.tsx +1 -4
- package/components/brand/theme-toggle/ThemeToggle.tsx +5 -1
- package/components/brand/xertica-provider/XerticaProvider.tsx +1 -4
- package/components/index.ts +1 -5
- package/components/layout/sidebar/sidebar.tsx +9 -3
- package/components/media/audio-player/AudioPlayer.tsx +4 -2
- package/components/pages/forgot-password-page/ForgotPasswordPage.tsx +188 -188
- package/components/pages/home-content/HomeContent.tsx +55 -55
- package/components/pages/home-page/HomePage.tsx +5 -1
- package/components/pages/login-page/LoginPage.tsx +4 -2
- package/components/pages/reset-password-page/ResetPasswordPage.tsx +7 -3
- package/components/pages/template-content/TemplateContent.tsx +268 -149
- package/components/pages/verify-email-page/VerifyEmailPage.tsx +9 -9
- package/components/shared/error-boundary.stories.tsx +114 -132
- package/components/shared/error-boundary.tsx +150 -154
- package/components/shared/error-fallbacks.tsx +222 -226
- package/components/ui/stats-card/stats-card-skeleton.tsx +1 -3
- package/components/ui/stats-card/stats-card.stories.tsx +18 -0
- package/components/ui/stats-card/stats-card.tsx +18 -2
- package/components.json +512 -892
- package/contexts/AuthContext.tsx +121 -118
- package/contexts/LanguageContext.tsx +1 -2
- package/dist/AssistantChart-BKVtGUKF.js +3383 -0
- package/dist/AssistantChart-WeycT5Pd.cjs +3551 -0
- package/dist/VerifyEmailPage-Bp1XXl3H.cjs +3305 -0
- package/dist/VerifyEmailPage-DGhuIqkb.js +3296 -0
- package/dist/XerticaProvider-BErr83Bg.js +42 -0
- package/dist/XerticaProvider-CwOkHxiT.cjs +44 -0
- package/dist/XerticaXLogo-BX3ueACh.js +255 -0
- package/dist/XerticaXLogo-qBPhwK3g.cjs +260 -0
- package/dist/assistant.cjs.js +1 -1
- package/dist/assistant.es.js +1 -1
- package/dist/brand.cjs.js +2 -2
- package/dist/brand.es.js +2 -2
- package/dist/cli.js +90 -37
- package/dist/components/brand/theme-toggle/ThemeToggle.d.ts +1 -1
- package/dist/components/index.d.ts +1 -1
- package/dist/components/ui/stats-card/stats-card.d.ts +10 -0
- package/dist/index.cjs.js +6 -6
- package/dist/index.es.js +6 -6
- package/dist/layout.cjs.js +1 -1
- package/dist/layout.es.js +1 -1
- package/dist/pages.cjs.js +1 -1
- package/dist/pages.es.js +1 -1
- package/dist/sidebar-B4ZWaMrE.js +792 -0
- package/dist/sidebar-BS1p2V7t.cjs +795 -0
- package/dist/ui.cjs.js +1 -1
- package/dist/ui.es.js +1 -1
- package/dist/xertica-assistant-B1NaSFFj.js +2173 -0
- package/dist/xertica-assistant-CIaUlbIt.cjs +2180 -0
- package/dist/xertica-ui.css +1 -1
- package/docs/architecture-improvements.md +5 -5
- package/docs/architecture.md +16 -10
- package/docs/components/card-patterns.md +19 -17
- package/docs/components/error-boundary.md +201 -191
- package/docs/components/hooks.md +15 -13
- package/docs/components/language-selector.md +20 -16
- package/docs/components/pages.md +323 -309
- package/docs/components/stats-card.md +20 -2
- package/docs/doc-audit.md +12 -11
- package/docs/getting-started.md +41 -28
- package/docs/guidelines.md +14 -12
- package/docs/i18n.md +61 -57
- package/docs/installation.md +268 -267
- package/docs/llms.md +17 -17
- package/docs/state-management.md +17 -17
- package/guidelines/Guidelines.md +17 -14
- package/llms-compact.txt +1 -1
- package/llms-full.txt +11553 -7133
- package/llms.txt +1 -1
- package/package.json +1 -1
- package/styles/xertica/base.css +90 -84
- package/templates/CLAUDE.md +16 -1
- package/templates/guidelines/Guidelines.md +42 -18
- package/templates/package.json +3 -3
- package/templates/src/app/components/AuthGuard.tsx +131 -82
- package/templates/src/features/auth/ui/AuthPageShell.tsx +32 -32
- package/templates/src/features/auth/ui/ForgotPasswordContent.tsx +1 -3
- package/templates/src/features/auth/ui/ResetPasswordContent.tsx +6 -2
- package/templates/src/features/auth/ui/VerifyEmailContent.tsx +2 -6
- package/templates/src/features/home/data/mock.ts +41 -35
- package/templates/src/features/home/ui/HomeContent.tsx +62 -64
- package/templates/src/features/template/ui/CrudTemplate.tsx +1 -4
- package/templates/src/features/template/ui/LoginTemplate.tsx +1 -1
- package/templates/src/features/template/ui/TemplateContent.tsx +28 -20
- package/templates/src/locales/en/pages/templates.json +17 -17
- package/templates/src/locales/es/pages/templates.json +17 -17
- package/templates/src/locales/pt-BR/pages/templates.json +17 -17
- package/templates/src/pages/AssistantPage.tsx +26 -20
- package/templates/src/pages/HomePage.tsx +5 -1
- package/templates/src/shared/error-boundary.tsx +150 -154
- package/templates/src/shared/error-fallbacks.tsx +222 -226
- package/templates/vite.config.ts +12 -9
|
@@ -47,7 +47,7 @@ export function VerifyEmailPage() {
|
|
|
47
47
|
};
|
|
48
48
|
|
|
49
49
|
return (
|
|
50
|
-
<div className="
|
|
50
|
+
<div className="h-screen w-full flex overflow-y-auto">
|
|
51
51
|
{/* Left side - Full background image */}
|
|
52
52
|
<div className="hidden lg:flex lg:flex-1 relative overflow-hidden">
|
|
53
53
|
{/* Background image filling all space */}
|
|
@@ -89,17 +89,13 @@ export function VerifyEmailPage() {
|
|
|
89
89
|
</div>
|
|
90
90
|
|
|
91
91
|
<h2 className="text-sm text-muted-foreground">{t('verifyEmail.heading')}</h2>
|
|
92
|
-
<p className="mt-2 text-muted-foreground">
|
|
93
|
-
{t('verifyEmail.instructionsSent')}
|
|
94
|
-
</p>
|
|
92
|
+
<p className="mt-2 text-muted-foreground">{t('verifyEmail.instructionsSent')}</p>
|
|
95
93
|
<p className="mt-1 text-primary">{email}</p>
|
|
96
94
|
</div>
|
|
97
95
|
|
|
98
96
|
{/* Instructions */}
|
|
99
97
|
<div className="bg-accent rounded-[var(--radius)] p-4 space-y-3">
|
|
100
|
-
<p className="text-muted-foreground">
|
|
101
|
-
{t('verifyEmail.instructions')}
|
|
102
|
-
</p>
|
|
98
|
+
<p className="text-muted-foreground">{t('verifyEmail.instructions')}</p>
|
|
103
99
|
<div className="flex items-start gap-2 text-muted-foreground">
|
|
104
100
|
<CheckCircle2 className="w-4 h-4 mt-0.5 flex-shrink-0 text-[var(--chart-2)]" />
|
|
105
101
|
<span className="text-sm">{t('verifyEmail.checkSpam')}</span>
|
|
@@ -110,7 +106,9 @@ export function VerifyEmailPage() {
|
|
|
110
106
|
{resendSuccess && (
|
|
111
107
|
<div className="bg-[var(--chart-2)]/10 border border-[var(--chart-2)]/20 rounded-[var(--radius)] p-3 flex items-center gap-2">
|
|
112
108
|
<CheckCircle2 className="w-5 h-5 text-[var(--chart-2)] flex-shrink-0" />
|
|
113
|
-
<span className="text-sm text-[var(--chart-2)]">
|
|
109
|
+
<span className="text-sm text-[var(--chart-2)]">
|
|
110
|
+
{t('verifyEmail.resentSuccess')}
|
|
111
|
+
</span>
|
|
114
112
|
</div>
|
|
115
113
|
)}
|
|
116
114
|
|
|
@@ -143,7 +141,9 @@ export function VerifyEmailPage() {
|
|
|
143
141
|
<div className="w-full border-t border-border"></div>
|
|
144
142
|
</div>
|
|
145
143
|
<div className="relative flex justify-center text-sm">
|
|
146
|
-
<span className="bg-muted px-2 text-muted-foreground">
|
|
144
|
+
<span className="bg-muted px-2 text-muted-foreground">
|
|
145
|
+
{t('login.orContinueWith')}
|
|
146
|
+
</span>
|
|
147
147
|
</div>
|
|
148
148
|
</div>
|
|
149
149
|
|
|
@@ -1,132 +1,114 @@
|
|
|
1
|
-
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
-
import React, { useState } from 'react';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
>
|
|
42
|
-
|
|
43
|
-
</
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
export
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
{(['Team table', 'Chart', 'Assistant panel'] as const).map(label => (
|
|
116
|
-
<CrashController
|
|
117
|
-
key={label}
|
|
118
|
-
Boundary={SectionErrorBoundary}
|
|
119
|
-
label={label}
|
|
120
|
-
/>
|
|
121
|
-
))}
|
|
122
|
-
</div>
|
|
123
|
-
),
|
|
124
|
-
parameters: {
|
|
125
|
-
docs: {
|
|
126
|
-
description: {
|
|
127
|
-
story:
|
|
128
|
-
'`SectionErrorBoundary` renders a compact inline fallback. Multiple independent sections on the same page can each fail in isolation.',
|
|
129
|
-
},
|
|
130
|
-
},
|
|
131
|
-
},
|
|
132
|
-
};
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import React, { useState } from 'react';
|
|
3
|
+
import { AppErrorBoundary, PageErrorBoundary, SectionErrorBoundary } from './error-boundary';
|
|
4
|
+
|
|
5
|
+
// ── Crash helper ─────────────────────────────────────────────────────────────
|
|
6
|
+
// A component that throws on the next render when `shouldCrash` is true.
|
|
7
|
+
// Used in every story to demonstrate real boundary behaviour.
|
|
8
|
+
|
|
9
|
+
function Crashable({ shouldCrash, label }: { shouldCrash: boolean; label: string }) {
|
|
10
|
+
if (shouldCrash) throw new Error(`Simulated crash in: ${label}`);
|
|
11
|
+
return (
|
|
12
|
+
<div className="flex items-center justify-center p-8 rounded-[var(--radius-lg)] border border-border bg-card text-card-foreground">
|
|
13
|
+
<p className="text-sm text-muted-foreground">
|
|
14
|
+
✅ <strong>{label}</strong> — rendering normally. Click the button to simulate a crash.
|
|
15
|
+
</p>
|
|
16
|
+
</div>
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// ── Wrapper that controls crash state ────────────────────────────────────────
|
|
21
|
+
|
|
22
|
+
function CrashController({
|
|
23
|
+
Boundary,
|
|
24
|
+
label,
|
|
25
|
+
}: {
|
|
26
|
+
Boundary: React.ComponentType<{ children: React.ReactNode }>;
|
|
27
|
+
label: string;
|
|
28
|
+
}) {
|
|
29
|
+
const [crashed, setCrashed] = useState(false);
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<div className="space-y-4">
|
|
33
|
+
<button
|
|
34
|
+
onClick={() => setCrashed(true)}
|
|
35
|
+
disabled={crashed}
|
|
36
|
+
className="inline-flex items-center px-4 py-2 text-sm rounded-[var(--radius-button)] bg-destructive text-destructive-foreground hover:bg-destructive/90 disabled:opacity-40 disabled:cursor-not-allowed"
|
|
37
|
+
>
|
|
38
|
+
Simulate crash
|
|
39
|
+
</button>
|
|
40
|
+
|
|
41
|
+
<Boundary>
|
|
42
|
+
<Crashable shouldCrash={crashed} label={label} />
|
|
43
|
+
</Boundary>
|
|
44
|
+
</div>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// ── Meta ──────────────────────────────────────────────────────────────────────
|
|
49
|
+
|
|
50
|
+
const meta: Meta = {
|
|
51
|
+
title: 'Shared/ErrorBoundary',
|
|
52
|
+
parameters: {
|
|
53
|
+
layout: 'padded',
|
|
54
|
+
docs: {
|
|
55
|
+
description: {
|
|
56
|
+
component:
|
|
57
|
+
'Three pre-configured ErrorBoundary variants for root, page, and section-level error isolation. Click "Simulate crash" to see each fallback UI.',
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export default meta;
|
|
64
|
+
|
|
65
|
+
// ── Stories ───────────────────────────────────────────────────────────────────
|
|
66
|
+
|
|
67
|
+
export const App: StoryObj = {
|
|
68
|
+
name: 'AppErrorBoundary (root fallback)',
|
|
69
|
+
render: () => <CrashController Boundary={AppErrorBoundary} label="App-level component" />,
|
|
70
|
+
parameters: {
|
|
71
|
+
docs: {
|
|
72
|
+
description: {
|
|
73
|
+
story:
|
|
74
|
+
'`AppErrorBoundary` renders a full-screen fallback using only inline styles — no Tailwind dependency — so it works even if the design system itself fails to load.',
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export const Page: StoryObj = {
|
|
81
|
+
name: 'PageErrorBoundary (route fallback)',
|
|
82
|
+
render: () => <CrashController Boundary={PageErrorBoundary} label="Page component" />,
|
|
83
|
+
parameters: {
|
|
84
|
+
docs: {
|
|
85
|
+
description: {
|
|
86
|
+
story:
|
|
87
|
+
'`PageErrorBoundary` shows a half-height Tailwind-styled fallback. The sidebar, header, and other chrome remain visible — only the page content area is replaced.',
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
export const Section: StoryObj = {
|
|
94
|
+
name: 'SectionErrorBoundary (inline fallback)',
|
|
95
|
+
render: () => (
|
|
96
|
+
<div className="space-y-6 max-w-2xl">
|
|
97
|
+
<p className="text-sm text-muted-foreground">
|
|
98
|
+
Each card below is independently wrapped. Crashing one does not affect the others.
|
|
99
|
+
</p>
|
|
100
|
+
|
|
101
|
+
{(['Team table', 'Chart', 'Assistant panel'] as const).map(label => (
|
|
102
|
+
<CrashController key={label} Boundary={SectionErrorBoundary} label={label} />
|
|
103
|
+
))}
|
|
104
|
+
</div>
|
|
105
|
+
),
|
|
106
|
+
parameters: {
|
|
107
|
+
docs: {
|
|
108
|
+
description: {
|
|
109
|
+
story:
|
|
110
|
+
'`SectionErrorBoundary` renders a compact inline fallback. Multiple independent sections on the same page can each fail in isolation.',
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
};
|
|
@@ -1,154 +1,150 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
|
|
3
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
4
|
-
// ErrorBoundary — reusable class-based error boundary
|
|
5
|
-
//
|
|
6
|
-
// React error boundaries MUST be class components. This is the single base
|
|
7
|
-
// implementation used throughout the app via three pre-configured wrappers:
|
|
8
|
-
//
|
|
9
|
-
// <AppErrorBoundary> — Root level: catches provider/context crashes
|
|
10
|
-
// <PageErrorBoundary> — Route level: catches page-level render errors
|
|
11
|
-
// <SectionErrorBoundary>— Feature level: catches isolated section errors
|
|
12
|
-
//
|
|
13
|
-
// Usage:
|
|
14
|
-
// import { PageErrorBoundary } from '@/components/shared/error-boundary';
|
|
15
|
-
// <PageErrorBoundary><MyPage /></PageErrorBoundary>
|
|
16
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
17
|
-
|
|
18
|
-
// ── Types ─────────────────────────────────────────────────────────────────────
|
|
19
|
-
|
|
20
|
-
export interface FallbackProps {
|
|
21
|
-
error: Error;
|
|
22
|
-
reset: () => void;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
interface ErrorBoundaryProps {
|
|
26
|
-
children: React.ReactNode;
|
|
27
|
-
/** Custom fallback UI. Receives the error and a reset callback. */
|
|
28
|
-
fallback: React.ComponentType<FallbackProps>;
|
|
29
|
-
/**
|
|
30
|
-
* Optional callback fired when an error is caught.
|
|
31
|
-
* Use to log to Sentry, Datadog, etc.
|
|
32
|
-
*/
|
|
33
|
-
onError?: (error: Error, info: React.ErrorInfo) => void;
|
|
34
|
-
/**
|
|
35
|
-
* List of values that, when changed, automatically reset the boundary.
|
|
36
|
-
* Useful for resetting on route changes (pass `location.pathname`).
|
|
37
|
-
*/
|
|
38
|
-
resetKeys?: unknown[];
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
interface ErrorBoundaryState {
|
|
42
|
-
hasError: boolean;
|
|
43
|
-
error: Error | null;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// ── Core class ────────────────────────────────────────────────────────────────
|
|
47
|
-
|
|
48
|
-
export class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundaryState> {
|
|
49
|
-
constructor(props: ErrorBoundaryProps) {
|
|
50
|
-
super(props);
|
|
51
|
-
this.state = { hasError: false, error: null };
|
|
52
|
-
this.reset = this.reset.bind(this);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
static getDerivedStateFromError(error: Error): ErrorBoundaryState {
|
|
56
|
-
return { hasError: true, error };
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
componentDidCatch(error: Error, info: React.ErrorInfo) {
|
|
60
|
-
this.props.onError?.(error, info);
|
|
61
|
-
|
|
62
|
-
if (import.meta.env.DEV) {
|
|
63
|
-
console.group('[ErrorBoundary] Uncaught error');
|
|
64
|
-
console.error(error);
|
|
65
|
-
console.error('Component stack:', info.componentStack);
|
|
66
|
-
console.groupEnd();
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
componentDidUpdate(prevProps: ErrorBoundaryProps) {
|
|
71
|
-
if (!this.state.hasError) return;
|
|
72
|
-
|
|
73
|
-
const { resetKeys } = this.props;
|
|
74
|
-
if (!resetKeys?.length) return;
|
|
75
|
-
|
|
76
|
-
const prevKeys = prevProps.resetKeys ?? [];
|
|
77
|
-
const changed = resetKeys.some((key, i) => key !== prevKeys[i]);
|
|
78
|
-
if (changed) this.reset();
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
reset() {
|
|
82
|
-
this.setState({ hasError: false, error: null });
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
render() {
|
|
86
|
-
const { hasError, error } = this.state;
|
|
87
|
-
const { children, fallback: Fallback } = this.props;
|
|
88
|
-
|
|
89
|
-
if (hasError && error) {
|
|
90
|
-
return <Fallback error={error} reset={this.reset} />;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return children;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// ── Pre-configured variants ───────────────────────────────────────────────────
|
|
98
|
-
// Import the fallbacks from error-fallbacks.tsx to avoid circular deps.
|
|
99
|
-
// These are thin wrappers so callers never need to wire up the fallback prop.
|
|
100
|
-
|
|
101
|
-
import {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
*
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
{children}
|
|
152
|
-
</ErrorBoundary>
|
|
153
|
-
);
|
|
154
|
-
}
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
4
|
+
// ErrorBoundary — reusable class-based error boundary
|
|
5
|
+
//
|
|
6
|
+
// React error boundaries MUST be class components. This is the single base
|
|
7
|
+
// implementation used throughout the app via three pre-configured wrappers:
|
|
8
|
+
//
|
|
9
|
+
// <AppErrorBoundary> — Root level: catches provider/context crashes
|
|
10
|
+
// <PageErrorBoundary> — Route level: catches page-level render errors
|
|
11
|
+
// <SectionErrorBoundary>— Feature level: catches isolated section errors
|
|
12
|
+
//
|
|
13
|
+
// Usage:
|
|
14
|
+
// import { PageErrorBoundary } from '@/components/shared/error-boundary';
|
|
15
|
+
// <PageErrorBoundary><MyPage /></PageErrorBoundary>
|
|
16
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
17
|
+
|
|
18
|
+
// ── Types ─────────────────────────────────────────────────────────────────────
|
|
19
|
+
|
|
20
|
+
export interface FallbackProps {
|
|
21
|
+
error: Error;
|
|
22
|
+
reset: () => void;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface ErrorBoundaryProps {
|
|
26
|
+
children: React.ReactNode;
|
|
27
|
+
/** Custom fallback UI. Receives the error and a reset callback. */
|
|
28
|
+
fallback: React.ComponentType<FallbackProps>;
|
|
29
|
+
/**
|
|
30
|
+
* Optional callback fired when an error is caught.
|
|
31
|
+
* Use to log to Sentry, Datadog, etc.
|
|
32
|
+
*/
|
|
33
|
+
onError?: (error: Error, info: React.ErrorInfo) => void;
|
|
34
|
+
/**
|
|
35
|
+
* List of values that, when changed, automatically reset the boundary.
|
|
36
|
+
* Useful for resetting on route changes (pass `location.pathname`).
|
|
37
|
+
*/
|
|
38
|
+
resetKeys?: unknown[];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
interface ErrorBoundaryState {
|
|
42
|
+
hasError: boolean;
|
|
43
|
+
error: Error | null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// ── Core class ────────────────────────────────────────────────────────────────
|
|
47
|
+
|
|
48
|
+
export class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundaryState> {
|
|
49
|
+
constructor(props: ErrorBoundaryProps) {
|
|
50
|
+
super(props);
|
|
51
|
+
this.state = { hasError: false, error: null };
|
|
52
|
+
this.reset = this.reset.bind(this);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
static getDerivedStateFromError(error: Error): ErrorBoundaryState {
|
|
56
|
+
return { hasError: true, error };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
componentDidCatch(error: Error, info: React.ErrorInfo) {
|
|
60
|
+
this.props.onError?.(error, info);
|
|
61
|
+
|
|
62
|
+
if (import.meta.env.DEV) {
|
|
63
|
+
console.group('[ErrorBoundary] Uncaught error');
|
|
64
|
+
console.error(error);
|
|
65
|
+
console.error('Component stack:', info.componentStack);
|
|
66
|
+
console.groupEnd();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
componentDidUpdate(prevProps: ErrorBoundaryProps) {
|
|
71
|
+
if (!this.state.hasError) return;
|
|
72
|
+
|
|
73
|
+
const { resetKeys } = this.props;
|
|
74
|
+
if (!resetKeys?.length) return;
|
|
75
|
+
|
|
76
|
+
const prevKeys = prevProps.resetKeys ?? [];
|
|
77
|
+
const changed = resetKeys.some((key, i) => key !== prevKeys[i]);
|
|
78
|
+
if (changed) this.reset();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
reset() {
|
|
82
|
+
this.setState({ hasError: false, error: null });
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
render() {
|
|
86
|
+
const { hasError, error } = this.state;
|
|
87
|
+
const { children, fallback: Fallback } = this.props;
|
|
88
|
+
|
|
89
|
+
if (hasError && error) {
|
|
90
|
+
return <Fallback error={error} reset={this.reset} />;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return children;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// ── Pre-configured variants ───────────────────────────────────────────────────
|
|
98
|
+
// Import the fallbacks from error-fallbacks.tsx to avoid circular deps.
|
|
99
|
+
// These are thin wrappers so callers never need to wire up the fallback prop.
|
|
100
|
+
|
|
101
|
+
import { AppErrorFallback, PageErrorFallback, SectionErrorFallback } from './error-fallbacks';
|
|
102
|
+
|
|
103
|
+
interface BoundaryProps {
|
|
104
|
+
children: React.ReactNode;
|
|
105
|
+
onError?: (error: Error, info: React.ErrorInfo) => void;
|
|
106
|
+
resetKeys?: unknown[];
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* `AppErrorBoundary` — root level.
|
|
111
|
+
*
|
|
112
|
+
* Place at the very top of the tree, outside all providers. If something inside
|
|
113
|
+
* the provider stack crashes during setup, this boundary prevents a blank screen.
|
|
114
|
+
*/
|
|
115
|
+
export function AppErrorBoundary({ children, onError, resetKeys }: BoundaryProps) {
|
|
116
|
+
return (
|
|
117
|
+
<ErrorBoundary fallback={AppErrorFallback} onError={onError} resetKeys={resetKeys}>
|
|
118
|
+
{children}
|
|
119
|
+
</ErrorBoundary>
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* `PageErrorBoundary` — route level.
|
|
125
|
+
*
|
|
126
|
+
* Wrap `<AppRoutes>` / `<AuthGuard>` inside the router. When a lazy page chunk
|
|
127
|
+
* fails to load, or a page component throws, the rest of the app (providers,
|
|
128
|
+
* nav chrome) stays alive and only the page area shows the error UI.
|
|
129
|
+
*/
|
|
130
|
+
export function PageErrorBoundary({ children, onError, resetKeys }: BoundaryProps) {
|
|
131
|
+
return (
|
|
132
|
+
<ErrorBoundary fallback={PageErrorFallback} onError={onError} resetKeys={resetKeys}>
|
|
133
|
+
{children}
|
|
134
|
+
</ErrorBoundary>
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* `SectionErrorBoundary` — feature/section level.
|
|
140
|
+
*
|
|
141
|
+
* Use around individual sections within a page (e.g., a data table, a chart,
|
|
142
|
+
* the assistant panel). An error in one section does not crash the entire page.
|
|
143
|
+
*/
|
|
144
|
+
export function SectionErrorBoundary({ children, onError, resetKeys }: BoundaryProps) {
|
|
145
|
+
return (
|
|
146
|
+
<ErrorBoundary fallback={SectionErrorFallback} onError={onError} resetKeys={resetKeys}>
|
|
147
|
+
{children}
|
|
148
|
+
</ErrorBoundary>
|
|
149
|
+
);
|
|
150
|
+
}
|