Skip to content

Commit

Permalink
fix: An error in the client causes a white screen crash.
Browse files Browse the repository at this point in the history
Signed-off-by: The1111mp <[email protected]>
  • Loading branch information
1111mp committed Nov 19, 2023
1 parent 63bf8a2 commit c1c597e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
15 changes: 15 additions & 0 deletions src/renderer/components/ErrorBoundary/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Result } from 'antd';
import { useRouteError } from 'react-router-dom';

export function ErrorBoundary() {
let error = useRouteError();

return (
<Result
status="error"
title="Sorry, something went wrong."
subTitle={(error as any).message}
style={{marginTop: 100}}
/>
);
}
18 changes: 12 additions & 6 deletions src/renderer/pages/versions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,19 @@ dayjs.extend(localizedFormat);
const { Title } = Typography;

export async function loader() {
const versions = Promise.all([
window.Context.getAllNodeVersions(),
window.Context.getInstalledNodeVersions(),
window.Context.getCurrentVersion(),
]);
try {
const versions = Promise.all([
window.Context.getAllNodeVersions(),
window.Context.getInstalledNodeVersions(),
window.Context.getCurrentVersion(),
]).catch((_err) => {
return [[], [], ''];
});

return defer({ versions: versions });
return defer({ versions: versions });
} catch (err) {
return defer({ versions: [[], [], ''] });
}
}

export function VersionsRoute() {
Expand Down
4 changes: 4 additions & 0 deletions src/renderer/routes.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createMemoryRouter } from 'react-router-dom';

import Home from './pages/home';
import { ErrorBoundary } from './components/ErrorBoundary';
import { VersionsRoute, loader as VersionsLoader } from './pages/versions';

import type { RouteObject } from 'react-router-dom';
Expand All @@ -14,14 +15,17 @@ const routes: RouteObject[] = [
path: 'all',
loader: VersionsLoader,
element: <VersionsRoute />,
errorElement: <ErrorBoundary />,
},
{
path: 'installed',
lazy: () => import('./pages/installed'),
errorElement: <ErrorBoundary />,
},
{
path: 'projects',
lazy: () => import('./pages/projects'),
errorElement: <ErrorBoundary />,
},
],
},
Expand Down

0 comments on commit c1c597e

Please sign in to comment.