about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-03-14 06:35:19 +0000
committerbors <bors@rust-lang.org>2021-03-14 06:35:19 +0000
commit2caeeb0527894cd61c22b5ca69bda28a2ff64de3 (patch)
treecfbfaa5035393312b1ad5d2f7106f3e1ea53d87f /src
parent1381dcfdc5da806e0907a6f9534b97b59a6e971f (diff)
parent56898ec6a7a9d3e221860c4c94f0e16c3a9d1c35 (diff)
downloadrust-2caeeb0527894cd61c22b5ca69bda28a2ff64de3.tar.gz
rust-2caeeb0527894cd61c22b5ca69bda28a2ff64de3.zip
Auto merge of #83028 - GuillaumeGomez:prevent-js-error-if-no-filter, r=Nemo157
Prevent JS error when there is no dependency or other crate documented (or --disable-per-crate-search has been used)

When there is only one crate, the dropdown is removed, creating an error (that you can see pretty easily on docs.rs for example).

r? `@jyn514`
Diffstat (limited to 'src')
-rw-r--r--src/librustdoc/html/static/main.js6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js
index ac2da5f779b..e8e4e21d70b 100644
--- a/src/librustdoc/html/static/main.js
+++ b/src/librustdoc/html/static/main.js
@@ -2948,7 +2948,11 @@ function defocusSearchBar() {
         search_input.removeAttribute('disabled');
 
         var crateSearchDropDown = document.getElementById("crate-search");
-        crateSearchDropDown.addEventListener("focus", loadSearch);
+        // `crateSearchDropDown` can be null in case there is only crate because in that case, the
+        // crate filter dropdown is removed.
+        if (crateSearchDropDown) {
+            crateSearchDropDown.addEventListener("focus", loadSearch);
+        }
         var params = getQueryStringParams();
         if (params.search !== undefined) {
             loadSearch();