Skip to content

Commit 4ca80ce

Browse files
committed
perf(bfcache): rehydrate UI on back/forward cache restore\n\n- Add pageshow handler to re-init Search/Theme/ToC/Math/Mermaid\n- Dispatch app:rehydrate for future hooks
1 parent 2a9d3ac commit 4ca80ce

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

templates/index.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,24 @@
246246
});
247247
</script>
248248
{% endif %}
249+
250+
<script>
251+
// Rehydrate on back/forward cache restore
252+
window.addEventListener('pageshow', function (event) {
253+
if (event.persisted) {
254+
try {
255+
if (typeof initSearch === 'function') initSearch();
256+
if (typeof initTheme === 'function') initTheme();
257+
if (typeof initToc === 'function') initToc();
258+
if (typeof initMath === 'function') initMath();
259+
if (typeof window.initMermaid === 'function') window.initMermaid();
260+
document.dispatchEvent(new Event('app:rehydrate'));
261+
} catch (err) {
262+
console.warn('bfcache rehydrate failed:', err);
263+
}
264+
}
265+
});
266+
</script>
249267
{% endblock js_body %}
250268
</body>
251269
</html>

0 commit comments

Comments
 (0)