Fix JS error when hasFocus method is overwritten on search index load

This commit is contained in:
Guillaume Gomez 2025-06-25 18:20:59 +02:00
parent f3ee794283
commit 63e1dac122
2 changed files with 5 additions and 1 deletions

View file

@ -69,7 +69,7 @@ pub fn create_files(
// To reduce the size of the generated JSON by preventing all `"` characters to be
// escaped, we instead surround the string with much less common `'` character.
format!(
"window.search = JSON.parse('{}');",
"window.search = Object.assign(window.search, JSON.parse('{}'));",
index.replace("\\", "\\\\").replace("'", "\\'")
)
.as_bytes(),

View file

@ -1,5 +1,6 @@
// This tests basic search behavior.
fail-on-js-error: true
go-to: |DOC_PATH| + "index.html"
define-function: (
@ -41,6 +42,9 @@ press-key: 's'
wait-for-css-false: ("#search-wrapper", {"display": "none"})
// We ensure the search bar has the focus.
assert: "#searchbar:focus"
// Pressing a key will therefore update the search input.
press-key: 't'
assert-text: ("#searchbar", "t")
// Now we press `Escape` to ensure that the search input disappears again.
press-key: 'Escape'