Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.17.0
0.17.1
4 changes: 2 additions & 2 deletions src/librustdoc/html/static/css/noscript.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 7 additions & 1 deletion src/librustdoc/html/static/css/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 5 additions & 2 deletions src/tools/tidy/src/rustdoc_css_themes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions tests/rustdoc-gui/javascript-disabled.goml
Original file line number Diff line number Diff line change
Expand Up @@ -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"})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem like it's actually testing what the commit is fixing.

The nightly docs aren't broken because javascript is disabled. They're broken because javascript is enabled, but the script fails to load. Your test case should actually create these conditions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't indeed because I couldn't find a way to have a "broken JS" state. So this ensure that the rules I modified still works for noscript. However for the "broken JS" state, well. Please trust me? ^^'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could reasonably be tested with a few minor changes to browser-ui-test. Puppeteer has an API for intercepting network requests. This could be used to implement a block-network-request: "*.js" command that we could use to simulate a broken network.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might also be possible to add a CSP through a meta tag that doesn't allow any script-source.
But I'm not sure if that triggers the noscript alternative.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be used to implement a block-network-request: "*.js" command that we could use to simulate a broken network.

Good idea!

It might also be possible to add a CSP through a meta tag that doesn't allow any script-source. But I'm not sure if that triggers the noscript alternative.

It would require to update the DOM before loading the page. Can be done but I'm not a big fan of this approach.


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"})