From 024b678ad3846e5e4906818e826749848c3ecc68 Mon Sep 17 00:00:00 2001 From: lezi-fun <177434121+lezi-fun@users.noreply.github.com> Date: Tue, 11 Aug 2026 10:52:21 +0800 Subject: [PATCH] fix: hydration mismatch (loading spinner restart) + cache strategy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Root cause of loading spinner restarting / name appearing twice: React hydration mismatch → whole tree regenerated. Fixed all sources: - AppProvider: remove typeof window in useState init (SSR/client diff); read cached forum name in useEffect instead - ToastProvider: remove createPortal(document.body) (SSR absent → mismatch) - LoadingScreen: name container uses dangerouslySetInnerHTML('') so React never manages/clobbers the inline-script-filled text - layout.js: inline script moved to body first child (React official anti-FOUC pattern) Cache: dynamic pages/API no-cache + ETag (304 on revalidate); static /_next/static assets immutable 1y. Verified: 304 + immutable headers. --- app/layout.js | 52 ++++++++++++++----------------------- app/page.js | 2 +- components/AppProvider.js | 31 +++++++++++----------- components/LoadingScreen.js | 14 ++++------ components/Toast.js | 20 +++++++------- next.config.js | 11 ++++++-- 6 files changed, 58 insertions(+), 72 deletions(-) diff --git a/app/layout.js b/app/layout.js index 9cf9ceb..1e4f768 100644 --- a/app/layout.js +++ b/app/layout.js @@ -13,41 +13,27 @@ export default function RootLayout({ children }) { return ( - {/* 首帧前同步主题,避免深色模式闪白(FOUC):手动设置优先,否则跟随系统 */} -