Skip to content
Merged
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
19 changes: 16 additions & 3 deletions packages/next-common/components/errorBoundary.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
import PartialBoundaryLayout from "next-common/components/layout/partialBoundaryLayout";
import ErrorLayout from "next-common/components/layout/errorLayout";
import { reportClientError } from "next-common/services/reportClientError";
import { CHAIN } from "next-common/utils/constants";
import { CHAIN, IS_PRODUCTION } from "next-common/utils/constants";
import Router from "next/router";

class ErrorBoundary extends React.Component {
constructor(props) {
Expand All @@ -19,18 +20,30 @@ class ErrorBoundary extends React.Component {
return { hasError: true, error };
}

componentDidMount() {
Router.events.on("routeChangeStart", this.resetErrorState);
}

componentWillUnmount() {
Router.events.off("routeChangeStart", this.resetErrorState);
}

componentDidCatch(error, errorInfo) {
const errorData = {
chain: CHAIN,
url: typeof window !== "undefined" ? window.location.href : "",
address: this.props.user?.address,
code: "",
error: error.message,
source: "client",
stack: error.stack,
componentStack: errorInfo.componentStack,
userAgent: window?.navigator?.userAgent || "",
};

reportClientError(errorData);
if (IS_PRODUCTION) {
reportClientError(errorData);
}
}

resetErrorState = () => {
Expand Down Expand Up @@ -70,4 +83,4 @@ class ErrorBoundary extends React.Component {
}
}

export default React.memo(ErrorBoundary);
export default ErrorBoundary;
5 changes: 4 additions & 1 deletion packages/next-common/components/pages/appShell.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { store } from "next-common/store";
import GlobalProvider from "next-common/context/global";
import Head from "next/head";
import SystemVersionUpgrade from "next-common/components/systemVersionUpgrade";
import ErrorBoundary from "next-common/components/errorBoundary";
import dynamic from "next/dynamic";

NProgress.configure({
Expand Down Expand Up @@ -70,7 +71,9 @@ export function AppShell({ Component, pageProps }) {
pathname={pathname}
>
<ClientOnlySystemUpgrade />
<Component {...otherProps} />
<ErrorBoundary user={user}>
<Component {...otherProps} />
</ErrorBoundary>
</GlobalProvider>
</Provider>
{/* </PostHogProvider> */}
Expand Down
Loading