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.
This commit is contained in:
lezi-fun committed 2026-08-11 10:18:42 +08:00
1 parent 0b86c54867
commit bfe8a80822
2 files changed
+20 -5

No files matched your search

+14
View File
@@ -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) {}
});
})();`,
}}
/>