Skip to content

Anchor links are not resolving to the correct scroll position #5079

@MarcelGeo

Description

@MarcelGeo

Describe the bug

If Markdown contains images without explicit width and height, the browser cannot determine the image dimensions until they are loaded or retrieved from cache. Consequently, anchor links may point to the wrong position on the page, sometimes resulting in the target header being hidden or misaligned.

Related issue in Mergin Maps docs:

MerginMaps/docs#656

Reproduction

Open page with images
Save anchor link
clean image cache in a browser
open link in new tab

Expected behavior

anchor links works on pages with images.

System Info

System:
    OS: Linux 6.16 Pop!_OS 22.04 LTS
    CPU: (16) x64 12th Gen Intel(R) Core(TM) i7-1260P
    Memory: 5.61 GB / 31.05 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 18.20.4 - /home/marcelkocisek/.nodenv/versions/18/bin/node
    Yarn: 1.22.22 - /usr/bin/yarn
    npm: 10.7.0 - /home/<>/.nodenv/versions/18/bin/npm
  Browsers:
    Firefox: 143.0.3
    Firefox Developer Edition: 143.0.3
  npmPackages:
    vitepress: ^1.6.3 => 1.6.3

Additional context

Is there any workaround or script to prevent mentioned behavior?

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    buildRelated to the build system

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions