Skip to content

Commit 76fa4cd

Browse files
committed
fix: refetch data on reconnect
1 parent 8457222 commit 76fa4cd

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

ui/src/CurrentUser.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export class CurrentUser {
1212
private reconnectTimeoutId: number | null = null;
1313
private reconnectTime = 7500;
1414
public loggedIn = false;
15+
public refreshKey = 0;
1516
public authenticating = true;
1617
public user: IUser = {name: 'unknown', admin: false, id: -1};
1718
public connectionErrorMessage: string | null = null;
@@ -22,6 +23,7 @@ export class CurrentUser {
2223
authenticating: observable,
2324
user: observable,
2425
connectionErrorMessage: observable,
26+
refreshKey: observable,
2527
});
2628
}
2729

ui/src/layout/Layout.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ const Layout = observer(() => {
5858
logout,
5959
tryReconnect,
6060
connectionErrorMessage,
61+
refreshKey,
6162
},
6263
} = useStores();
6364
const {classes} = useStyles();
@@ -84,7 +85,9 @@ const Layout = observer(() => {
8485
<StyledEngineProvider injectFirst>
8586
<ThemeProvider theme={theme}>
8687
<HashRouter>
87-
<div>
88+
{/* This forces all components to fully rerender including useEffects.
89+
The refreshKey is updated when store data was cleaned and pages should refetch their data. */}
90+
<div key={refreshKey}>
8891
{!connectionErrorMessage ? null : (
8992
<ConnectionErrorBanner
9093
height={64}

ui/src/reactions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export const registerReactions = (stores: StoreMapping) => {
4040
if (!connectionErrorMessage) {
4141
clearAll();
4242
loadAll();
43+
stores.currentUser.refreshKey++;
4344
}
4445
}
4546
);

0 commit comments

Comments
 (0)