@akinon/next 2.0.21-beta.0 → 2.0.21

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,10 +1,10 @@
1
1
  # @akinon/next
2
2
 
3
- ## 2.0.21-beta.0
3
+ ## 2.0.21
4
4
 
5
5
  ### Patch Changes
6
6
 
7
- - cbbbfd75: ZERO-4376: Bootstrap beta cycle (next-main pre-release motor)
7
+ - dc78d1f: ZERO-4493: Fix CacheKey serialization so URLSearchParams instances produce distinct cache keys per search param value. withSegmentDefaults normalizes Next 16's plain searchParams into a URLSearchParams instance, and JSON.stringify on URLSearchParams always returns "{}" — every variant of a route collapsed onto one cache entry and product detail variant changes served stale data (add-to-cart button stuck in loading). The CacheKey.Product, .GroupProduct, .List, .Category and .SpecialPage helpers now route searchParams through a helper that converts URLSearchParams to a plain object before JSON.stringify, keeping plain-object inputs from generateMetadata paths unchanged.
8
8
 
9
9
  ## 2.0.20
10
10
 
package/lib/cache.ts CHANGED
@@ -77,9 +77,29 @@ const hashCacheKey = (object?: Record<string, string>) => {
77
77
 
78
78
  return `_${encodeURIComponent(cacheKey)}`;
79
79
  };
80
+
81
+ // JSON.stringify on a URLSearchParams instance always returns "{}" because its
82
+ // entries live on the prototype, not as own enumerable properties. withSegmentDefaults
83
+ // normalizes Next 16's plain searchParams object into a URLSearchParams instance for
84
+ // v1 brand compatibility, which means every CacheKey below that took JSON.stringify
85
+ // of searchParams was collapsing every variant of a route onto a single cache entry —
86
+ // product detail variant changes served stale data and the add-to-cart button stuck
87
+ // in its loading state. Convert URLSearchParams to a plain object before serializing
88
+ // so the resulting key reflects the actual params.
89
+ const stringifySearchParams = (searchParams?: SearchParams) => {
90
+ if (!searchParams) return JSON.stringify(searchParams);
91
+ if (
92
+ typeof URLSearchParams !== 'undefined' &&
93
+ searchParams instanceof URLSearchParams
94
+ ) {
95
+ return JSON.stringify(Object.fromEntries(searchParams));
96
+ }
97
+ return JSON.stringify(searchParams);
98
+ };
99
+
80
100
  export const CacheKey = {
81
101
  List: (searchParams: SearchParams, headers?: Record<string, string>) =>
82
- `list_${encodeURIComponent(JSON.stringify(searchParams))}${hashCacheKey(
102
+ `list_${encodeURIComponent(stringifySearchParams(searchParams))}${hashCacheKey(
83
103
  headers
84
104
  )}`,
85
105
  Category: (
@@ -88,7 +108,7 @@ export const CacheKey = {
88
108
  headers?: Record<string, string>
89
109
  ) =>
90
110
  `category_${pk}_${encodeURIComponent(
91
- JSON.stringify(searchParams)
111
+ stringifySearchParams(searchParams)
92
112
  )}${hashCacheKey(headers)}`,
93
113
  Basket: (namespace?: string) => `basket${namespace ? `_${namespace}` : ''}`,
94
114
  AllBaskets: () => 'all_baskets',
@@ -99,12 +119,12 @@ export const CacheKey = {
99
119
  headers?: Record<string, string>
100
120
  ) =>
101
121
  `special_page_${pk}_${encodeURIComponent(
102
- JSON.stringify(searchParams)
122
+ stringifySearchParams(searchParams)
103
123
  )}${hashCacheKey(headers)}`,
104
124
  Product: (pk: number, searchParams: SearchParams) =>
105
- `product_${pk}_${encodeURIComponent(JSON.stringify(searchParams))}`,
125
+ `product_${pk}_${encodeURIComponent(stringifySearchParams(searchParams))}`,
106
126
  GroupProduct: (pk: number, searchParams: SearchParams) =>
107
- `group_product_${pk}_${encodeURIComponent(JSON.stringify(searchParams))}`,
127
+ `group_product_${pk}_${encodeURIComponent(stringifySearchParams(searchParams))}`,
108
128
  FlatPage: (pk: number) => `flat_page_${pk}`,
109
129
  LandingPage: (pk: number) => `landing_page_${pk}`,
110
130
  Widget: (slug: string) => `widget_${slug}`,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@akinon/next",
3
3
  "description": "Core package for Project Zero Next",
4
- "version": "2.0.21-beta.0",
4
+ "version": "2.0.21",
5
5
  "private": false,
6
6
  "license": "MIT",
7
7
  "bin": {
@@ -36,7 +36,7 @@
36
36
  "set-cookie-parser": "2.6.0"
37
37
  },
38
38
  "devDependencies": {
39
- "@akinon/eslint-plugin-projectzero": "2.0.21-beta.0",
39
+ "@akinon/eslint-plugin-projectzero": "2.0.21",
40
40
  "@babel/core": "7.26.10",
41
41
  "@babel/preset-env": "7.26.9",
42
42
  "@babel/preset-typescript": "7.27.0",