scala / scala3

The Scala 3 compiler, also known as Dotty.
https://dotty.epfl.ch
Apache License 2.0
5.81k stars 1.05k forks source link

Scaladoc: scaladoc anchor navigation can't handle some same page links #17182

Closed KacperFKorban closed 1 year ago

KacperFKorban commented 1 year ago

Compiler version

main

Description

In some cases, scaladoc can't properly scroll to anchors that are on the same page. In those cases, it takes several tries for scaladoc to scroll the entire way. e.g.

scaladoc-anchor-same-page-oopsie

Expectation

Scaladoc should always be able to scroll to anchors.

Dedelweiss commented 1 year ago

Hello, from what I noticed during my test, the problem comes from the fact that the anchor does not remain in the URL. After some research, I found this javascript that replaces the anchor with an empty string. In scaladoc/resources/dotty_res/scripts/ux.js:

if (lastEntry.isIntersecting) {
  window.location.hash = "";
  removeAllHighlights();
  const id = getIdOfElement(lastEntry);

  getTocListElement(id).parentElement.classList.toggle("active");
}

So from what I see, this if statement checks if the last entry in entries is intersecting with the window, indicating that it is visible on the screen. If that's the case, the code performs the following actions:

So I know what the purpose of this if is but when I delete it, I don't see any change (and it works better).

Before:

https://github.com/lampepfl/dotty/assets/44496264/69160bd2-ffe5-4cf0-b9f2-97c859fe185a

After:

Screenshot 2023-06-06 at 10 14 34

https://github.com/lampepfl/dotty/assets/44496264/a9ccdf11-e523-4659-a097-dd11d8ddfaaf

The issue is not present on Firefox.

julienrf commented 1 year ago

@KacperFKorban Which browser do you use? On my Firefox I can’t reproduce the issue.

KacperFKorban commented 1 year ago

@julienrf I use Chrome. I see that the issue is reproducible, based on the previous comment.

@Florian3k Can you take a look at @Dedelweiss suggestion?