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} +
加载中...