Skip to content

Commit 2edc54c

Browse files
Default to light theme is JS is enabled but not working
1 parent c7491b9 commit 2edc54c

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

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;

0 commit comments

Comments
 (0)