@pack/hydrogen 3.2.2 → 3.2.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/dist/index.js +18 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -5537,6 +5537,14 @@ async function fetchTestRulesShared(packClient, withCache, token) {
|
|
|
5537
5537
|
}
|
|
5538
5538
|
);
|
|
5539
5539
|
}
|
|
5540
|
+
function isPrefetchRequest(request) {
|
|
5541
|
+
const secPurpose = request.headers.get("sec-purpose")?.toLowerCase();
|
|
5542
|
+
const purpose = request.headers.get("purpose")?.toLowerCase();
|
|
5543
|
+
const xPurpose = request.headers.get("x-purpose")?.toLowerCase();
|
|
5544
|
+
return [secPurpose, purpose, xPurpose].some(
|
|
5545
|
+
(value) => value?.split(",").map((part) => part.trim()).includes("prefetch")
|
|
5546
|
+
);
|
|
5547
|
+
}
|
|
5540
5548
|
async function packClientFetchTestByRules(packClient, testTargetAudienceAttributes, testSession, request, withCache, token, exposedTest, validateOnly) {
|
|
5541
5549
|
try {
|
|
5542
5550
|
debug3(
|
|
@@ -5768,6 +5776,10 @@ async function getTestInfo({
|
|
|
5768
5776
|
requestUrl: request.url
|
|
5769
5777
|
})
|
|
5770
5778
|
);
|
|
5779
|
+
if (isPrefetchRequest(request)) {
|
|
5780
|
+
debug3("[Pack Test] Skipping test assignment for prefetch request.");
|
|
5781
|
+
return void 0;
|
|
5782
|
+
}
|
|
5771
5783
|
let testInfo = void 0;
|
|
5772
5784
|
let exposedTest = void 0;
|
|
5773
5785
|
if (!testSession) {
|
|
@@ -6370,7 +6382,9 @@ function createPackClient(options) {
|
|
|
6370
6382
|
queryVariables.language = i18n.language;
|
|
6371
6383
|
queryVariables.country = i18n.country;
|
|
6372
6384
|
}
|
|
6373
|
-
|
|
6385
|
+
const explicitTest = testFromQueryParams || test;
|
|
6386
|
+
const resolveTestInfo = !previewEnabled && !explicitTest;
|
|
6387
|
+
if (resolveTestInfo && packClient && token && !testInfoForRequest && currentRequest) {
|
|
6374
6388
|
try {
|
|
6375
6389
|
if (!testInfoPromise) {
|
|
6376
6390
|
debug4(
|
|
@@ -6403,20 +6417,19 @@ function createPackClient(options) {
|
|
|
6403
6417
|
testInfoForRequest = void 0;
|
|
6404
6418
|
testInfoPromise = void 0;
|
|
6405
6419
|
}
|
|
6406
|
-
} else if (packClient && token && testInfoForRequest) {
|
|
6420
|
+
} else if (resolveTestInfo && packClient && token && testInfoForRequest) {
|
|
6407
6421
|
debug4("[Pack Test] Using cached testInfo - subsequent query");
|
|
6408
6422
|
if (process.env.NODE_ENV === "development") {
|
|
6409
6423
|
console.log("[Pack Test] Using cached testInfo - subsequent query");
|
|
6410
6424
|
}
|
|
6411
6425
|
}
|
|
6412
|
-
if (testInfoForRequest?.isFirstExposure) {
|
|
6426
|
+
if (resolveTestInfo && testInfoForRequest?.isFirstExposure) {
|
|
6413
6427
|
const { isFirstExposure: _isFirstExposure, ...testInfo } = testInfoForRequest;
|
|
6414
6428
|
testInfoForLoader = testInfo;
|
|
6415
6429
|
}
|
|
6416
6430
|
headers = setTestHeaders(headers, {
|
|
6417
|
-
previewEnabled,
|
|
6418
6431
|
testInfoForRequest,
|
|
6419
|
-
testFromQueryParams:
|
|
6432
|
+
testFromQueryParams: explicitTest
|
|
6420
6433
|
});
|
|
6421
6434
|
if (previewEnabled) {
|
|
6422
6435
|
try {
|