Skip to content

Commit 44bf482

Browse files
committed
fix(vue): always read router callback
fixes algolia/instantsearch#6561
1 parent 5057297 commit 44bf482

File tree

4 files changed

+9
-42
lines changed

4 files changed

+9
-42
lines changed

vue-instantsearch/routing-vue-router/src/views/Home.vue

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,8 @@ export default {
6767
}).href;
6868
},
6969
onUpdate(cb) {
70-
this._onPopState = event => {
71-
const routeState = event.state;
72-
// at initial load, the state is read from the URL without
73-
// update. Therefore the state object is not there. In this
74-
// case we fallback and read the URL.
75-
if (!routeState) {
76-
cb(this.read());
77-
} else {
78-
cb(routeState);
79-
}
70+
this._onPopState = () => {
71+
cb(this.read());
8072
};
8173
window.addEventListener('popstate', this._onPopState);
8274
},

vue-instantsearch/server-side-rendering/src/main.js

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,22 +74,13 @@ export async function createApp({
7474
return;
7575
}
7676
// TODO: handle vue route changes
77-
this._onPopState = event => {
77+
this._onPopState = () => {
7878
if (this.writeTimer) {
7979
window.clearTimeout(this.writeTimer);
8080
this.writeTimer = undefined;
8181
}
8282

83-
const routeState = event.state;
84-
85-
// At initial load, the state is read from the URL without update.
86-
// Therefore the state object is not available.
87-
// In this case, we fallback and read the URL.
88-
if (!routeState) {
89-
callback(this.read());
90-
} else {
91-
callback(routeState);
92-
}
83+
callback(this.read());
9384
};
9485

9586
window.addEventListener('popstate', this._onPopState);
@@ -119,7 +110,7 @@ export async function createApp({
119110
}
120111
},
121112
router,
122-
render: h => h(App),
113+
render: (h) => h(App),
123114
});
124115

125116
const result = {

vue-instantsearch/vue3-ssr-vite/src/main.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,8 @@ export function createApp({ renderToString, context } = {}) {
5353
return router.resolve({ query: routeState }).href;
5454
},
5555
onUpdate(callback) {
56-
this._onPopState = (event) => {
57-
const routeState = event.state;
58-
// at initial load, the state is read from the URL without
59-
// update. Therefore the state object is not there. In this
60-
// case we fallback and read the URL.
61-
if (!routeState) {
62-
callback(this.read());
63-
} else {
64-
callback(routeState);
65-
}
56+
this._onPopState = () => {
57+
callback(this.read());
6658
};
6759
typeof window === 'object' &&
6860
window.addEventListener('popstate', this._onPopState);

vue-instantsearch/vue3-ssr-vue-cli/src/app.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,8 @@ export function createApp({ renderToString, context } = {}) {
4949
return router.resolve({ query: routeState }).href;
5050
},
5151
onUpdate(callback) {
52-
this._onPopState = event => {
53-
const routeState = event.state;
54-
// at initial load, the state is read from the URL without
55-
// update. Therefore the state object is not there. In this
56-
// case we fallback and read the URL.
57-
if (!routeState) {
58-
callback(this.read());
59-
} else {
60-
callback(routeState);
61-
}
52+
this._onPopState = () => {
53+
callback(this.read());
6254
};
6355
typeof window === 'object' &&
6456
window.addEventListener('popstate', this._onPopState);

0 commit comments

Comments
 (0)