From abd9c77613d3a9406909f748808fc75bfbceadc3 Mon Sep 17 00:00:00 2001 From: David Grimason Date: Tue, 26 Nov 2019 15:48:00 +0900 Subject: [PATCH 1/2] Use cloneDeep to make deep copies of filters --- core/modules/catalog-next/store/category/actions.ts | 5 +++-- core/modules/catalog/store/product/actions.ts | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/core/modules/catalog-next/store/category/actions.ts b/core/modules/catalog-next/store/category/actions.ts index 53ab1fa6e2..06b514ef47 100644 --- a/core/modules/catalog-next/store/category/actions.ts +++ b/core/modules/catalog-next/store/category/actions.ts @@ -20,6 +20,7 @@ import { preConfigureProduct } from '@vue-storefront/core/modules/catalog/helper import chunk from 'lodash-es/chunk' import Product from 'core/modules/catalog/types/Product'; import omit from 'lodash-es/omit' +import cloneDeep from 'lodash-es/cloneDeep' import config from 'config' import { parseCategoryPath } from '@vue-storefront/core/modules/breadcrumbs/helpers' @@ -140,7 +141,7 @@ const actions: ActionTree = { categorySearchOptions.filters.id = searchedIds.filter(categoryId => !getters.getCategoriesMap[categoryId] && !getters.getNotFoundCategoryIds.includes(categoryId)) } if (!searchingByIds || categorySearchOptions.filters.id.length) { - categorySearchOptions.filters = Object.assign(config.entities.category.filterFields, categorySearchOptions.filters) + categorySearchOptions.filters = Object.assign(cloneDeep(config.entities.category.filterFields), categorySearchOptions.filters ? cloneDeep(categorySearchOptions.filters) : {}) const categories = await CategoryService.getCategories(categorySearchOptions) const notFoundCategories = searchedIds.filter(categoryId => !categories.some(cat => cat.id === parseInt(categoryId))) @@ -176,7 +177,7 @@ const actions: ActionTree = { let resultFilters = aggregationFilters const filtersKeys = Object.keys(filters) if (categoryMappedFilters && filtersKeys.length) { - resultFilters = Object.assign({}, categoryMappedFilters, omit(aggregationFilters, filtersKeys)) + resultFilters = Object.assign(cloneDeep(categoryMappedFilters), cloneDeep(omit(aggregationFilters, filtersKeys))) } commit(types.CATEGORY_SET_CATEGORY_FILTERS, {category, filters: resultFilters}) }, diff --git a/core/modules/catalog/store/product/actions.ts b/core/modules/catalog/store/product/actions.ts index 671f8b84c3..f38cc3577f 100644 --- a/core/modules/catalog/store/product/actions.ts +++ b/core/modules/catalog/store/product/actions.ts @@ -19,6 +19,7 @@ import { optionLabel } from '../../helpers/optionLabel' import { isOnline } from '@vue-storefront/core/lib/search' import omit from 'lodash-es/omit' import trim from 'lodash-es/trim' +import cloneDeep from 'lodash-es/cloneDeep' import uniqBy from 'lodash-es/uniqBy' import rootStore from '@vue-storefront/core/store' import RootState from '@vue-storefront/core/types/RootState' @@ -684,7 +685,7 @@ const actions: ActionTree = { if (product && product.category_ids) { let currentCategory = rootGetters['category-next/getCurrentCategory'] // use current category, if set if (!currentCategory || !currentCategory.id || !product.category_ids.includes(currentCategory.id.toString())) { - const categoryFilters = Object.assign({ 'id': product.category_ids }, config.entities.category.breadcrumbFilterFields) + const categoryFilters = Object.assign({ 'id': [...product.category_ids] }, cloneDeep(config.entities.category.breadcrumbFilterFields)) const categories = await dispatch('category-next/loadCategories', {filters: categoryFilters}, { root: true }) currentCategory = categories.sort((a, b) => (a.level > b.level) ? -1 : 1)[0] // sort starting by deepest level } From fb483eb5476a1e300342914193618d6c1785c8c2 Mon Sep 17 00:00:00 2001 From: David Grimason Date: Tue, 3 Dec 2019 10:24:22 +0900 Subject: [PATCH 2/2] Changelog update for #3843 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a69f6e218e..78bc17e1d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed AMP pages - @andrzejewsky (#3799) - Fixed Product page breadcrumbs problem when products are in multiple categories in different branches of the category tree - @grimasod (#3691) - Change translation from jp-JP to ja-JP - @gibkigonzo (#3824) +- Fixed some potential mutations of Config object in `catalog` and `catalog-next` - @grimasod (#3843) ### Changed / Improved - Changed pre commit hook to use NODE_ENV production to check for debugger statements - @resubaka (#3686)