@faststore/core 4.11.4-dev.5 → 4.11.4
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/.turbo/turbo-generate.log +3 -3
- package/.turbo/turbo-test.log +190 -199
- package/CHANGELOG.md +1 -27
- package/cms/faststore/components/cms_component__navbar.jsonc +1 -11
- package/cms/faststore/schema.json +1 -11
- package/cms/faststore/sections.json +1 -11
- package/discovery.config.default.js +0 -5
- package/package.json +6 -6
- package/src/components/navigation/Navbar/Navbar.tsx +0 -4
- package/src/components/search/SearchDropdown/SearchDropdown.tsx +2 -11
- package/src/components/search/SearchHistory/SearchHistory.tsx +2 -12
- package/src/components/search/SearchInput/SearchInput.tsx +0 -12
- package/src/components/sections/Navbar/Navbar.tsx +0 -2
- package/src/pages/[...slug].tsx +0 -10
- package/src/server/cms/index.ts +2 -3
- package/test/components/search/SearchInputComponent.test.tsx +4 -71
- package/src/server/cms/ResilientClientCMS.ts +0 -168
- package/src/utils/toRevalidate.ts +0 -74
- package/test/components/search/SearchDropdown.test.tsx +0 -80
- package/test/server/cms/ResilientClientCMS.test.ts +0 -482
- package/test/utils/toRevalidate.test.ts +0 -118
package/CHANGELOG.md
CHANGED
|
@@ -3,33 +3,7 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
## [4.11.4
|
|
7
|
-
|
|
8
|
-
### Bug Fixes
|
|
9
|
-
|
|
10
|
-
- **core:** retry CMS fetch bypassing cache on invalid JSON ([#3590](https://github.com/vtex/faststore/issues/3590)) ([12f9062](https://github.com/vtex/faststore/commit/12f9062184eef948f29d2aeac0308c97300d842f))
|
|
11
|
-
|
|
12
|
-
## [4.11.4-dev.4](https://github.com/vtex/faststore/compare/v4.11.4-dev.3...v4.11.4-dev.4) (2026-11-19)
|
|
13
|
-
|
|
14
|
-
### Bug Fixes
|
|
15
|
-
|
|
16
|
-
- **core:** forward search dropdown labels from the CMS ([#3600](https://github.com/vtex/faststore/issues/3600)) ([0f18b72](https://github.com/vtex/faststore/commit/0f18b729eb90e7053b823ceb90207967d9d383f8)), closes [#3334](https://github.com/vtex/faststore/issues/3334) [#3334](https://github.com/vtex/faststore/issues/3334) [#3240](https://github.com/vtex/faststore/issues/3240) [#3240](https://github.com/vtex/faststore/issues/3240)
|
|
17
|
-
|
|
18
|
-
## [4.11.4-dev.3](https://github.com/vtex/faststore/compare/v4.11.4-dev.2...v4.11.4-dev.3) (2026-11-18)
|
|
19
|
-
|
|
20
|
-
### Bug Fixes
|
|
21
|
-
|
|
22
|
-
- **core:** add experimental.revalidatePLP to refresh cached PLPs ([#3595](https://github.com/vtex/faststore/issues/3595)) ([f14ca23](https://github.com/vtex/faststore/commit/f14ca23c3581d94961eac3bdc6839207066eff74)), closes [#3553](https://github.com/vtex/faststore/issues/3553) [#3553](https://github.com/vtex/faststore/issues/3553)
|
|
23
|
-
|
|
24
|
-
## [4.11.4-dev.2](https://github.com/vtex/faststore/compare/v4.11.4-dev.1...v4.11.4-dev.2) (2026-11-17)
|
|
25
|
-
|
|
26
|
-
**Note:** Version bump only for package @faststore/core
|
|
27
|
-
|
|
28
|
-
## [4.11.4-dev.1](https://github.com/vtex/faststore/compare/v4.11.4-dev.0...v4.11.4-dev.1) (2026-11-16)
|
|
29
|
-
|
|
30
|
-
**Note:** Version bump only for package @faststore/core
|
|
31
|
-
|
|
32
|
-
## [4.11.4-dev.0](https://github.com/vtex/faststore/compare/v4.11.3...v4.11.4-dev.0) (2026-11-10)
|
|
6
|
+
## [4.11.4](https://github.com/vtex/faststore/compare/v4.11.3...v4.11.4) (2026-11-19)
|
|
33
7
|
|
|
34
8
|
**Note:** Version bump only for package @faststore/core
|
|
35
9
|
|
|
@@ -93,17 +93,7 @@
|
|
|
93
93
|
"searchTopTitle": {
|
|
94
94
|
"title": "Top Search Title",
|
|
95
95
|
"type": "string",
|
|
96
|
-
"default": "Top
|
|
97
|
-
},
|
|
98
|
-
"searchHistoryClearLabel": {
|
|
99
|
-
"title": "Clear Search History Button Label",
|
|
100
|
-
"type": "string",
|
|
101
|
-
"default": "Clear History"
|
|
102
|
-
},
|
|
103
|
-
"searchProductsTitle": {
|
|
104
|
-
"title": "Suggested Products Title",
|
|
105
|
-
"type": "string",
|
|
106
|
-
"default": "Suggested Products"
|
|
96
|
+
"default": "Top search"
|
|
107
97
|
},
|
|
108
98
|
"quickOrderSettings": {
|
|
109
99
|
"title": "Quick Order settings",
|
|
@@ -2064,17 +2064,7 @@
|
|
|
2064
2064
|
"searchTopTitle": {
|
|
2065
2065
|
"title": "Top Search Title",
|
|
2066
2066
|
"type": "string",
|
|
2067
|
-
"default": "Top
|
|
2068
|
-
},
|
|
2069
|
-
"searchHistoryClearLabel": {
|
|
2070
|
-
"title": "Clear Search History Button Label",
|
|
2071
|
-
"type": "string",
|
|
2072
|
-
"default": "Clear History"
|
|
2073
|
-
},
|
|
2074
|
-
"searchProductsTitle": {
|
|
2075
|
-
"title": "Suggested Products Title",
|
|
2076
|
-
"type": "string",
|
|
2077
|
-
"default": "Suggested Products"
|
|
2067
|
+
"default": "Top search"
|
|
2078
2068
|
},
|
|
2079
2069
|
"quickOrderSettings": {
|
|
2080
2070
|
"title": "Quick Order settings",
|
|
@@ -235,17 +235,7 @@
|
|
|
235
235
|
"searchTopTitle": {
|
|
236
236
|
"title": "Top Search Title",
|
|
237
237
|
"type": "string",
|
|
238
|
-
"default": "Top
|
|
239
|
-
},
|
|
240
|
-
"searchHistoryClearLabel": {
|
|
241
|
-
"title": "Clear Search History Button Label",
|
|
242
|
-
"type": "string",
|
|
243
|
-
"default": "Clear History"
|
|
244
|
-
},
|
|
245
|
-
"searchProductsTitle": {
|
|
246
|
-
"title": "Suggested Products Title",
|
|
247
|
-
"type": "string",
|
|
248
|
-
"default": "Suggested Products"
|
|
238
|
+
"default": "Top search"
|
|
249
239
|
},
|
|
250
240
|
"quickOrderSettings": {
|
|
251
241
|
"title": "Quick Order settings",
|
|
@@ -196,11 +196,6 @@ module.exports = {
|
|
|
196
196
|
enableRedirects: false,
|
|
197
197
|
// ISR window (seconds) for notFound PDP/PLP paths.
|
|
198
198
|
revalidate404: 60 * 5, // 5 minutes
|
|
199
|
-
// ISR window (seconds) for PLPs served by `[...slug]`. `false` (default)
|
|
200
|
-
// caches the page until the next deploy. Set a positive integer number of
|
|
201
|
-
// seconds (values below 60 are raised to 60) to refresh the
|
|
202
|
-
// server-rendered first page (price, stock, order).
|
|
203
|
-
revalidatePLP: false,
|
|
204
199
|
enableSearchSSR: false,
|
|
205
200
|
enableFaststoreMyAccount: false,
|
|
206
201
|
useIsGiftFromOrderForm: false,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faststore/core",
|
|
3
|
-
"version": "4.11.4
|
|
3
|
+
"version": "4.11.4",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -70,11 +70,11 @@
|
|
|
70
70
|
"style-loader": "^3.3.1",
|
|
71
71
|
"swr": "^2.2.5",
|
|
72
72
|
"use-sync-external-store": "^1.6.0",
|
|
73
|
-
"@faststore/api": "4.11.4
|
|
74
|
-
"@faststore/
|
|
75
|
-
"@faststore/
|
|
76
|
-
"@faststore/
|
|
77
|
-
"@faststore/ui": "4.11.4
|
|
73
|
+
"@faststore/api": "4.11.4",
|
|
74
|
+
"@faststore/lighthouse": "4.11.4",
|
|
75
|
+
"@faststore/diagnostics": "4.11.4",
|
|
76
|
+
"@faststore/sdk": "4.11.4",
|
|
77
|
+
"@faststore/ui": "4.11.4"
|
|
78
78
|
},
|
|
79
79
|
"devDependencies": {
|
|
80
80
|
"@cypress/code-coverage": "^3.12.1",
|
|
@@ -185,8 +185,6 @@ function Navbar({
|
|
|
185
185
|
loadingLabel={searchInput?.loadingLabel}
|
|
186
186
|
searchHistoryTitle={searchInput?.searchHistoryTitle}
|
|
187
187
|
searchTopTitle={searchInput?.searchTopTitle}
|
|
188
|
-
searchHistoryClearLabel={searchInput?.searchHistoryClearLabel}
|
|
189
|
-
searchProductsTitle={searchInput?.searchProductsTitle}
|
|
190
188
|
/>
|
|
191
189
|
)}
|
|
192
190
|
|
|
@@ -224,8 +222,6 @@ function Navbar({
|
|
|
224
222
|
loadingLabel={searchInput?.loadingLabel}
|
|
225
223
|
searchHistoryTitle={searchInput?.searchHistoryTitle}
|
|
226
224
|
searchTopTitle={searchInput?.searchTopTitle}
|
|
227
|
-
searchHistoryClearLabel={searchInput?.searchHistoryClearLabel}
|
|
228
|
-
searchProductsTitle={searchInput?.searchProductsTitle}
|
|
229
225
|
/>
|
|
230
226
|
)}
|
|
231
227
|
|
|
@@ -24,9 +24,7 @@ interface SearchDropdownProps {
|
|
|
24
24
|
sort: SearchState['sort']
|
|
25
25
|
quickOrderSettings?: NavbarProps['searchInput']['quickOrderSettings']
|
|
26
26
|
searchHistoryTitle?: string
|
|
27
|
-
searchHistoryClearLabel?: string
|
|
28
27
|
searchTopTitle?: string
|
|
29
|
-
searchProductsTitle?: string
|
|
30
28
|
[key: string]: any
|
|
31
29
|
onChangeCustomSearchDropdownVisible?: Dispatch<SetStateAction<boolean>>
|
|
32
30
|
}
|
|
@@ -49,12 +47,10 @@ function SearchDropdown({
|
|
|
49
47
|
sort,
|
|
50
48
|
quickOrderSettings,
|
|
51
49
|
searchHistoryTitle,
|
|
52
|
-
searchHistoryClearLabel,
|
|
53
50
|
searchTopTitle,
|
|
54
|
-
searchProductsTitle,
|
|
55
51
|
onChangeCustomSearchDropdownVisible,
|
|
56
52
|
...otherProps
|
|
57
|
-
}:
|
|
53
|
+
}: SearchDropdownProps) {
|
|
58
54
|
const {
|
|
59
55
|
values: { onSearchSelection, products, term, terms, searchId },
|
|
60
56
|
} = useSearch()
|
|
@@ -62,11 +58,7 @@ function SearchDropdown({
|
|
|
62
58
|
|
|
63
59
|
return (
|
|
64
60
|
<UISearchDropdown {...otherProps}>
|
|
65
|
-
<SearchHistory
|
|
66
|
-
title={searchHistoryTitle}
|
|
67
|
-
clearLabel={searchHistoryClearLabel}
|
|
68
|
-
sort={sort}
|
|
69
|
-
/>
|
|
61
|
+
<SearchHistory title={searchHistoryTitle} sort={sort} />
|
|
70
62
|
<SearchTop title={searchTopTitle} sort={sort} />
|
|
71
63
|
<UISearchAutoComplete>
|
|
72
64
|
{terms?.map(({ value: suggestion }) => (
|
|
@@ -103,7 +95,6 @@ function SearchDropdown({
|
|
|
103
95
|
))}
|
|
104
96
|
</UISearchAutoComplete>
|
|
105
97
|
<SearchProducts
|
|
106
|
-
title={searchProductsTitle}
|
|
107
98
|
data-af-element={searchId && 'search-autocomplete'}
|
|
108
99
|
data-af-onimpression={!!searchId}
|
|
109
100
|
data-af-search-id={searchId}
|
|
@@ -7,15 +7,10 @@ import useSearchHistory from 'src/sdk/search/useSearchHistory'
|
|
|
7
7
|
|
|
8
8
|
interface SearchHistoryProps {
|
|
9
9
|
title?: string
|
|
10
|
-
clearLabel?: string
|
|
11
10
|
[key: string]: unknown
|
|
12
11
|
}
|
|
13
12
|
|
|
14
|
-
const SearchHistory = ({
|
|
15
|
-
title,
|
|
16
|
-
clearLabel,
|
|
17
|
-
...props
|
|
18
|
-
}: Readonly<SearchHistoryProps>) => {
|
|
13
|
+
const SearchHistory = ({ title, ...props }: SearchHistoryProps) => {
|
|
19
14
|
const {
|
|
20
15
|
values: { onSearchSelection },
|
|
21
16
|
} = useSearch()
|
|
@@ -26,12 +21,7 @@ const SearchHistory = ({
|
|
|
26
21
|
}
|
|
27
22
|
|
|
28
23
|
return (
|
|
29
|
-
<UISearchHistory
|
|
30
|
-
title={title}
|
|
31
|
-
clearLabel={clearLabel}
|
|
32
|
-
onClear={clearSearchHistory}
|
|
33
|
-
{...props}
|
|
34
|
-
>
|
|
24
|
+
<UISearchHistory title={title} onClear={clearSearchHistory} {...props}>
|
|
35
25
|
{searchHistory.map((item) => (
|
|
36
26
|
<UISearchHistoryTerm
|
|
37
27
|
key={item.term}
|
|
@@ -73,9 +73,7 @@ export type SearchInputProps = {
|
|
|
73
73
|
submitButtonAriaLabel?: string
|
|
74
74
|
loadingLabel?: string
|
|
75
75
|
searchHistoryTitle?: string
|
|
76
|
-
searchHistoryClearLabel?: string
|
|
77
76
|
searchTopTitle?: string
|
|
78
|
-
searchProductsTitle?: string
|
|
79
77
|
} & Omit<UISearchInputFieldProps, 'onSubmit' | 'attachmentButtonIcon'>
|
|
80
78
|
|
|
81
79
|
export type SearchInputRef = UISearchInputFieldRef & {
|
|
@@ -116,11 +114,6 @@ const SearchInput = forwardRef<SearchInputRef, SearchInputProps>(
|
|
|
116
114
|
sort,
|
|
117
115
|
placeholder,
|
|
118
116
|
quickOrderSettings,
|
|
119
|
-
loadingLabel,
|
|
120
|
-
searchHistoryTitle,
|
|
121
|
-
searchHistoryClearLabel,
|
|
122
|
-
searchTopTitle,
|
|
123
|
-
searchProductsTitle,
|
|
124
117
|
...otherProps
|
|
125
118
|
},
|
|
126
119
|
ref
|
|
@@ -397,11 +390,6 @@ const SearchInput = forwardRef<SearchInputRef, SearchInputProps>(
|
|
|
397
390
|
onChangeCustomSearchDropdownVisible={
|
|
398
391
|
setCustomSearchDropdownVisibleCondition
|
|
399
392
|
}
|
|
400
|
-
loadingLabel={loadingLabel}
|
|
401
|
-
searchHistoryTitle={searchHistoryTitle}
|
|
402
|
-
searchHistoryClearLabel={searchHistoryClearLabel}
|
|
403
|
-
searchTopTitle={searchTopTitle}
|
|
404
|
-
searchProductsTitle={searchProductsTitle}
|
|
405
393
|
/>
|
|
406
394
|
</Suspense>
|
|
407
395
|
)}
|
|
@@ -25,9 +25,7 @@ export interface NavbarProps {
|
|
|
25
25
|
sort: string
|
|
26
26
|
submitButtonAriaLabel?: string
|
|
27
27
|
searchHistoryTitle?: string
|
|
28
|
-
searchHistoryClearLabel?: string
|
|
29
28
|
searchTopTitle?: string
|
|
30
|
-
searchProductsTitle?: string
|
|
31
29
|
collapseSearchAriaLabel?: string
|
|
32
30
|
quickOrderSettings?: {
|
|
33
31
|
quickOrder: boolean
|
package/src/pages/[...slug].tsx
CHANGED
|
@@ -32,7 +32,6 @@ import { contentService } from 'src/server/content/service'
|
|
|
32
32
|
import type { PreviewData } from 'src/server/content/types'
|
|
33
33
|
import { getDynamicContent } from 'src/utils/dynamicContent'
|
|
34
34
|
import { fetchServerManyProducts } from 'src/utils/fetchProductGallerySSR'
|
|
35
|
-
import { toRevalidate } from 'src/utils/toRevalidate'
|
|
36
35
|
|
|
37
36
|
const LandingPage = dynamic(
|
|
38
37
|
() => import('src/components/templates/LandingPage')
|
|
@@ -245,15 +244,6 @@ export const getStaticProps: GetStaticProps<
|
|
|
245
244
|
type: 'plp',
|
|
246
245
|
key: slug,
|
|
247
246
|
},
|
|
248
|
-
// Without a window, the first page's products (price, stock, order) stay
|
|
249
|
-
// frozen at the state of their first render until the next deploy. Each
|
|
250
|
-
// regeneration reruns the CMS, collection and first-page search queries,
|
|
251
|
-
// so the window has a floor to bound the upstream load.
|
|
252
|
-
revalidate: toRevalidate(
|
|
253
|
-
storeConfig.experimental.revalidatePLP,
|
|
254
|
-
'experimental.revalidatePLP',
|
|
255
|
-
{ min: 60 }
|
|
256
|
-
),
|
|
257
247
|
}
|
|
258
248
|
}
|
|
259
249
|
|
package/src/server/cms/index.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import type { ContentData, Locator } from '@vtex/client-cms'
|
|
2
|
-
import
|
|
2
|
+
import ClientCMS from '@vtex/client-cms'
|
|
3
3
|
|
|
4
4
|
import MultipleContentError from 'src/sdk/error/MultipleContentError'
|
|
5
5
|
import { getStoreURL } from 'src/sdk/localization/useLocalizationConfig'
|
|
6
6
|
import { createPromiseCache } from 'src/server/content/promiseCache'
|
|
7
7
|
import { sanitizeHost } from 'src/utils/utilities'
|
|
8
8
|
import config from '../../../discovery.config'
|
|
9
|
-
import { ResilientClientCMS } from './ResilientClientCMS'
|
|
10
9
|
|
|
11
10
|
export type Options =
|
|
12
11
|
| Locator
|
|
@@ -73,7 +72,7 @@ export const isLocator = (x: any): x is Locator =>
|
|
|
73
72
|
typeof x.documentId === 'string' ||
|
|
74
73
|
typeof x.versionId === 'string')
|
|
75
74
|
|
|
76
|
-
export const clientCMS = new
|
|
75
|
+
export const clientCMS = new ClientCMS({
|
|
77
76
|
workspace: config.api.workspace,
|
|
78
77
|
tenant: config.api.storeId,
|
|
79
78
|
builder:
|
|
@@ -3,30 +3,12 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import React from 'react'
|
|
6
|
-
import { act,
|
|
6
|
+
import { act, render, waitFor } from '@testing-library/react'
|
|
7
7
|
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
8
8
|
|
|
9
|
-
// ─── next/dynamic:
|
|
10
|
-
// `onFocus` opens the dropdown, and props leaked from SearchInput show up as
|
|
11
|
-
// DOM attributes.
|
|
9
|
+
// ─── next/dynamic: return a plain functional component ───────────────────────
|
|
12
10
|
vi.mock('next/dynamic', () => ({
|
|
13
|
-
default: () =>
|
|
14
|
-
function InputField({
|
|
15
|
-
onFocus,
|
|
16
|
-
...props
|
|
17
|
-
}: Readonly<React.InputHTMLAttributes<HTMLInputElement>>) {
|
|
18
|
-
const domProps = Object.fromEntries(
|
|
19
|
-
Object.entries(props).filter(([, value]) => typeof value === 'string')
|
|
20
|
-
)
|
|
21
|
-
return (
|
|
22
|
-
<input
|
|
23
|
-
data-testid="search-field"
|
|
24
|
-
readOnly
|
|
25
|
-
onFocus={onFocus}
|
|
26
|
-
{...domProps}
|
|
27
|
-
/>
|
|
28
|
-
)
|
|
29
|
-
},
|
|
11
|
+
default: () => () => null,
|
|
30
12
|
}))
|
|
31
13
|
|
|
32
14
|
// ─── next/router ─────────────────────────────────────────────────────────────
|
|
@@ -35,16 +17,7 @@ vi.mock('next/router', () => ({
|
|
|
35
17
|
}))
|
|
36
18
|
|
|
37
19
|
// ─── lazy-loaded chunk ───────────────────────────────────────────────────────
|
|
38
|
-
|
|
39
|
-
current: null as Record<string, unknown> | null,
|
|
40
|
-
}))
|
|
41
|
-
|
|
42
|
-
vi.mock('src/components/search/SearchDropdown', () => ({
|
|
43
|
-
default: (props: Record<string, unknown>) => {
|
|
44
|
-
dropdownProps.current = props
|
|
45
|
-
return null
|
|
46
|
-
},
|
|
47
|
-
}))
|
|
20
|
+
vi.mock('src/components/search/SearchDropdown', () => ({ default: () => null }))
|
|
48
21
|
|
|
49
22
|
// ─── discovery.config ────────────────────────────────────────────────────────
|
|
50
23
|
vi.mock('discovery.config', () => ({
|
|
@@ -152,7 +125,6 @@ import SearchInput from '../../../src/components/search/SearchInput/SearchInput'
|
|
|
152
125
|
|
|
153
126
|
afterEach(() => {
|
|
154
127
|
vi.clearAllMocks()
|
|
155
|
-
dropdownProps.current = null
|
|
156
128
|
oesState.status = null
|
|
157
129
|
oesState.isUploading = false
|
|
158
130
|
oesState.isProcessing = false
|
|
@@ -302,42 +274,3 @@ describe('SearchInput (OES integration)', () => {
|
|
|
302
274
|
expect(true).toBe(true)
|
|
303
275
|
})
|
|
304
276
|
})
|
|
305
|
-
|
|
306
|
-
describe('SearchInput dropdown labels', () => {
|
|
307
|
-
const labels = {
|
|
308
|
-
loadingLabel: 'Carregando...',
|
|
309
|
-
searchHistoryTitle: 'Histórico',
|
|
310
|
-
searchHistoryClearLabel: 'Limpar histórico',
|
|
311
|
-
searchTopTitle: 'Mais buscados',
|
|
312
|
-
searchProductsTitle: 'Produtos sugeridos',
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
it('forwards the CMS labels to the SearchDropdown', async () => {
|
|
316
|
-
const { getByTestId } = render(
|
|
317
|
-
<Wrapper>
|
|
318
|
-
<SearchInput {...labels} />
|
|
319
|
-
</Wrapper>
|
|
320
|
-
)
|
|
321
|
-
|
|
322
|
-
await act(async () => {
|
|
323
|
-
fireEvent.focus(getByTestId('search-field'))
|
|
324
|
-
})
|
|
325
|
-
|
|
326
|
-
await waitFor(() => {
|
|
327
|
-
expect(dropdownProps.current).toMatchObject(labels)
|
|
328
|
-
})
|
|
329
|
-
})
|
|
330
|
-
|
|
331
|
-
it('does not leak the CMS labels to the input element', () => {
|
|
332
|
-
const { getByTestId } = render(
|
|
333
|
-
<Wrapper>
|
|
334
|
-
<SearchInput {...labels} />
|
|
335
|
-
</Wrapper>
|
|
336
|
-
)
|
|
337
|
-
|
|
338
|
-
const field = getByTestId('search-field')
|
|
339
|
-
for (const name of Object.keys(labels)) {
|
|
340
|
-
expect(field.hasAttribute(name)).toBe(false)
|
|
341
|
-
}
|
|
342
|
-
})
|
|
343
|
-
})
|
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
import ClientCMS from '@vtex/client-cms'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Query param added to the retry request. The CDN in front of the CMS API
|
|
5
|
-
* includes the query string in its cache key, so a new value is a cache miss
|
|
6
|
-
* that reaches the origin. A `Cache-Control: no-cache` request header is not
|
|
7
|
-
* enough, since CDNs commonly ignore it.
|
|
8
|
-
*/
|
|
9
|
-
export const CACHE_BUST_PARAM = 'cb'
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* The cache-busting value changes once per window instead of per request, so
|
|
13
|
-
* retries for the same URL within a window share one CDN cache entry: at most
|
|
14
|
-
* one of them reaches the origin, instead of every page generation causing a
|
|
15
|
-
* new cache miss while the bad response stays cached under the original URL.
|
|
16
|
-
*/
|
|
17
|
-
export const CACHE_BUST_WINDOW_MS = 60 * 1000
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* How long a URL whose cache-busting retry also failed skips further retries.
|
|
21
|
-
*
|
|
22
|
-
* Must be at least `CACHE_BUST_WINDOW_MS`: the next retry after the cooldown
|
|
23
|
-
* has to fall in a later window, so it uses a new cache-busting value instead
|
|
24
|
-
* of the one whose cached response just failed. Derived from it to keep that
|
|
25
|
-
* invariant when either value changes.
|
|
26
|
-
*/
|
|
27
|
-
export const RETRY_COOLDOWN_MS = CACHE_BUST_WINDOW_MS
|
|
28
|
-
|
|
29
|
-
type ErrorShape = {
|
|
30
|
-
name?: unknown
|
|
31
|
-
type?: unknown
|
|
32
|
-
cause?: { code?: unknown }
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Error codes Node raises while decompressing a response body: zlib (gzip,
|
|
37
|
-
* deflate) uses `Z_*` (e.g. `Z_DATA_ERROR`, `Z_BUF_ERROR`), and brotli uses
|
|
38
|
-
* `ERR_` + the decoder error name, which itself starts with an underscore (e.g.
|
|
39
|
-
* `ERR__ERROR_FORMAT_PADDING_1`). The double underscore is not a typo.
|
|
40
|
-
*/
|
|
41
|
-
const BODY_DECODING_ERROR_CODE = /^(Z_|ERR__ERROR_)/
|
|
42
|
-
|
|
43
|
-
const decodingErrorCode = (error: unknown) => {
|
|
44
|
-
const code = (error as ErrorShape | null)?.cause?.code
|
|
45
|
-
|
|
46
|
-
return typeof code === 'string' && BODY_DECODING_ERROR_CODE.test(code)
|
|
47
|
-
? code
|
|
48
|
-
: undefined
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Whether `error` means the response arrived but its body could not be parsed
|
|
53
|
-
* or decoded:
|
|
54
|
-
* - `SyntaxError`: `response.json()` on a body that is not valid JSON. Checked
|
|
55
|
-
* by name so it also matches errors created in another realm (e.g. a test vm
|
|
56
|
-
* context).
|
|
57
|
-
* - A decoding error while reading the body, when `Content-Encoding` does not
|
|
58
|
-
* match the bytes: undici rejects with `TypeError: terminated`, caused by a
|
|
59
|
-
* zlib or brotli error.
|
|
60
|
-
* - `invalid-json`: the parse failure as reported by `node-fetch`.
|
|
61
|
-
* `@vtex/client-cms` only falls back to it when there is no global fetch,
|
|
62
|
-
* which does not happen on the Node versions core supports (>= 20.9), so this
|
|
63
|
-
* case is only a safeguard.
|
|
64
|
-
*
|
|
65
|
-
* Bodies that parse to an unexpected value (e.g. `null`) are not retried: they
|
|
66
|
-
* keep reaching callers as before.
|
|
67
|
-
*/
|
|
68
|
-
const isInvalidBodyError = (error: unknown) => {
|
|
69
|
-
const { name, type } = (error ?? {}) as ErrorShape
|
|
70
|
-
|
|
71
|
-
return (
|
|
72
|
-
name === 'SyntaxError' ||
|
|
73
|
-
type === 'invalid-json' ||
|
|
74
|
-
decodingErrorCode(error) !== undefined
|
|
75
|
-
)
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/** Error name plus decoding code, without the message (it may embed body). */
|
|
79
|
-
const describeError = (error: unknown) =>
|
|
80
|
-
[(error as ErrorShape | null)?.name, decodingErrorCode(error)]
|
|
81
|
-
.filter(Boolean)
|
|
82
|
-
.join(': ')
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* `ClientCMS` that retries a request once, bypassing CDN caches, when the
|
|
86
|
-
* response body cannot be parsed or decoded. A single bad cached response
|
|
87
|
-
* (e.g. a compressed body stored without its `Content-Encoding`) would
|
|
88
|
-
* otherwise fail every page that depends on it until the cache entry expires.
|
|
89
|
-
*
|
|
90
|
-
* Only that case is retried: network errors are already retried by
|
|
91
|
-
* `@vtex/client-cms`, and non-2xx responses keep failing as before.
|
|
92
|
-
*
|
|
93
|
-
* The retry reaches the origin. When the retry fails too, for any reason (an
|
|
94
|
-
* invalid body, a 5xx, a network error), the origin itself is likely unhealthy,
|
|
95
|
-
* so that URL fails fast without retrying for `RETRY_COOLDOWN_MS` instead of
|
|
96
|
-
* adding an uncached origin hit to every page generation. Skipping the retry
|
|
97
|
-
* only falls back to the behavior without this class.
|
|
98
|
-
*/
|
|
99
|
-
export class ResilientClientCMS extends ClientCMS {
|
|
100
|
-
/** URL -> time until which its cache-busting retry is skipped. */
|
|
101
|
-
private readonly retryCooldownUntil = new Map<string, number>()
|
|
102
|
-
|
|
103
|
-
async fetch<T>(path = '', params?: URLSearchParams): Promise<T> {
|
|
104
|
-
try {
|
|
105
|
-
return await super.fetch<T>(path, params)
|
|
106
|
-
} catch (error) {
|
|
107
|
-
if (!isInvalidBodyError(error)) {
|
|
108
|
-
throw error
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
const url = [path, params?.toString()].filter(Boolean).join('?')
|
|
112
|
-
if (this.isCoolingDown(url)) {
|
|
113
|
-
throw error
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// Only the error name (and decoding error code) is logged: a JSON parse
|
|
117
|
-
// error message embeds the start of the body, which may be binary.
|
|
118
|
-
console.warn(
|
|
119
|
-
`[CMS] Invalid response body for "${url}" (${describeError(error)}). Retrying once bypassing the cache.`
|
|
120
|
-
)
|
|
121
|
-
|
|
122
|
-
const cacheBustingParams = new URLSearchParams(params)
|
|
123
|
-
cacheBustingParams.set(
|
|
124
|
-
CACHE_BUST_PARAM,
|
|
125
|
-
Math.floor(Date.now() / CACHE_BUST_WINDOW_MS).toString()
|
|
126
|
-
)
|
|
127
|
-
|
|
128
|
-
try {
|
|
129
|
-
return await super.fetch<T>(path, cacheBustingParams)
|
|
130
|
-
} catch (retryError) {
|
|
131
|
-
// Any retry failure backs off, not only another invalid body: a 5xx or
|
|
132
|
-
// network error from the origin is also a reason not to add load.
|
|
133
|
-
this.startCooldown(url)
|
|
134
|
-
console.warn(
|
|
135
|
-
`[CMS] Cache-busting retry failed for "${url}" (${describeError(retryError)}). Skipping retries for this URL for ${RETRY_COOLDOWN_MS / 1000}s.`
|
|
136
|
-
)
|
|
137
|
-
throw retryError
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
private isCoolingDown(url: string) {
|
|
143
|
-
const until = this.retryCooldownUntil.get(url)
|
|
144
|
-
|
|
145
|
-
if (until === undefined) {
|
|
146
|
-
return false
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
if (until > Date.now()) {
|
|
150
|
-
return true
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
this.retryCooldownUntil.delete(url)
|
|
154
|
-
return false
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
private startCooldown(url: string) {
|
|
158
|
-
const now = Date.now()
|
|
159
|
-
|
|
160
|
-
// Drop expired entries so URLs that are never requested again do not pile
|
|
161
|
-
// up for the lifetime of the process.
|
|
162
|
-
this.retryCooldownUntil.forEach((until, key) => {
|
|
163
|
-
if (until <= now) this.retryCooldownUntil.delete(key)
|
|
164
|
-
})
|
|
165
|
-
|
|
166
|
-
this.retryCooldownUntil.set(url, now + RETRY_COOLDOWN_MS)
|
|
167
|
-
}
|
|
168
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Config keys already warned about in this process. `getStaticProps` runs on
|
|
3
|
-
* every regeneration, so a per-call warning would repeat for every hot page.
|
|
4
|
-
*/
|
|
5
|
-
const warnedKeys = new Set<string>()
|
|
6
|
-
|
|
7
|
-
function warnOnce(key: string, message: string) {
|
|
8
|
-
if (warnedKeys.has(key)) {
|
|
9
|
-
return
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
warnedKeys.add(key)
|
|
13
|
-
console.warn(message)
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Normalizes an ISR `revalidate` window read from the store config.
|
|
18
|
-
*
|
|
19
|
-
* Returns the value when it is a positive integer number of seconds, raised
|
|
20
|
-
* to `min` when it is lower. Any other value returns `false`, which keeps
|
|
21
|
-
* Next.js' default for static pages: the page is cached until the next
|
|
22
|
-
* deploy. Next.js rejects `0`, negative and fractional windows at render
|
|
23
|
-
* time, so those fall back to `false` with a warning instead of breaking the
|
|
24
|
-
* page.
|
|
25
|
-
*
|
|
26
|
-
* @param value The configured window, e.g. `experimental.revalidatePLP`.
|
|
27
|
-
* @param key The config key, used in the warnings.
|
|
28
|
-
* @param options.min The shortest window allowed, in seconds. Defaults to 1.
|
|
29
|
-
*/
|
|
30
|
-
export function toRevalidate(
|
|
31
|
-
value: unknown,
|
|
32
|
-
key: string,
|
|
33
|
-
{ min = 1 }: { min?: number } = {}
|
|
34
|
-
): number | false {
|
|
35
|
-
if (typeof value === 'number' && Number.isInteger(value) && value > 0) {
|
|
36
|
-
if (value < min) {
|
|
37
|
-
warnOnce(
|
|
38
|
-
key,
|
|
39
|
-
`[FastStore] ${key} is ${value}s. Using the minimum of ${min}s.`
|
|
40
|
-
)
|
|
41
|
-
|
|
42
|
-
return min
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return value
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (value !== false && value !== undefined && value !== null) {
|
|
49
|
-
warnOnce(
|
|
50
|
-
key,
|
|
51
|
-
`[FastStore] Invalid ${key}: ${describeValue(value)}. Expected a positive integer number of seconds or false. The page will be cached until the next deploy.`
|
|
52
|
-
)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return false
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Describes a config value for a warning without ever throwing: objects can
|
|
60
|
-
* be circular or hold bigints, which JSON.stringify rejects, so only their
|
|
61
|
-
* type is printed.
|
|
62
|
-
*/
|
|
63
|
-
function describeValue(value: unknown): string {
|
|
64
|
-
switch (typeof value) {
|
|
65
|
-
case 'number':
|
|
66
|
-
case 'bigint':
|
|
67
|
-
case 'boolean':
|
|
68
|
-
return `${value}`
|
|
69
|
-
case 'string':
|
|
70
|
-
return JSON.stringify(value)
|
|
71
|
-
default:
|
|
72
|
-
return `a value of type ${typeof value}`
|
|
73
|
-
}
|
|
74
|
-
}
|