Rollup merge of #123407 - GuillaumeGomez:js-failed-theme, r=notriddle

Default to light theme if JS is enabled but not working

It doesn't [fix] #123399 but it allows to reduce the problem:

* if JS is completely disabled, then `noscript.css` will be applied
* if JS failed for any reason, then the light theme will be applied (because `noscript.css` won't be applied)

r? `@notriddle`
This commit is contained in:
Jacob Pratt 2024-04-04 21:16:56 -04:00 committed by GitHub
commit ac298726af
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 29 additions and 6 deletions

View File

@ -34,7 +34,7 @@ nav.sub {
in rustdoc.css */
/* Begin theme: light */
:root {
:root, :root:not([data-theme]) {
--main-background-color: white;
--main-color: black;
--settings-input-color: #2196f3;
@ -140,7 +140,7 @@ nav.sub {
@media (prefers-color-scheme: dark) {
/* Begin theme: dark */
:root {
:root, :root:not([data-theme]) {
--main-background-color: #353535;
--main-color: #ddd;
--settings-input-color: #2196f3;

View File

@ -2315,8 +2315,14 @@ in src-script.js and main.js
tooling to ensure different themes all define all the variables. Do not
alter their formatting. */
/*
About `:root:not([data-theme])`: if for any reason the JS is enabled but cannot be loaded,
`noscript` won't be enabled and the doc will have no color applied. To do around this, we
add a selector check that if `data-theme` is not defined, then we apply the light theme
by default.
*/
/* Begin theme: light */
:root[data-theme="light"] {
:root[data-theme="light"], :root:not([data-theme]) {
--main-background-color: white;
--main-color: black;
--settings-input-color: #2196f3;

View File

@ -74,8 +74,11 @@ fn compare_themes<'a>(
(noscript_css_line_number, noscript_css_line),
) in rustdoc_css_lines.zip(noscript_css_lines)
{
if noscript_css_line.starts_with(":root {")
&& rustdoc_css_line.starts_with(&format!(r#":root[data-theme="{name}"] {{"#))
if noscript_css_line.starts_with(":root, :root:not([data-theme]) {")
&& (rustdoc_css_line.starts_with(&format!(r#":root[data-theme="{name}"] {{"#))
|| rustdoc_css_line.starts_with(&format!(
r#":root[data-theme="{name}"], :root:not([data-theme]) {{"#
)))
{
// selectors are different between rustdoc.css and noscript.css
// that's why they both exist: one uses JS, the other uses media queries

View File

@ -3,4 +3,18 @@
javascript: false
go-to: "file://" + |DOC_PATH| + "/test_docs/struct.Foo.html"
show-text: true
assert-css: (".sub", {"display": "none"})
// Even though JS is disabled, we should still have themes applied. Links are never black-colored
// if styles are applied so we check that they are not.
assert-css-false: ("a.src", {"color": "#000"})
javascript: true
fail-on-request-error: false
block-network-request: "*.js"
reload:
// JS is enabled but wasn't loaded, we should still have the light theme applied. Links are never
// black-colored if styles are applied so we check that they are not.
assert-css-false: ("a.src", {"color": "#000"})