diff options
| author | bors <bors@rust-lang.org> | 2023-12-15 10:50:09 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-12-15 10:50:09 +0000 |
| commit | 96df4943409564a187894018f15f795426dc2e1f (patch) | |
| tree | c5ad76afae23bf85e0fdff647180aa42f205dafe /src/librustdoc/html/render | |
| parent | d253bf61ad38a59cc579aee688f81a06c31283d3 (diff) | |
| parent | 09c8fd35ac1e24416207feaae04a499768994498 (diff) | |
| download | rust-96df4943409564a187894018f15f795426dc2e1f.tar.gz rust-96df4943409564a187894018f15f795426dc2e1f.zip | |
Auto merge of #118961 - notriddle:notriddle/varconst, r=GuillaumeGomez
rustdoc-search: fix a race condition in search index loading `var` declare it in the global scope, and `const` does not. It needs to be declared in global scope. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/var https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const > const declarations do not create properties on [globalThis](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis) when declared at the top level of a script. Fixes a regression introduced by https://github.com/rust-lang/rust/pull/118910
Diffstat (limited to 'src/librustdoc/html/render')
| -rw-r--r-- | src/librustdoc/html/render/write_shared.rs | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/librustdoc/html/render/write_shared.rs b/src/librustdoc/html/render/write_shared.rs index 4b5d1c0d87c..c4a6e920031 100644 --- a/src/librustdoc/html/render/write_shared.rs +++ b/src/librustdoc/html/render/write_shared.rs @@ -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()) @@ -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#"\ |
