Skip to content

Commit

Permalink
Merge pull request #10781 from DestinyItemManager/error-boundaries
Browse files Browse the repository at this point in the history
Add error boundaries to more places
  • Loading branch information
bhollis authored Nov 4, 2024
2 parents e76b9a6 + 8e4335f commit 660063b
Show file tree
Hide file tree
Showing 12 changed files with 315 additions and 188 deletions.
74 changes: 66 additions & 8 deletions src/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,64 @@ export default function App() {
<ErrorBoundary name="DIM Code">
<Suspense fallback={<ShowPageLoading message={t('Loading.Code')} />}>
<Routes>
<Route path="about" element={<About />} />
<Route path="privacy" element={<Privacy />} />
<Route path="whats-new" element={<WhatsNew />} />
<Route path="login" element={<Login />} />
<Route path="settings" element={<SettingsPage />} />
<Route path="debug" element={<Debug />} />
{$DIM_FLAVOR === 'dev' && <Route path="developer" element={<Developer />} />}
<Route
path="about"
element={
<ErrorBoundary name="about" key="about">
<About />
</ErrorBoundary>
}
/>
<Route
path="privacy"
element={
<ErrorBoundary name="privacy" key="privacy">
<Privacy />
</ErrorBoundary>
}
/>
<Route
path="whats-new"
element={
<ErrorBoundary name="whatsNew" key="whatsNew">
<WhatsNew />
</ErrorBoundary>
}
/>
<Route
path="login"
element={
<ErrorBoundary name="login" key="login">
<Login />
</ErrorBoundary>
}
/>
<Route
path="settings"
element={
<ErrorBoundary name="settings" key="settings">
<SettingsPage />
</ErrorBoundary>
}
/>
<Route
path="debug"
element={
<ErrorBoundary name="debug" key="debug">
<Debug />
</ErrorBoundary>
}
/>
{$DIM_FLAVOR === 'dev' && (
<Route
path="developer"
element={
<ErrorBoundary name="developer" key="developer">
<Developer />
</ErrorBoundary>
}
/>
)}
{needsLogin ? (
<Route
path="*"
Expand All @@ -77,7 +128,14 @@ export default function App() {
/>
) : (
<>
<Route path="search-history" element={<SearchHistory />} />
<Route
path="search-history"
element={
<ErrorBoundary name="searchHistory" key="searchHistory">
<SearchHistory />
</ErrorBoundary>
}
/>
<Route path="armory/*" element={<DefaultAccount />} />
<Route path=":membershipId/:destinyVersion/*" element={<Destiny />} />
<Route path="*" element={<DefaultAccount />} />
Expand Down
6 changes: 2 additions & 4 deletions src/app/bungie-api/bungie-service-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,8 @@ const logThrottle = (timesThrottled: number, waitTime: number, url: string) =>
export const authenticatedHttpClient = dimErrorHandledHttpClient(
responsivelyThrottleHttpClient(
createHttpClient(
createFetchWithNonStoppingTimeout(
rateLimitedFetch(fetchWithBungieOAuth),
TIMEOUT,
notifyTimeout,
rateLimitedFetch(
createFetchWithNonStoppingTimeout(fetchWithBungieOAuth, TIMEOUT, notifyTimeout),
),
API_KEY,
),
Expand Down
5 changes: 4 additions & 1 deletion src/app/dim-ui/CollapsibleTitle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useSelector } from 'react-redux';
import { toggleCollapsedSection } from '../settings/actions';
import { AppIcon, collapseIcon } from '../shell/icons';
import styles from './CollapsibleTitle.m.scss';
import ErrorBoundary from './ErrorBoundary';

export const Title = forwardRef(function Title(
{
Expand Down Expand Up @@ -114,7 +115,9 @@ export default function CollapsibleTitle({
onClick={toggle}
/>
<CollapsedSection collapsed={collapsed} headerId={headerId} contentId={contentId}>
{children}
<ErrorBoundary name={`collapse-${sectionId}`} key={contentId}>
{children}
</ErrorBoundary>
</CollapsedSection>
</>
);
Expand Down
6 changes: 6 additions & 0 deletions src/app/dim-ui/ErrorBoundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ export default class ErrorBoundary extends Component<Props, State> {
reportException(name, error, errorInfo);
}

componentDidUpdate(prevProps: Readonly<Props>): void {
if (prevProps.name !== this.props.name) {
this.setState({ error: undefined });
}
}

render() {
const { error } = this.state;
const { children } = this.props;
Expand Down
7 changes: 6 additions & 1 deletion src/app/dim-ui/PageWithMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import useResizeObserver from '@react-hook/resize-observer';
import clsx from 'clsx';
import React, { useRef, useState } from 'react';
import ErrorBoundary from './ErrorBoundary';
import styles from './PageWithMenu.m.scss';

function PageWithMenu({ children, className }: { children: React.ReactNode; className?: string }) {
Expand Down Expand Up @@ -50,7 +51,11 @@ PageWithMenu.Contents = function Contents({
children: React.ReactNode;
className?: string;
}) {
return <div className={clsx(className, styles.contents)}>{children}</div>;
return (
<div className={clsx(className, styles.contents)}>
<ErrorBoundary name="pageWithMenu-contents">{children}</ErrorBoundary>
</div>
);
};

/** A header for a section of links (MenuButtons) within a Menu. */
Expand Down
5 changes: 4 additions & 1 deletion src/app/dim-ui/Sheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import React, {
useState,
} from 'react';
import { AppIcon, disabledIcon } from '../shell/icons';
import ErrorBoundary from './ErrorBoundary';
import { PressTipRoot } from './PressTip';
import styles from './Sheet.m.scss';
import { useFixOverscrollBehavior } from './useFixOverscrollBehavior';
Expand Down Expand Up @@ -299,7 +300,9 @@ export default function Sheet({
style={frozenHeight ? { flexBasis: frozenHeight } : undefined}
ref={sheetContents}
>
{typeof children === 'function' ? children({ onClose: triggerClose }) : children}
<ErrorBoundary name="sheet-contents">
{typeof children === 'function' ? children({ onClose: triggerClose }) : children}
</ErrorBoundary>
</div>

{Boolean(footer) && (
Expand Down
5 changes: 2 additions & 3 deletions src/app/inventory-page/Inventory.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { DestinyAccount } from 'app/accounts/destiny-account';
import ErrorBoundary from 'app/dim-ui/ErrorBoundary';
import ShowPageLoading from 'app/dim-ui/ShowPageLoading';
import GearPower from 'app/gear-power/GearPower';
import { t } from 'app/i18next-t';
Expand All @@ -18,11 +17,11 @@ export default function Inventory({ account }: { account: DestinyAccount }) {
}

return (
<ErrorBoundary name="Inventory">
<>
<Stores />
<DragPerformanceFix />
{account.destinyVersion === 2 && <GearPower />}
{account.destinyVersion === 2 && <MaterialCountsSheet />}
</ErrorBoundary>
</>
);
}
7 changes: 2 additions & 5 deletions src/app/organizer/Organizer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { DestinyAccount } from 'app/accounts/destiny-account';
import ErrorBoundary from 'app/dim-ui/ErrorBoundary';
import ShowPageLoading from 'app/dim-ui/ShowPageLoading';
import { t } from 'app/i18next-t';
import { useLoadStores } from 'app/inventory/store/hooks';
Expand Down Expand Up @@ -121,10 +120,8 @@ export default function Organizer({ account }: Props) {

return (
<div className={styles.organizer}>
<ErrorBoundary name="Organizer">
<ItemTypeSelector selection={selection} selectionTree={types} onSelection={onSelection} />
<ItemTable categories={selection} />
</ErrorBoundary>
<ItemTypeSelector selection={selection} selectionTree={types} onSelection={onSelection} />
<ItemTable categories={selection} />
</div>
);
}
Loading

0 comments on commit 660063b

Please sign in to comment.