fix: Adding guard against double reload

closes #5384
This commit is contained in:
Tom Moor
2023-07-08 10:29:42 -04:00
parent c952dfa065
commit a8674c7dda

View File

@@ -5,6 +5,11 @@ import useIdle from "./useIdle";
import useInterval from "./useInterval"; import useInterval from "./useInterval";
import usePageVisibility from "./usePageVisibility"; import usePageVisibility from "./usePageVisibility";
// The case of isReloaded=true should never be hit as the app will reload
// before the hook is called again, however seems like the only possible
// cause of #5384, adding to debug.
let isReloaded = false;
/** /**
* Hook to reload the app around once a day to stop old code from running. * Hook to reload the app around once a day to stop old code from running.
*/ */
@@ -25,9 +30,14 @@ export default function useAutoRefresh() {
Logger.debug("lifecycle", "Skipping reload due to user activity"); Logger.debug("lifecycle", "Skipping reload due to user activity");
return; return;
} }
if (isReloaded) {
Logger.error("lifecycle", new Error("Attempted to reload twice"));
return;
}
Logger.debug("lifecycle", "Auto-reloading app…"); Logger.debug("lifecycle", "Auto-reloading app…");
window.location.reload(); window.location.reload();
isReloaded = true;
} }
}, Minute); }, Minute);
} }