Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add global error boundary for capturing client-side errors #531

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/components/Feedbacks/GlobalErrorBoundary.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Center } from '@chakra-ui/react';
import { ErrorBoundary } from '@sentry/nextjs';
import { ReactElement, ReactNode } from 'react';
import { SuspendedAlert } from './SuspendedAlert';

export const GlobalErrorBoundary = ({ children }: { children: ReactNode | ReactElement }) => {
return (
<ErrorBoundary
fallback={({ error, resetError }) => (
<Center>
<SuspendedAlert
label="Sorry, we've encountered an application error"
error={error}
resetErrorBoundary={resetError}
/>
</Center>
)}
>
{children}
</ErrorBoundary>
);
};
3 changes: 2 additions & 1 deletion src/components/Layout/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Notification } from '@/components/Notification';
import Head from 'next/head';
import { Favicons } from '@/components/Favicons/Favicons';
import { BRAND_NAME_FULL } from '@/config';
import { GlobalErrorBoundary } from '@/components/Feedbacks/GlobalErrorBoundary';

const LandingTabs = dynamic(() => import('@/components/LandingTabs/LandingTabs').then((mod) => mod.LandingTabs), {
ssr: false,
Expand Down Expand Up @@ -38,7 +39,7 @@ export const Layout: FC = ({ children }) => {
<main>
{isLandingPage && <LandingTabs />}
<Container maxW={isLandingPage ? 'container.md' : 'container.xl'} id="main-content">
{children}
<GlobalErrorBoundary>{children}</GlobalErrorBoundary>
</Container>
</main>
{isPrint ? null : <Footer />}
Expand Down
15 changes: 12 additions & 3 deletions src/pages/search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,10 @@ const SearchPage: NextPage = () => {

// generate search string and trigger page transition, also update store
const search = makeSearchParams({ ...params, ...query, sort, p: 1 });
void router.push({ pathname: router.pathname, search }, null, { scroll: false, shallow: true });
void router.push({ pathname: router.pathname, search }, null, {
scroll: false,
shallow: true,
});
};

// On submission handler
Expand All @@ -165,7 +168,10 @@ const SearchPage: NextPage = () => {

// generate a URL search string and trigger a page transition, and update store
const search = makeSearchParams({ ...params, ...query, q, p: 1 });
void router.push({ pathname: router.pathname, search }, null, { scroll: false, shallow: true });
void router.push({ pathname: router.pathname, search }, null, {
scroll: false,
shallow: true,
});
};

// Update the store when we have data
Expand Down Expand Up @@ -193,7 +199,10 @@ const SearchPage: NextPage = () => {
// clear current docs on filter change
clearSelectedDocs();

void router.push({ pathname: router.pathname, search }, null, { scroll: false, shallow: true });
void router.push({ pathname: router.pathname, search }, null, {
scroll: false,
shallow: true,
});
};

const handleToggleExpand = () => {
Expand Down
Loading