@shopify/hydrogen 0.25.1 → 0.27.0
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 +127 -5
- package/dist/esnext/components/{CartEstimatedCost/CartEstimatedCost.client.d.ts → CartCost/CartCost.client.d.ts} +3 -3
- package/dist/esnext/components/{CartEstimatedCost/CartEstimatedCost.client.js → CartCost/CartCost.client.js} +7 -7
- package/dist/esnext/components/CartCost/index.d.ts +1 -0
- package/dist/esnext/components/CartCost/index.js +1 -0
- package/dist/esnext/components/CartLinePrice/CartLinePrice.client.js +2 -2
- package/dist/esnext/components/CartLineProvider/context.d.ts +3 -3
- package/dist/esnext/components/CartProvider/CartProvider.client.js +37 -27
- package/dist/esnext/components/CartProvider/cart-queries.d.ts +1 -1
- package/dist/esnext/components/CartProvider/cart-queries.js +3 -3
- package/dist/esnext/components/CartProvider/graphql/CartAttributesUpdateMutation.d.ts +5 -5
- package/dist/esnext/components/CartProvider/graphql/CartBuyerIdentityUpdateMutation.d.ts +5 -5
- package/dist/esnext/components/CartProvider/graphql/CartCreateMutation.d.ts +5 -5
- package/dist/esnext/components/CartProvider/graphql/CartDiscountCodesUpdateMutation.d.ts +5 -5
- package/dist/esnext/components/CartProvider/graphql/CartFragment.d.ts +5 -5
- package/dist/esnext/components/CartProvider/graphql/CartLineAddMutation.d.ts +5 -5
- package/dist/esnext/components/CartProvider/graphql/CartLineRemoveMutation.d.ts +5 -5
- package/dist/esnext/components/CartProvider/graphql/CartLineUpdateMutation.d.ts +5 -5
- package/dist/esnext/components/CartProvider/graphql/CartNoteUpdateMutation.d.ts +5 -5
- package/dist/esnext/components/CartProvider/graphql/CartQuery.d.ts +5 -5
- package/dist/esnext/components/CartProvider/hooks.client.d.ts +1 -1
- package/dist/esnext/components/CartProvider/hooks.client.js +16 -11
- package/dist/esnext/components/CartProvider/types.d.ts +3 -3
- package/dist/esnext/components/CartShopPayButton/CartShopPayButton.client.d.ts +1 -3
- package/dist/esnext/components/CartShopPayButton/CartShopPayButton.client.js +2 -4
- package/dist/esnext/components/Link/Link.client.d.ts +2 -0
- package/dist/esnext/components/Link/Link.client.js +14 -7
- package/dist/esnext/components/LocalizationProvider/LocalizationClientProvider.client.d.ts +2 -2
- package/dist/esnext/components/LocalizationProvider/LocalizationClientProvider.client.js +1 -1
- package/dist/esnext/components/LocalizationProvider/LocalizationContext.client.d.ts +6 -3
- package/dist/esnext/components/LocalizationProvider/LocalizationProvider.server.d.ts +8 -20
- package/dist/esnext/components/LocalizationProvider/LocalizationProvider.server.js +16 -33
- package/dist/esnext/components/LocalizationProvider/index.d.ts +0 -1
- package/dist/esnext/components/LocalizationProvider/index.js +0 -1
- package/dist/esnext/components/Metafield/Metafield.client.js +3 -3
- package/dist/esnext/components/Money/Money.client.d.ts +1 -1
- package/dist/esnext/components/Money/Money.client.js +1 -1
- package/dist/esnext/components/Seo/DefaultPageSeo.client.js +3 -3
- package/dist/esnext/components/Seo/DescriptionSeo.client.js +1 -1
- package/dist/esnext/components/Seo/HomePageSeo.client.d.ts +1 -1
- package/dist/esnext/components/Seo/HomePageSeo.client.js +3 -3
- package/dist/esnext/components/Seo/ImageSeo.client.js +1 -1
- package/dist/esnext/components/Seo/NoIndexSeo.client.js +3 -3
- package/dist/esnext/components/Seo/ProductSeo.client.js +2 -2
- package/dist/esnext/components/Seo/Seo.client.js +1 -1
- package/dist/esnext/components/Seo/TitleSeo.client.js +1 -1
- package/dist/esnext/components/Seo/TwitterSeo.client.js +1 -1
- package/dist/esnext/components/Seo/seo-types.d.ts +1 -0
- package/dist/esnext/components/ShopPayButton/ShopPayButton.client.d.ts +3 -1
- package/dist/esnext/components/ShopPayButton/ShopPayButton.client.js +8 -3
- package/dist/esnext/components/index.d.ts +2 -2
- package/dist/esnext/components/index.js +2 -2
- package/dist/esnext/constants.d.ts +1 -1
- package/dist/esnext/constants.js +1 -1
- package/dist/esnext/entry-client.js +7 -5
- package/dist/esnext/entry-server.js +40 -40
- package/dist/esnext/foundation/Analytics/ServerAnalyticsRoute.js +31 -16
- package/dist/esnext/foundation/Analytics/connectors/PerformanceMetrics/PerformanceMetrics.client.js +20 -3
- package/dist/esnext/foundation/Analytics/connectors/PerformanceMetrics/PerformanceMetricsDebug.client.js +1 -1
- package/dist/esnext/foundation/Analytics/connectors/PerformanceMetrics/ServerAnalyticsConnector.d.ts +1 -1
- package/dist/esnext/foundation/Analytics/connectors/PerformanceMetrics/ServerAnalyticsConnector.js +3 -23
- package/dist/esnext/foundation/Analytics/connectors/Shopify/ServerAnalyticsConnector.d.ts +1 -1
- package/dist/esnext/foundation/Analytics/connectors/Shopify/ServerAnalyticsConnector.js +3 -17
- package/dist/esnext/foundation/Analytics/connectors/Shopify/ShopifyAnalytics.client.js +5 -13
- package/dist/esnext/foundation/Analytics/connectors/Shopify/ShopifyAnalytics.server.js +20 -0
- package/dist/esnext/foundation/DevTools/DevTools.server.js +2 -2
- package/dist/esnext/foundation/FileRoutes/FileRoutes.server.js +1 -1
- package/dist/esnext/foundation/HydrogenRequest/HydrogenRequest.server.d.ts +9 -1
- package/dist/esnext/foundation/HydrogenRequest/HydrogenRequest.server.js +6 -0
- package/dist/esnext/foundation/Route/Route.server.js +1 -1
- package/dist/esnext/foundation/Router/BrowserRouter.client.d.ts +1 -1
- package/dist/esnext/foundation/Router/BrowserRouter.client.js +7 -5
- package/dist/esnext/foundation/ServerRequestProvider/ServerRequestProvider.d.ts +5 -4
- package/dist/esnext/foundation/ServerRequestProvider/ServerRequestProvider.js +9 -7
- package/dist/esnext/foundation/ShopifyProvider/ShopifyProvider.server.js +9 -5
- package/dist/esnext/foundation/ShopifyProvider/types.d.ts +4 -3
- package/dist/esnext/foundation/constants.d.ts +2 -1
- package/dist/esnext/foundation/constants.js +2 -1
- package/dist/esnext/foundation/useNavigate/useNavigate.d.ts +2 -0
- package/dist/esnext/foundation/useNavigate/useNavigate.js +19 -0
- package/dist/esnext/foundation/useQuery/hooks.js +1 -4
- package/dist/esnext/foundation/useRouteParams/RouteParamsProvider.client.d.ts +3 -0
- package/dist/esnext/foundation/useRouteParams/RouteParamsProvider.client.js +8 -3
- package/dist/esnext/foundation/useUrl/useUrl.js +5 -3
- package/dist/esnext/framework/cache/in-memory.d.ts +12 -7
- package/dist/esnext/framework/cache/in-memory.js +49 -21
- package/dist/esnext/framework/load-config.d.ts +5 -0
- package/dist/esnext/framework/load-config.js +7 -0
- package/dist/esnext/framework/plugin.js +1 -1
- package/dist/esnext/framework/plugins/vite-plugin-hydrogen-client-middleware.js +2 -3
- package/dist/esnext/framework/plugins/vite-plugin-hydrogen-config.js +2 -2
- package/dist/esnext/framework/plugins/vite-plugin-hydrogen-rsc.d.ts +2 -1
- package/dist/esnext/framework/plugins/vite-plugin-hydrogen-rsc.js +2 -1
- package/dist/esnext/framework/types.d.ts +1 -0
- package/dist/esnext/framework/viteception.d.ts +2 -1
- package/dist/esnext/framework/viteception.js +2 -1
- package/dist/esnext/hooks/useCartLine/useCartLine.d.ts +3 -3
- package/dist/esnext/hooks/useLocalization/useLocalization.d.ts +4 -0
- package/dist/esnext/hooks/useLocalization/useLocalization.js +14 -0
- package/dist/esnext/hooks/useMeasurement/hooks.js +2 -2
- package/dist/esnext/hooks/useMoney/hooks.d.ts +1 -1
- package/dist/esnext/hooks/useMoney/hooks.js +2 -2
- package/dist/esnext/index.d.ts +3 -0
- package/dist/esnext/index.js +1 -0
- package/dist/esnext/platforms/node.d.ts +1 -1
- package/dist/esnext/platforms/node.js +2 -1
- package/dist/esnext/shared-types.d.ts +2 -1
- package/dist/esnext/storefront-api-types.d.ts +105 -3
- package/dist/esnext/storefront-api-types.js +8 -0
- package/dist/esnext/types.d.ts +11 -1
- package/dist/esnext/utilities/apiRoutes.d.ts +4 -3
- package/dist/esnext/utilities/image_size.js +11 -0
- package/dist/esnext/utilities/log/log-cache-api-status.js +3 -0
- package/dist/esnext/utilities/storefrontApi.d.ts +1 -0
- package/dist/esnext/utilities/storefrontApi.js +1 -1
- package/dist/esnext/version.d.ts +1 -1
- package/dist/esnext/version.js +1 -1
- package/dist/node/framework/cache/in-memory.d.ts +12 -7
- package/dist/node/framework/cache/in-memory.js +49 -21
- package/dist/node/framework/load-config.d.ts +5 -0
- package/dist/node/framework/load-config.js +11 -0
- package/dist/node/framework/plugin.js +1 -1
- package/dist/node/framework/plugins/vite-plugin-hydrogen-client-middleware.js +2 -3
- package/dist/node/framework/plugins/vite-plugin-hydrogen-config.js +2 -2
- package/dist/node/framework/plugins/vite-plugin-hydrogen-rsc.d.ts +2 -1
- package/dist/node/framework/plugins/vite-plugin-hydrogen-rsc.js +2 -1
- package/dist/node/framework/types.d.ts +1 -0
- package/dist/node/framework/viteception.d.ts +2 -1
- package/dist/node/framework/viteception.js +2 -1
- package/dist/node/shared-types.d.ts +2 -1
- package/package.json +13 -3
- package/vendor/react-server-dom-vite/cjs/react-server-dom-vite-plugin.js +46 -17
- package/vendor/react-server-dom-vite/cjs/react-server-dom-vite.development.js +18 -3
- package/vendor/react-server-dom-vite/cjs/react-server-dom-vite.production.min.js +2 -2
- package/vendor/react-server-dom-vite/esm/react-server-dom-vite-client-proxy.js +2 -1
- package/vendor/react-server-dom-vite/esm/react-server-dom-vite-plugin.js +46 -17
- package/vendor/react-server-dom-vite/esm/react-server-dom-vite.js +18 -3
- package/dist/esnext/components/CartEstimatedCost/index.d.ts +0 -1
- package/dist/esnext/components/CartEstimatedCost/index.js +0 -1
- package/dist/esnext/hooks/useCountry/index.d.ts +0 -1
- package/dist/esnext/hooks/useCountry/index.js +0 -1
- package/dist/esnext/hooks/useCountry/useCountry.d.ts +0 -7
- package/dist/esnext/hooks/useCountry/useCountry.js +0 -17
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"engines": {
|
|
8
8
|
"node": ">=14"
|
|
9
9
|
},
|
|
10
|
-
"version": "0.
|
|
10
|
+
"version": "0.27.0",
|
|
11
11
|
"description": "Modern custom Shopify storefronts",
|
|
12
12
|
"license": "MIT",
|
|
13
13
|
"main": "dist/esnext/index.js",
|
|
@@ -22,11 +22,19 @@
|
|
|
22
22
|
"import": "./dist/esnext/framework/middleware.js",
|
|
23
23
|
"require": "./dist/node/framework/middleware.js"
|
|
24
24
|
},
|
|
25
|
+
"./load-config": {
|
|
26
|
+
"import": "./dist/esnext/framework/load-config.js",
|
|
27
|
+
"require": "./dist/node/framework/load-config.js"
|
|
28
|
+
},
|
|
25
29
|
"./web-polyfills": {
|
|
26
30
|
"import": "./dist/esnext/utilities/web-api-polyfill",
|
|
27
31
|
"require": "./dist/node/utilities/web-api-polyfill"
|
|
28
32
|
},
|
|
29
33
|
"./vendor/*": "./vendor/*",
|
|
34
|
+
"./cache/*": {
|
|
35
|
+
"import": "./dist/esnext/framework/cache/*.js",
|
|
36
|
+
"require": "./dist/node/framework/cache/*.js"
|
|
37
|
+
},
|
|
30
38
|
"./package.json": "./package.json",
|
|
31
39
|
"./*": "./dist/esnext/*.js"
|
|
32
40
|
},
|
|
@@ -111,6 +119,7 @@
|
|
|
111
119
|
"@vitejs/plugin-react": "^1.3.0",
|
|
112
120
|
"abort-controller": "^3.0.0",
|
|
113
121
|
"body-parser": "^1.20.0",
|
|
122
|
+
"compression": "^1.7.4",
|
|
114
123
|
"connect": "^3.7.0",
|
|
115
124
|
"es-module-lexer": "^0.10.0",
|
|
116
125
|
"fast-glob": "^3.2.11",
|
|
@@ -123,11 +132,12 @@
|
|
|
123
132
|
"path-to-regexp": "^6.2.0",
|
|
124
133
|
"react-error-boundary": "^3.1.3",
|
|
125
134
|
"react-helmet-async": "^1.2.3",
|
|
135
|
+
"serve-static": "^1.15.0",
|
|
126
136
|
"set-cookie-parser": "^2.5.0",
|
|
137
|
+
"undici": "^5.5.1",
|
|
127
138
|
"uuid": "^8.3.2",
|
|
128
139
|
"vite-plugin-inspect": "^0.3.6",
|
|
129
140
|
"web-streams-polyfill": "^3.2.0",
|
|
130
|
-
"worktop": "^0.7.3"
|
|
131
|
-
"undici": "^5.5.1"
|
|
141
|
+
"worktop": "^0.7.3"
|
|
132
142
|
}
|
|
133
143
|
}
|
|
@@ -104,6 +104,8 @@ var isClientComponent = function (id) {
|
|
|
104
104
|
function ReactFlightVitePlugin() {
|
|
105
105
|
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
106
106
|
serverBuildEntries = _ref.serverBuildEntries,
|
|
107
|
+
_ref$optimizeBoundari = _ref.optimizeBoundaries,
|
|
108
|
+
optimizeBoundaries = _ref$optimizeBoundari === void 0 ? 'build' : _ref$optimizeBoundari,
|
|
107
109
|
_ref$isServerComponen = _ref.isServerComponentImporterAllowed,
|
|
108
110
|
isServerComponentImporterAllowed = _ref$isServerComponen === void 0 ? function (importer) {
|
|
109
111
|
return false;
|
|
@@ -111,13 +113,28 @@ function ReactFlightVitePlugin() {
|
|
|
111
113
|
|
|
112
114
|
var config;
|
|
113
115
|
var server;
|
|
114
|
-
var globImporterPath;
|
|
115
116
|
var resolveAlias;
|
|
117
|
+
var globImporterPath;
|
|
118
|
+
var allClientBoundaries = new Set();
|
|
119
|
+
|
|
120
|
+
function invalidateGlobImporter() {
|
|
121
|
+
if (globImporterPath && server) {
|
|
122
|
+
server.watcher.emit('change', globImporterPath);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
116
126
|
return {
|
|
117
127
|
name: 'vite-plugin-react-server-components',
|
|
118
128
|
enforce: 'pre',
|
|
119
129
|
configureServer: function (_server) {
|
|
120
130
|
server = _server;
|
|
131
|
+
var seenModules = {};
|
|
132
|
+
server.ws.on('rsc:cc404', function (data) {
|
|
133
|
+
if (!seenModules[data.id]) {
|
|
134
|
+
seenModules[data.id] = true;
|
|
135
|
+
invalidateGlobImporter();
|
|
136
|
+
}
|
|
137
|
+
});
|
|
121
138
|
},
|
|
122
139
|
configResolved: async function (_config) {
|
|
123
140
|
await esModuleLexer.init;
|
|
@@ -194,13 +211,10 @@ function ReactFlightVitePlugin() {
|
|
|
194
211
|
if (!moduleNode.meta) moduleNode.meta = {};
|
|
195
212
|
|
|
196
213
|
if (!moduleNode.meta.isClientComponent) {
|
|
197
|
-
moduleNode.meta.isClientComponent = true;
|
|
214
|
+
moduleNode.meta.isClientComponent = true; // Invalidate glob importer file to account for the
|
|
215
|
+
// newly discovered client component.
|
|
198
216
|
|
|
199
|
-
|
|
200
|
-
// Invalidate glob importer file to account for the
|
|
201
|
-
// newly discovered client component.
|
|
202
|
-
server.watcher.emit('change', globImporterPath);
|
|
203
|
-
}
|
|
217
|
+
invalidateGlobImporter();
|
|
204
218
|
}
|
|
205
219
|
}
|
|
206
220
|
|
|
@@ -250,7 +264,7 @@ function ReactFlightVitePlugin() {
|
|
|
250
264
|
});
|
|
251
265
|
var injectedGlobs = "Object.assign(Object.create(null), " + importers.map(function (glob) {
|
|
252
266
|
return (// Mark the globs to modify the result after Vite resolves them.
|
|
253
|
-
"/* HASH_BEGIN */ " + ("import.meta.glob('" + vite.normalizePath(glob) + "') /* HASH_END */")
|
|
267
|
+
"\n/* HASH_BEGIN */ " + ("import.meta.glob('" + vite.normalizePath(glob) + "') /* HASH_END */")
|
|
254
268
|
);
|
|
255
269
|
}).join(', ') + ");";
|
|
256
270
|
s.replace(INJECTING_RE, injectedGlobs);
|
|
@@ -264,15 +278,24 @@ function ReactFlightVitePlugin() {
|
|
|
264
278
|
};
|
|
265
279
|
|
|
266
280
|
if (config.command === 'serve') {
|
|
267
|
-
globImporterPath = id;
|
|
268
|
-
|
|
281
|
+
globImporterPath = id; // When mixing client and server components from the same
|
|
282
|
+
// facade file, the module graph can break and miss certain
|
|
283
|
+
// import connections (bug in Vite?) due to HMR. Instead of
|
|
284
|
+
// creating a new list of discovered components from scratch,
|
|
285
|
+
// reuse the already discovered ones and simply add new ones
|
|
286
|
+
// to the list without removing anything.
|
|
287
|
+
|
|
288
|
+
findClientBoundaries(server.moduleGraph, optimizeBoundaries === true).forEach(function (boundary) {
|
|
289
|
+
return allClientBoundaries.add(boundary);
|
|
290
|
+
});
|
|
291
|
+
return injectGlobs(Array.from(allClientBoundaries));
|
|
269
292
|
}
|
|
270
293
|
|
|
271
294
|
if (!serverBuildEntries) {
|
|
272
295
|
throw new Error('[react-server-dom-vite] Parameter serverBuildEntries is required for client build');
|
|
273
296
|
}
|
|
274
297
|
|
|
275
|
-
return findClientBoundariesForClientBuild(serverBuildEntries).then(injectGlobs);
|
|
298
|
+
return findClientBoundariesForClientBuild(serverBuildEntries, optimizeBoundaries !== false).then(injectGlobs);
|
|
276
299
|
}
|
|
277
300
|
}
|
|
278
301
|
};
|
|
@@ -336,6 +359,7 @@ async function proxyClientComponent(filepath, src) {
|
|
|
336
359
|
}
|
|
337
360
|
|
|
338
361
|
function findClientBoundaries(moduleGraph) {
|
|
362
|
+
var optimizeBoundaries = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
339
363
|
var clientBoundaries = []; // eslint-disable-next-line no-for-of-loops/no-for-of-loops
|
|
340
364
|
|
|
341
365
|
var _iterator = _createForOfIteratorHelper(moduleGraph.fileToModulesMap.values()),
|
|
@@ -348,7 +372,7 @@ function findClientBoundaries(moduleGraph) {
|
|
|
348
372
|
return moduleNode.meta && moduleNode.meta.isClientComponent;
|
|
349
373
|
});
|
|
350
374
|
|
|
351
|
-
if (clientModule && isDirectImportInServer(clientModule)) {
|
|
375
|
+
if (clientModule && (!optimizeBoundaries || isDirectImportInServer(clientModule))) {
|
|
352
376
|
clientBoundaries.push(clientModule.file);
|
|
353
377
|
}
|
|
354
378
|
}
|
|
@@ -361,7 +385,7 @@ function findClientBoundaries(moduleGraph) {
|
|
|
361
385
|
return clientBoundaries;
|
|
362
386
|
}
|
|
363
387
|
|
|
364
|
-
async function findClientBoundariesForClientBuild(serverEntries) {
|
|
388
|
+
async function findClientBoundariesForClientBuild(serverEntries, optimizeBoundaries) {
|
|
365
389
|
// Viteception
|
|
366
390
|
var server = await vite.createServer({
|
|
367
391
|
clearScreen: false,
|
|
@@ -379,7 +403,7 @@ async function findClientBoundariesForClientBuild(serverEntries) {
|
|
|
379
403
|
}
|
|
380
404
|
|
|
381
405
|
await server.close();
|
|
382
|
-
return findClientBoundaries(server.moduleGraph);
|
|
406
|
+
return findClientBoundaries(server.moduleGraph, optimizeBoundaries);
|
|
383
407
|
}
|
|
384
408
|
|
|
385
409
|
var hashImportsPlugin = {
|
|
@@ -457,7 +481,7 @@ function isDirectImportInServer(originalMod, currentMod, accModInfo) {
|
|
|
457
481
|
});
|
|
458
482
|
}
|
|
459
483
|
|
|
460
|
-
return Array.from((currentMod || originalMod).importers).some(function (importer) {
|
|
484
|
+
return Array.from((currentMod || originalMod).importers || []).some(function (importer) {
|
|
461
485
|
return (// eslint-disable-next-line no-unused-vars
|
|
462
486
|
isDirectImportInServer(originalMod, importer, accModInfo)
|
|
463
487
|
);
|
|
@@ -477,7 +501,7 @@ function isDirectImportInServer(originalMod, currentMod, accModInfo) {
|
|
|
477
501
|
// the original module before marking it as client boundary.
|
|
478
502
|
|
|
479
503
|
return currentMod.meta.imports.some(function (imp) {
|
|
480
|
-
return imp.
|
|
504
|
+
return imp.from === accModInfo.file && (imp.variables || []).some(function (_ref3) {
|
|
481
505
|
var name = _ref3[0];
|
|
482
506
|
return accModInfo.exports.includes(name);
|
|
483
507
|
});
|
|
@@ -531,10 +555,15 @@ function augmentModuleGraph(moduleGraph, id, code, root, resolveAlias) {
|
|
|
531
555
|
var resolvedAliasPath = resolveAlias(modPath, 'rsc_importer', {});
|
|
532
556
|
|
|
533
557
|
if (resolvedAliasPath && resolvedAliasPath.id) {
|
|
534
|
-
modPath =
|
|
558
|
+
modPath = resolvedAliasPath.id;
|
|
535
559
|
}
|
|
536
560
|
}
|
|
537
561
|
|
|
562
|
+
if (modPath && modPath.startsWith('/src/')) {
|
|
563
|
+
// Vite default alias
|
|
564
|
+
modPath = vite.normalizePath(path.join(root, modPath));
|
|
565
|
+
}
|
|
566
|
+
|
|
538
567
|
var resolvedPath = resolveModPath(modPath, dirname);
|
|
539
568
|
if (!resolvedPath) return; // Virtual modules or other exceptions
|
|
540
569
|
|
|
@@ -33,7 +33,9 @@ function parseModel(response, json) {
|
|
|
33
33
|
return JSON.parse(json, response._fromJSON);
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
var META_HOT = undefined;
|
|
37
|
+
var META_ENV_DEV = undefined.DEV;
|
|
38
|
+
|
|
37
39
|
function resolveModuleReference(bundlerConfig, moduleData) {
|
|
38
40
|
return moduleData;
|
|
39
41
|
} // Vite import globs will be injected here.
|
|
@@ -42,7 +44,7 @@ var allClientComponents = {
|
|
|
42
44
|
__INJECTED_CLIENT_IMPORTERS__: null
|
|
43
45
|
}; // Mock client component imports during testing
|
|
44
46
|
|
|
45
|
-
if (typeof jest !== 'undefined') {
|
|
47
|
+
if (META_ENV_DEV && typeof jest !== 'undefined') {
|
|
46
48
|
global.allClientComponents = allClientComponents;
|
|
47
49
|
}
|
|
48
50
|
|
|
@@ -50,7 +52,20 @@ function importClientComponent(moduleId) {
|
|
|
50
52
|
var modImport = allClientComponents[moduleId];
|
|
51
53
|
|
|
52
54
|
if (!modImport) {
|
|
53
|
-
|
|
55
|
+
var error = new Error("Could not find client component " + moduleId);
|
|
56
|
+
|
|
57
|
+
if (META_HOT) {
|
|
58
|
+
META_HOT.send('rsc:cc404', {
|
|
59
|
+
id: moduleId
|
|
60
|
+
});
|
|
61
|
+
return new Promise(function (_, reject) {
|
|
62
|
+
return setTimeout(function () {
|
|
63
|
+
return reject(error);
|
|
64
|
+
}, 200);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return Promise.reject(error);
|
|
54
69
|
}
|
|
55
70
|
|
|
56
71
|
return typeof modImport === 'function' ? modImport() : Promise.resolve(modImport);
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
9
|
*/
|
|
10
|
-
'use strict';var g=require("react"),h={stream:!0},l={__INJECTED_CLIENT_IMPORTERS__:null};"undefined"!==typeof jest&&(global.allClientComponents=l);function m(a){var b=l[a];return b?"function"===typeof b?b():Promise.resolve(b):Promise.reject(Error("Could not find client component "+a))}var n=new Map;function p(a){function b(a){n.set(c,a);return a}var c=a.id;n.has(c)||(a=m(c),b(a),a.then(b,b))}
|
|
11
|
-
function w(a){v[a]||(v[a]=g.createServerContext(a,t));return v[a]}function x(a,b,c){this._status=a;this._value=b;this._response=c}x.prototype.then=function(a){0===this._status?(null===this._value&&(this._value=[]),this._value.push(a)):a()};
|
|
10
|
+
'use strict';var g=require("react"),h={stream:!0},l={__INJECTED_CLIENT_IMPORTERS__:null};(void 0).DEV&&"undefined"!==typeof jest&&(global.allClientComponents=l);function m(a){var b=l[a];return b?"function"===typeof b?b():Promise.resolve(b):Promise.reject(Error("Could not find client component "+a))}var n=new Map;function p(a){function b(a){n.set(c,a);return a}var c=a.id;n.has(c)||(a=m(c),b(a),a.then(b,b))}
|
|
11
|
+
var q=Symbol.for("react.element"),r=Symbol.for("react.lazy"),t=Symbol.for("react.default_value"),v=g.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ContextRegistry;function w(a){v[a]||(v[a]=g.createServerContext(a,t));return v[a]}function x(a,b,c){this._status=a;this._value=b;this._response=c}x.prototype.then=function(a){0===this._status?(null===this._value&&(this._value=[]),this._value.push(a)):a()};
|
|
12
12
|
function y(a){switch(a._status){case 3:return a._value;case 1:var b=JSON.parse(a._value,a._response._fromJSON);a._status=3;return a._value=b;case 2:var c=a._value;b=c.name;c=n.get(c.id);if(!c||c instanceof Promise||c instanceof Error)throw c;b=c[b];a._status=3;return a._value=b;case 0:throw a;default:throw a._value;}}function z(){var a=A(this,0);return y(a)}function B(a,b){return new x(3,b,a)}function C(a){if(null!==a)for(var b=0;b<a.length;b++)(0,a[b])()}
|
|
13
13
|
function D(a,b){if(0===a._status){var c=a._value;a._status=4;a._value=b;C(c)}}function E(a,b){a._chunks.forEach(function(a){D(a,b)})}function A(a,b){var c=a._chunks,d=c.get(b);d||(d=new x(0,null,a),c.set(b,d));return d}function F(a,b,c){switch(c[0]){case "$":if("$"===c)return q;if("$"===c[1]||"@"===c[1])return c.substring(1);b=parseInt(c.substring(1),16);a=A(a,b);return y(a);case "@":return b=parseInt(c.substring(1),16),a=A(a,b),{$$typeof:r,_payload:a,_init:y}}return c}
|
|
14
14
|
function G(a){E(a,Error("Connection closed."))}
|
|
@@ -20,7 +20,8 @@ var MODULE_TAG = Symbol.for('react.module.reference');
|
|
|
20
20
|
var STRING_SIZE_LIMIT = 64;
|
|
21
21
|
var FN_RSC_ERROR = 'Functions exported from client components cannot be called or used as constructors from a server component.';
|
|
22
22
|
function isRsc() {
|
|
23
|
-
|
|
23
|
+
var currentDispatcher = __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentDispatcher.current;
|
|
24
|
+
return !!(currentDispatcher && currentDispatcher.isRsc);
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
function createModuleReference(id, value, name, isDefault) {
|
|
@@ -100,6 +100,8 @@ var isClientComponent = function (id) {
|
|
|
100
100
|
function ReactFlightVitePlugin() {
|
|
101
101
|
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
102
102
|
serverBuildEntries = _ref.serverBuildEntries,
|
|
103
|
+
_ref$optimizeBoundari = _ref.optimizeBoundaries,
|
|
104
|
+
optimizeBoundaries = _ref$optimizeBoundari === void 0 ? 'build' : _ref$optimizeBoundari,
|
|
103
105
|
_ref$isServerComponen = _ref.isServerComponentImporterAllowed,
|
|
104
106
|
isServerComponentImporterAllowed = _ref$isServerComponen === void 0 ? function (importer) {
|
|
105
107
|
return false;
|
|
@@ -107,13 +109,28 @@ function ReactFlightVitePlugin() {
|
|
|
107
109
|
|
|
108
110
|
var config;
|
|
109
111
|
var server;
|
|
110
|
-
var globImporterPath;
|
|
111
112
|
var resolveAlias;
|
|
113
|
+
var globImporterPath;
|
|
114
|
+
var allClientBoundaries = new Set();
|
|
115
|
+
|
|
116
|
+
function invalidateGlobImporter() {
|
|
117
|
+
if (globImporterPath && server) {
|
|
118
|
+
server.watcher.emit('change', globImporterPath);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
112
122
|
return {
|
|
113
123
|
name: 'vite-plugin-react-server-components',
|
|
114
124
|
enforce: 'pre',
|
|
115
125
|
configureServer: function (_server) {
|
|
116
126
|
server = _server;
|
|
127
|
+
var seenModules = {};
|
|
128
|
+
server.ws.on('rsc:cc404', function (data) {
|
|
129
|
+
if (!seenModules[data.id]) {
|
|
130
|
+
seenModules[data.id] = true;
|
|
131
|
+
invalidateGlobImporter();
|
|
132
|
+
}
|
|
133
|
+
});
|
|
117
134
|
},
|
|
118
135
|
configResolved: async function (_config) {
|
|
119
136
|
await init;
|
|
@@ -190,13 +207,10 @@ function ReactFlightVitePlugin() {
|
|
|
190
207
|
if (!moduleNode.meta) moduleNode.meta = {};
|
|
191
208
|
|
|
192
209
|
if (!moduleNode.meta.isClientComponent) {
|
|
193
|
-
moduleNode.meta.isClientComponent = true;
|
|
210
|
+
moduleNode.meta.isClientComponent = true; // Invalidate glob importer file to account for the
|
|
211
|
+
// newly discovered client component.
|
|
194
212
|
|
|
195
|
-
|
|
196
|
-
// Invalidate glob importer file to account for the
|
|
197
|
-
// newly discovered client component.
|
|
198
|
-
server.watcher.emit('change', globImporterPath);
|
|
199
|
-
}
|
|
213
|
+
invalidateGlobImporter();
|
|
200
214
|
}
|
|
201
215
|
}
|
|
202
216
|
|
|
@@ -246,7 +260,7 @@ function ReactFlightVitePlugin() {
|
|
|
246
260
|
});
|
|
247
261
|
var injectedGlobs = "Object.assign(Object.create(null), " + importers.map(function (glob) {
|
|
248
262
|
return (// Mark the globs to modify the result after Vite resolves them.
|
|
249
|
-
"/* HASH_BEGIN */ " + ("import.meta.glob('" + normalizePath(glob) + "') /* HASH_END */")
|
|
263
|
+
"\n/* HASH_BEGIN */ " + ("import.meta.glob('" + normalizePath(glob) + "') /* HASH_END */")
|
|
250
264
|
);
|
|
251
265
|
}).join(', ') + ");";
|
|
252
266
|
s.replace(INJECTING_RE, injectedGlobs);
|
|
@@ -260,15 +274,24 @@ function ReactFlightVitePlugin() {
|
|
|
260
274
|
};
|
|
261
275
|
|
|
262
276
|
if (config.command === 'serve') {
|
|
263
|
-
globImporterPath = id;
|
|
264
|
-
|
|
277
|
+
globImporterPath = id; // When mixing client and server components from the same
|
|
278
|
+
// facade file, the module graph can break and miss certain
|
|
279
|
+
// import connections (bug in Vite?) due to HMR. Instead of
|
|
280
|
+
// creating a new list of discovered components from scratch,
|
|
281
|
+
// reuse the already discovered ones and simply add new ones
|
|
282
|
+
// to the list without removing anything.
|
|
283
|
+
|
|
284
|
+
findClientBoundaries(server.moduleGraph, optimizeBoundaries === true).forEach(function (boundary) {
|
|
285
|
+
return allClientBoundaries.add(boundary);
|
|
286
|
+
});
|
|
287
|
+
return injectGlobs(Array.from(allClientBoundaries));
|
|
265
288
|
}
|
|
266
289
|
|
|
267
290
|
if (!serverBuildEntries) {
|
|
268
291
|
throw new Error('[react-server-dom-vite] Parameter serverBuildEntries is required for client build');
|
|
269
292
|
}
|
|
270
293
|
|
|
271
|
-
return findClientBoundariesForClientBuild(serverBuildEntries).then(injectGlobs);
|
|
294
|
+
return findClientBoundariesForClientBuild(serverBuildEntries, optimizeBoundaries !== false).then(injectGlobs);
|
|
272
295
|
}
|
|
273
296
|
}
|
|
274
297
|
};
|
|
@@ -332,6 +355,7 @@ async function proxyClientComponent(filepath, src) {
|
|
|
332
355
|
}
|
|
333
356
|
|
|
334
357
|
function findClientBoundaries(moduleGraph) {
|
|
358
|
+
var optimizeBoundaries = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
335
359
|
var clientBoundaries = []; // eslint-disable-next-line no-for-of-loops/no-for-of-loops
|
|
336
360
|
|
|
337
361
|
var _iterator = _createForOfIteratorHelper(moduleGraph.fileToModulesMap.values()),
|
|
@@ -344,7 +368,7 @@ function findClientBoundaries(moduleGraph) {
|
|
|
344
368
|
return moduleNode.meta && moduleNode.meta.isClientComponent;
|
|
345
369
|
});
|
|
346
370
|
|
|
347
|
-
if (clientModule && isDirectImportInServer(clientModule)) {
|
|
371
|
+
if (clientModule && (!optimizeBoundaries || isDirectImportInServer(clientModule))) {
|
|
348
372
|
clientBoundaries.push(clientModule.file);
|
|
349
373
|
}
|
|
350
374
|
}
|
|
@@ -357,7 +381,7 @@ function findClientBoundaries(moduleGraph) {
|
|
|
357
381
|
return clientBoundaries;
|
|
358
382
|
}
|
|
359
383
|
|
|
360
|
-
async function findClientBoundariesForClientBuild(serverEntries) {
|
|
384
|
+
async function findClientBoundariesForClientBuild(serverEntries, optimizeBoundaries) {
|
|
361
385
|
// Viteception
|
|
362
386
|
var server = await createServer({
|
|
363
387
|
clearScreen: false,
|
|
@@ -375,7 +399,7 @@ async function findClientBoundariesForClientBuild(serverEntries) {
|
|
|
375
399
|
}
|
|
376
400
|
|
|
377
401
|
await server.close();
|
|
378
|
-
return findClientBoundaries(server.moduleGraph);
|
|
402
|
+
return findClientBoundaries(server.moduleGraph, optimizeBoundaries);
|
|
379
403
|
}
|
|
380
404
|
|
|
381
405
|
var hashImportsPlugin = {
|
|
@@ -453,7 +477,7 @@ function isDirectImportInServer(originalMod, currentMod, accModInfo) {
|
|
|
453
477
|
});
|
|
454
478
|
}
|
|
455
479
|
|
|
456
|
-
return Array.from((currentMod || originalMod).importers).some(function (importer) {
|
|
480
|
+
return Array.from((currentMod || originalMod).importers || []).some(function (importer) {
|
|
457
481
|
return (// eslint-disable-next-line no-unused-vars
|
|
458
482
|
isDirectImportInServer(originalMod, importer, accModInfo)
|
|
459
483
|
);
|
|
@@ -473,7 +497,7 @@ function isDirectImportInServer(originalMod, currentMod, accModInfo) {
|
|
|
473
497
|
// the original module before marking it as client boundary.
|
|
474
498
|
|
|
475
499
|
return currentMod.meta.imports.some(function (imp) {
|
|
476
|
-
return imp.
|
|
500
|
+
return imp.from === accModInfo.file && (imp.variables || []).some(function (_ref3) {
|
|
477
501
|
var name = _ref3[0];
|
|
478
502
|
return accModInfo.exports.includes(name);
|
|
479
503
|
});
|
|
@@ -527,10 +551,15 @@ function augmentModuleGraph(moduleGraph, id, code, root, resolveAlias) {
|
|
|
527
551
|
var resolvedAliasPath = resolveAlias(modPath, 'rsc_importer', {});
|
|
528
552
|
|
|
529
553
|
if (resolvedAliasPath && resolvedAliasPath.id) {
|
|
530
|
-
modPath =
|
|
554
|
+
modPath = resolvedAliasPath.id;
|
|
531
555
|
}
|
|
532
556
|
}
|
|
533
557
|
|
|
558
|
+
if (modPath && modPath.startsWith('/src/')) {
|
|
559
|
+
// Vite default alias
|
|
560
|
+
modPath = normalizePath(path.join(root, modPath));
|
|
561
|
+
}
|
|
562
|
+
|
|
534
563
|
var resolvedPath = resolveModPath(modPath, dirname);
|
|
535
564
|
if (!resolvedPath) return; // Virtual modules or other exceptions
|
|
536
565
|
|
|
@@ -27,7 +27,9 @@ function parseModel(response, json) {
|
|
|
27
27
|
return JSON.parse(json, response._fromJSON);
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
var META_HOT = import.meta.hot;
|
|
31
|
+
var META_ENV_DEV = import.meta.env.DEV;
|
|
32
|
+
|
|
31
33
|
function resolveModuleReference(bundlerConfig, moduleData) {
|
|
32
34
|
return moduleData;
|
|
33
35
|
} // Vite import globs will be injected here.
|
|
@@ -36,7 +38,7 @@ var allClientComponents = {
|
|
|
36
38
|
__INJECTED_CLIENT_IMPORTERS__: null
|
|
37
39
|
}; // Mock client component imports during testing
|
|
38
40
|
|
|
39
|
-
if (typeof jest !== 'undefined') {
|
|
41
|
+
if (META_ENV_DEV && typeof jest !== 'undefined') {
|
|
40
42
|
global.allClientComponents = allClientComponents;
|
|
41
43
|
}
|
|
42
44
|
|
|
@@ -44,7 +46,20 @@ function importClientComponent(moduleId) {
|
|
|
44
46
|
var modImport = allClientComponents[moduleId];
|
|
45
47
|
|
|
46
48
|
if (!modImport) {
|
|
47
|
-
|
|
49
|
+
var error = new Error("Could not find client component " + moduleId);
|
|
50
|
+
|
|
51
|
+
if (META_HOT) {
|
|
52
|
+
META_HOT.send('rsc:cc404', {
|
|
53
|
+
id: moduleId
|
|
54
|
+
});
|
|
55
|
+
return new Promise(function (_, reject) {
|
|
56
|
+
return setTimeout(function () {
|
|
57
|
+
return reject(error);
|
|
58
|
+
}, 200);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return Promise.reject(error);
|
|
48
63
|
}
|
|
49
64
|
|
|
50
65
|
return typeof modImport === 'function' ? modImport() : Promise.resolve(modImport);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { CartEstimatedCost } from './CartEstimatedCost.client';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { CartEstimatedCost } from './CartEstimatedCost.client';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { useCountry } from './useCountry';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { useCountry } from './useCountry';
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The `useCountry` hook returns a tuple of the current localization country and a function for updating it.
|
|
3
|
-
* It must be a descendent of a `LocalizationProvider` component.
|
|
4
|
-
*/
|
|
5
|
-
export declare function useCountry(): (({
|
|
6
|
-
__typename?: "Country" | undefined;
|
|
7
|
-
} & Pick<import("../../storefront-api-types").Country, "name" | "isoCode">) | undefined)[];
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { useContext } from 'react';
|
|
2
|
-
import { LocalizationContext } from '../../components/LocalizationProvider/LocalizationContext.client';
|
|
3
|
-
function useLocalization() {
|
|
4
|
-
const context = useContext(LocalizationContext);
|
|
5
|
-
if (context == null) {
|
|
6
|
-
throw new Error('No Localization Context available');
|
|
7
|
-
}
|
|
8
|
-
return context;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* The `useCountry` hook returns a tuple of the current localization country and a function for updating it.
|
|
12
|
-
* It must be a descendent of a `LocalizationProvider` component.
|
|
13
|
-
*/
|
|
14
|
-
export function useCountry() {
|
|
15
|
-
const context = useLocalization();
|
|
16
|
-
return [context.country];
|
|
17
|
-
}
|