Fix doc anchor links and TOC scrolling by W0rma · Pull Request #920 · Codeception/codeception.github.com
Repository navigation
Fix doc anchor links and TOC scrolling - #920
Open
W0rma wants to merge 2 commits into Codeception:master from W0rma:fix-anchor-scroll
Open
Fix doc anchor links and TOC scrolling #920 W0rma wants to merge 2 commits into Codeception:master from W0rma:fix-anchor-scroll
Conversation
W0rma commented Dec 6, 2026
Copy link Copy Markdown
Contributor
Since the Bootstrap 5 / jQuery 3 upgrade, links to a heading no longer scroll to it. Both problems come from that upgrade.
- Opening a link with an anchor (e.g.
/docs/modules/Asserts#assertContains): the anchors are spans the TOC script adds to the page. jQuery 3 runsreadyhandlers asynchronously, so the spans now appear after the browser has already tried to scroll. A newreadyhandler scrolls to the anchor once the TOC is built. - Clicking a TOC entry: the TOC plugin cancels the normal jump and scrolls with its own animation. To find the element to scroll, it sets
scrollTop(1)and reads it back, but Bootstrap 5'sscroll-behavior: smoothmeans the value read back is still 0. No element is found, so nothing scrolls. Turning off the plugin's smooth scrolling lets the browser handle the click. Bootstrap's CSS still makes the jump smooth, and the URL hash updates as usual.
Tested locally with Jekyll: opening /docs/modules/Filesystem#deleteDir directly and clicking TOC entries both scroll to the heading.
Scroll to the URL fragment after the TOC created the anchors
c8e5617
Links like /docs/modules/Asserts#assertContains point to spans that the TOC script inserts before each heading. Since the jQuery 3 upgrade, ready handlers run asynchronously, so the spans are created after the browser has already tried to scroll to the fragment. Scroll to it again once the TOC is built.
Let the browser scroll to TOC entries
d14630a
Clicking a TOC entry did not scroll. The TOC plugin cancels the default
jump and animates the scroll container it detected on load by setting
scrollTop(1) and reading it back. Bootstrap 5 sets
:root { scroll-behavior: smooth }, so the read-back is still 0, no
container is found and the animation does nothing.
Disable the plugin's smooth scrolling so the link works natively; the
jump is still smooth thanks to Bootstrap's scroll-behavior.
W0rma
requested review from
Arhell and
TavoNiievez
December 6, 2026 10:23
This branch has not been deployed
No deployments
Sign up for free to join this conversation on GitHub . Already have an account? Sign in to comment