diff options
| author | Michael Goulet <michael@errs.io> | 2022-06-23 14:39:10 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-06-23 14:39:10 -0700 |
| commit | cc95225feefd81ab77ffc373649ae91e3811d491 (patch) | |
| tree | 1b47a080e4678b7551903606c57db767ed980bc0 /src/librustdoc/html/static/js/source-script.js | |
| parent | 0ed2feca617de0d99f23f96859b372be2e2baab3 (diff) | |
| parent | b37a05bd01a4f1fdcdfda77df4a9008d04236528 (diff) | |
| download | rust-cc95225feefd81ab77ffc373649ae91e3811d491.tar.gz rust-cc95225feefd81ab77ffc373649ae91e3811d491.zip | |
Rollup merge of #98310 - jsha:defer-source-sidebar, r=GuillaumeGomez
rustdoc: optimize loading of source sidebar The source sidebar has a setting to remember whether it should be open or closed. Previously, this setting was handled in source-script.js, which is loaded with `defer`, meaning it is often run after the document is rendered. Since CSS renders the source sidebar as closed by default, changing this after the initial render results in a relayout. Instead, handle the setting in storage.js, which is the first script to load and is the only script that blocks render. This avoids a relayout and means navigating between files with the sidebar open is faster. Demo: https://rustdoc.crud.net/jsha/defer-source-sidebar/src/alloc/ffi/c_str.rs.html r? ````@GuillaumeGomez````
Diffstat (limited to 'src/librustdoc/html/static/js/source-script.js')
| -rw-r--r-- | src/librustdoc/html/static/js/source-script.js | 10 |
1 files changed, 2 insertions, 8 deletions
diff --git a/src/librustdoc/html/static/js/source-script.js b/src/librustdoc/html/static/js/source-script.js index 10f93a1c058..290c29d3141 100644 --- a/src/librustdoc/html/static/js/source-script.js +++ b/src/librustdoc/html/static/js/source-script.js @@ -63,14 +63,13 @@ function createDirEntry(elem, parent, fullPath, hasFoundFile) { } function toggleSidebar() { - const sidebar = document.querySelector("nav.sidebar"); const child = this.children[0]; if (child.innerText === ">") { - sidebar.classList.add("expanded"); + addClass(document.documentElement, "source-sidebar-expanded"); child.innerText = "<"; updateLocalStorage("source-sidebar-show", "true"); } else { - sidebar.classList.remove("expanded"); + removeClass(document.documentElement, "source-sidebar-expanded"); child.innerText = ">"; updateLocalStorage("source-sidebar-show", "false"); } @@ -103,11 +102,6 @@ function createSourceSidebar() { const sidebar = document.createElement("div"); sidebar.id = "source-sidebar"; - if (getCurrentValue("source-sidebar-show") !== "true") { - container.classList.remove("expanded"); - } else { - container.classList.add("expanded"); - } let hasFoundFile = false; |
