Skip to content

Commit 94e84dd

Browse files
authored
Unrolled build for rust-lang#123407
Rollup merge of rust-lang#123407 - GuillaumeGomez:js-failed-theme, r=notriddle Default to light theme if JS is enabled but not working It doesn't [fix] rust-lang#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`
2 parents 9cbaa01 + a815b97 commit 94e84dd

File tree

5 files changed

+29
-6
lines changed

5 files changed

+29
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.17.0
1+
0.17.1

src/librustdoc/html/static/css/noscript.css

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ nav.sub {
3434
in rustdoc.css */
3535

3636
/* Begin theme: light */
37-
:root {
37+
:root, :root:not([data-theme]) {
3838
--main-background-color: white;
3939
--main-color: black;
4040
--settings-input-color: #2196f3;
@@ -140,7 +140,7 @@ nav.sub {
140140

141141
@media (prefers-color-scheme: dark) {
142142
/* Begin theme: dark */
143-
:root {
143+
:root, :root:not([data-theme]) {
144144
--main-background-color: #353535;
145145
--main-color: #ddd;
146146
--settings-input-color: #2196f3;

src/librustdoc/html/static/css/rustdoc.css

+7-1
Original file line numberDiff line numberDiff line change
@@ -2315,8 +2315,14 @@ in src-script.js and main.js
23152315
tooling to ensure different themes all define all the variables. Do not
23162316
alter their formatting. */
23172317

2318+
/*
2319+
About `:root:not([data-theme])`: if for any reason the JS is enabled but cannot be loaded,
2320+
`noscript` won't be enabled and the doc will have no color applied. To do around this, we
2321+
add a selector check that if `data-theme` is not defined, then we apply the light theme
2322+
by default.
2323+
*/
23182324
/* Begin theme: light */
2319-
:root[data-theme="light"] {
2325+
:root[data-theme="light"], :root:not([data-theme]) {
23202326
--main-background-color: white;
23212327
--main-color: black;
23222328
--settings-input-color: #2196f3;

src/tools/tidy/src/rustdoc_css_themes.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,11 @@ fn compare_themes<'a>(
7474
(noscript_css_line_number, noscript_css_line),
7575
) in rustdoc_css_lines.zip(noscript_css_lines)
7676
{
77-
if noscript_css_line.starts_with(":root {")
78-
&& rustdoc_css_line.starts_with(&format!(r#":root[data-theme="{name}"] {{"#))
77+
if noscript_css_line.starts_with(":root, :root:not([data-theme]) {")
78+
&& (rustdoc_css_line.starts_with(&format!(r#":root[data-theme="{name}"] {{"#))
79+
|| rustdoc_css_line.starts_with(&format!(
80+
r#":root[data-theme="{name}"], :root:not([data-theme]) {{"#
81+
)))
7982
{
8083
// selectors are different between rustdoc.css and noscript.css
8184
// that's why they both exist: one uses JS, the other uses media queries

tests/rustdoc-gui/javascript-disabled.goml

+14
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,18 @@
33
javascript: false
44

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

0 commit comments

Comments
 (0)