Skip to content

Commit 2ad7509

Browse files
committed
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 5d0ad16 commit 2ad7509

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

CHANGES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ Bugs fixed
140140
* #14059: LaTeX: Footnotes cause pdflatex error with French language
141141
(since late June 2025 upstream change to LaTeX ``babel-french``).
142142
Patch by Jean-François B.
143+
* #13916: HTML Search: do not clear text fragments from the URL on page load.
144+
Patch by Harmen Stoppels.
143145

144146

145147
Testing

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)