Skip to content

Commit 0fc7e07

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 780fd83 commit 0fc7e07

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
@@ -156,7 +156,7 @@ let mdbookThresholdDebug = false;
156156
// proportional to the difference in size.
157157
if (documentHeight < windowHeight * 2) {
158158
const maxPixelsBelow = documentHeight - windowHeight;
159-
const t = 1 - pixelsBelow / maxPixelsBelow;
159+
const t = 1 - pixelsBelow / Math.max(1, maxPixelsBelow);
160160
const clamp = Math.max(0, Math.min(1, t));
161161
bottomAdd *= clamp;
162162
}

0 commit comments

Comments
 (0)