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: "Show declaration" causes layout shift during page load #83075

Closed
jsha opened this issue Mar 13, 2021 · 2 comments
Closed

rustdoc: "Show declaration" causes layout shift during page load #83075

jsha opened this issue Mar 13, 2021 · 2 comments
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 Mar 13, 2021

The top of a rustdoc page for a struct or trait always has [+] Show declaration at the top. This text is generated by main.js as part of building all the open/close toggles. Because it's built by JS, it comes in very late in the page load, which generates a noticeable layout shift.

This is particularly noticeable on mobile, here the "Show declaration" text takes up a significant fraction of the screen.

One solution would be to render this text as part of the HTML, so it doesn't have to be generated by JS.

However, I'd like to propose a different fix: For structs and traits, remove "Show declaration" text, and the declaration behind it entirely. The same content is provided in more readable form in the "Fields", "Required methods," and "Provided methods" sections. For the user who wants a link near the top of the document to see the actual declaration as it would be written out in Rust, there's already the [src] link.

This fix has the added advantage that besides removing a layout shift, it also reclaims some above-the-fold space for the documentation.

image

image

Profile-20210312T190703

@jsha jsha changed the title rustdoc: "Show declaration" causes layout shift rustdoc: "Show declaration" causes layout shift during page load Mar 13, 2021
@taylordotfish
Copy link

A few issues with getting rid of the declaration:

  • rustdoc doesn't generate a “Fields” section for tuple-like structs. The declaration is the only place where tuple-like struct fields appear, unless they're documented manually.

  • Without the declaration, it's not clear whether a struct has any private fields, which determines whether users of that struct can directly create instances of it, or whether they have to use constructor functions.

  • It's not clear what the type parameters of a generic type are without the declaration. Often, you can piece together this information by looking at the various inherent and trait impls, but not always. For example, given this struct:

    pub struct Test<T: Copy = u8>(pub T);

    aside from the declaration, the only place where the type parameter T appears is in the auto-generated impls of Send, Sync, and Unpin, and it seems non-ideal to have to rely on those. The biggest issue, though, is that the Copy bound on T and the default value of u8 don't appear anywhere except in the declaration.

The “[src]” link doesn't always provide this information in an easily accessible format either—if the struct/trait/etc. was generated by a macro, the “[src]” link simply goes to the outermost macro invocation.

@GuillaumeGomez GuillaumeGomez added A-rustdoc-ui Area: rustdoc UI (generated HTML) T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Mar 15, 2021
@jsha
Copy link
Contributor Author

jsha commented Apr 22, 2021

This has been resolved by #83337

@jsha jsha closed this as completed Apr 22, 2021
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

No branches or pull requests

3 participants