Skip to content

Commit 42134ec

Browse files
Make implementors list visible only when filled
1 parent 2045fb0 commit 42134ec

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
@@ -812,21 +812,21 @@ function preLoadCss(cssUrl) {
812812
return [elem, elem ? elem.querySelector(".negative-marker") : null];
813813
}
814814
const implementors = implementorsElems("implementors-list");
815-
const synthetic_implementors = implementorsElems("synthetic-implementors-list");
815+
const syntheticImplementors = implementorsElems("synthetic-implementors-list");
816816
const inlined_types = new Set();
817817

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

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

862862
struct_loop:
863863
for (const struct of structs) {
864-
const list = struct[SYNTHETIC_IDX] ? synthetic_implementors : implementors;
864+
const list = struct[SYNTHETIC_IDX] ? syntheticImplementors : implementors;
865865

866866
// The types list is only used for synthetic impls.
867867
// If this changes, `main.js` and `write_shared.rs` both need changed.
@@ -909,6 +909,12 @@ function preLoadCss(cssUrl) {
909909
currentNbImpls += 1;
910910
}
911911
}
912+
if (implementors[0]) {
913+
implementors[0].style.display = "block";
914+
}
915+
if (syntheticImplementors[0]) {
916+
syntheticImplementors[0].style.display = "block";
917+
}
912918
};
913919
if (window.pending_implementors) {
914920
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)