Skip to content

Commit 20f0ae8

Browse files
authored
Unrolled build for rust-lang#121590
Rollup merge of rust-lang#121590 - GuillaumeGomez:rustdoc-js-changed, r=notriddle Correctly handle if rustdoc JS script hash changed It's something that annoyed me for quite some time: I have nightly docs open (for both std and compiler). And often, I don't look at the page for some days. Then when I come back to it, I make a search... except nothing happens. Took me a while to figure out that it was because the hash of one of the JS files we load for the search (either `search.js` or `search-index.js`) was updated in the meantime, preventing the search to be done. To go around it, I added to press `ENTER` to make the form submitted (which would reload the same page but with the correct hashes this time and the search being run). r? `@notriddle`
2 parents dc00e8c + 3af67bb commit 20f0ae8

File tree

1 file changed

+11
-3
lines changed
  • src/librustdoc/html/static/js

1 file changed

+11
-3
lines changed

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

+11-3
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,12 @@ function preLoadCss(cssUrl) {
185185
(function() {
186186
const isHelpPage = window.location.pathname.endsWith("/help.html");
187187

188-
function loadScript(url) {
188+
function loadScript(url, errorCallback) {
189189
const script = document.createElement("script");
190190
script.src = url;
191+
if (errorCallback !== undefined) {
192+
script.onerror = errorCallback;
193+
}
191194
document.head.append(script);
192195
}
193196

@@ -292,11 +295,16 @@ function preLoadCss(cssUrl) {
292295
return;
293296
}
294297
let searchLoaded = false;
298+
// If you're browsing the nightly docs, the page might need to be refreshed for the
299+
// search to work because the hash of the JS scripts might have changed.
300+
function sendSearchForm() {
301+
document.getElementsByClassName("search-form")[0].submit();
302+
}
295303
function loadSearch() {
296304
if (!searchLoaded) {
297305
searchLoaded = true;
298-
loadScript(getVar("static-root-path") + getVar("search-js"));
299-
loadScript(resourcePath("search-index", ".js"));
306+
loadScript(getVar("static-root-path") + getVar("search-js"), sendSearchForm);
307+
loadScript(resourcePath("search-index", ".js"), sendSearchForm);
300308
}
301309
}
302310

0 commit comments

Comments
 (0)