[rustdoc] Only generate search DOM elements if the search is actually needed - #160639
[rustdoc] Only generate search DOM elements if the search is actually needed#160639GuillaumeGomez wants to merge 3 commits into
Conversation
|
Some changes occurred in HTML/CSS/JS. |
| @@ -16,6 +17,7 @@ define-function: ("collapsed-from-search", [], block { | |||
| // Then we collapse the section again... | |||
| set-property: ("#implementations-list .implementors-toggle", {"open": "false"}) | |||
| // Then we run the search. | |||
| call-function: ("open-search", {}) | |||
There was a problem hiding this comment.
Ah that was my original "quest": looking at fixing the new flakyness which happened in #159593 (comment). ^^'
This comment has been minimized.
This comment has been minimized.
24284c5 to
977669b
Compare
|
Added the missing Typescript type definition update and CI is now happy. |
|
Added comments as suggested for clarification. |
| // 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. |
There was a problem hiding this comment.
nit: technically this doesn't just apply to nightly, it's just way more common there
| if (!window.StringdexOnload) { | ||
| window.StringdexOnload = []; | ||
| } | ||
| window.StringdexOnload.push(() => { | ||
| loadScript( | ||
| getVar("static-root-path") + getVar("search-js"), | ||
| sendSearchForm, | ||
| ); | ||
| }); |
There was a problem hiding this comment.
the structure of this doesn't make a ton of sense to me in combination, shouldn't we just be initializing it to an array with a single element? otherwise we could hypothetically end up with an array of duplicate initializers?
There was a problem hiding this comment.
Just moved existing code, didn't modify anything. I think it's because you can have multiple search indexes loaded in parallel.
| // We load the search input. | ||
| window.searchState.inputElement(); |
There was a problem hiding this comment.
best i can tell, inputElement() doesn't directly load the search, it sets up a focus handler that loads the search.. why not just load the search and get something more readable and less indirect?
There was a problem hiding this comment.
I'll improve the comment as it's quite unclear.
3367289 to
730e9a6
Compare
|
Improved the problematic comment. As I mentioned, the rest is just code I moved around. |
I realized that we were generating the search DOM elements (everything contained into
#search) all the times, even when there is no search query parameters in the URL. That seems unnecessary so I reworked the JS a bit to remove that.r? @lolbinarycat