|
1 | 1 | import Vue from 'vue'
|
2 | 2 | import { ActionTree } from 'vuex'
|
3 | 3 | import * as types from './mutation-types'
|
4 |
| -import { breadCrumbRoutes, productThumbnailPath } from '@vue-storefront/core/helpers' |
| 4 | +import { breadCrumbRoutes, productThumbnailPath, isServer } from '@vue-storefront/core/helpers' |
5 | 5 | import { currentStoreView } from '@vue-storefront/core/lib/multistore'
|
6 | 6 | import { configureProductAsync,
|
7 | 7 | doPlatformPricesSync,
|
@@ -617,18 +617,20 @@ const actions: ActionTree<ProductState, RootState> = {
|
617 | 617 | const productFields = Object.keys(product).filter(fieldName => {
|
618 | 618 | return rootStore.state.config.entities.product.standardSystemFields.indexOf(fieldName) < 0 // don't load metadata info for standard fields
|
619 | 619 | })
|
620 |
| - subloaders.push(context.dispatch('attribute/list', { // load attributes to be shown on the product details - the request is now async |
| 620 | + const attributesPromise = context.dispatch('attribute/list', { // load attributes to be shown on the product details - the request is now async |
621 | 621 | filterValues: rootStore.state.config.entities.product.useDynamicAttributeLoader ? productFields : null,
|
622 | 622 | only_visible: rootStore.state.config.entities.product.useDynamicAttributeLoader ? true : false,
|
623 | 623 | only_user_defined: true,
|
624 | 624 | includeFields: rootStore.state.config.entities.optimize ? rootStore.state.config.entities.attribute.includeFields : null
|
625 |
| - }, { root: true })) |
| 625 | + }, { root: true }) // TODO: it might be refactored to kind of: `await context.dispatch('attributes/list) - or using new Promise() .. to wait for attributes to be loaded before executing the next action. However it may decrease the performance - so for now we're just waiting with the breadcrumbs |
626 | 626 | if (Vue.prototype.$isServer) {
|
| 627 | + subloaders.push(context.dispatch('setupBreadcrumbs', { product: product })) |
627 | 628 | subloaders.push(context.dispatch('filterUnavailableVariants', { product: product }))
|
628 | 629 | } else {
|
| 630 | + attributesPromise.then(() => context.dispatch('setupBreadcrumbs', { product: product })) // if this is client's side request postpone breadcrumbs setup till attributes are loaded to avoid too-early breadcrumb switch #2469 |
629 | 631 | context.dispatch('filterUnavailableVariants', { product: product }) // exec async
|
630 | 632 | }
|
631 |
| - subloaders.push(context.dispatch('setupBreadcrumbs', { product: product })) |
| 633 | + subloaders.push(attributesPromise) |
632 | 634 |
|
633 | 635 | // subloaders.push(context.dispatch('setupVariants', { product: product })) -- moved to "product/single"
|
634 | 636 | /* if (product.type_id === 'grouped' || product.type_id === 'bundle') { -- moved to "product/single"
|
|
0 commit comments