diff --git a/client/package.json b/client/package.json index 6a9ac8b6c..ba3362635 100644 --- a/client/package.json +++ b/client/package.json @@ -32,6 +32,7 @@ "react": "^18.2.0", "react-calendar": "^5.0.0", "react-dom": "^18.2.0", + "react-error-boundary": "^4.0.13", "react-firebase-hooks": "^5.1.1", "react-router-dom": "^6.10.0", "react-sweet-state": "^2.7.1", diff --git a/client/src/App.tsx b/client/src/App.tsx index 1b4949b27..f8bf0e4db 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -3,6 +3,8 @@ import queryClient from "services/QueryClient" import { QueryClientProvider } from "@tanstack/react-query" import { AllRoutes } from "./routes/routes" import { AppNavbar } from "components/composite/Navbar/AppNavbar" +import { ErrorBoundary } from "react-error-boundary" +import RefreshNotification from "pages/RefreshNotification/RefreshNotification" function App() { return ( @@ -10,7 +12,14 @@ function App() {
- + } + onError={() => { + window.location.reload() + }} + > + +
diff --git a/client/src/pages/RefreshNotification/RefreshNotification.story.tsx b/client/src/pages/RefreshNotification/RefreshNotification.story.tsx new file mode 100644 index 000000000..0ace63112 --- /dev/null +++ b/client/src/pages/RefreshNotification/RefreshNotification.story.tsx @@ -0,0 +1,12 @@ +import type { Meta, StoryObj } from "@storybook/react" +import RefreshNotification from "./RefreshNotification" +const meta: Meta = { + component: RefreshNotification +} + +export default meta +type Story = StoryObj + +export const DefaultRefreshNotification: Story = { + args: {} +} diff --git a/client/src/pages/RefreshNotification/RefreshNotification.tsx b/client/src/pages/RefreshNotification/RefreshNotification.tsx new file mode 100644 index 000000000..3243ca713 --- /dev/null +++ b/client/src/pages/RefreshNotification/RefreshNotification.tsx @@ -0,0 +1,16 @@ +/** + * Used for if there is a lazy load error due to a chunk not being found + * + * Also catches any unhandled errors + */ +const RefreshNotification = () => { + return ( +
+

+ Something went wrong. Please refresh the page +

+
+ ) +} + +export default RefreshNotification diff --git a/yarn.lock b/yarn.lock index 1717374b1..e77ef0970 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8249,6 +8249,7 @@ __metadata: react: "npm:^18.2.0" react-calendar: "npm:^5.0.0" react-dom: "npm:^18.2.0" + react-error-boundary: "npm:^4.0.13" react-firebase-hooks: "npm:^5.1.1" react-router-dom: "npm:^6.10.0" react-sweet-state: "npm:^2.7.1" @@ -16354,6 +16355,17 @@ __metadata: languageName: node linkType: hard +"react-error-boundary@npm:^4.0.13": + version: 4.0.13 + resolution: "react-error-boundary@npm:4.0.13" + dependencies: + "@babel/runtime": "npm:^7.12.5" + peerDependencies: + react: ">=16.13.1" + checksum: 10c0/6f3e0e4d7669f680ccf49c08c9571519c6e31f04dcfc30a765a7136c7e6fbbbe93423dd5a9fce12107f8166e54133e9dd5c2079a00c7a38201ac811f7a28b8e7 + languageName: node + linkType: hard + "react-firebase-hooks@npm:^5.1.1": version: 5.1.1 resolution: "react-firebase-hooks@npm:5.1.1"