Skip to content

Commit

Permalink
feat: add root-level error fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
stdavis committed Nov 29, 2024
1 parent 12d0fb5 commit afbff8c
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import '@arcgis/core/assets/esri/themes/light/main.css';
import React from 'react';
import { createRoot } from 'react-dom/client';
import { ErrorBoundary } from 'react-error-boundary';
import App from './App';
import { AnalyticsProvider, FirebaseAppProvider, MapProvider } from './components/contexts';
import './index.css';
Expand All @@ -19,14 +20,30 @@ if (import.meta.env.VITE_FIREBASE_CONFIG) {
firebaseConfig = JSON.parse(import.meta.env.VITE_FIREBASE_CONFIG);
}

const MainErrorFallback = ({ error, resetErrorBoundary }: { error: Error; resetErrorBoundary: () => void }) => {
return (
<div className="static flex h-screen w-screen items-center justify-center">
<div className="flex-col items-center">
<h1>Something went wrong</h1>
<pre style={{ color: 'red' }}>{error.message}</pre>
<button className="w-full rounded-full border p-1" onClick={resetErrorBoundary}>
Try again
</button>
</div>
</div>
);
};

createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<FirebaseAppProvider firebaseConfig={firebaseConfig}>
<AnalyticsProvider>
<MapProvider>
<App />
</MapProvider>
</AnalyticsProvider>
</FirebaseAppProvider>
<ErrorBoundary FallbackComponent={MainErrorFallback} onReset={() => window.location.reload()}>
<FirebaseAppProvider firebaseConfig={firebaseConfig}>
<AnalyticsProvider>
<MapProvider>
<App />
</MapProvider>
</AnalyticsProvider>
</FirebaseAppProvider>
</ErrorBoundary>
</React.StrictMode>,
);

0 comments on commit afbff8c

Please sign in to comment.