Skip to content

Commit 401d81f

Browse files
haampieAA-Turner
andauthored
Do not run window.history.replaceState() unconditionally (#13918)
Co-authored-by: Adam Turner <[email protected]>
1 parent c06bfce commit 401d81f

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

CHANGES.rst

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

152154

153155
Testing

sphinx/themes/basic/static/sphinx_highlight.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,12 @@ 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+
// Update history only if '?highlight' is present; otherwise it
84+
// clears text fragments (not set in window.location by the browser)
85+
if (url.searchParams.has("highlight")) {
86+
url.searchParams.delete("highlight");
87+
window.history.replaceState({}, "", url);
88+
}
8589

8690
// get individual terms from highlight string
8791
const terms = highlight

0 commit comments

Comments
 (0)