Skip to content

Commit

Permalink
fix: flicker on docsearch button while loading the search component (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Justineo authored Sep 16, 2024
1 parent cfcb540 commit 07b73b7
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/vitepress/components/VPNavBarSearch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const VPAlgoliaSearchBox = defineAsyncComponent(
// to avoid loading the docsearch js upfront (which is more than 1/3 of the
// payload), we delay initializing it until the user has actually clicked or
// hit the hotkey to invoke it
const started = ref(false)
const loaded = ref(false)
const metaKey = ref('Meta')
Expand All @@ -37,16 +38,16 @@ onMounted(() => {
})
function load() {
if (!loaded.value) {
loaded.value = true
if (!started.value) {
started.value = true
}
}
</script>

<template>
<div v-if="config.algolia" class="VPNavBarSearch">
<VPAlgoliaSearchBox v-if="loaded" />
<div v-else id="docsearch" @click="load">
<VPAlgoliaSearchBox v-if="started" @vue:mounted="loaded = true" />
<div v-if="!loaded" id="docsearch" @click="load">
<button
type="button"
class="DocSearch DocSearch-Button"
Expand Down

0 comments on commit 07b73b7

Please sign in to comment.