Skip to content

Commit 3323d0e

Browse files
authored
Do not run window.history.replaceState unconditionally
Currently every Sphinx documentation page *always* drops `#:~:text=...` Text Fragments unconditionally due to `window.history.replaceState`. The solution is to only call `window.history.replaceState` when a `?highlight=...` param is part of the URL.
1 parent eaebbec commit 3323d0e

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

sphinx/themes/basic/static/sphinx_highlight.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,10 @@ const SphinxHighlight = {
8080
|| url.searchParams.get("highlight")
8181
|| "";
8282
localStorage.removeItem("sphinx_highlight_terms");
83-
url.searchParams.delete("highlight");
84-
window.history.replaceState({}, "", url);
83+
if (url.searchParams.has("highlight")) {
84+
url.searchParams.delete("highlight");
85+
window.history.replaceState({}, "", url);
86+
}
8587

8688
// get individual terms from highlight string
8789
const terms = highlight

0 commit comments

Comments
 (0)