From 4b5004b621bf162eded751bb84e6a670eca61367 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 20 Oct 2025 17:03:06 -0700 Subject: [PATCH] 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. --- crates/mdbook-html/front-end/templates/toc.js.hbs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/mdbook-html/front-end/templates/toc.js.hbs b/crates/mdbook-html/front-end/templates/toc.js.hbs index 9d26f3da..0f71ddde 100644 --- a/crates/mdbook-html/front-end/templates/toc.js.hbs +++ b/crates/mdbook-html/front-end/templates/toc.js.hbs @@ -132,7 +132,7 @@ window.customElements.define('mdbook-sidebar-scrollbox', MDBookSidebarScrollbox) // proportional to the difference in size. if (documentHeight < windowHeight * 2) { const maxPixelsBelow = documentHeight - windowHeight; - const t = 1 - pixelsBelow / maxPixelsBelow; + const t = 1 - pixelsBelow / Math.max(1, maxPixelsBelow); const clamp = Math.max(0, Math.min(1, t)); adjustedBottomAdd *= clamp; }