From 3706bf51af143c627709a848873124c8cc556817 Mon Sep 17 00:00:00 2001
From: Kasper Fabricius Kristensen
<45367945+kasperkristensen@users.noreply.github.com>
Date: Tue, 20 Aug 2024 15:09:30 +0200
Subject: [PATCH] feat(dashboard): Wrap each route in an ErrorBoundary (#8674)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
**What**
- Updates the copy of the different error types
- Wraps each route (+ custom routes) in an ErrorBoundary to preserve app layout on error (sidebar and topbar)

**Note**
If the user goes to a route that does not exist at all, e.g. `/some-weird-url`, then we have no way of knowing if the user is inside of a context where we can render the sidebar and topbar (as they require the user to be authenticated). So in this case we still show an ErrorBoundary where the two aren't included (see second picture), and include a button that takes the user to "/", which depending on whether the user is logged in will take them to "/login" or "/orders".

Resolves CC-248
---
.../src/components/layout/shell/shell.tsx | 15 ++++-
.../error-boundary/error-boundary.tsx | 58 +++++--------------
.../dashboard/src/i18n/translations/en.json | 16 ++---
.../dashboard/src/lib/extension-helpers.ts | 2 +
.../src/providers/router-provider/index.ts | 2 +-
.../providers/router-provider/route-map.tsx | 35 +++++++++--
.../src/routes/no-match/no-match.tsx | 34 ++++++++++-
7 files changed, 106 insertions(+), 56 deletions(-)
diff --git a/packages/admin-next/dashboard/src/components/layout/shell/shell.tsx b/packages/admin-next/dashboard/src/components/layout/shell/shell.tsx
index 626696b3bf..a177e48040 100644
--- a/packages/admin-next/dashboard/src/components/layout/shell/shell.tsx
+++ b/packages/admin-next/dashboard/src/components/layout/shell/shell.tsx
@@ -53,11 +53,24 @@ const Breadcrumbs = () => {
.map((match) => {
const handle = match.handle
+ let label: string | null = null
+
+ try {
+ label = handle.crumb!(match.data)
+ } catch (error) {
+ // noop
+ }
+
+ if (!label) {
+ return null
+ }
+
return {
- label: handle.crumb!(match.data),
+ label: label,
path: match.pathname,
}
})
+ .filter(Boolean) as { label: string; path: string }[]
return (
with ErrorBoundary for more granular error handling.
export const ErrorBoundary = () => {
const error = useRouteError()
const location = useLocation()
@@ -45,47 +43,23 @@ export const ErrorBoundary = () => {
}
return (
-