Skip to content

Scaladoc generates broken local links #19208

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dixine55 opened this issue Dec 5, 2023 · 6 comments · Fixed by #22013
Closed

Scaladoc generates broken local links #19208

dixine55 opened this issue Dec 5, 2023 · 6 comments · Fixed by #22013

Comments

@dixine55
Copy link

dixine55 commented Dec 5, 2023

As of currently, when you generate documentation for your library, the links that are generated are not clickable locally.
I believe that this is due to that the network request made by jQuery is denied because of a CORS error, which is seen in the network tab.
error

Compiler version

sbt:> print scalaVersion
3.3.0

Minimized code

scala-cli doc .
sbt doc

Both generations will lead to broken local links, I have not been able to generate it and try with Scaladoc directly, no matter what I've attempted as an arg to Scaladoc I get "The system cannot find the path specified.", but since both scala-cli and sbt doc are based on Scaladoc I feel pretty confident it's an issue with Scaladoc itself.

Output

Directory with
packageName/
fonts/
hljs/
images/
scripts/
styles/
webfonts/
packageName.html
favicon.ico
index.html
scaladoc.version (3.3.0)

And when you open packageName.html or index.html or any of the html files in packageName/* the linking doesn't work.

Expectation

I believe it should work out of the box, or it feels really weird for it not to..

But, in order to fix it I made this code that does almost patch all the links perfectly, I tried to understand how Scaladoc works by itself, but it's over my paygrade.

So if it is a bug and/or if we could add it as a feature to build it locally by passing an argument -local, that'd be very helpful to people that don't know how to boot up a webserver and configure headers.

Link to the program that fixes the links:
https://github.com/dixine55/Scaladoc-Local-Version-Patcher

Edit; As som-snytt pointed out I missspelled Scaladoc as scalaDoc, changed it so it's consistent.

@dixine55 dixine55 added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Dec 5, 2023
@som-snytt
Copy link
Contributor

how scalaDoc works

Someone will say "Scaladoc", so it might as well be me. I don't know why it departs from "JavaDoc".

I don't know why an option would be needed, in the sense that URLs should just work. Scaladoc tool is always unexpectedly complex. I would expect the complexity at runtime, to support its useful features.

@dixine55
Copy link
Author

dixine55 commented Dec 5, 2023

@som-snytt Thank you for pointing out that inconsistency, fixed it now!

I agree that it'd be good if it worked straight out of the box, but as I haven't really developed a good enough understanding of how the code interacts in the grand scheme of things I was suggesting the "-local" option in case there is no "two world"-solution where it works both for local and online deployment right away.

I assume that the majority who use the tool will end up uploading it online anyway and therefore wouldn't want to tweak around too much with it, but then again, there's also cases where you want to try building it locally first..

@bjornregnell
Copy link
Contributor

bjornregnell commented Dec 6, 2023

I think it should "Just work" out of the box for both local and server deployment, if possible, without any configs etc. If configs are needed it should work out of the box with no config for local usage and then require setting/config for server deployment. This is best because local usage is the simplest use case for beginners.

@bjornregnell
Copy link
Contributor

bjornregnell commented Dec 6, 2023

BTW: Many thanks @dixine55 for fixing a simple-to-use workaround. This will help many students of Scala!

@SethTisue
Copy link
Member

SethTisue commented Dec 6, 2023

seems related? #18903

@Math-ias
Copy link
Contributor

This is the important code path here. It is making a GET request to whatever's linked. It then downloads the content and replaces the page's contents. I suppose one of the benefits is that a lot of assets don't have to get reloaded. That may make it feel snappier.

It's not necessarily related to removing jQuery, though jQuery is used to make the GET request. I will post changes to restore functionality when browsing locally.

Gedochao pushed a commit that referenced this issue Nov 26, 2024
…22013)

If we detect scaladocs are being served locally
(i.e page on the "file" protocol)
then we let the link click event go back to normal handling.

Otherwise unless a user has allowed pages on the file protocol to access
other files

https://github.com/chromium/chromium/blob/b6c23ba2056e65081f8a5bcbf73b176baaa42645/content/public/common/content_switches.cc#L15
for example with the allow-file-access-from-files flag in chrome then
SPA routing won't work.

Fixes #19208.
KacperFKorban pushed a commit to dotty-staging/dotty that referenced this issue Nov 29, 2024
…g. (scala#22013)

If we detect scaladocs are being served locally
(i.e page on the "file" protocol)
then we let the link click event go back to normal handling.

Otherwise unless a user has allowed pages on the file protocol to access
other files

https://github.com/chromium/chromium/blob/b6c23ba2056e65081f8a5bcbf73b176baaa42645/content/public/common/content_switches.cc#L15
for example with the allow-file-access-from-files flag in chrome then
SPA routing won't work.

Fixes scala#19208.
tgodzik pushed a commit to scala/scala3-lts that referenced this issue Mar 11, 2025
…g. (scala#22013)

If we detect scaladocs are being served locally
(i.e page on the "file" protocol)
then we let the link click event go back to normal handling.

Otherwise unless a user has allowed pages on the file protocol to access
other files

https://github.com/chromium/chromium/blob/b6c23ba2056e65081f8a5bcbf73b176baaa42645/content/public/common/content_switches.cc#L15
for example with the allow-file-access-from-files flag in chrome then
SPA routing won't work.

Fixes scala#19208.
[Cherry-picked 75ddad2]
tgodzik pushed a commit to scala/scala3-lts that referenced this issue Mar 11, 2025
…g. (scala#22013)

If we detect scaladocs are being served locally
(i.e page on the "file" protocol)
then we let the link click event go back to normal handling.

Otherwise unless a user has allowed pages on the file protocol to access
other files

https://github.com/chromium/chromium/blob/b6c23ba2056e65081f8a5bcbf73b176baaa42645/content/public/common/content_switches.cc#L15
for example with the allow-file-access-from-files flag in chrome then
SPA routing won't work.

Fixes scala#19208.
[Cherry-picked 75ddad2]
tgodzik added a commit to scala/scala3-lts that referenced this issue Mar 12, 2025
Backport "[ISSUE-scala#19208] If scaladocs on file protocol don't do SPA routing." to 3.3 LTS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants