Skip to content
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

Rewrite lints page #13269

Open
wants to merge 23 commits into
base: master
Choose a base branch
from

Conversation

GuillaumeGomez
Copy link
Member

This PR has multiple goals:

  • Make lints page to work without needing a web server by removing the json file.
  • Prepare the field to also make the page work with JS (not done in this PR but should be straightforward).
  • Remove angular dependency.

r? @Alexendoo

changelog: make lint page work without web server

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Aug 15, 2024
@@ -9,7 +9,6 @@ echo "Making the docs for master"
mkdir out/master/
cp util/gh-pages/index.html out/master
cp util/gh-pages/script.js out/master
cp util/gh-pages/lints.json out/master
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With

git checkout origin/master -- .github/deploy.sh util/versions.py util/gh-pages/versions.html

Would this create an issue with deploying the 1.81 docs? cc @flip1995

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What issue do you expect?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it uses the index.html of the time but the latest deploy.sh it would be missing the required lints.json

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see. An in-between situation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we probably have to push old versions of the html files to the gh-pages` branch manually for the 2 releases following this.

Thanks for the ping! This should block improvements here though. I figured something similar out before and am optimistic to be able to do that again :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to confirm: did you forget "not" in "This should block improvements"? 😨

<li role="separator" class="divider"></li>
</ul>
</div>
<div class="btn-group", id="lint-applicabilities" tabindex="-1">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't be a comma here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arf, good catch!

Comment on lines 189 to 190
{% endif %}
</div>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Suggested change
{% endif %}
</div>
</div>
{% endif %}

@GuillaumeGomez
Copy link
Member Author

Fixed both DOM issues.

@Alexendoo
Copy link
Member

I've found that it's slower to load than the current site, not so much on my desktop but it's noticeable on my laptop/phone. There may be some value in keeping the lints.json method around so we can lazily create the lint bodies as requested

Relatedly having to rerun collect-metadata after any change to the template isn't great

@GuillaumeGomez
Copy link
Member Author

It's slower but since I'm aiming at having the website work even with JS disabled, we can't do much about it unfortunately. I have some tricks up my sleeve to reduce the page size by a lot though. I wanted to send follow-ups since this PR is already quite big.

Relatedly having to rerun collect-metadata after any change to the template isn't great

It's not really a big impact though. I don't expect many people will have this problem.

@Alexendoo
Copy link
Member

It's slower but since I'm aiming at having the website work even with JS disabled, we can't do much about it unfortunately

To me that's not a worthwhile trade off

@GuillaumeGomez
Copy link
Member Author

It's the usual: do you prefer users accessibility or users comfort? And in this case, since I plan to make more changes, it might not even be one or the other once I'm done since like I said, I have a lot of others changes lined up. Let me describe them so maybe it'll help you in your decision:

  1. Transform all lints into <details> so the JS to collapse/expand can be removed.
  2. Enable auto-whitespace stripping in rinja so that all rinja tags (like {% %}, {# #}...) will strip all whitespace surrounding them by default (more information here).
  3. Generate the menus and anything that require JS to work in JS directly like we do in rustdoc to reduce even further the page size by default.

And final argument: this website won't even need a server anymore once this PR is merged to work locally since the JSON file won't exist anymore. Meaning we can even distribute the website very easily and open it locally with cargo clippy doc or something like that.

@Alexendoo
Copy link
Member

What accessibility are we referring to here? Assistive technologies have no issue with elements created via JS

That aside, it was a response to us not being able to do much about it, if that's not the case then it's completely fine to ditch the JSON file

I've had a closer look and it's not solely down to the increase in transfer size/HTML parsing. With a couple changes it should be on par with master

  1. Make theme selection happen earlier (preferably inlined in <head>), currently the unthemed page becomes visible while the page is loading which makes the slowdown more noticeable
    image

  2. Make syntax highlighting lazy, a significant amount of the time is spent here upfront when it could happen only when the section is expanded

@Alexendoo
Copy link
Member

  1. Transform all lints into <details> so the JS to collapse/expand can be removed.

Personally I find the ctrl + F behaviour of <details> to be frustrating, auto expanding sections is not something I want it to do

  1. Enable auto-whitespace stripping in rinja so that all rinja tags (like {% %}, {# #}...) will strip all whitespace surrounding them by default (more information here).

Sounds good

  1. Generate the menus and anything that require JS to work in JS directly like we do in rustdoc to reduce even further the page size by default.

Seems like it would be a neutral change size wise if it's added to the JS, the menus are pretty small anyway

@GuillaumeGomez
Copy link
Member Author

What accessibility are we referring to here? Assistive technologies have no issue with elements created via JS

Mostly smaller devices like e-reader will have issues with JS. But in any case, it's bad practice to have the rendering done in two passes (one loading JS which in turn generates HTML) as it prevents to have information on the page directly.

I've had a closer look and it's not solely down to the increase in transfer size/HTML parsing. With a couple changes it should be on par with master

Yes, but that's something I wanted to do in another PR originally. Do you want me to do it in this PR directly? Also please note that when hosted on a web server (so not locally), all queries are compressed so the download time shouldn't be impacted much.

Make theme selection happen earlier (preferably inlined in ), currently the unthemed page becomes visible while the page is loading which makes the slowdown more noticeable

Agreed, going to change it then (likely moving the theme-handling JS into a different file, loaded a the beginning).

Make syntax highlighting lazy, a significant amount of the time is spent here upfront when it could happen only when the section is expanded

This is a very good idea!

Personally I find the ctrl + F behaviour of

to be frustrating, auto expanding sections is not something I want it to do

At least in firefox it doesn't expand <details> when using ctrl+f. I'm surprised any web browser would do it.

Seems like it would be a neutral change size wise if it's added to the JS, the menus are pretty small anyway

True. But I'll hide them if JS is disabled so at this point, why not just not generate them if the JS disabled. Less CSS required then. ;)

@Alexendoo
Copy link
Member

Yes, but that's something I wanted to do in another PR originally. Do you want me to do it in this PR directly?

Yes please, I think we should hit parity before landing it

when hosted on a web server (so not locally), all queries are compressed so the download time shouldn't be impacted much.

I did my testing on a server with it hosted alongside the master version, overall it transferred an extra ~30kb which yeah, is fine

At least in firefox it doesn't expand <details> when using ctrl+f. I'm surprised any web browser would do it.

Unfortunately chrome does

@GuillaumeGomez
Copy link
Member Author

Ok, going to do it another way (like I did in my blog for the "support me" button). But that's a task for another day anyway. Applying your suggestions in the meantime.

Since all angular code was removed, there is no conflict anymore before angular and jinja2 syntaxes so we can just use plain jinja2 syntax.
@GuillaumeGomez
Copy link
Member Author

GuillaumeGomez commented Aug 29, 2024

Moved the theme handling code into its own file, removed some inlined CSS, only run syntax highlighting when needed (when expanding lints) and greatly reduced the generated HTML page size:

before: 2.477.532 bytes
after:  1.777.286 bytes

@GuillaumeGomez
Copy link
Member Author

@Alexendoo Is there anything else to be done here?

@@ -39,6 +39,8 @@ toml = "0.7.3"
walkdir = "2.3"
filetime = "0.2.9"
itertools = "0.12"
pulldown-cmark = "0.11"
rinja = { version = "0.3", default-features = false, features = ["config"] }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A high level question - is there a particular reason we're going for this templating framework rather than a more common one? I had not heard of it before

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might have heard of askama. I contributed to it a lot but some issues happened there (nothing bad, just different opinion on some specific things) and another askama maintainer and I decided to fork it.

You can see more information about it here.

The biggest advantage of rinja is that if the template code is wrong, it will prevent compilation (which is the big reason why we moved to this framework for docs.rs).

util/gh-pages/index_template.html Outdated Show resolved Hide resolved
Comment on lines -275 to -276
padding-left: 4px;
padding-top: 3px;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks unintentional, this moves the settings cog off-centre

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strangely enough, if I put it back I get:

image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is more noticeable in chrome (the UA stylesheet for button padding is different)
image

But the image is slightly below centre in firefox also, before/after:
image
image

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum. Let me check if I can unify this across browsers.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of having something set by the default, I now force its position by using absolute positioning. I checked on firefox and chrome and both look the same now.

Comment on lines +574 to +575
generateSettings();
generateSearch();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's put these in the HTML from the start, it currently causes the page to move around a bit after a small delay

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This script is downloaded in a non-async method before the DOM is rendered, so there should not be any layout re-rendering (also I can't reproduce the bug locally, even with throttling).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is in a regular script tag before the end of the document, but browsers do not wait for the document to be complete before they begin rendering

When exactly browsers incrementally render varies but here it happens to be more pronounced in chrome, it's still visible as a flicker in firefox though. It's most noticeable when the size happens to cause a line break e.g. in firefox with disable cache ticked and 3G throttling:

Desktop.2024.09.19.-.14.54.53.07.mp4

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! The current lint page (before this PR) is displaying everything once it's loaded, so a different kind of "layout break". Seems like it's part of what I want to do as a follow-up: render buttons and any JS-bound element with JS instead of keeping it into HTML. Do you want me to do it in this PR directly or as a follow-up like I originally planned?

@GuillaumeGomez
Copy link
Member Author

Applied the suggestion for the HTML comment, for the rest, I can't reproduce the bugs locally...

@GuillaumeGomez
Copy link
Member Author

Fixed the settings button icon position.

@bors
Copy link
Collaborator

bors commented Sep 21, 2024

☔ The latest upstream changes (presumably #13384) made this pull request unmergeable. Please resolve the merge conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants