@graphcommerce/magento-product 9.1.0-canary.47 → 9.1.0-canary.49

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # Change Log
2
2
 
3
+ ## 9.1.0-canary.49
4
+
5
+ ### Patch Changes
6
+
7
+ - [#2533](https://github.com/graphcommerce-org/graphcommerce/pull/2533) [`dc3be1d`](https://github.com/graphcommerce-org/graphcommerce/commit/dc3be1da43916b65b1d3d4170c09e63ad3818bac) - Solve issue when a user applies their first filter on a category page, a redundant GraphQL call would be made, even though the user was navigating to the `/c/[..url]` route. ([@paales](https://github.com/paales))
8
+
9
+ - [#2533](https://github.com/graphcommerce-org/graphcommerce/pull/2533) [`45c2fbb`](https://github.com/graphcommerce-org/graphcommerce/commit/45c2fbbed55e3ba42f1ecc45e80039977b6ffe7c) - Solve issue where in some cases a second ProductList query was made because the category used an `eq` filter instead of an `in` filter. ([@paales](https://github.com/paales))
10
+
11
+ - [#2533](https://github.com/graphcommerce-org/graphcommerce/pull/2533) [`88abcbf`](https://github.com/graphcommerce-org/graphcommerce/commit/88abcbf011b65b0cd1235e984f5d8306256bd518) - When loading the category/search page in the case that there are no filters applied, the amount or product related queries is reduced from 2 to 1 (ProductFilters is skipped). Pagination, sorting and search terms also do not affect this. When a filter is applied we fall back to the previous functionality and do a second query to retrieve the filters.
12
+
13
+ This did not matter when the categories/search pages were served by Magento as Magento would cache the result of the ProductFilters query. When the the catalog is served by an external service like Algolia this might be a problem.
14
+
15
+ Implementation details: When filters are applied (e.g., filtering by color:blue), the ProductList query only returns products matching that filter, which means other filter options (like other colors) are excluded from the filter options. This behavior is expected since those other options wouldn't return any products. However, when no filters are applied, the ProductList query returns all products along with all available filter options, eliminating the need for a separate ProductFilters query. ([@paales](https://github.com/paales))
16
+
17
+ ## 9.1.0-canary.48
18
+
3
19
  ## 9.1.0-canary.47
4
20
 
5
21
  ## 9.1.0-canary.46
@@ -142,7 +142,7 @@ export function ProductFiltersPro(props: FilterFormProviderProps) {
142
142
  submit,
143
143
  appliedAggregations,
144
144
  filterTypes,
145
- aggregations,
145
+ aggregations: aggregations ?? appliedAggregations,
146
146
  }
147
147
  globalFormContextRef.current = ctx
148
148
  return ctx
@@ -13,6 +13,7 @@ import {
13
13
  import type { SetRequired } from 'type-fest'
14
14
  import { useProductListLinkReplace } from '../../hooks/useProductListLinkReplace'
15
15
  import { useProductListParamsContext } from '../../hooks/useProductListParamsContext'
16
+ import { hasUserFilterActive } from '../ProductListItems/hasUserFilterActive'
16
17
  import { ProductListLink } from '../ProductListLink/ProductListLink'
17
18
  import type { ProductListFiltersFragment } from './ProductListFilters.gql'
18
19
 
@@ -55,7 +56,7 @@ export function FilterEqualType(props: FilterEqualTypeProps) {
55
56
  in: [],
56
57
  }
57
58
 
58
- const anyFilterActive = Object.keys(params?.filters ?? {}).length >= 1
59
+ const anyFilterActive = hasUserFilterActive(params)
59
60
 
60
61
  const currentLabels =
61
62
  options
@@ -47,7 +47,7 @@ export function parseParams(
47
47
  return undefined
48
48
  }
49
49
  if (param === 'category_uid') {
50
- productListParams.filters.category_uid = { eq: value }
50
+ productListParams.filters.category_uid = { in: [value] }
51
51
  return undefined
52
52
  }
53
53
 
@@ -0,0 +1,22 @@
1
+ import type { ProductListQueryVariables } from '../ProductList/ProductList.gql'
2
+ import type { ProductListParams } from './filterTypes'
3
+
4
+ /**
5
+ * Checks if a user defined filter is active.
6
+ *
7
+ * 1. Engine never counts as an active filter, so strip that.
8
+ * 2. For the category page the category_uid is not a filter, strip that.
9
+ */
10
+ export function hasUserFilterActive(
11
+ params: ProductListParams | ProductListQueryVariables | undefined,
12
+ ) {
13
+ if (!params?.filters) return false
14
+
15
+ const skipKeys = ['engine']
16
+ const filterKeys = Object.keys(params.filters)
17
+
18
+ const isCategory = typeof params.search !== 'string' && params.filters.category_uid
19
+ if (isCategory) skipKeys.push('category_uid')
20
+
21
+ return filterKeys.filter((k) => !skipKeys.includes(k)).length > 0
22
+ }
@@ -24,8 +24,8 @@ export function useProductListApplyCategoryDefaults(
24
24
  else if (defaultSort) variables.sort = { [defaultSort]: 'ASC' }
25
25
  }
26
26
 
27
- if (!variables.filters.category_uid?.in?.[0]) {
28
- variables.filters.category_uid = { eq: category?.uid }
27
+ if (!variables.filters.category_uid?.in?.[0] && category?.uid) {
28
+ variables.filters.category_uid = { in: [category.uid] }
29
29
  }
30
30
 
31
31
  return variables
@@ -62,7 +62,8 @@ export async function productListApplyCategoryDefaults(
62
62
  }
63
63
 
64
64
  if (!newParams.filters.category_uid?.in?.[0]) {
65
- newParams.filters.category_uid = { eq: (await category)?.uid }
65
+ const uid = (await category)?.uid
66
+ if (uid) newParams.filters.category_uid = { in: [uid] }
66
67
  }
67
68
 
68
69
  return newParams
@@ -8,19 +8,23 @@ export * from './ProductListCount/ProductListCount'
8
8
  export * from './ProductListFilters'
9
9
  export * from './ProductListFiltersContainer/ProductListFiltersContainer'
10
10
  export * from './ProductListItem'
11
+ export * from './ProductListItems/CategoryDefault.gql'
11
12
  export * from './ProductListItems/filteredProductList'
12
13
  export * from './ProductListItems/filterTypes'
13
14
  export * from './ProductListItems/getFilterTypes'
15
+ export * from './ProductListItems/hasUserFilterActive'
16
+ export * from './ProductListItems/productListApplyCategoryDefaults'
14
17
  export * from './ProductListItems/ProductListItems.gql'
15
18
  export * from './ProductListItems/ProductListItemsBase'
16
- export * from './ProductListItems/productListApplyCategoryDefaults'
17
- export * from './ProductListItems/CategoryDefault.gql'
18
19
  export * from './ProductListItems/ProductListParamsProvider'
19
20
  export * from './ProductListItems/renderer'
20
21
  export * from './ProductListLink/ProductListLink'
21
22
  export * from './ProductListPagination/ProductListPagination'
23
+ export * from './ProductListPrice'
22
24
  export * from './ProductListSort'
23
- export * from './ProductPageName'
25
+ export * from './ProductListSuggestions/ProductListSearchSuggestion.gql'
26
+ export * from './ProductListSuggestions/ProductListSuggestions'
27
+ export * from './ProductListSuggestions/ProductListSuggestions.gql'
24
28
  export * from './ProductPage/ProductPageAddToCartRow'
25
29
  export * from './ProductPageBreadcrumb'
26
30
  export * from './ProductPageCategory/productPageCategory'
@@ -28,6 +32,7 @@ export * from './ProductPageDescription/ProductPageDescription'
28
32
  export * from './ProductPageGallery/ProductPageGallery'
29
33
  export * from './ProductPageMeta/ProductPageMeta'
30
34
  export * from './ProductPageMeta/ProductPageMeta.gql'
35
+ export * from './ProductPageName'
31
36
  export * from './ProductPagePrice'
32
37
  export * from './ProductRelated/RelatedProducts.gql'
33
38
  export * from './ProductScroller/ProductScroller'
@@ -40,7 +45,4 @@ export * from './ProductStaticPaths/getProductStaticPaths'
40
45
  export * from './ProductStaticPaths/getSitemapPaths'
41
46
  export * from './ProductUpsells/UpsellProducts.gql'
42
47
  export * from './ProductWeight/ProductWeight'
43
- export * from './ProductListPrice'
44
- export * from './ProductListSuggestions/ProductListSuggestions'
45
- export * from './ProductListSuggestions/ProductListSuggestions.gql'
46
- export * from './ProductListSuggestions/ProductListSearchSuggestion.gql'
48
+
@@ -9,7 +9,7 @@ import type {
9
9
  ProductFiltersQuery,
10
10
  ProductFiltersQueryVariables,
11
11
  } from '../components'
12
- import { ProductFiltersDocument } from '../components'
12
+ import { hasUserFilterActive, ProductFiltersDocument } from '../components'
13
13
  import type {
14
14
  ProductListQuery,
15
15
  ProductListQueryVariables,
@@ -106,7 +106,10 @@ export function useProductList<
106
106
  const result = usePrivateQuery(ProductListDocument, { variables, skip: !shallow }, props)
107
107
  const filters = usePrivateQuery(
108
108
  ProductFiltersDocument,
109
- { variables: categoryDefaultsToProductListFilters(variables), skip: !shallow },
109
+ {
110
+ variables: categoryDefaultsToProductListFilters(variables),
111
+ skip: !shallow || !hasUserFilterActive(params),
112
+ },
110
113
  props,
111
114
  )
112
115
 
@@ -122,8 +125,8 @@ export function useProductList<
122
125
  category,
123
126
  )
124
127
 
125
- const shallowNow =
126
- JSON.stringify(vars.filters?.category_uid) === JSON.stringify(params?.filters.category_uid)
128
+ const shallowNow = hasUserFilterActive(params) === hasUserFilterActive(vars)
129
+
127
130
  await prefetchProductList(
128
131
  vars,
129
132
  categoryDefaultsToProductListFilters(vars),
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@graphcommerce/magento-product",
3
3
  "homepage": "https://www.graphcommerce.org/",
4
4
  "repository": "github:graphcommerce-org/graphcommerce",
5
- "version": "9.1.0-canary.47",
5
+ "version": "9.1.0-canary.49",
6
6
  "sideEffects": false,
7
7
  "prettier": "@graphcommerce/prettier-config-pwa",
8
8
  "eslintConfig": {
@@ -18,18 +18,18 @@
18
18
  "typescript": "5.7.2"
19
19
  },
20
20
  "peerDependencies": {
21
- "@graphcommerce/ecommerce-ui": "^9.1.0-canary.47",
22
- "@graphcommerce/eslint-config-pwa": "^9.1.0-canary.47",
23
- "@graphcommerce/framer-next-pages": "^9.1.0-canary.47",
24
- "@graphcommerce/framer-scroller": "^9.1.0-canary.47",
25
- "@graphcommerce/graphql": "^9.1.0-canary.47",
26
- "@graphcommerce/graphql-mesh": "^9.1.0-canary.47",
27
- "@graphcommerce/image": "^9.1.0-canary.47",
28
- "@graphcommerce/magento-cart": "^9.1.0-canary.47",
29
- "@graphcommerce/magento-store": "^9.1.0-canary.47",
30
- "@graphcommerce/next-ui": "^9.1.0-canary.47",
31
- "@graphcommerce/prettier-config-pwa": "^9.1.0-canary.47",
32
- "@graphcommerce/typescript-config-pwa": "^9.1.0-canary.47",
21
+ "@graphcommerce/ecommerce-ui": "^9.1.0-canary.49",
22
+ "@graphcommerce/eslint-config-pwa": "^9.1.0-canary.49",
23
+ "@graphcommerce/framer-next-pages": "^9.1.0-canary.49",
24
+ "@graphcommerce/framer-scroller": "^9.1.0-canary.49",
25
+ "@graphcommerce/graphql": "^9.1.0-canary.49",
26
+ "@graphcommerce/graphql-mesh": "^9.1.0-canary.49",
27
+ "@graphcommerce/image": "^9.1.0-canary.49",
28
+ "@graphcommerce/magento-cart": "^9.1.0-canary.49",
29
+ "@graphcommerce/magento-store": "^9.1.0-canary.49",
30
+ "@graphcommerce/next-ui": "^9.1.0-canary.49",
31
+ "@graphcommerce/prettier-config-pwa": "^9.1.0-canary.49",
32
+ "@graphcommerce/typescript-config-pwa": "^9.1.0-canary.49",
33
33
  "@lingui/core": "^4.2.1",
34
34
  "@lingui/macro": "^4.2.1",
35
35
  "@lingui/react": "^4.2.1",