From 36b899d7edc3adfb06c59f92a97dc3c21de7a56e Mon Sep 17 00:00:00 2001 From: hailin Date: Wed, 4 Mar 2026 18:55:19 -0800 Subject: [PATCH] =?UTF-8?q?fix(admin-web):=20=E7=AE=80=E5=8C=96=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E8=BE=B9=E7=95=8C=E4=B8=BA=E9=9D=99=E9=BB=98=20reload?= =?UTF-8?q?=EF=BC=8C=E5=8E=BB=E6=8E=89=E5=A4=9A=E4=BD=99=20UI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Sonnet 4.6 --- frontend/admin-web/src/app/(admin)/error.tsx | 81 ++--------------- frontend/admin-web/src/app/global-error.tsx | 91 ++------------------ 2 files changed, 11 insertions(+), 161 deletions(-) diff --git a/frontend/admin-web/src/app/(admin)/error.tsx b/frontend/admin-web/src/app/(admin)/error.tsx index 008a73c..ed6b538 100644 --- a/frontend/admin-web/src/app/(admin)/error.tsx +++ b/frontend/admin-web/src/app/(admin)/error.tsx @@ -2,91 +2,20 @@ import { useEffect } from 'react'; -/** - * Admin 路由段错误边界 - * - * 捕获 (admin) 路由内的客户端异常。 - * 当检测到 Next.js stale bundle / Server Action 不匹配错误时自动刷新页面。 - */ export default function AdminError({ error, - reset, }: { error: Error & { digest?: string }; reset: () => void; }) { useEffect(() => { - const msg = error?.message ?? ''; - const isStaleBundle = - msg.includes('Server Action') || - msg.includes('Failed to find') || - msg.includes('An unexpected response was received') || - (error?.digest ?? '').startsWith('NEXT_'); - - if (isStaleBundle) { + const key = 'gcx_admin_reload_count'; + const count = parseInt(sessionStorage.getItem(key) ?? '0', 10); + if (count < 3) { + sessionStorage.setItem(key, String(count + 1)); window.location.reload(); } }, [error]); - return ( -
-
-
⚠️
-

- 页面加载出错 -

-

- 检测到新版本,正在自动刷新… -

-
- - -
-
-
- ); + return null; } diff --git a/frontend/admin-web/src/app/global-error.tsx b/frontend/admin-web/src/app/global-error.tsx index 05e84ce..2b1a393 100644 --- a/frontend/admin-web/src/app/global-error.tsx +++ b/frontend/admin-web/src/app/global-error.tsx @@ -1,105 +1,26 @@ 'use client'; -/** - * Next.js App Router 根级错误边界 - * - * 捕获未处理的客户端异常,避免显示 Next.js 默认的 - * "Application error: a client-side exception has occurred" 全屏崩溃页。 - * - * 常见触发场景: - * - 重新部署后,浏览器仍持有旧 bundle,内部 Server Action ID("r" / "multi") - * 已不匹配新服务器构建 → Failed to find Server Action → 客户端异常 - * - 此时自动刷新页面即可恢复正常(加载新 bundle) - * - * global-error.tsx 必须自带 ,因为它会替换根 layout。 - */ - import { useEffect } from 'react'; export default function GlobalError({ error, - reset, }: { error: Error & { digest?: string }; reset: () => void; }) { useEffect(() => { - // 检测 Next.js stale bundle 导致的 Server Action 不匹配错误 - // 自动刷新页面以加载新版本 - const msg = error?.message ?? ''; - const isStaleBundle = - msg.includes('Server Action') || - msg.includes('Failed to find') || - msg.includes('An unexpected response was received') || - (error?.digest ?? '').startsWith('NEXT_'); - - if (isStaleBundle) { + // 捕获根级异常后立即刷新,防止无限循环限制 3 次 + const key = 'gcx_admin_reload_count'; + const count = parseInt(sessionStorage.getItem(key) ?? '0', 10); + if (count < 3) { + sessionStorage.setItem(key, String(count + 1)); window.location.reload(); } }, [error]); return ( - -
-
⚠️
-

- 页面加载出错 -

-

- 检测到新版本,正在自动刷新… -

-
- - -
-
- + ); }