Skip to content

Commit

Permalink
121 add react error boundary to app between navbar (#143)
Browse files Browse the repository at this point in the history
* feat(frontend): install react error boundary

* feat(frontend): ✨ create an error boundary compoennt and add to root layout

* run prettier with tailwind plugin
  • Loading branch information
Magnus Alexander Strømseng authored and GitHub committed Mar 18, 2024
1 parent 04349f8 commit 28332c5
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
12 changes: 12 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"qs": "^6.11.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-error-boundary": "^4.0.13",
"react-markdown": "^9.0.1",
"react-plotly.js": "^2.6.0",
"satellite.js": "^5.0.0",
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export const metadata: Metadata = {
description: "Generated by create next app",
};

import ErrorBoundaryNavigation from "@/components/ErrorBoundaryNavigation";

export default function RootLayout({
children,
}: Readonly<{
Expand All @@ -31,7 +33,9 @@ export default function RootLayout({
disableTransitionOnChange
>
<Navbar />
<main className="flex-grow">{children}</main>
<ErrorBoundaryNavigation>
<main className="flex-grow">{children}</main>
</ErrorBoundaryNavigation>
<Footer />
</ThemeProvider>
</ApolloWrapper>
Expand Down
22 changes: 22 additions & 0 deletions frontend/src/components/ErrorBoundaryNavigation.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"use client";
import React from "react";

import { ErrorBoundary } from "react-error-boundary";

export default function ErrorBoundaryNavigation({
children,
}: {
children: React.ReactNode;
}) {
return (
<ErrorBoundary
fallback={
<div className="flex h-[calc(100vh-36px)] items-center justify-center">
Something went wrong loading this page.
</div>
}
>
{children}
</ErrorBoundary>
);
}

0 comments on commit 28332c5

Please sign in to comment.