Skip to content

Commit 903f525

Browse files
Copilottyler-dane
andcommitted
fix(web): address code review feedback - prevent multiple reloads
Co-authored-by: tyler-dane <[email protected]>
1 parent 8fa48ca commit 903f525

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

packages/web/src/common/hooks/useChunkLoadErrorHandler.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import { useEffect } from "react";
66
*/
77
export const useChunkLoadErrorHandler = () => {
88
useEffect(() => {
9+
let isReloading = false;
10+
911
const handleError = (event: ErrorEvent) => {
12+
if (isReloading) return;
13+
1014
const isChunkLoadError =
1115
event.message?.includes("Loading chunk") ||
1216
event.message?.includes("ChunkLoadError") ||
@@ -20,12 +24,17 @@ export const useChunkLoadErrorHandler = () => {
2024
// Prevent default error handling
2125
event.preventDefault();
2226

27+
// Set flag to prevent multiple reloads
28+
isReloading = true;
29+
2330
// Reload the page to get the new chunks
2431
window.location.reload();
2532
}
2633
};
2734

2835
const handleUnhandledRejection = (event: PromiseRejectionEvent) => {
36+
if (isReloading) return;
37+
2938
const isChunkLoadError =
3039
event.reason?.message?.includes("Loading chunk") ||
3140
event.reason?.name === "ChunkLoadError";
@@ -38,6 +47,9 @@ export const useChunkLoadErrorHandler = () => {
3847
// Prevent default error handling
3948
event.preventDefault();
4049

50+
// Set flag to prevent multiple reloads
51+
isReloading = true;
52+
4153
// Reload the page to get the new chunks
4254
window.location.reload();
4355
}

packages/web/src/common/hooks/useVersionCheck.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ export const useVersionCheck = (): VersionCheckResult => {
4747
const serverVersion = data.version;
4848

4949
// Check if server version differs from current version
50+
// Once an update is detected, we keep showing the indicator
51+
// until the user refreshes to get the new version
5052
if (serverVersion && serverVersion !== CURRENT_VERSION) {
5153
setIsUpdateAvailable(true);
5254
}

0 commit comments

Comments
 (0)