Skip to content

A local-first personal finance app

Add scoped ErrorBoundary to Rules page to contain rendering crashes (#7437)

Trevin Chowc77b4cc22093
diff --git a/packages/desktop-client/src/components/FeatureErrorFallback.tsx b/packages/desktop-client/src/components/FeatureErrorFallback.tsx
new file mode 100644
index 0000000000..39ad484f2a
--- /dev/null
+++ b/packages/desktop-client/src/components/FeatureErrorFallback.tsx
@@ -0,0 +1,51 @@
+import React, { useEffect } from 'react';
+import type { FallbackProps } from 'react-error-boundary';
+import { Trans } from 'react-i18next';
+
+import { Button } from '@actual-app/components/button';
+import { styles } from '@actual-app/components/styles';
+import { Text } from '@actual-app/components/text';
+import { theme } from '@actual-app/components/theme';
+import { View } from '@actual-app/components/view';
+
+export function FeatureErrorFallback({
+ error,
+ resetErrorBoundary,
+}: FallbackProps) {
+ useEffect(() => {
+ console.error(error);
+ }, [error]);
+
+ return (
+ <View
+ style={{
+ flex: 1,
+ justifyContent: 'center',
+ alignItems: 'center',
+ padding: 20,
+ }}
+ >
+ <Text style={{ ...styles.mediumText, color: theme.errorText }}>
+ <Trans>Something went wrong loading this section.</Trans>
+ </Text>
+ {error?.message && (
+ <Text
+ style={{
+ ...styles.smallText,
+ fontFamily: 'monospace',
+ color: theme.errorText,
+ marginTop: 10,
+ maxWidth: 600,
+ textAlign: 'center',
+ userSelect: 'text',
+ }}
+ >
+ {error.message}
+ </Text>
+ )}
+ <Button onPress={resetErrorBoundary} style={{ marginTop: 15 }}>
+ <Trans>Try again</Trans>
+ </Button>
+ </View>
+ );
+}
diff --git a/packages/desktop-client/src/components/FinancesApp.tsx b/packages/desktop-client/src/components/FinancesApp.tsx
index 561984c9a6..75ebf2161e 100644
--- a/packages/desktop-client/src/components/FinancesApp.tsx
+++ b/packages/desktop-client/src/components/FinancesApp.tsx
@@ -1,5 +1,6 @@
import React, { useEffect, useEffectEvent, useRef } from 'react';
import type { ReactElement } from 'react';
+import { ErrorBoundary } from 'react-error-boundary';
import { useTranslation } from 'react-i18next';
import { Navigate, Route, Routes, useHref, useLocation } from 'react-router';
@@ -23,6 +24,7 @@ import { useDispatch, useSelector } from '#redux';
import { UserAccessPage } from './admin/UserAccess/UserAccessPage';
import { BankSyncStatus } from './BankSyncStatus';
import { CommandBar } from './CommandBar';
+import { FeatureErrorFallback } from './FeatureErrorFallback';
import { GlobalKeys } from './GlobalKeys';
import { MobileBankSyncAccountEditPage } from './mobile/banksync/MobileBankSyncAccountEditPage';
import { MobileNavTabs } from './mobile/MobileNavTabs';
@@ -86,6 +88,7 @@ export function FinancesApp() {
const { isNarrowWidth } = useResponsive();
useMetaThemeColor(isNarrowWidth ? theme.mobileViewTheme : undefined);
+ const location = useLocation();
const dispatch = useDispatch();
const { t } = useTranslation();
@@ -286,11 +289,25 @@ export function FinancesApp() {
/>
<Route
path="/rules"
- element={<NarrowAlternate name="Rules" />}
+ element={
+ <ErrorBoundary
+ FallbackComponent={FeatureErrorFallback}
+ resetKeys={[location.pathname]}
+ >
+ <NarrowAlternate name="Rules" />
+ </ErrorBoundary>
+ }
/>
<Route
path="/rules/:id"
- element={<NarrowAlternate name="RuleEdit" />}
+ element={
+ <ErrorBoundary
+ FallbackComponent={FeatureErrorFallback}
+ resetKeys={[location.pathname]}
+ >
+ <NarrowAlternate name="RuleEdit" />
+ </ErrorBoundary>
+ }
/>
<Route
path="/bank-sync"
diff --git a/upcoming-release-notes/7437.md b/upcoming-release-notes/7437.md
new file mode 100644
index 0000000000..ac6be9eb31
--- /dev/null
+++ b/upcoming-release-notes/7437.md
@@ -0,0 +1,6 @@
+---
+category: Enhancements
+authors: [tmchow]
+---
+
+Add scoped ErrorBoundary to Rules page to contain rendering crashes.