Skip to content

Commit 40cd9ce

Browse files
committed
Removed suspense after new Vue release
1 parent ab69ce7 commit 40cd9ce

File tree

3 files changed

+46
-50
lines changed

3 files changed

+46
-50
lines changed

resources/js/components/Search/Autocomplete.vue

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { useDebounceFn } from '@vueuse/core'
1616
import { rapidezAPI } from '../../fetch'
1717
import { searchHistory } from '../../stores/useSearchHistory'
1818
19+
let focusId = document.activeElement.id
1920
export default {
2021
mixins: [InstantSearchMixin],
2122
components: {
@@ -40,25 +41,27 @@ export default {
4041
},
4142
},
4243
43-
data() {
44-
return {
45-
focusId: null,
46-
}
47-
},
48-
4944
render() {
5045
return this.$slots.default(this)
5146
},
5247
created() {
53-
this.focusId = document.activeElement.id
48+
focusId ??= document.activeElement.id
5449
},
5550
mounted() {
51+
let element = null
52+
if (focusId && (element = this.$el.nextSibling.querySelector('#' + focusId))) {
53+
setTimeout(() => {
54+
requestAnimationFrame(() => {
55+
element?.focus()
56+
})
57+
})
58+
}
5659
this.$nextTick(() => {
5760
this.$emit('mounted')
5861
setTimeout(() => {
5962
requestAnimationFrame(() => {
6063
let element = null
61-
if (this.focusId && (element = this.$el.nextSibling.querySelector('#' + this.focusId))) {
64+
if (focusId && (element = this.$el.nextSibling.querySelector('#' + focusId))) {
6265
element?.focus()
6366
}
6467
})

resources/js/vue-components.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ document.addEventListener('vue:loaded', function (event) {
5757
}),
5858

5959
render() {
60-
// TODO: seems broken, replaced by <Suspense> (https://github.com/vuejs/core/pull/13997)
6160
return this.$slots.default(this)
6261
},
6362
delay: 0,
Lines changed: 35 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,43 @@
1-
<Suspense>
2-
<template #default>
3-
<autocomplete v-slot="autocompleteSlotProps" :hits-per-page="{{ config('rapidez.frontend.autocomplete.size', 3) }}">
4-
<div class="relative w-full" ref="root">
5-
<ais-instant-search
6-
v-if="autocompleteSlotProps.searchClient"
7-
:future="{ preserveSharedStateOnUnmount: true }"
8-
:search-client="autocompleteSlotProps.searchClient"
9-
:middlewares="autocompleteSlotProps.middlewares"
10-
:index-name="config.index.product"
11-
class="contents"
12-
v-cloak
13-
>
14-
<div class="contents">
15-
<div class="searchbox group/autocomplete">
16-
<ais-autocomplete>
17-
<template v-slot="{ currentRefinement, refine }">
18-
<x-rapidez::autocomplete.input
19-
v-bind:value="currentRefinement"
20-
v-on:focus="() => {
21-
refine(autocompleteFacadeQuery || currentRefinement);
22-
autocompleteFacadeQuery = null;
23-
}"
24-
v-on:input="refine($event.currentTarget.value)"
25-
list="search-history"
26-
/>
27-
<div v-on:click="refine('')" class="fixed inset-0 bg-backdrop z-header-autocomplete-overlay hidden group-has-[input:not(:placeholder-shown)]/autocomplete:block group-has-[:focus]/autocomplete:block"></div>
28-
</template>
29-
</ais-autocomplete>
30-
<div class="absolute inset-x-0 top-full mt-1 bg-white rounded-md z-header-autocomplete hidden group-has-[input:not(:placeholder-shown)]/autocomplete:block group-has-[:focus]/autocomplete:block hover:block">
31-
@include('rapidez::layouts.partials.header.autocomplete.results')
32-
</div>
33-
<ais-stats-analytics></ais-stats-analytics>
34-
</div>
1+
<autocomplete v-slot="autocompleteSlotProps" :hits-per-page="{{ config('rapidez.frontend.autocomplete.size', 3) }}">
2+
<div class="relative w-full" ref="root">
3+
<ais-instant-search
4+
v-if="autocompleteSlotProps.searchClient"
5+
:future="{ preserveSharedStateOnUnmount: true }"
6+
:search-client="autocompleteSlotProps.searchClient"
7+
:middlewares="autocompleteSlotProps.middlewares"
8+
:index-name="config.index.product"
9+
class="contents"
10+
v-cloak
11+
>
12+
<div class="contents">
13+
<div class="searchbox group/autocomplete">
14+
<ais-autocomplete>
15+
<template v-slot="{ currentRefinement, refine }">
16+
<x-rapidez::autocomplete.input
17+
v-bind:value="currentRefinement"
18+
v-on:focus="() => {
19+
refine(autocompleteFacadeQuery || currentRefinement);
20+
autocompleteFacadeQuery = null;
21+
}"
22+
v-on:input="refine($event.currentTarget.value)"
23+
list="search-history"
24+
/>
25+
<div v-on:click="refine('')" class="fixed inset-0 bg-backdrop z-header-autocomplete-overlay hidden group-has-[input:not(:placeholder-shown)]/autocomplete:block group-has-[:focus]/autocomplete:block"></div>
26+
</template>
27+
</ais-autocomplete>
28+
<div class="absolute inset-x-0 top-full mt-1 bg-white rounded-md z-header-autocomplete hidden group-has-[input:not(:placeholder-shown)]/autocomplete:block group-has-[:focus]/autocomplete:block hover:block">
29+
@include('rapidez::layouts.partials.header.autocomplete.results')
3530
</div>
36-
</ais-instant-search>
31+
<ais-stats-analytics></ais-stats-analytics>
32+
</div>
3733
</div>
38-
</autocomplete>
39-
</template>
40-
<template #fallback>
41-
<div class="relative w-full">
34+
</ais-instant-search>
35+
<div v-else class="relative w-full">
4236
<x-rapidez::autocomplete.input
4337
v-model="autocompleteFacadeQuery"
4438
v-on:focus="window.document.dispatchEvent(new window.Event('loadAutoComplete'))"
4539
v-on:mouseover="window.document.dispatchEvent(new window.Event('loadAutoComplete'))"
4640
/>
4741
</div>
48-
</template>
49-
</Suspense>
42+
</div>
43+
</autocomplete>

0 commit comments

Comments
 (0)