Skip to content

Commit

Permalink
Merge pull request #380 from bartoval/error_no_route
Browse files Browse the repository at this point in the history
fix(Core UI): 🐞 Routing after an app error is not possible
  • Loading branch information
bartoval authored Feb 17, 2024
2 parents 0309540 + 379bf26 commit d1a5dc3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
18 changes: 6 additions & 12 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import { Suspense } from 'react';

import { Page } from '@patternfly/react-core';
import { QueryErrorResetBoundary } from '@tanstack/react-query';
import { ErrorBoundary } from 'react-error-boundary';
import { AnimatePresence } from 'framer-motion';

import SkBreadcrumb from '@core/components/SkBreadcrumb';
import { getThemePreference, reflectThemePreference } from '@core/utils/isDarkTheme';
import SkHeader from '@layout/Header';
import RouteContainer from '@layout/RouteContainer';
import SkSidebar from '@layout/SideBar';
import ErrorConsole from '@pages/shared/Errors/Console';
import LoadingPage from '@pages/shared/Loading';
import { routes } from 'routes';

Expand All @@ -27,15 +25,11 @@ const App = function () {
isManagedSidebar
isBreadcrumbGrouped
additionalGroupedContent={
<QueryErrorResetBoundary>
{({ reset }) => (
<ErrorBoundary onReset={reset} FallbackComponent={ErrorConsole}>
<Suspense fallback={<LoadingPage />}>
<RouteContainer>{routes}</RouteContainer>
</Suspense>
</ErrorBoundary>
)}
</QueryErrorResetBoundary>
<Suspense fallback={<LoadingPage />}>
<AnimatePresence mode="wait">
<RouteContainer>{routes}</RouteContainer>
</AnimatePresence>
</Suspense>
}
/>
);
Expand Down
16 changes: 13 additions & 3 deletions src/layout/RouteContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
import { AnimatePresence } from 'framer-motion';
import { QueryErrorResetBoundary } from '@tanstack/react-query';
import { ErrorBoundary } from 'react-error-boundary';
import { useRoutes, RouteObject } from 'react-router-dom';

import ErrorConsole from '@pages/shared/Errors/Console';

interface RouteProps {
children: RouteObject[];
}

const RouteContainer = function ({ children: routes }: RouteProps) {
const appRoutes = useRoutes([...routes, { path: '/', element: routes[0].element }]);

if (!appRoutes) {
return null;
}

return <AnimatePresence mode="wait">{appRoutes}</AnimatePresence>;
return (
<QueryErrorResetBoundary>
{({ reset }) => (
<ErrorBoundary key={window.location.hash} onReset={reset} FallbackComponent={ErrorConsole}>
{appRoutes}
</ErrorBoundary>
)}
</QueryErrorResetBoundary>
);
};

export default RouteContainer;

0 comments on commit d1a5dc3

Please sign in to comment.