From 56898ec6a7a9d3e221860c4c94f0e16c3a9d1c35 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 11 Mar 2021 21:13:42 +0100 Subject: [PATCH] Prevent JS error when there is no dependency or other crate documented --- src/librustdoc/html/static/main.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index d5071cec0c8..7827548aa1c 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -2955,7 +2955,11 @@ function defocusSearchBar() { enableSearchInput(); 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();