diff options
| author | Guillaume Gomez <guillaume.gomez@huawei.com> | 2024-02-25 16:28:38 +0100 |
|---|---|---|
| committer | Guillaume Gomez <guillaume.gomez@huawei.com> | 2024-02-25 16:28:38 +0100 |
| commit | 3af67bba18f7a204a93831f3eafa26a73de11721 (patch) | |
| tree | eadbdf2db4be4ce89c6f7bcab1a38fb8c2e4e3e2 /src | |
| parent | 1d447a9946effc38c4b964a888ab408a3df3c246 (diff) | |
Correctly handle if rustdoc JS script hash changed
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustdoc/html/static/js/main.js | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/librustdoc/html/static/js/main.js b/src/librustdoc/html/static/js/main.js index b26efb75ff6..b9a769a7c6d 100644 --- a/src/librustdoc/html/static/js/main.js +++ b/src/librustdoc/html/static/js/main.js @@ -185,9 +185,12 @@ function preLoadCss(cssUrl) { (function() { const isHelpPage = window.location.pathname.endsWith("/help.html"); - function loadScript(url) { + function loadScript(url, errorCallback) { const script = document.createElement("script"); script.src = url; + if (errorCallback !== undefined) { + script.onerror = errorCallback; + } document.head.append(script); } @@ -292,11 +295,16 @@ function preLoadCss(cssUrl) { return; } let searchLoaded = false; + // If you're browsing the nightly docs, the page might need to be refreshed for the + // search to work because the hash of the JS scripts might have changed. + function sendSearchForm() { + document.getElementsByClassName("search-form")[0].submit(); + } function loadSearch() { if (!searchLoaded) { searchLoaded = true; - loadScript(getVar("static-root-path") + getVar("search-js")); - loadScript(resourcePath("search-index", ".js")); + loadScript(getVar("static-root-path") + getVar("search-js"), sendSearchForm); + loadScript(resourcePath("search-index", ".js"), sendSearchForm); } } |
