@netlify/plugin-nextjs 5.10.3 → 5.10.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.
@@ -8,7 +8,7 @@ import "./chunk-OEQOKJGE.js";
8
8
 
9
9
  // package.json
10
10
  var name = "@netlify/plugin-nextjs";
11
- var version = "5.10.3";
11
+ var version = "5.10.4";
12
12
  var description = "Run Next.js seamlessly on Netlify";
13
13
  var main = "./dist/index.js";
14
14
  var type = "module";
@@ -195,7 +195,7 @@ var import_constants = require("next/dist/lib/constants.js");
195
195
 
196
196
  // package.json
197
197
  var name = "@netlify/plugin-nextjs";
198
- var version = "5.10.3";
198
+ var version = "5.10.4";
199
199
 
200
200
  // src/run/handlers/cache.cts
201
201
  var import_cache_types = require("../../shared/cache-types.cjs");
@@ -399,6 +399,10 @@ var NetlifyCacheHandler = class {
399
399
  };
400
400
  }
401
401
  case "APP_PAGE": {
402
+ const requestContext = (0, import_request_context.getRequestContext)();
403
+ if (requestContext && blob.value?.kind === "APP_PAGE") {
404
+ requestContext.isCacheableAppPage = true;
405
+ }
402
406
  const { revalidate, rscData, ...restOfPageValue } = blob.value;
403
407
  span.addEvent(blob.value?.kind, { lastModified: blob.lastModified, revalidate, ttl });
404
408
  await this.injectEntryToPrerenderManifest(key, blob.value);
@@ -457,6 +461,12 @@ var NetlifyCacheHandler = class {
457
461
  this.captureCacheTags(value, key);
458
462
  }
459
463
  await this.cacheStore.set(key, { lastModified, value }, "blobStore.set");
464
+ if (data?.kind === "APP_PAGE") {
465
+ const requestContext = (0, import_request_context.getRequestContext)();
466
+ if (requestContext) {
467
+ requestContext.isCacheableAppPage = true;
468
+ }
469
+ }
460
470
  if (!data && !isDataReq || data?.kind === "PAGE" || data?.kind === "PAGES") {
461
471
  const requestContext = (0, import_request_context.getRequestContext)();
462
472
  if (requestContext?.didPagesRouterOnDemandRevalidate) {
@@ -3101,7 +3101,7 @@ import {
3101
3101
  import { nextResponseProxy } from "../revalidate.js";
3102
3102
  import { setFetchBeforeNextPatchedIt } from "../storage/storage.cjs";
3103
3103
  import { getLogger } from "./request-context.cjs";
3104
- import { getTracer } from "./tracer.cjs";
3104
+ import { getTracer, recordWarning } from "./tracer.cjs";
3105
3105
  import { setupWaitUntil } from "./wait-until.cjs";
3106
3106
  setFetchBeforeNextPatchedIt(globalThis.fetch);
3107
3107
  var nextImportPromise = import("../next.cjs");
@@ -3165,10 +3165,6 @@ var server_default = async (request, _context, topLevelSpan, requestContext) =>
3165
3165
  }
3166
3166
  const nextCache = response.headers.get("x-nextjs-cache");
3167
3167
  const isServedFromNextCache = nextCache === "HIT" || nextCache === "STALE";
3168
- topLevelSpan.setAttributes({
3169
- "x-nextjs-cache": nextCache ?? void 0,
3170
- isServedFromNextCache
3171
- });
3172
3168
  if (isServedFromNextCache) {
3173
3169
  await adjustDateHeader({
3174
3170
  headers: response.headers,
@@ -3181,6 +3177,33 @@ var server_default = async (request, _context, topLevelSpan, requestContext) =>
3181
3177
  setCacheTagsHeaders(response.headers, requestContext);
3182
3178
  setVaryHeaders(response.headers, request, nextConfig);
3183
3179
  setCacheStatusHeader(response.headers, nextCache);
3180
+ const netlifyVary = response.headers.get("netlify-vary") ?? void 0;
3181
+ const netlifyCdnCacheControl = response.headers.get("netlify-cdn-cache-control") ?? void 0;
3182
+ topLevelSpan.setAttributes({
3183
+ "x-nextjs-cache": nextCache ?? void 0,
3184
+ isServedFromNextCache,
3185
+ netlifyVary,
3186
+ netlifyCdnCacheControl
3187
+ });
3188
+ if (requestContext.isCacheableAppPage) {
3189
+ const isRSCRequest = request.headers.get("rsc") === "1";
3190
+ const contentType = response.headers.get("content-type") ?? void 0;
3191
+ const isExpectedContentType = (isRSCRequest && contentType?.includes("text/x-component") || !isRSCRequest && contentType?.includes("text/html")) ?? false;
3192
+ topLevelSpan.setAttributes({
3193
+ isRSCRequest,
3194
+ isCacheableAppPage: true,
3195
+ contentType,
3196
+ isExpectedContentType
3197
+ });
3198
+ if (!isExpectedContentType) {
3199
+ recordWarning(
3200
+ new Error(
3201
+ `Unexpected content type was produced for App Router page response (isRSCRequest: ${isRSCRequest}, contentType: ${contentType})`
3202
+ ),
3203
+ topLevelSpan
3204
+ );
3205
+ }
3206
+ }
3184
3207
  async function waitForBackgroundWork() {
3185
3208
  await nextHandlerPromise;
3186
3209
  res.emit("close");
@@ -68866,7 +68866,7 @@ var import_semantic_conventions = __toESM(require_src(), 1);
68866
68866
  import { getLogger } from "./request-context.cjs";
68867
68867
  var {
68868
68868
  default: { version, name }
68869
- } = await import("../../esm-chunks/package-AKXSA3EX.js");
68869
+ } = await import("../../esm-chunks/package-GF3YXDC5.js");
68870
68870
  var sdk = new import_sdk_node.NodeSDK({
68871
68871
  resource: new import_resources.Resource({
68872
68872
  [import_semantic_conventions.SEMRESATTRS_SERVICE_NAME]: name,
@@ -1409,36 +1409,49 @@ function setInMemoryCacheMaxSizeFromNextConfig(size) {
1409
1409
  extendedGlobalThis[IN_MEMORY_CACHE_MAX_SIZE] = size;
1410
1410
  }
1411
1411
  }
1412
- var estimateBlobSize = (valueToStore) => {
1412
+ var isPositiveNumber = (value) => {
1413
+ return typeof value === "number" && value > 0;
1414
+ };
1415
+ var BASE_BLOB_SIZE = 25;
1416
+ var estimateBlobKnownTypeSize = (valueToStore) => {
1413
1417
  if (valueToStore === null || (0, import_types.isPromise)(valueToStore) || (0, import_blob_types.isTagManifest)(valueToStore)) {
1414
- return 25;
1418
+ return BASE_BLOB_SIZE;
1415
1419
  }
1416
1420
  if ((0, import_blob_types.isHtmlBlob)(valueToStore)) {
1417
- return valueToStore.html.length;
1421
+ return BASE_BLOB_SIZE + valueToStore.html.length;
1422
+ }
1423
+ if (valueToStore.value?.kind === "FETCH") {
1424
+ return BASE_BLOB_SIZE + valueToStore.value.data.body.length;
1425
+ }
1426
+ if (valueToStore.value?.kind === "APP_PAGE") {
1427
+ return BASE_BLOB_SIZE + valueToStore.value.html.length + (valueToStore.value.rscData?.length ?? 0);
1418
1428
  }
1419
- let knownKindFailed = false;
1429
+ if (valueToStore.value?.kind === "PAGE" || valueToStore.value?.kind === "PAGES") {
1430
+ return BASE_BLOB_SIZE + valueToStore.value.html.length + JSON.stringify(valueToStore.value.pageData).length;
1431
+ }
1432
+ if (valueToStore.value?.kind === "ROUTE" || valueToStore.value?.kind === "APP_ROUTE") {
1433
+ return BASE_BLOB_SIZE + valueToStore.value.body.length;
1434
+ }
1435
+ };
1436
+ var estimateBlobSize = (valueToStore) => {
1437
+ let estimatedKnownTypeSize;
1438
+ let estimateBlobKnownTypeSizeError;
1420
1439
  try {
1421
- if (valueToStore.value?.kind === "FETCH") {
1422
- return valueToStore.value.data.body.length;
1423
- }
1424
- if (valueToStore.value?.kind === "APP_PAGE") {
1425
- return valueToStore.value.html.length + (valueToStore.value.rscData?.length ?? 0);
1426
- }
1427
- if (valueToStore.value?.kind === "PAGE" || valueToStore.value?.kind === "PAGES") {
1428
- return valueToStore.value.html.length + JSON.stringify(valueToStore.value.pageData).length;
1440
+ estimatedKnownTypeSize = estimateBlobKnownTypeSize(valueToStore);
1441
+ if (isPositiveNumber(estimatedKnownTypeSize)) {
1442
+ return estimatedKnownTypeSize;
1429
1443
  }
1430
- if (valueToStore.value?.kind === "ROUTE" || valueToStore.value?.kind === "APP_ROUTE") {
1431
- return valueToStore.value.body.length;
1432
- }
1433
- } catch {
1434
- knownKindFailed = true;
1444
+ } catch (error) {
1445
+ estimateBlobKnownTypeSizeError = error;
1435
1446
  }
1447
+ const calculatedSize = JSON.stringify(valueToStore).length;
1436
1448
  (0, import_tracer.recordWarning)(
1437
1449
  new Error(
1438
- `Blob size calculation did fallback to JSON.stringify. Kind: KnownKindFailed: ${knownKindFailed}, ${valueToStore.value?.kind ?? "undefined"}`
1450
+ `Blob size calculation did fallback to JSON.stringify. EstimatedKnownTypeSize: ${estimatedKnownTypeSize}, CalculatedSize: ${calculatedSize}, ValueToStore: ${JSON.stringify(valueToStore)}`,
1451
+ estimateBlobKnownTypeSizeError ? { cause: estimateBlobKnownTypeSizeError } : void 0
1439
1452
  )
1440
1453
  );
1441
- return JSON.stringify(valueToStore).length;
1454
+ return isPositiveNumber(calculatedSize) ? calculatedSize : BASE_BLOB_SIZE;
1442
1455
  };
1443
1456
  function getInMemoryLRUCache() {
1444
1457
  if (typeof extendedGlobalThis[IN_MEMORY_LRU_CACHE] === "undefined") {
@@ -1459,12 +1472,20 @@ var getRequestScopedInMemoryCache = () => {
1459
1472
  return {
1460
1473
  get(key) {
1461
1474
  if (!requestContext) return;
1462
- const value = inMemoryLRUCache?.get(`${requestContext.requestID}:${key}`);
1463
- return value === NullValue ? null : value;
1475
+ try {
1476
+ const value = inMemoryLRUCache?.get(`${requestContext.requestID}:${key}`);
1477
+ return value === NullValue ? null : value;
1478
+ } catch (error) {
1479
+ (0, import_tracer.recordWarning)(new Error("Failed to get value from memory cache", { cause: error }));
1480
+ }
1464
1481
  },
1465
1482
  set(key, value) {
1466
1483
  if (!requestContext) return;
1467
- inMemoryLRUCache?.set(`${requestContext?.requestID}:${key}`, value ?? NullValue);
1484
+ try {
1485
+ inMemoryLRUCache?.set(`${requestContext?.requestID}:${key}`, value ?? NullValue);
1486
+ } catch (error) {
1487
+ (0, import_tracer.recordWarning)(new Error("Failed to store value in memory cache", { cause: error }));
1488
+ }
1468
1489
  }
1469
1490
  };
1470
1491
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/plugin-nextjs",
3
- "version": "5.10.3",
3
+ "version": "5.10.4",
4
4
  "description": "Run Next.js seamlessly on Netlify",
5
5
  "main": "./dist/index.js",
6
6
  "type": "module",