From a136d468af3b3ded9b8e22719125f8c29e91171c Mon Sep 17 00:00:00 2001 From: lezi-fun <177434121+lezi-fun@users.noreply.github.com> Date: Tue, 11 Aug 2026 10:18:42 +0800 Subject: [PATCH] fix: show cached forum name at first paint via inline script Loading screen now always renders the title container; layout.js inline script fills the cached name on DOMContentLoaded (before React hydrate), so 2nd+ visits show the forum name immediately instead of waiting for React to start. Static appear class avoids hydrate clobbering. --- app/layout.js | 14 ++++++++++++++ components/LoadingScreen.js | 11 ++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/app/layout.js b/app/layout.js index c1fd8c5..9cf9ceb 100644 --- a/app/layout.js +++ b/app/layout.js @@ -29,6 +29,20 @@ export default function RootLayout({ children }) { var n = localStorage.getItem('forumlify-forum-name'); if (n) document.title = n; } catch (e) {} + // 加载页名字:DOMContentLoaded(早于 React hydrate)时把缓存名填入, + // 二次访问首帧就显示论坛名,不必等 React 启动 + document.addEventListener('DOMContentLoaded', function () { + try { + var n2 = localStorage.getItem('forumlify-forum-name'); + if (n2) { + var el = document.getElementById('loadingTitle'); + if (el && !el.textContent) { + el.textContent = n2; + document.title = n2; + } + } + } catch (e) {} + }); })();`, }} /> diff --git a/components/LoadingScreen.js b/components/LoadingScreen.js index 73c88a6..eb53609 100644 --- a/components/LoadingScreen.js +++ b/components/LoadingScreen.js @@ -1,16 +1,17 @@ 'use client'; // 全屏加载页:初始化未完成时显示转圈,加载完成后淡出 -// - 未收到论坛名时:只显示 spinner,不显示名字/图标 -// - 收到论坛名后:名字在原位置渐渐淡入出现 +// - 名字容器总是渲染(空):layout.js 内联脚本会在 DOMContentLoaded(早于 +// React hydrate)时把缓存的论坛名填入,实现二次访问首帧即显示名字 +// - 首次访问无缓存:由 React 在收到服务器论坛名后淡入显示 export default function LoadingScreen({ forumName, forumNameLoaded }) { return (
- {forumNameLoaded && forumName && ( -
{forumName}
- )} +
+ {forumNameLoaded && forumName} +
加载中...