Skip to content

Commit 466b48b

Browse files
committed
Fix Forced reflow in menu scroll handler
A forced reflow occurs when JavaScript queries geometric properties (such as offsetWidth) after styles have been invalidated by a change to the DOM state. This can result in poor performance. https://pagespeed.web.dev/analysis/https-adityatelange-github-io-hugo-PaperMod/n5w29pnr5o?form_factor=mobile
1 parent b63c195 commit 466b48b

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

layouts/partials/footer.html

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,14 @@
3333
{{- partial "extend_footer.html" . }}
3434

3535
<script>
36-
let menu = document.getElementById('menu')
36+
let menu = document.getElementById('menu');
3737
if (menu) {
38-
menu.scrollLeft = localStorage.getItem("menu-scroll-position");
38+
// Set the scroll position
39+
const scrollPosition = localStorage.getItem("menu-scroll-position");
40+
if (scrollPosition) {
41+
menu.scrollLeft = parseInt(scrollPosition, 10);
42+
}
43+
3944
menu.onscroll = function () {
4045
localStorage.setItem("menu-scroll-position", menu.scrollLeft);
4146
}

0 commit comments

Comments
 (0)