@faststore/core 4.0.1-dev.1 → 4.0.1-dev.2

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.
@@ -1,9 +1,9 @@
1
1
 
2
- > @faststore/core@4.0.1-dev.0 generate /home/runner/work/faststore/faststore/packages/core
2
+ > @faststore/core@4.0.1-dev.1 generate /home/runner/work/faststore/faststore/packages/core
3
3
  > pnpm run gen-types && pnpm run cache-graphql
4
4
 
5
5
 
6
- > @faststore/core@4.0.1-dev.0 gen-types /home/runner/work/faststore/faststore/packages/core
6
+ > @faststore/core@4.0.1-dev.1 gen-types /home/runner/work/faststore/faststore/packages/core
7
7
  > node ../cli/bin/run generate-types .
8
8
 
9
9
  [STARTED] Parse Configuration
@@ -19,7 +19,7 @@
19
19
  [COMPLETED] Generate to /home/runner/work/faststore/faststore/packages/core/@generated/
20
20
  [COMPLETED] Generate outputs
21
21
 
22
- > @faststore/core@4.0.1-dev.0 cache-graphql /home/runner/work/faststore/faststore/packages/core
22
+ > @faststore/core@4.0.1-dev.1 cache-graphql /home/runner/work/faststore/faststore/packages/core
23
23
  > node ../cli/bin/run cache-graphql --config=./discovery.config.default.js --queries=./@generated/persisted-documents.json
24
24
 
25
25
  [Info] - Config file location: /home/runner/work/faststore/faststore/packages/core/discovery.config.default.js
@@ -1,13 +1,13 @@
1
1
 
2
- > @faststore/core@4.0.1-dev.0 test /home/runner/work/faststore/faststore/packages/core
2
+ > @faststore/core@4.0.1-dev.1 test /home/runner/work/faststore/faststore/packages/core
3
3
  > vitest run
4
4
 
5
5
 
6
6
   RUN  v4.0.7 /home/runner/work/faststore/faststore/packages/core
7
7
 
8
8
  ✓  node  test/utils/match-url.test.ts (10 tests) 37ms
9
- ✓  node  test/utils/localization/bindingPaths.test.ts (71 tests) 82ms
10
- ✓  node  test/sdk/localization/bindingSelector.test.ts (18 tests) 29ms
9
+ ✓  node  test/utils/localization/bindingPaths.test.ts (71 tests) 122ms
10
+ ✓  node  test/sdk/localization/bindingSelector.test.ts (18 tests) 37ms
11
11
  stderr | test/sdk/localization/store-url.browser.test.ts
12
12
  Error in optimistic validation: TypeError: Cannot read properties of undefined (reading 'read')
13
13
  at validateCart (/home/runner/work/faststore/faststore/packages/core/src/sdk/cart/index.ts:119:27)
@@ -15,6 +15,7 @@
15
15
  at a (/home/runner/work/faststore/faststore/packages/sdk/dist/es/index.mjs:342:23)
16
16
   at processTicksAndRejections (node:internal/process/task_queues:103:5)
17
17
 
18
+ ✓  node  test/utils/cookieCacheBusting.test.ts (10 tests) 40ms
18
19
  stderr | test/sdk/localization/store-url.browser.test.ts
19
20
  Error in optimistic validation: ReferenceError: Cannot access '__vite_ssr_import_4__' before initialization
20
21
  at getSettings (/home/runner/work/faststore/faststore/packages/core/src/sdk/localization/useLocalizationConfig.tsx:126:45)
@@ -23,25 +24,24 @@
23
24
  at a (/home/runner/work/faststore/faststore/packages/sdk/dist/es/index.mjs:342:23)
24
25
   at processTicksAndRejections (node:internal/process/task_queues:103:5)
25
26
 
26
- ✓  node  test/utils/cookieCacheBusting.test.ts (10 tests) 45ms
27
- ✓  browser  test/sdk/localization/store-url.browser.test.ts (3 tests) 12ms
28
- ✓  node  test/sdk/search/useSearchHistory.test.ts (13 tests) 145ms
29
- ✓  node  test/utils/multipleTemplates.test.ts (8 tests) 19ms
30
- ✓  node  test/sdk/localization/useBindingSelector.test.tsx (12 tests) 23ms
31
- ✓  node  test/utils/clearCookies.test.ts (20 tests) 72ms
32
- ✓  node  test/server/cms/global.test.ts (3 tests) 24ms
33
- ✓  node  test/server/content/service.test.ts (5 tests) 7ms
34
- ✓  node  test/utils/getRequestHostname.test.ts (12 tests) 34ms
35
- ✓  node  test/sdk/localization/store-url.test.ts (1 test) 16ms
36
- ✓  node  test/utils/validateSessionRefreshToken.test.ts (6 tests) 14ms
37
- ✓  node  test/pages/api/preview.test.ts (2 tests) 18ms
38
- ✓  node  test/server/cms/index.test.ts (2 tests) 12ms
39
- ✓  node  test/server/index.test.ts (7 tests) 1205ms
40
- ✓ should return a valid merged GraphQL schema  556ms
41
- ✓ should handle options and execute  326ms
27
+ ✓  browser  test/sdk/localization/store-url.browser.test.ts (3 tests) 15ms
28
+ ✓  node  test/sdk/localization/useBindingSelector.test.tsx (12 tests) 22ms
29
+ ✓  node  test/sdk/search/useSearchHistory.test.ts (13 tests) 92ms
30
+ ✓  node  test/utils/multipleTemplates.test.ts (8 tests) 25ms
31
+ ✓  node  test/utils/clearCookies.test.ts (20 tests) 79ms
32
+ ✓  node  test/server/content/service.test.ts (5 tests) 10ms
33
+ ✓  node  test/server/cms/global.test.ts (3 tests) 12ms
34
+ ✓  node  test/utils/getRequestHostname.test.ts (12 tests) 16ms
35
+ ✓  node  test/sdk/localization/store-url.test.ts (1 test) 12ms
36
+ ✓  node  test/utils/validateSessionRefreshToken.test.ts (6 tests) 18ms
37
+ ✓  node  test/pages/api/preview.test.ts (2 tests) 24ms
38
+ ✓  node  test/server/cms/index.test.ts (2 tests) 7ms
39
+ ✓  node  test/server/index.test.ts (7 tests) 1259ms
40
+ ✓ should return a valid merged GraphQL schema  599ms
41
+ ✓ should exist with its plugins  406ms
42
42
 
43
43
   Test Files  17 passed (17)
44
44
   Tests  203 passed (203)
45
-  Start at  21:31:36
46
-  Duration  13.22s (transform 5.15s, setup 0ms, collect 15.16s, tests 1.79s, environment 7.75s, prepare 789ms)
45
+  Start at  15:30:48
46
+  Duration  13.81s (transform 5.83s, setup 0ms, collect 16.52s, tests 1.83s, environment 9.75s, prepare 663ms)
47
47
 
package/CHANGELOG.md CHANGED
@@ -3,6 +3,12 @@
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.0.1-dev.2](https://github.com/vtex/faststore/compare/v4.0.1-dev.1...v4.0.1-dev.2) (2026-05-11)
7
+
8
+ ### Bug Fixes
9
+
10
+ - localization selector stale and reset selection for unsaved changes ([#3301](https://github.com/vtex/faststore/issues/3301)) ([023e52e](https://github.com/vtex/faststore/commit/023e52ee3c8798cfc9f12ed98e99e8efacb1f1d5))
11
+
6
12
  ## [4.0.1-dev.1](https://github.com/vtex/faststore/compare/v4.0.1-dev.0...v4.0.1-dev.1) (2026-05-07)
7
13
 
8
14
  ### Bug Fixes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faststore/core",
3
- "version": "4.0.1-dev.1",
3
+ "version": "4.0.1-dev.2",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -39,11 +39,11 @@
39
39
  "@envelop/graphql-jit": "catalog:",
40
40
  "@envelop/parser-cache": "catalog:",
41
41
  "@envelop/validation-cache": "catalog:",
42
- "@faststore/api": "4.0.1-dev.1",
43
- "@faststore/diagnostics": "4.0.1-dev.1",
44
- "@faststore/lighthouse": "4.0.1-dev.1",
45
- "@faststore/sdk": "4.0.1-dev.1",
46
- "@faststore/ui": "4.0.1-dev.1",
42
+ "@faststore/api": "4.0.1-dev.2",
43
+ "@faststore/diagnostics": "4.0.1-dev.2",
44
+ "@faststore/lighthouse": "4.0.1-dev.2",
45
+ "@faststore/sdk": "4.0.1-dev.2",
46
+ "@faststore/ui": "4.0.1-dev.2",
47
47
  "@graphql-codegen/cli": "catalog:",
48
48
  "@graphql-codegen/client-preset": "4.2.6",
49
49
  "@graphql-codegen/typescript": "catalog:",
@@ -113,5 +113,5 @@
113
113
  "react": "catalog:",
114
114
  "react-dom": "catalog:"
115
115
  },
116
- "gitHead": "de1a5b1ae2466025e8c007f8bca5b9dd34d82daa"
116
+ "gitHead": "78469e62248563c911ba449ea69fc1edacf7277e"
117
117
  }
@@ -49,6 +49,7 @@ const LocalizationButton = ({
49
49
  setLocaleCode,
50
50
  setCurrencyCode,
51
51
  save,
52
+ reset,
52
53
  isSaveEnabled,
53
54
  error,
54
55
  } = useBindingSelector()
@@ -97,7 +98,10 @@ const LocalizationButton = ({
97
98
  {isSelectorOpen && (
98
99
  <LocalizationSelector
99
100
  isOpen={isSelectorOpen}
100
- onClose={() => setIsSelectorOpen(false)}
101
+ onClose={() => {
102
+ setIsSelectorOpen(false)
103
+ reset()
104
+ }}
101
105
  triggerRef={buttonRef}
102
106
  languages={languages}
103
107
  currencies={currencies}
@@ -1,4 +1,4 @@
1
- import { useCallback, useMemo, useState } from 'react'
1
+ import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
2
2
 
3
3
  import storeConfig from '../../../discovery.config'
4
4
  import { buildRedirectUrl } from '../../utils/localization/bindingPaths'
@@ -56,6 +56,8 @@ export interface UseBindingSelectorReturn {
56
56
  setCurrencyCode: (code: string) => void
57
57
  /** Action to save selections and redirect */
58
58
  save: () => void
59
+ /** Discards unsaved changes and resets selections to current session values */
60
+ reset: () => void
59
61
  }
60
62
 
61
63
  /**
@@ -77,6 +79,23 @@ export function useBindingSelector(): UseBindingSelectorReturn {
77
79
  )
78
80
  const [error, setError] = useState<BindingSelectorError | null>(null)
79
81
 
82
+ const hasUserEditedSelection = useRef(false)
83
+
84
+ // Sync selections when session resolves after initial render (e.g. stale session
85
+ // from a previous locale when navigating between locale-prefixed paths).
86
+ // Skipped once the user has made an in-progress selection; call reset() on close to re-enable.
87
+ useEffect(() => {
88
+ if (!hasUserEditedSelection.current) {
89
+ setLocaleCode(currentLocale ?? null)
90
+ }
91
+ }, [currentLocale])
92
+
93
+ useEffect(() => {
94
+ if (!hasUserEditedSelection.current) {
95
+ setCurrencyCode(currentCurrency?.code ?? null)
96
+ }
97
+ }, [currentCurrency?.code])
98
+
80
99
  // Build language options with disambiguation - returns Record<localeCode, languageName>
81
100
  const languages = useMemo(
82
101
  () => buildLanguageOptions(localizationConfig.locales),
@@ -98,6 +117,7 @@ export function useBindingSelector(): UseBindingSelectorReturn {
98
117
  // Handle locale code change
99
118
  const handleSetLocaleCode = useCallback(
100
119
  (code: string) => {
120
+ hasUserEditedSelection.current = true
101
121
  setLocaleCode(code)
102
122
  setError(null)
103
123
 
@@ -126,6 +146,7 @@ export function useBindingSelector(): UseBindingSelectorReturn {
126
146
 
127
147
  // Handle currency code change
128
148
  const handleSetCurrencyCode = useCallback((code: string) => {
149
+ hasUserEditedSelection.current = true
129
150
  setCurrencyCode(code)
130
151
  setError(null)
131
152
  }, [])
@@ -169,6 +190,14 @@ export function useBindingSelector(): UseBindingSelectorReturn {
169
190
 
170
191
  const isSaveEnabled = Boolean(localeCode && currencyCode && !error)
171
192
 
193
+ // Discards unsaved changes and re-enables session syncing
194
+ const reset = useCallback(() => {
195
+ hasUserEditedSelection.current = false
196
+ setLocaleCode(currentLocale ?? null)
197
+ setCurrencyCode(currentCurrency?.code ?? null)
198
+ setError(null)
199
+ }, [currentLocale, currentCurrency?.code])
200
+
172
201
  return {
173
202
  languages,
174
203
  currencies,
@@ -179,5 +208,6 @@ export function useBindingSelector(): UseBindingSelectorReturn {
179
208
  setLocaleCode: handleSetLocaleCode,
180
209
  setCurrencyCode: handleSetCurrencyCode,
181
210
  save,
211
+ reset,
182
212
  }
183
213
  }