Uh oh!
There was an error while loading. Please reload this page.
Add settings to rustdoc to use the system theme - #77809
Conversation
rust-highfive
commented
Oct 11, 2020
Some changes occurred in HTML/CSS/JS. |
rust-highfive
commented
Oct 11, 2020
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @jyn514 (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
jyn514
left a comment
There was a problem hiding this comment.
Small nit, but I think guillaume is the better reviewer for this. This looks really cool, thanks for working on it!
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
nasso
commented
Oct 11, 2020
I'm not sure I understand how the current implementation of the theme system works. It says here that it works by changing the href of the I'd like to know so I can properly implement a fix to support JavaScript disabled browsers to use the system theme :) |
jyn514
commented
Oct 11, 2020
@Cldfire might know ^ |
GuillaumeGomez
commented
Oct 11, 2020
The |
I tried getting rid of the Usage of the |
Nemo157
commented
Oct 12, 2020
What is the forward/backwards compatibility of this? All docs hosted on docs.rs are using a shared |
I didn't change the way It actually even improves backwards: when the system theme is set, it's saved to |
Nemo157
commented
Oct 12, 2020
(This also looks relatively easy for docs.rs to hijack to configure its own theme (when we get support), other than the lack of self- |
GuillaumeGomez
commented
Oct 12, 2020
nasso
commented
Oct 12, 2020
Actually I think I should make sure it works properly with JavaScript disabled before merging. Currently it doesn't work, because the logic is in @import"{static_root_path}light{suffix}.css" (prefers-color-scheme: light);
@import"{static_root_path}dark{suffix}.css" (prefers-color-scheme: dark);The problem with this is that the styles might override each other in bad ways (since there's already the javascript controlled |
GuillaumeGomez
commented
Oct 12, 2020
By default it's the light theme that gets displayed, so if you get the same result, it's working the same as currently! But if you want to extend it (which would be nice!), please do so but in another PR so we can get this one merged. |
nasso
commented
Oct 12, 2020
Actually the old behavior was using the system theme by default! You can try it by opening the standard library documentation in a private window (so that |
GuillaumeGomez
commented
Oct 12, 2020
Hmmmm... Makes sense in a way I guess? |
Yeah, because the old method used So should I add support for JavaScript disabled browsers in another PR or this one to keep backwards compatibility with the old behavior? |
jyn514
commented
Oct 12, 2020
Isn't that the intended behavior? What more is there to change? |
jyn514
commented
Oct 13, 2020
Also, if |
jyn514
commented
Oct 13, 2020
nasso
commented
Oct 13, 2020
I can implement that logic! I suppose that for now I should hard-code what theme is "dark" and what theme is "light"? |
nasso
commented
Oct 13, 2020
This can cause issues:
One potential fix would be to not save the theme to |
Seems a bit of an edge case ... but since it leads to rustdoc overriding the user's selection, better to avoid it. Rather than having complicated logic, let's just only implement my first suggestion: If use-system-theme and preferred-dark-theme aren't set, but rustdoc-theme is set to a dark theme, update preferred-dark-theme to that theme. |
pickfire
commented
Oct 15, 2020
Is it an edge case? My phone does this too. |
jyn514
commented
Oct 15, 2020
You can write the canonical list :) There's only three themes, it seems reasonable to have a |
If the user doesn't have a preferred dark theme but is already using a dark theme, set the preferred dark theme to be that theme
nasso
commented
Oct 15, 2020
That should be implemented now! I think it's ready now. |
jyn514
commented
Oct 15, 2020
Looks great! Thanks so much for working on this :) @bors r=jyn514,guillaumegomez |
bors
commented
Oct 15, 2020
📌 Commit 59f9cf2 has been approved by |
I wonder if we can have a css fallback rather than relying on javascript? Some users may have disabled javascript. |
nasso
commented
Oct 15, 2020
I thought about this already and I think I may implement a CSS fallback in a future PR. I already have a few ideas about how it could work but I'd prefer to discuss about it first :) |
bors
commented
Oct 16, 2020
bors
commented
Oct 16, 2020
☀️ Test successful - checks-actions, checks-azure |
This PR adds new settings to
rustdocto use the operating system color scheme.rustdocactually had basic support for this, but the setting wasn't visible and couldn't be set back once the theme was explicitly set by the user. It also didn't update if the operating system theme preference changed while viewing a page.I'm using this method to query and listen to changes to the
(prefers-color-scheme: dark)media query. I kept the old method (based ongetComputedStyle) as a fallback in case the user-agent doesn't supportwindow.matchMedia(so like... pretty much nobody).Since there's now more than one official ""dark"" theme in
rustdoc(and also to support custom/third-party themes), the preferred dark and light themes can be configured in the settings page (the defaults are just "dark" and "light").This is also my very first "proper" PR to Rust! Please let me know if I did anything wrong :).