@salesforce/commerce-sdk-react 5.1.1-preview.0 → 5.1.1
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,6 @@
|
|
|
1
|
-
## v5.1.1
|
|
1
|
+
## v5.1.1 (Mar 20, 2026)
|
|
2
2
|
- 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)
|
|
3
4
|
|
|
4
5
|
## v5.1.0 (Mar 12, 2026)
|
|
5
6
|
- Add Page Designer Support [#3727](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/3727)
|
|
@@ -12,8 +12,8 @@ type OptionalWhenDisabled<T> = ({
|
|
|
12
12
|
* @param enabled - flag to turn on/off Storefront Preview feature. By default, it is set to true.
|
|
13
13
|
* This flag only applies if storefront is running in a Runtime Admin iframe.
|
|
14
14
|
* @param getToken - A method that returns the access token for the current user
|
|
15
|
-
* @param getBasePath - A method that returns the router base path of the app.
|
|
16
|
-
* base path for router routes (showBasePath is true in url config).
|
|
15
|
+
* @param getBasePath - A method that returns the router base path of the app.
|
|
16
|
+
* Required if using a base path for router routes (showBasePath is true in url config).
|
|
17
17
|
*/
|
|
18
18
|
export declare const StorefrontPreview: {
|
|
19
19
|
({ children, enabled, getToken, onContextChange, getBasePath }: React.PropsWithChildren<OptionalWhenDisabled<{
|
|
@@ -30,6 +30,29 @@ function removeBasePathFromPath(path, basePath) {
|
|
|
30
30
|
const matches = path.startsWith(basePath + '/') || path === basePath;
|
|
31
31
|
return matches ? path.slice(basePath.length) || '/' : path;
|
|
32
32
|
}
|
|
33
|
+
const PWA_KIT_PATH_PREFIX = '/__pwa-kit/';
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Runtime Admin always prepends envBasePath to /__pwa-kit/ paths (e.g. /test/__pwa-kit/refresh),
|
|
37
|
+
* but when showBasePath is false, React Router has no basename and expects /__pwa-kit/refresh.
|
|
38
|
+
*
|
|
39
|
+
* This ensures that regardless of the showBasePath setting, these paths are normalized to
|
|
40
|
+
* remove the base path.
|
|
41
|
+
*/
|
|
42
|
+
function normalizePwaKitPath(pathOrLocation) {
|
|
43
|
+
if (typeof pathOrLocation === 'string') {
|
|
44
|
+
const idx = pathOrLocation.indexOf(PWA_KIT_PATH_PREFIX);
|
|
45
|
+
return idx > 0 ? pathOrLocation.slice(idx) : pathOrLocation;
|
|
46
|
+
}
|
|
47
|
+
const pathname = pathOrLocation.pathname ?? '/';
|
|
48
|
+
const idx = pathname.indexOf(PWA_KIT_PATH_PREFIX);
|
|
49
|
+
if (idx > 0) {
|
|
50
|
+
return _objectSpread(_objectSpread({}, pathOrLocation), {}, {
|
|
51
|
+
pathname: pathname.slice(idx)
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
return pathOrLocation;
|
|
55
|
+
}
|
|
33
56
|
|
|
34
57
|
/**
|
|
35
58
|
* Strip the base path from a path
|
|
@@ -53,8 +76,8 @@ function removeBasePathFromLocation(pathOrLocation, basePath) {
|
|
|
53
76
|
* @param enabled - flag to turn on/off Storefront Preview feature. By default, it is set to true.
|
|
54
77
|
* This flag only applies if storefront is running in a Runtime Admin iframe.
|
|
55
78
|
* @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.
|
|
57
|
-
* base path for router routes (showBasePath is true in url config).
|
|
79
|
+
* @param getBasePath - A method that returns the router base path of the app.
|
|
80
|
+
* Required if using a base path for router routes (showBasePath is true in url config).
|
|
58
81
|
*/
|
|
59
82
|
const StorefrontPreview = ({
|
|
60
83
|
children,
|
|
@@ -77,7 +100,8 @@ const StorefrontPreview = ({
|
|
|
77
100
|
siteId,
|
|
78
101
|
experimentalUnsafeNavigate: (path, action = 'push', ...args) => {
|
|
79
102
|
const basePath = (getBasePath === null || getBasePath === void 0 ? void 0 : getBasePath()) ?? '';
|
|
80
|
-
const
|
|
103
|
+
const normalizedPath = normalizePwaKitPath(path);
|
|
104
|
+
const pathWithoutBase = removeBasePathFromLocation(normalizedPath, basePath);
|
|
81
105
|
history[action](pathWithoutBase, ...args);
|
|
82
106
|
}
|
|
83
107
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforce/commerce-sdk-react",
|
|
3
|
-
"version": "5.1.1
|
|
3
|
+
"version": "5.1.1",
|
|
4
4
|
"description": "A library that provides react hooks for fetching data from Commerce Cloud",
|
|
5
5
|
"homepage": "https://github.com/SalesforceCommerceCloud/pwa-kit/tree/develop/packages/ecom-react-hooks#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"jwt-decode": "^4.0.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@salesforce/pwa-kit-dev": "3.17.1
|
|
49
|
+
"@salesforce/pwa-kit-dev": "3.17.1",
|
|
50
50
|
"@tanstack/react-query": "^4.28.0",
|
|
51
51
|
"@testing-library/jest-dom": "^5.16.5",
|
|
52
52
|
"@testing-library/react": "^14.0.0",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"@types/react-helmet": "~6.1.6",
|
|
62
62
|
"@types/react-router-dom": "~5.3.3",
|
|
63
63
|
"cross-env": "^5.2.1",
|
|
64
|
-
"internal-lib-build": "3.17.1
|
|
64
|
+
"internal-lib-build": "3.17.1",
|
|
65
65
|
"jsonwebtoken": "^9.0.0",
|
|
66
66
|
"nock": "^13.3.0",
|
|
67
67
|
"nodemon": "^2.0.22",
|
|
@@ -97,5 +97,5 @@
|
|
|
97
97
|
"publishConfig": {
|
|
98
98
|
"directory": "dist"
|
|
99
99
|
},
|
|
100
|
-
"gitHead": "
|
|
100
|
+
"gitHead": "d09ed57f84432913ab3e55e3073802d319c5dc3c"
|
|
101
101
|
}
|