fix: refetch data on reconnect

This commit is contained in:
Jannis Mattheis 2025-08-08 10:24:39 +02:00
parent 271f555102
commit d99b42324e
3 changed files with 7 additions and 1 deletions

View File

@ -12,6 +12,7 @@ export class CurrentUser {
private reconnectTimeoutId: number | null = null; private reconnectTimeoutId: number | null = null;
private reconnectTime = 7500; private reconnectTime = 7500;
public loggedIn = false; public loggedIn = false;
public refreshKey = 0;
public authenticating = true; public authenticating = true;
public user: IUser = {name: 'unknown', admin: false, id: -1}; public user: IUser = {name: 'unknown', admin: false, id: -1};
public connectionErrorMessage: string | null = null; public connectionErrorMessage: string | null = null;
@ -22,6 +23,7 @@ export class CurrentUser {
authenticating: observable, authenticating: observable,
user: observable, user: observable,
connectionErrorMessage: observable, connectionErrorMessage: observable,
refreshKey: observable,
}); });
} }

View File

@ -58,6 +58,7 @@ const Layout = observer(() => {
logout, logout,
tryReconnect, tryReconnect,
connectionErrorMessage, connectionErrorMessage,
refreshKey,
}, },
} = useStores(); } = useStores();
const {classes} = useStyles(); const {classes} = useStyles();
@ -84,7 +85,9 @@ const Layout = observer(() => {
<StyledEngineProvider injectFirst> <StyledEngineProvider injectFirst>
<ThemeProvider theme={theme}> <ThemeProvider theme={theme}>
<HashRouter> <HashRouter>
<div> {/* This forces all components to fully rerender including useEffects.
The refreshKey is updated when store data was cleaned and pages should refetch their data. */}
<div key={refreshKey}>
{!connectionErrorMessage ? null : ( {!connectionErrorMessage ? null : (
<ConnectionErrorBanner <ConnectionErrorBanner
height={64} height={64}

View File

@ -40,6 +40,7 @@ export const registerReactions = (stores: StoreMapping) => {
if (!connectionErrorMessage) { if (!connectionErrorMessage) {
clearAll(); clearAll();
loadAll(); loadAll();
stores.currentUser.refreshKey++;
} }
} }
); );