Skip to content

Commit 4b5004b

Browse files
committed
Avoid divide-by-zero in heading nav computation
This particular value can go to zero when the document height and the window height are exactly the same value. This causes a NaN which causes the "current" heading nav bug to not update properly. This clamps the value to 1 to avoid that.
1 parent 816913b commit 4b5004b

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

crates/mdbook-html/front-end/templates/toc.js.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ window.customElements.define('mdbook-sidebar-scrollbox', MDBookSidebarScrollbox)
132132
// proportional to the difference in size.
133133
if (documentHeight < windowHeight * 2) {
134134
const maxPixelsBelow = documentHeight - windowHeight;
135-
const t = 1 - pixelsBelow / maxPixelsBelow;
135+
const t = 1 - pixelsBelow / Math.max(1, maxPixelsBelow);
136136
const clamp = Math.max(0, Math.min(1, t));
137137
adjustedBottomAdd *= clamp;
138138
}

0 commit comments

Comments
 (0)