Skip to content

Commit 13091dd

Browse files
Make implementors list visible only when filled
1 parent 985178d commit 13091dd

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ nav.sub {
2929
display: none;
3030
}
3131

32+
#synthetic-implementors-list, #implementors-list {
33+
display: block;
34+
}
35+
3236
/* Begin: styles for themes
3337
Keep the default light and dark themes synchronized with the ones
3438
in rustdoc.css */

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,6 +1158,12 @@ div.where {
11581158
margin-left: calc(var(--docblock-indent) + var(--impl-items-indent));
11591159
}
11601160

1161+
#synthetic-implementors-list, #implementors-list {
1162+
/* To prevent layout shift when loading the page with extra implementors being loaded
1163+
from JS, we hide the list until it's complete. */
1164+
display: none;
1165+
}
1166+
11611167
.item-info code {
11621168
font-size: 0.875rem;
11631169
}

src/librustdoc/html/static/js/main.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -813,21 +813,21 @@ function preLoadCss(cssUrl) {
813813
return [elem, elem ? elem.querySelector(".negative-marker") : null];
814814
}
815815
const implementors = implementorsElems("implementors-list");
816-
const synthetic_implementors = implementorsElems("synthetic-implementors-list");
816+
const syntheticImplementors = implementorsElems("synthetic-implementors-list");
817817
const inlined_types = new Set();
818818

819819
const TEXT_IDX = 0;
820820
const IS_NEG_IDX = 1;
821821
const SYNTHETIC_IDX = 2;
822822
const TYPES_IDX = 3;
823823

824-
if (synthetic_implementors[0]) {
824+
if (syntheticImplementors[0]) {
825825
// This `inlined_types` variable is used to avoid having the same implementation
826826
// showing up twice. For example "String" in the "Sync" doc page.
827827
//
828828
// By the way, this is only used by and useful for traits implemented automatically
829829
// (like "Send" and "Sync").
830-
onEachLazy(synthetic_implementors[0].getElementsByClassName("impl"), el => {
830+
onEachLazy(syntheticImplementors[0].getElementsByClassName("impl"), el => {
831831
const aliases = el.getAttribute("data-aliases");
832832
if (!aliases) {
833833
return;
@@ -862,7 +862,7 @@ function preLoadCss(cssUrl) {
862862

863863
struct_loop:
864864
for (const struct of structs) {
865-
const list = struct[SYNTHETIC_IDX] ? synthetic_implementors : implementors;
865+
const list = struct[SYNTHETIC_IDX] ? syntheticImplementors : implementors;
866866

867867
// The types list is only used for synthetic impls.
868868
// If this changes, `main.js` and `write_shared.rs` both need changed.
@@ -910,6 +910,12 @@ function preLoadCss(cssUrl) {
910910
currentNbImpls += 1;
911911
}
912912
}
913+
if (implementors[0]) {
914+
implementors[0].style.display = "block";
915+
}
916+
if (syntheticImplementors[0]) {
917+
syntheticImplementors[0].style.display = "block";
918+
}
913919
};
914920
if (window.pending_implementors) {
915921
window.register_implementors(window.pending_implementors);

tests/rustdoc-gui/implementors.goml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// The goal of this test is to check that the external trait implementors, generated with JS,
22
// have the same display than the "local" ones.
33
go-to: "file://" + |DOC_PATH| + "/implementors/trait.Whatever.html"
4-
assert: "#implementors-list"
4+
wait-for-css: ("#implementors-list", {"display": "block"})
55
// There are supposed to be four implementors listed.
66
assert-count: ("#implementors-list .impl", 4)
77
// There are supposed to be two non-negative implementors.
@@ -66,3 +66,8 @@ assert-count: ("#implementors-list .impl", 1)
6666
go-to: "file://" + |DOC_PATH| + "/http/trait.HttpTrait.html"
6767
assert-count: ("#implementors-list .impl", 1)
6868
assert-attribute: ("#implementors-list .impl a.trait", {"href": "../http/trait.HttpTrait.html"})
69+
70+
// Now we check that if JS is disabled, the implementors list will be visible.
71+
javascript: false
72+
reload:
73+
assert-css: ("#implementors-list", {"display": "block"})

0 commit comments

Comments
 (0)