From 6605bfbf7cdea86492b33070167634284af0ffe7 Mon Sep 17 00:00:00 2001 From: Santos Gallegos Date: Mon, 31 Jan 2022 19:07:51 -0500 Subject: [PATCH 1/2] Searchtools: don't assume that all themes define some elements When retrieving a non-existent element, jQuery would still return an object (kind of empty one, so method calls won't raise a null exception), but now `getElementById` will return null and raise an exception when trying to call a method on that value. This mainly affects the rtd theme, which completely overrides the search page https://github.com/readthedocs/sphinx_rtd_theme/blob/d64dadf1ceec4f9ff6c1ca2d3ea4c3d0fdb0e8d2/sphinx_rtd_theme/search.html --- sphinx/themes/basic/static/searchtools.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/sphinx/themes/basic/static/searchtools.js b/sphinx/themes/basic/static/searchtools.js index 94350750820..35341f16540 100644 --- a/sphinx/themes/basic/static/searchtools.js +++ b/sphinx/themes/basic/static/searchtools.js @@ -48,7 +48,7 @@ if (!Scorer) { } const _removeChildren = (element) => { - while (element.lastChild) element.removeChild(element.lastChild); + while (element && element.lastChild) element.removeChild(element.lastChild); }; /** @@ -208,9 +208,11 @@ const Search = { Search.status = out.appendChild(searchSummary); Search.output = out.appendChild(searchList); - document.getElementById("search-progress").innerText = _( - "Preparing search..." - ); + const searchProgress = document.getElementById("search-progress"); + // Not all themes may have this element. + if (searchProgress) { + searchProgress.innerText = _("Preparing search..."); + } Search.startPulse(); // index already loaded, the browser was quick! From a45e4d4482245bfc3b75eec420592f4be8fea1bf Mon Sep 17 00:00:00 2001 From: Santos Gallegos Date: Mon, 7 Feb 2022 10:31:50 -0500 Subject: [PATCH 2/2] Update sphinx/themes/basic/static/searchtools.js Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com> --- sphinx/themes/basic/static/searchtools.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sphinx/themes/basic/static/searchtools.js b/sphinx/themes/basic/static/searchtools.js index 35341f16540..b1f14f3a9b5 100644 --- a/sphinx/themes/basic/static/searchtools.js +++ b/sphinx/themes/basic/static/searchtools.js @@ -209,7 +209,7 @@ const Search = { Search.output = out.appendChild(searchList); const searchProgress = document.getElementById("search-progress"); - // Not all themes may have this element. + // Some themes don't use the search progress node if (searchProgress) { searchProgress.innerText = _("Preparing search..."); }