Skip to content

Commit 9ae9734

Browse files
committed
feat: add reload page when cached modules
1 parent 770b5cf commit 9ae9734

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

src/client/error/DashboardErrorBoundary.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1+
import { useRouteError } from 'react-router-dom';
12
import GenericError from './GenericError';
3+
import ReloadPage from './ReloadPage';
24

35
export default function DashboardErrorBoundary(props: Record<string, any>) {
6+
const error = useRouteError();
7+
if (error instanceof Error && error.message.startsWith('Failed to fetch dynamically imported module:')) {
8+
return <ReloadPage />;
9+
}
10+
411
return (
512
<GenericError
613
title='Dashboard Client Error'

src/client/error/ReloadPage.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { Button, Collapse, Container, Text, Title } from '@mantine/core';
2+
import { IconReload } from '@tabler/icons-react';
3+
import GenericError from './GenericError';
4+
import { useState } from 'react';
5+
6+
export default function ReloadPage() {
7+
const [view, setView] = useState(false);
8+
9+
return (
10+
<Container my='lg'>
11+
<Title order={3}>Update available</Title>
12+
13+
<Text size='lg'>A new version of the app is available. Please reload the page to update.</Text>
14+
15+
<Button leftSection={<IconReload size='1rem' />} mr='sm' mt='md' onClick={() => window.location.reload()}>
16+
Reload Page
17+
</Button>
18+
19+
<Button variant='subtle' mt='md' onClick={() => setView((v) => !v)}>
20+
Why am I seeing this?
21+
</Button>
22+
23+
<Collapse in={view}>
24+
<GenericError
25+
title='Failed to fetch dynamically imported module'
26+
message='This error can occur when a new version of the app is deployed while you have the page open. Please reload the page to update to the latest version.'
27+
details={{}}
28+
/>
29+
</Collapse>
30+
</Container>
31+
);
32+
}

0 commit comments

Comments
 (0)