Skip to content

Commit d09ed57

Browse files
vcua-mobifynayanavishwaamittapallidannyphan2000
authored
@W-21671037@ Release PWA Kit 3.17.1 (#3761)
* W-2129587: removed wrapperStyle, add position fixed for LoadingSpinner to have full screen overlay * bump version to preview.1 * @W-21414441@ Bugfix - Fix adding to cart from a master product in the wishlist (#3732) * Fix add to cart bug and add e2e test * Update CHANGELOG.md * W-21432256 fix redirect payment methods status value during preview t… (#3734) * W-21432256 fix redirect payment methods status value during preview testing * @W-21551291: [1CC][PWA Kit] Custom billing address lost after OTP registration (#3741) * @W-21551291: [1CC][PWA Kit] Custom billing address lost after OTP registration Signed-off-by: d.phan <d.phan@salesforce.com> * add changelog Signed-off-by: d.phan <d.phan@salesforce.com> * lint fix Signed-off-by: d.phan <d.phan@salesforce.com> * lint fix Signed-off-by: d.phan <d.phan@salesforce.com> --------- Signed-off-by: d.phan <d.phan@salesforce.com> * clean up changelog * bump versions * Add missing overrides to extensible app (#3745) * Add missing overrides to extensible app * Update CHANGELOG.md * Bump versions * @W-20784635@ Productize base paths (#3614) * @W-20784722@ Move envBasePath into ssrParameters (#3590) * Move envBasePath into ssrParameters * Apply MRT restrictions on supported base paths * Update changelogs * one more changelog * Update express.test.js * Remove whitespace trimming * Remove test base path * Add comment * @W-20784635@ Support adding base paths to shopper facing URLs (#3615) * Add base path to react router routes * Handle basename for urls that bypass react router * Add a feature toggle for app base names * Add tests * Update config templates * Rename getBasename to getRouterBasePath * Update changelogs * Test fixes * Remove unused import and cleanup comments * Apply suggestions * Clean up redundant code * Fix issues from merge conflict * Update CHANGELOG.md * [Storefront Preview] Address base path duplication for manually entered urls (#3666) * Address base path duplication * Update CHANGELOG.md * Update CHANGELOG.md * Update CHANGELOG.md * Apply suggestions * Fix unwanted basePath removal if base path is a substring * Lint * Add console warn * Update refresh component to avoid duplicate base paths * Fix merge issue * Add tests for coverage * Squash changelogs * Remove warning --------- Signed-off-by: vcua-mobify <47404250+vcua-mobify@users.noreply.github.com> * Bump version to 3.17.1-preview.0 * Update CHANGELOG.md * @W-21671037@ Remove base path from /__pwa-kit requests if showBasePath is false (#3758) * Remove base path from /__pwa-kit requests if showBasePath is false * Update CHANGELOG.md * Use a redirect so client side is able hydrate. * Apply storefront preview component changes to deal with client-side single page navigation * Update CHANGELOG.md * Bump version to 3.17.1 --------- Signed-off-by: nayanavishwa <nayana.vishwa@salesforce.com> Signed-off-by: d.phan <d.phan@salesforce.com> Signed-off-by: vcua-mobify <47404250+vcua-mobify@users.noreply.github.com> Co-authored-by: nayanavishwa <nayana.vishwa@salesforce.com> Co-authored-by: amittapalli <amittapalli@yahoo.com> Co-authored-by: Danny Phan <125327707+dannyphan2000@users.noreply.github.com>
1 parent beabe8a commit d09ed57

38 files changed

Lines changed: 269 additions & 83 deletions

e2e/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

e2e/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "e2e-scripts",
3-
"version": "3.17.1-preview.0",
3+
"version": "3.17.1",
44
"description": "E2E test scripts for PWA Kit",
55
"main": "index.js",
66
"private": true,
@@ -15,7 +15,7 @@
1515
"@actions/core": "^1.11.1",
1616
"@aws-sdk/client-s3": "3.450.0",
1717
"@aws-sdk/client-sts": "3.450.0",
18-
"@salesforce/pwa-kit-dev": "3.17.1-preview.0",
18+
"@salesforce/pwa-kit-dev": "3.17.1",
1919
"jest": "^29.7.0"
2020
},
2121
"jest": {

lerna.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "3.17.1-preview.0",
2+
"version": "3.17.1",
33
"packages": [
44
"packages/*",
55
"e2e"

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pwa-kit",
3-
"version": "3.17.1-preview.0",
3+
"version": "3.17.1",
44
"scripts": {
55
"bump-version": "node ./scripts/bump-version/index.js",
66
"bump-version:retail-react-app": "node ./scripts/bump-version/index.js --package=@salesforce/retail-react-app",

packages/commerce-sdk-react/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
## v5.1.1-preview.0 (Mar 13, 2026)
1+
## v5.1.1 (Mar 20, 2026)
22
- Update storefront preview to support base paths [#3614](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/3614)
3+
- Remove base path from /__pwa-kit route requests when showBasePath is false [#3758](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/3758)
34

45
## v5.1.0 (Mar 12, 2026)
56
- Add Page Designer Support [#3727](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/3727)

packages/commerce-sdk-react/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/commerce-sdk-react/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@salesforce/commerce-sdk-react",
3-
"version": "5.1.1-preview.0",
3+
"version": "5.1.1",
44
"description": "A library that provides react hooks for fetching data from Commerce Cloud",
55
"homepage": "https://github.com/SalesforceCommerceCloud/pwa-kit/tree/develop/packages/ecom-react-hooks#readme",
66
"bugs": {
@@ -46,7 +46,7 @@
4646
"jwt-decode": "^4.0.0"
4747
},
4848
"devDependencies": {
49-
"@salesforce/pwa-kit-dev": "3.17.1-preview.0",
49+
"@salesforce/pwa-kit-dev": "3.17.1",
5050
"@tanstack/react-query": "^4.28.0",
5151
"@testing-library/jest-dom": "^5.16.5",
5252
"@testing-library/react": "^14.0.0",
@@ -61,7 +61,7 @@
6161
"@types/react-helmet": "~6.1.6",
6262
"@types/react-router-dom": "~5.3.3",
6363
"cross-env": "^5.2.1",
64-
"internal-lib-build": "3.17.1-preview.0",
64+
"internal-lib-build": "3.17.1",
6565
"jsonwebtoken": "^9.0.0",
6666
"nock": "^13.3.0",
6767
"nodemon": "^2.0.22",

packages/commerce-sdk-react/src/components/StorefrontPreview/storefront-preview.test.tsx

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,102 @@ describe('Storefront Preview Component', function () {
213213
expect(mockPush).toHaveBeenCalledWith({pathname: '/product/123', search: '?q=1'})
214214
})
215215

216+
test('experimentalUnsafeNavigate strips base path prefix from /__pwa-kit/ paths when getBasePath returns empty (showBasePath false)', () => {
217+
;(detectStorefrontPreview as jest.Mock).mockReturnValue(true)
218+
219+
render(
220+
<StorefrontPreview
221+
enabled={true}
222+
getToken={() => 'my-token'}
223+
getBasePath={() => ''}
224+
/>
225+
)
226+
227+
// Runtime Admin sends /test/__pwa-kit/refresh but React Router has no basename
228+
window.STOREFRONT_PREVIEW?.experimentalUnsafeNavigate?.(
229+
'/test/__pwa-kit/refresh?referrer=/some-page',
230+
'replace'
231+
)
232+
expect(mockReplace).toHaveBeenCalledWith('/__pwa-kit/refresh?referrer=/some-page')
233+
})
234+
235+
test('experimentalUnsafeNavigate strips base path prefix from /__pwa-kit/ location objects when getBasePath returns empty', () => {
236+
;(detectStorefrontPreview as jest.Mock).mockReturnValue(true)
237+
238+
render(
239+
<StorefrontPreview
240+
enabled={true}
241+
getToken={() => 'my-token'}
242+
getBasePath={() => ''}
243+
/>
244+
)
245+
246+
window.STOREFRONT_PREVIEW?.experimentalUnsafeNavigate?.(
247+
{pathname: '/test/__pwa-kit/refresh', search: '?referrer=/some-page'},
248+
'replace'
249+
)
250+
expect(mockReplace).toHaveBeenCalledWith({
251+
pathname: '/__pwa-kit/refresh',
252+
search: '?referrer=/some-page'
253+
})
254+
})
255+
256+
test('experimentalUnsafeNavigate normalizes /__pwa-kit/ paths and then strips router base path (showBasePath true)', () => {
257+
;(detectStorefrontPreview as jest.Mock).mockReturnValue(true)
258+
259+
render(
260+
<StorefrontPreview
261+
enabled={true}
262+
getToken={() => 'my-token'}
263+
getBasePath={() => '/test'}
264+
/>
265+
)
266+
267+
// Runtime Admin sends /test/__pwa-kit/refresh, normalizePwaKitPath strips to
268+
// /__pwa-kit/refresh, then removeBasePathFromLocation is a no-op (doesn't start with /test/)
269+
// React Router re-adds the basename, so history receives /__pwa-kit/refresh
270+
window.STOREFRONT_PREVIEW?.experimentalUnsafeNavigate?.(
271+
'/test/__pwa-kit/refresh?referrer=/test/some-page',
272+
'replace'
273+
)
274+
expect(mockReplace).toHaveBeenCalledWith('/__pwa-kit/refresh?referrer=/test/some-page')
275+
})
276+
277+
test('experimentalUnsafeNavigate does not alter /__pwa-kit/ paths that have no prefix', () => {
278+
;(detectStorefrontPreview as jest.Mock).mockReturnValue(true)
279+
280+
render(
281+
<StorefrontPreview
282+
enabled={true}
283+
getToken={() => 'my-token'}
284+
getBasePath={() => ''}
285+
/>
286+
)
287+
288+
// Path already starts with /__pwa-kit/ — no prefix to strip
289+
window.STOREFRONT_PREVIEW?.experimentalUnsafeNavigate?.(
290+
'/__pwa-kit/refresh?referrer=/some-page',
291+
'push'
292+
)
293+
expect(mockPush).toHaveBeenCalledWith('/__pwa-kit/refresh?referrer=/some-page')
294+
})
295+
296+
test('experimentalUnsafeNavigate does not affect non /__pwa-kit/ paths when showBasePath is false', () => {
297+
;(detectStorefrontPreview as jest.Mock).mockReturnValue(true)
298+
299+
render(
300+
<StorefrontPreview
301+
enabled={true}
302+
getToken={() => 'my-token'}
303+
getBasePath={() => ''}
304+
/>
305+
)
306+
307+
// Regular navigation paths should pass through untouched
308+
window.STOREFRONT_PREVIEW?.experimentalUnsafeNavigate?.('/products/123', 'push')
309+
expect(mockPush).toHaveBeenCalledWith('/products/123')
310+
})
311+
216312
test('cache breaker is added to the parameters of SCAPI requests, only if in storefront preview', () => {
217313
;(detectStorefrontPreview as jest.Mock).mockReturnValue(true)
218314
mockQueryEndpoint('baskets/123', {})

packages/commerce-sdk-react/src/components/StorefrontPreview/storefront-preview.tsx

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,28 @@ function removeBasePathFromPath(path: string, basePath: string): string {
2727
return matches ? path.slice(basePath.length) || '/' : path
2828
}
2929

30+
const PWA_KIT_PATH_PREFIX = '/__pwa-kit/'
31+
32+
/**
33+
* Runtime Admin always prepends envBasePath to /__pwa-kit/ paths (e.g. /test/__pwa-kit/refresh),
34+
* but when showBasePath is false, React Router has no basename and expects /__pwa-kit/refresh.
35+
*
36+
* This ensures that regardless of the showBasePath setting, these paths are normalized to
37+
* remove the base path.
38+
*/
39+
function normalizePwaKitPath<T>(pathOrLocation: LocationDescriptor<T>): LocationDescriptor<T> {
40+
if (typeof pathOrLocation === 'string') {
41+
const idx = pathOrLocation.indexOf(PWA_KIT_PATH_PREFIX)
42+
return idx > 0 ? pathOrLocation.slice(idx) : pathOrLocation
43+
}
44+
const pathname = pathOrLocation.pathname ?? '/'
45+
const idx = pathname.indexOf(PWA_KIT_PATH_PREFIX)
46+
if (idx > 0) {
47+
return {...pathOrLocation, pathname: pathname.slice(idx)}
48+
}
49+
return pathOrLocation
50+
}
51+
3052
/**
3153
* Strip the base path from a path
3254
*
@@ -53,8 +75,8 @@ function removeBasePathFromLocation<T>(
5375
* @param enabled - flag to turn on/off Storefront Preview feature. By default, it is set to true.
5476
* This flag only applies if storefront is running in a Runtime Admin iframe.
5577
* @param getToken - A method that returns the access token for the current user
56-
* @param getBasePath - A method that returns the router base path of the app. Requird if using
57-
* base path for router routes (showBasePath is true in url config).
78+
* @param getBasePath - A method that returns the router base path of the app.
79+
* Required if using a base path for router routes (showBasePath is true in url config).
5880
*/
5981
export const StorefrontPreview = ({
6082
children,
@@ -88,7 +110,8 @@ export const StorefrontPreview = ({
88110
...args: unknown[]
89111
) => {
90112
const basePath = getBasePath?.() ?? ''
91-
const pathWithoutBase = removeBasePathFromLocation(path, basePath)
113+
const normalizedPath = normalizePwaKitPath(path)
114+
const pathWithoutBase = removeBasePathFromLocation(normalizedPath, basePath)
92115
history[action](pathWithoutBase, ...args)
93116
}
94117
}

0 commit comments

Comments
 (0)