fix: trigger disconnected state when chunk loads exhaust retries

When lazyWithRetry exhausts all retry attempts on a chunk error, also
call setDisconnected() so the reconnecting banner appears alongside the
ErrorBoundary's "Update Available" card.
This commit is contained in:
ashim-hq
2026-04-21 00:06:46 +08:00
parent 70f9f3d51d
commit a145ffdc68
+7 -1
View File
@@ -1,4 +1,5 @@
import { type ComponentType, lazy } from "react";
import { useConnectionStore } from "@/stores/connection-store";
export function isChunkError(error: unknown): boolean {
if (!(error instanceof Error)) return false;
@@ -21,7 +22,12 @@ export async function retryDynamicImport<T>(
try {
return await importFn();
} catch (error) {
if (!isChunkError(error) || attempt === retries) throw error;
if (!isChunkError(error) || attempt === retries) {
if (isChunkError(error)) {
useConnectionStore.getState().setDisconnected();
}
throw error;
}
await new Promise((resolve) => setTimeout(resolve, delay));
}
}