fix: show cached forum name immediately on reload (no server wait)

- forumNameLoaded initializes true when localStorage has a cached name,
  so 2nd+ visits show the name right away instead of waiting for the
  settings fetch
- layout.js inline script writes cached name to <title> on first paint
  (first request HTML now carries the name)
This commit is contained in:
lezi-fun committed 2026-08-11 10:02:03 +08:00
1 parent c55fce445c
commit fe71b03d2e
2 files changed
+13 -1

No files matched your search

+5
View File
@@ -24,6 +24,11 @@ export default function RootLayout({ children }) {
}
document.documentElement.setAttribute('data-theme', t);
} catch (e) {}
// 论坛名:有缓存立即写入 <title>(第二次访问首帧即显示),无缓存保持 Loading...
try {
var n = localStorage.getItem('forumlify-forum-name');
if (n) document.title = n;
} catch (e) {}
})();`,
}}
/>
+8 -1
View File
@@ -27,7 +27,14 @@ export default function AppProvider({ children }) {
const [sort, setSort] = useState('latest');
const [refreshKey, setRefreshKey] = useState(0);
const [ready, setReady] = useState(false); // 初始加载完成标记(控制加载页/淡入)
const [forumNameLoaded, setForumNameLoaded] = useState(false); // 已从服务器收到论坛名
// 有缓存论坛名即视为"已加载"(第二次访问立即显示缓存名,不必等服务器);
// 首次访问无缓存 → 等服务器返回后才显示名字
const [forumNameLoaded, setForumNameLoaded] = useState(() => {
if (typeof window !== 'undefined') {
return !!localStorage.getItem('forumlify-forum-name');
}
return false;
});
const loadedRef = useRef(false);
const refresh = useCallback(() => setRefreshKey((k) => k + 1), []);