Auto merge of #82511 - jsha:fix-bfcache2, r=GuillaumeGomez
Fix back-forward cache in rustdoc frontend Rustdoc's frontend set a no-op unload handler, specifically to disable Firefox's back-forward cache because it caused a bug. It's nice to allow the back-forward cache because it permits faster navigations. This change addresses the issues that were caused by back-forward cache. https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Releases/1.5/Using_Firefox_1.5_caching https://web.dev/bfcache/ Demo: https://jacob.hoffman-andrews.com/rust/fix-bfcache/std/string/struct.String.html Related: #72272
This commit is contained in:
commit
0846043440
1 changed files with 14 additions and 6 deletions
|
@ -2000,6 +2000,20 @@ function defocusSearchBar() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
search();
|
search();
|
||||||
|
|
||||||
|
// This is required in firefox to avoid this problem: Navigating to a search result
|
||||||
|
// with the keyboard, hitting enter, and then hitting back would take you back to
|
||||||
|
// the doc page, rather than the search that should overlay it.
|
||||||
|
// This was an interaction between the back-forward cache and our handlers
|
||||||
|
// that try to sync state between the URL and the search input. To work around it,
|
||||||
|
// do a small amount of re-init on page show.
|
||||||
|
window.onpageshow = function(){
|
||||||
|
var qSearch = getQueryStringParams().search;
|
||||||
|
if (search_input.value === "" && qSearch) {
|
||||||
|
search_input.value = qSearch;
|
||||||
|
}
|
||||||
|
search();
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
index = buildIndex(rawSearchIndex);
|
index = buildIndex(rawSearchIndex);
|
||||||
|
@ -2958,9 +2972,3 @@ function defocusSearchBar() {
|
||||||
onHashChange(null);
|
onHashChange(null);
|
||||||
window.onhashchange = onHashChange;
|
window.onhashchange = onHashChange;
|
||||||
}());
|
}());
|
||||||
|
|
||||||
// This is required in firefox. Explanations: when going back in the history, firefox doesn't re-run
|
|
||||||
// the JS, therefore preventing rustdoc from setting a few things required to be able to reload the
|
|
||||||
// previous search results (if you navigated to a search result with the keyboard, pressed enter on
|
|
||||||
// it to navigate to that result, and then came back to this page).
|
|
||||||
window.onunload = function(){};
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue