Skip to content

Commit 824e152

Browse files
authored
fix: correct hydration for instant search (#1866)
1 parent 76070c1 commit 824e152

2 files changed

Lines changed: 44 additions & 28 deletions

File tree

app/components/InstantSearch.vue

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<script setup lang="ts">
2+
import { useSettings } from '~/composables/useSettings'
3+
4+
const { settings } = useSettings()
5+
6+
onPrehydrate(el => {
7+
const settingsSaved = JSON.parse(localStorage.getItem('npmx-settings') || '{}')
8+
const enabled = settingsSaved.instantSearch
9+
if (enabled === false) {
10+
el.classList.add('hidden')
11+
}
12+
})
13+
</script>
14+
15+
<template>
16+
<p
17+
id="instant-search-advisory"
18+
class="text-fg-muted text-sm text-pretty"
19+
:class="settings.instantSearch ? '' : 'hidden'"
20+
>
21+
<span
22+
class="i-lucide:zap align-middle text-fg relative top-[-0.1em] me-1"
23+
style="font-size: 0.8em"
24+
aria-hidden="true"
25+
></span>
26+
<i18n-t keypath="search.instant_search_advisory">
27+
<template #label>
28+
<strong>{{ $t('search.instant_search') }}</strong>
29+
</template>
30+
<template #settings>
31+
<LinkBase to="/settings">{{ $t('settings.title') }}</LinkBase>
32+
</template>
33+
<template #shortcut>
34+
<kbd class="text-xs"
35+
><kbd class="text-fg bg-bg-muted border border-border px-1 py-[2px] rounded-sm">Ctrl</kbd
36+
>+<kbd class="text-fg bg-bg-muted border border-border px-1 py-[2px] rounded-sm"
37+
>/</kbd
38+
></kbd
39+
>
40+
</template>
41+
</i18n-t>
42+
</p>
43+
</template>

app/pages/index.vue

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -107,34 +107,7 @@ defineOgImageComponent('Default', {
107107
</div>
108108
</div>
109109

110-
<p
111-
v-if="settings.instantSearch"
112-
id="instant-search-advisory"
113-
class="text-fg-muted text-sm text-pretty"
114-
>
115-
<span
116-
class="i-lucide:zap align-middle text-fg relative top-[-0.1em] me-1"
117-
style="font-size: 0.8em"
118-
aria-hidden="true"
119-
></span>
120-
<i18n-t keypath="search.instant_search_advisory">
121-
<template #label>
122-
<strong>{{ $t('search.instant_search') }}</strong>
123-
</template>
124-
<template #settings>
125-
<LinkBase to="/settings">{{ $t('settings.title') }}</LinkBase>
126-
</template>
127-
<template #shortcut>
128-
<kbd class="text-xs"
129-
><kbd class="text-fg bg-bg-muted border border-border px-1 py-[2px] rounded-sm"
130-
>Ctrl</kbd
131-
>+<kbd class="text-fg bg-bg-muted border border-border px-1 py-[2px] rounded-sm"
132-
>/</kbd
133-
></kbd
134-
>
135-
</template>
136-
</i18n-t>
137-
</p>
110+
<InstantSearch />
138111
</form>
139112
</search>
140113

0 commit comments

Comments
 (0)