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

rustdoc-search: fix a race condition in search index loading #118961

Merged
merged 1 commit into from
Dec 15, 2023
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
10 changes: 8 additions & 2 deletions src/librustdoc/html/render/write_shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,10 @@ pub(super) fn write_shared(
.replace("\\\"", "\\\\\"")
));
all_sources.sort();
let mut v = String::from("const srcIndex = new Map(JSON.parse('[\\\n");
// This needs to be `var`, not `const`.
// This variable needs declared in the current global scope so that if
// src-script.js loads first, it can pick it up.
let mut v = String::from("var srcIndex = new Map(JSON.parse('[\\\n");
v.push_str(&all_sources.join(",\\\n"));
v.push_str("\\\n]'));\ncreateSrcSidebar();\n");
Ok(v.into_bytes())
Expand All @@ -317,7 +320,10 @@ pub(super) fn write_shared(
// with rustdoc running in parallel.
all_indexes.sort();
write_invocation_specific("search-index.js", &|| {
let mut v = String::from("const searchIndex = new Map(JSON.parse('[\\\n");
// This needs to be `var`, not `const`.
// This variable needs declared in the current global scope so that if
// search.js loads first, it can pick it up.
let mut v = String::from("var searchIndex = new Map(JSON.parse('[\\\n");
v.push_str(&all_indexes.join(",\\\n"));
v.push_str(
r#"\
Expand Down
Loading