diff --git a/CHANGELOG.md b/CHANGELOG.md index 8abade3c6a..ba5e3659c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Disable product mutation when assigning product variant - @gibkigonzo (#3735) - Fixed null value of search input - @AdKamil (#3778) - Sorting fixed on category page - @AdKamil (#3785) +- Mount app in 'beforeResolve' if it's not dispatched in 'onReady' - @gibkigonzo (#3669) ## [1.10.4] - 18.10.2019 diff --git a/core/client-entry.ts b/core/client-entry.ts index 38f242ab50..72437fc3d7 100755 --- a/core/client-entry.ts +++ b/core/client-entry.ts @@ -63,8 +63,22 @@ const invokeClientEntry = async () => { }) } router.onReady(async () => { + // check if app can be mounted + const canBeMounted = () => RouterManager.isRouteDispatched() && // route is dispatched + !(router as any).history.pending && // there is no pending in router history + !(app as any)._isMounted // it's not mounted before + + if (canBeMounted()) { + app.$mount('#app') + } router.beforeResolve((to, from, next) => { - if (!from.name) return next() // do not resolve asyncData on server render - already been done + if (!from.name) { + next() + if (canBeMounted()) { + app.$mount('#app') + } + return // do not resolve asyncData on server render - already been done + } if (Vue.prototype.$ssrRequestContext) Vue.prototype.$ssrRequestContext.output.cacheTags = new Set() const matched = router.getMatchedComponents(to) if (to) { // this is from url @@ -99,14 +113,6 @@ const invokeClientEntry = async () => { } })) }) - // Mounting app - if (!RouterManager.isRouteDispatched()) { - RouterManager.addDispatchCallback(() => { - app.$mount('#app') - }) - } else { - app.$mount('#app') - } }) registerSyncTaskProcessor() window.addEventListener('online', () => { onNetworkStatusChange(store) }) diff --git a/core/lib/search/adapter/api/searchAdapter.ts b/core/lib/search/adapter/api/searchAdapter.ts index 556c6f6603..b40e8fb204 100644 --- a/core/lib/search/adapter/api/searchAdapter.ts +++ b/core/lib/search/adapter/api/searchAdapter.ts @@ -80,10 +80,10 @@ export class SearchAdapter { }, body: config.elasticsearch.queryMethod === 'POST' ? JSON.stringify(ElasticsearchQueryBody) : null }) - .then(resp => { return resp.json() }) - .catch(error => { - throw new Error('FetchError in request to ES: ' + error.toString()) - }) + .then(resp => { return resp.json() }) + .catch(error => { + throw new Error('FetchError in request to ES: ' + error.toString()) + }) } public handleResult (resp, type, start = 0, size = 50): SearchResponse {