Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly handle if rustdoc JS script hash changed #121590

Merged
merged 1 commit into from
Feb 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/librustdoc/html/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}
}

Expand Down
Loading