-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Disable stylesheet objects rather than link elements #75063
Conversation
Some changes occurred in HTML/CSS/JS. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm worried about this change: until the storage.js
file is executed, all themes are enabled at the same time, right? This is a huge step backward. :-/
Correct, do you think that will be a problem? |
On slowest computers, it's gonna be an issue for sure: the browser will have to parse and render multiple styles at once. Definitely not optimal... |
True, although this was the behavior of rustdoc before 03f565c. As far as I'm aware this wasn't causing issues before with 2 theme stylesheets, do we believe it would cause an issue with 3? (EDIT: thinking about this some more we likely have a similar problem in the code's current state anyway? The non-disabled stylesheet ( The |
This is a good point. Only way would be to just compare I guess. Also, what do you @rust-lang/rustdoc ? |
Personally I don't think the themes are going to be affecting render time the most, it's the gobs of generated HTML. If you're worried though, maybe we could load the theme preference from local storage before loading the CSS? |
Isn't it already what we do? |
No, |
@Manishearth This is what we do currently but this PR, unless I'm missing something, is removing this mechanism and the disable is added by the JS, not by rustdoc. |
@GuillaumeGomez right, as long as the JS occurs in the head tag it doesn't matter The parsing is inevitable. It's the relayout you want to avoid |
Yes, on that point we agree. Thanks for the precision! |
ping from triage: |
This isn't waiting on anything AFAIK - @GuillaumeGomez are you happy with it? |
Yep, this one is good to go if everyone else is happy :) |
I guess we are. Moving forward then, thanks! @bors: r+ |
📌 Commit c4d0a1b has been approved by |
With JS disabled the ayu theme will now be used instead of the light theme. Is that change intentional? |
With JS disabled the themes will now conflict with one another (they will all be enabled at the same time), so regardless of which stylesheet comes first in the HTML things could look funky. Do we need to support no-JS usage? Doesn't that break search? |
Well, I think there's a difference between a feature that's JS-only and completely breaking the page if JS is turned off. I see the way this is implemented is |
Maybe we could have |
Yes and yes. We don't consider the search breakage when JS is disabled as an issue though, but the rendering has to be "clean", or at least readable. |
Note: if this is broken under no-JS then it will also be broken if the relevant JS is in a separate file and needs to load, on bad networks. I think the default theme code is inline but if so we need a comment there that makes sure it's never moved out, and if not we need to make this work if that JS file fails to load |
I investigated using I came up with what appears to be a nice compromise here that still uses the r#"<link rel="stylesheet" type="text/css" href="{}.css"{}>"#,
Escape(&format!("{}{}{}", static_root_path, t, page.resource_suffix)),
if t == "light" { "" } else { " disabled" } And then in the theme switcher we simply remove the themeSheet.removeAttribute('disabled');
themeSheet.disabled = themeName !== newTheme; This works well across most things I tested:
Unfortunately Waterfox Classic with JS disabled is still broken because, well, it doesn't support the I would guess that the set of people using Waterfox Classic is going to happen to intersect with the set of people that want to be able to use rustdoc with JS disabled, so this doesn't really accomplish anything. The other idea I had was to only load the dark / ayu themes if JS is enabled (by adding them dynamically on page load). Should I try that out or nah?
@jyn514 good thought, but unfortunately I don't think |
Can we insert the other stylesheets with JS? So they don't show up at all in the HTML and only appear once the JS executes? |
and if that doesn't work I really think we should close this as wontfix, it's not worth the effort for fixing such a small minority of browsers. |
https://stackoverflow.com/a/577002/7669110 might possibly be what we want |
I tried something similar to this and it looks like it will work. I don't have time to finish it right now though. Will return and poke at it another night. |
Branch here that implements that idea (add stylesheets to page using JS in the head tag). Unfortunately this causes flashing on page load on my machine. Unless anyone has any other bright ideas (or can see something wrong in the above branch) we are unfortunately going to have to close this PR 😞 |
Well, at least now we know... |
Resolves #75011.
I changed the way themes are switched in rustdoc to more closely resemble that of mdbook. This method uses StyleSheet.disabled which has much better browser support than the usage of
disabled
onlink
that I introduced in a previous PR.As added bonuses, we no longer need to use the IDs
mainThemeStyle
orthemeStyle
, usage ofswitchTheme
is simpler, and we no longer need the hack that changes the href on thelight.css
stylesheet.I've tested this in Firefox, Chromium, and Waterfox Classic, and it works well across all those browsers. @Nemo157 would perhaps be able to test this in Safari as well?
r? @GuillaumeGomez