yfm-docs icon indicating copy to clipboard operation
yfm-docs copied to clipboard

Page does not scroll to the anchor section

Open anton-fomichev opened this issue 5 months ago • 1 comments

Package version

5.0.11

Node version

20.19.2

Platform

Static build

What steps will reproduce the bug?

  1. Click to the anchor link of a specific section
  2. Copy link
  3. Paste link to the browser window

What is the expected behavior?

Page scrolls to the section with id from link.

What do you see instead?

Page does not scroll if I copy anchor link to specific section (i.e. http://localhost:5005/sandbox.html#uspeshnoe-sozdanie-tokena). I tried to curl the page and element with id I copied already was ready in the layout.

Image

Additional information

There is a workaround:

//_assets/scripts

(function () {
  window.addEventListener("DOMContentLoaded", function () {
    setTimeout(scrollToHash, 100);
  });

  window.addEventListener("hashchange", function () {
    setTimeout(scrollToHash, 50);
  });

  function scrollToHash() {
    if (location.hash) {
      const id = decodeURIComponent(location.hash.substring(1));
      const el = document.getElementById(id);
      if (el) {
        el.scrollIntoView({ behavior: "auto", block: "start" });
      }
    }
  }
})();
# .yfm

resources:
  script:
    - _assets/scripts/fix-anchors.js

anton-fomichev avatar Jul 08 '25 09:07 anton-fomichev

hi, this behavior is not reproduced on client 5.6.0 and higher, can you confirm that the problem is still relevant and if so, attach an example of the source code on which you compile the documentation and the prompt does not work there

martyanovandrey avatar Sep 11 '25 07:09 martyanovandrey