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

rustdoc: sidebar items not shown on crate page on docs.rs #99121

Closed
jsha opened this issue Jul 10, 2022 · 1 comment · Fixed by #99209
Closed

rustdoc: sidebar items not shown on crate page on docs.rs #99121

jsha opened this issue Jul 10, 2022 · 1 comment · Fixed by #99209
Labels
A-rustdoc-ui Area: Rustdoc UI (generated HTML) T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@jsha
Copy link
Contributor

jsha commented Jul 10, 2022

On docs.rs pages, until recently, the crate page (the top of the hierarchy for a crate) would show structs, enums, traits, etc in the sidebar, in addition to the page contents:

https://docs.rs/rustls/0.20.6/rustls/index.html

In more recently built pages, it doesn't:

I believe this is in part due to my refactoring in #98124 - I believed (based on behavior for library/std) that crate pages were not intended to show structs, etc in the sidebar.

However, it gets more complicated. The code in main.js shows that it's not supposed to display those "sidebar items" on module pages. Crate pages are considered module pages (they have class="crate mod ...").

const isModule = hasClass(document.body, "mod");
if (!isModule) {

So why does docs.rs show the sidebar items on a crate page? The check above operates on document.body, but docs.rs rewrites the HTML so what used to be the body tag becomes <div id="rustdoc_body_wrapper" class="...">. So the class is still present from CSS' perspective but it's on the wrong div so the check passes. On doc.rs, nothing is considered a module page so every page gets the full list of sidebar items. The check is buggy; or another way of thinking about it is that the interface between rustdoc and docs.rs is not clearly defined. A better way to do this particular check might be to use rustdoc-vars instead of piggybacking on CSS semantics.

I think we should fix the most recent change, so docs.rs gets sidebar items on crate and module pages again, and then discuss what behavior we actually intend.

Some context: here's the PR from about a year ago where we tried to suppress showing structs etc on module pages: https://github.com/rust-lang/rust/pull/84834/files#r625337543

@jsha jsha added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. A-rustdoc-ui Area: Rustdoc UI (generated HTML) labels Jul 10, 2022
@GuillaumeGomez
Copy link
Member

I think a simpler approach would be instead to check like this: document.querySelector(".rustdoc").classList.contains("mod"). Like that no need to worry about docs.rs. Sending a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rustdoc-ui Area: Rustdoc UI (generated HTML) T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants