diff --git a/src/lib/lazyWithRetry.ts b/src/lib/lazyWithRetry.ts index ca4c6e9d2..1b627b683 100644 --- a/src/lib/lazyWithRetry.ts +++ b/src/lib/lazyWithRetry.ts @@ -1,16 +1,16 @@ import { lazy, type ComponentType, createElement } from 'react'; -import { logger } from "@/lib/logger"; -import { attemptChunkRecovery, isChunkLoadError, extractChunkUrl } from "@/lib/chunk-recovery"; -import { getFallback } from "@/components/layout/SkeletonLoaders"; +import { logger } from '@/lib/logger'; +import { attemptChunkRecovery, isChunkLoadError } from '@/lib/chunk-recovery'; +import { getFallback } from '@/components/layout/SkeletonLoaders'; /** * Wrapper around React.lazy that retries on chunk loading failures. * Handles stale cache issues after deployments and Vite 502 spikes. */ -export function lazyWithRetry>( +export function lazyWithRetry>( componentImport: () => Promise<{ default: T }>, retries = 3, - interval = 1000 + interval = 1000, ): React.LazyExoticComponent { return lazy(async () => { let lastError: Error | undefined; @@ -23,7 +23,7 @@ export function lazyWithRetry>( if (isChunkLoadError(error)) { logger.warn(`Chunk load failed (attempt ${i + 1}/${retries}), retrying...`); - await new Promise(resolve => setTimeout(resolve, interval * (i + 1))); + await new Promise((resolve) => setTimeout(resolve, interval * (i + 1))); // Ăšltima tentativa: aciona recovery agressivo (hard reload + cache bust). if (i === retries - 1) { @@ -31,13 +31,17 @@ export function lazyWithRetry>( if (reloaded) { // Retorna um componente placeholder que renderiza o esqueleto apropriado // enquanto o hard-reload acontece no fundo. - return { + return { default: (() => { const url = typeof window !== 'undefined' ? window.location.pathname : '/'; - return createElement('div', { - className: "animate-pulse" - }, getFallback(url)); - }) as unknown as T + return createElement( + 'div', + { + className: 'animate-pulse', + }, + getFallback(url), + ); + }) as unknown as T, }; } throw error; @@ -51,4 +55,3 @@ export function lazyWithRetry>( throw lastError; }); } -