diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts index 7e929400..9c507797 100644 --- a/frontend/src/router/index.ts +++ b/frontend/src/router/index.ts @@ -400,9 +400,33 @@ router.beforeEach((to, _from, next) => { /** * Navigation guard: Error handling + * Handles dynamic import failures caused by deployment updates */ router.onError((error) => { console.error('Router error:', error) + + // Check if this is a dynamic import failure (chunk loading error) + const isChunkLoadError = + error.message?.includes('Failed to fetch dynamically imported module') || + error.message?.includes('Loading chunk') || + error.message?.includes('Loading CSS chunk') || + error.name === 'ChunkLoadError' + + if (isChunkLoadError) { + // Avoid infinite reload loop by checking sessionStorage + const reloadKey = 'chunk_reload_attempted' + const lastReload = sessionStorage.getItem(reloadKey) + const now = Date.now() + + // Allow reload if never attempted or more than 10 seconds ago + if (!lastReload || now - parseInt(lastReload) > 10000) { + sessionStorage.setItem(reloadKey, now.toString()) + console.warn('Chunk load error detected, reloading page to fetch latest version...') + window.location.reload() + } else { + console.error('Chunk load error persists after reload. Please clear browser cache.') + } + } }) export default router