Skip to content

Commit 98cdd2f

Browse files
committed
Harden URLDocSearch init
1 parent 687b8e3 commit 98cdd2f

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

.vuepress/components/URLDocSearch.vue

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
</template>
44

55
<script setup lang="ts">
6-
import { DocSearch, DocSearchOptions } from '@vuepress/plugin-docsearch/client';
6+
import { DocSearch } from '@vuepress/plugin-docsearch/client';
77
import {
88
useDebounceFn,
99
useElementVisibility,
@@ -22,10 +22,13 @@ const inputElement = ref<HTMLInputElement>();
2222
const isNavigating = ref(false);
2323
2424
// Handle initial search query, if one is set
25-
onMounted(async () => {
25+
onMounted(() => {
2626
const query = new URL(window.location.href).searchParams.get(SEARCH_KEY);
2727
if (query) {
28-
(document.querySelector('.DocSearch-Button') as HTMLButtonElement).click();
28+
const button =
29+
document.querySelector<HTMLButtonElement>('.DocSearch-Button');
30+
if (!button) return;
31+
button.click();
2932
// Set value in the input element once it appears
3033
performInitialQuery(query);
3134
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"@vuepress/plugin-shiki": "2.0.0-rc.118",
2121
"@vuepress/plugin-sitemap": "2.0.0-rc.118",
2222
"@vuepress/theme-default": "2.0.0-rc.118",
23+
"@vueuse/core": "^14.0.0",
2324
"asciinema-player": "^3.15.1",
2425
"cross-env": "^10.1.0",
2526
"lefthook": "1.8.2",

0 commit comments

Comments
 (0)