vinext 1.2.1 → 1.3.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.
Files changed (212) hide show
  1. package/README.md +12 -9
  2. package/dist/build/client-build-config.d.ts +64 -3
  3. package/dist/build/client-build-config.js +131 -4
  4. package/dist/build/client-reference-groups.d.ts +163 -0
  5. package/dist/build/client-reference-groups.js +534 -0
  6. package/dist/build/module-dependency-cache.d.ts +31 -0
  7. package/dist/build/module-dependency-cache.js +51 -1
  8. package/dist/build/next-client-runtime-manifests.d.ts +10 -1
  9. package/dist/build/next-client-runtime-manifests.js +19 -4
  10. package/dist/build/nitro-public-files.d.ts +24 -0
  11. package/dist/build/nitro-public-files.js +60 -0
  12. package/dist/build/pages-client-assets-module.js +1 -1
  13. package/dist/build/prerender-paths.js +5 -2
  14. package/dist/build/server-actions-encryption-key.d.ts +23 -0
  15. package/dist/build/server-actions-encryption-key.js +101 -0
  16. package/dist/build/ssr-manifest.d.ts +3 -0
  17. package/dist/build/ssr-manifest.js +10 -1
  18. package/dist/client/client-rewrite-params.d.ts +9 -0
  19. package/dist/client/client-rewrite-params.js +20 -0
  20. package/dist/client/dev-error-overlay.js +2 -1
  21. package/dist/client/navigation-runtime.d.ts +25 -2
  22. package/dist/client/navigation-runtime.js +42 -11
  23. package/dist/client/vinext-next-data.d.ts +0 -1
  24. package/dist/config/config-matchers.d.ts +15 -40
  25. package/dist/config/config-matchers.js +183 -255
  26. package/dist/config/config-source.d.ts +34 -0
  27. package/dist/config/config-source.js +141 -0
  28. package/dist/config/header-params.d.ts +29 -0
  29. package/dist/config/header-params.js +106 -0
  30. package/dist/config/next-config.d.ts +7 -5
  31. package/dist/config/next-config.js +120 -7
  32. package/dist/entries/app-browser-entry.d.ts +14 -1
  33. package/dist/entries/app-browser-entry.js +26 -36
  34. package/dist/entries/app-rsc-entry.d.ts +2 -0
  35. package/dist/entries/app-rsc-entry.js +92 -57
  36. package/dist/entries/app-rsc-manifest.d.ts +10 -0
  37. package/dist/entries/app-rsc-manifest.js +20 -1
  38. package/dist/entries/app-ssr-entry.d.ts +4 -1
  39. package/dist/entries/app-ssr-entry.js +9 -2
  40. package/dist/entries/pages-client-entry.d.ts +1 -0
  41. package/dist/entries/pages-client-entry.js +6 -6
  42. package/dist/entries/pages-server-entry.js +17 -14
  43. package/dist/index.d.ts +11 -0
  44. package/dist/index.js +239 -83
  45. package/dist/init.js +17 -0
  46. package/dist/plugins/optimize-imports.d.ts +25 -2
  47. package/dist/plugins/optimize-imports.js +106 -20
  48. package/dist/plugins/rsc-client-reference-loaders.d.ts +45 -1
  49. package/dist/plugins/rsc-client-reference-loaders.js +336 -18
  50. package/dist/plugins/use-cache-callable.d.ts +5 -0
  51. package/dist/plugins/use-cache-callable.js +30 -8
  52. package/dist/plugins/worker-image-imports.d.ts +1 -0
  53. package/dist/plugins/worker-image-imports.js +1 -1
  54. package/dist/routing/app-route-graph.d.ts +1 -1
  55. package/dist/routing/browser-route-manifest.d.ts +43 -0
  56. package/dist/routing/browser-route-manifest.js +195 -0
  57. package/dist/routing/hashed-route-patterns.d.ts +4 -0
  58. package/dist/routing/hashed-route-patterns.js +22 -0
  59. package/dist/routing/optimistic-route-trie.d.ts +27 -0
  60. package/dist/routing/optimistic-route-trie.js +102 -0
  61. package/dist/routing/route-validation.d.ts +6 -1
  62. package/dist/routing/route-validation.js +26 -10
  63. package/dist/server/app-action-forwarding.d.ts +8 -0
  64. package/dist/server/app-action-forwarding.js +15 -1
  65. package/dist/server/app-browser-entry.js +147 -60
  66. package/dist/server/app-browser-error.d.ts +3 -1
  67. package/dist/server/app-browser-error.js +7 -2
  68. package/dist/server/app-browser-interception-context.d.ts +2 -2
  69. package/dist/server/app-browser-mpa-navigation.d.ts +1 -0
  70. package/dist/server/app-browser-mpa-navigation.js +6 -5
  71. package/dist/server/app-browser-navigation-controller.d.ts +17 -6
  72. package/dist/server/app-browser-navigation-controller.js +88 -26
  73. package/dist/server/app-browser-state.d.ts +2 -2
  74. package/dist/server/app-browser-visible-commit.d.ts +4 -4
  75. package/dist/server/app-client-reference-preloader.d.ts +23 -0
  76. package/dist/server/app-client-reference-preloader.js +30 -7
  77. package/dist/server/app-fallback-renderer.js +2 -1
  78. package/dist/server/app-middleware.d.ts +6 -0
  79. package/dist/server/app-middleware.js +8 -10
  80. package/dist/server/app-optimistic-routing.d.ts +8 -10
  81. package/dist/server/app-optimistic-routing.js +4 -95
  82. package/dist/server/app-page-boundary-render.js +8 -1
  83. package/dist/server/app-page-cache-render.js +1 -0
  84. package/dist/server/app-page-dispatch.js +2 -0
  85. package/dist/server/app-page-render.js +3 -1
  86. package/dist/server/app-page-rsc-render-status.d.ts +1 -0
  87. package/dist/server/app-page-rsc-render-status.js +1 -0
  88. package/dist/server/app-page-search-params-observation.d.ts +1 -4
  89. package/dist/server/app-page-search-params-observation.js +8 -10
  90. package/dist/server/app-page-stream.d.ts +7 -0
  91. package/dist/server/app-page-stream.js +1 -0
  92. package/dist/server/app-pages-bridge.d.ts +2 -1
  93. package/dist/server/app-pages-bridge.js +11 -7
  94. package/dist/server/app-prerender-static-params.js +3 -2
  95. package/dist/server/app-render-dependency.js +42 -2
  96. package/dist/server/app-request-stage-independent-entry.js +2 -2
  97. package/dist/server/app-response-stage-entry.js +3 -3
  98. package/dist/server/app-route-handler-dispatch.js +3 -1
  99. package/dist/server/app-route-handler-execution.d.ts +2 -0
  100. package/dist/server/app-route-handler-execution.js +9 -2
  101. package/dist/server/app-route-handler-middleware-context.d.ts +2 -1
  102. package/dist/server/app-route-handler-middleware-context.js +3 -3
  103. package/dist/server/app-route-handler-response.d.ts +2 -1
  104. package/dist/server/app-route-handler-response.js +2 -2
  105. package/dist/server/app-route-handler-runtime.d.ts +2 -0
  106. package/dist/server/app-route-handler-runtime.js +20 -3
  107. package/dist/server/app-route-module-loader.js +7 -6
  108. package/dist/server/app-route-tree.d.ts +20 -0
  109. package/dist/server/app-route-tree.js +18 -0
  110. package/dist/server/app-router-entry.js +2 -2
  111. package/dist/server/app-rsc-combined-handler.js +8 -1
  112. package/dist/server/app-rsc-errors.d.ts +7 -0
  113. package/dist/server/app-rsc-errors.js +9 -2
  114. package/dist/server/app-rsc-handler.d.ts +4 -1
  115. package/dist/server/app-rsc-handler.js +146 -130
  116. package/dist/server/app-rsc-response-finalizer.d.ts +5 -0
  117. package/dist/server/app-rsc-response-finalizer.js +4 -1
  118. package/dist/server/app-rsc-response-stage.js +3 -1
  119. package/dist/server/app-rsc-route-matching.d.ts +1 -0
  120. package/dist/server/app-rsc-route-matching.js +1 -1
  121. package/dist/server/app-server-action-execution.d.ts +23 -6
  122. package/dist/server/app-server-action-execution.js +50 -56
  123. package/dist/server/app-ssr-entry.d.ts +6 -0
  124. package/dist/server/app-ssr-entry.js +16 -7
  125. package/dist/server/app-ssr-stream.d.ts +7 -0
  126. package/dist/server/app-ssr-stream.js +13 -1
  127. package/dist/server/config-headers.js +12 -3
  128. package/dist/server/isolate-shared-promise.d.ts +10 -0
  129. package/dist/server/isolate-shared-promise.js +33 -0
  130. package/dist/server/isr-cache.js +3 -2
  131. package/dist/server/middleware-matcher-pattern.d.ts +0 -1
  132. package/dist/server/middleware-matcher-pattern.js +11 -140
  133. package/dist/server/middleware-matcher.js +5 -6
  134. package/dist/server/middleware-response-headers.d.ts +31 -0
  135. package/dist/server/middleware-response-headers.js +57 -1
  136. package/dist/server/middleware-runtime.js +26 -13
  137. package/dist/server/navigation-planner.d.ts +2 -2
  138. package/dist/server/nitro-public-files-plugin.d.ts +38 -0
  139. package/dist/server/nitro-public-files-plugin.js +106 -0
  140. package/dist/server/nitro-public-files.d.ts +21 -0
  141. package/dist/server/nitro-public-files.js +39 -0
  142. package/dist/server/pages-asset-tags.d.ts +5 -0
  143. package/dist/server/pages-asset-tags.js +9 -2
  144. package/dist/server/pages-client-assets.d.ts +4 -1
  145. package/dist/server/pages-i18n.d.ts +18 -0
  146. package/dist/server/pages-i18n.js +18 -2
  147. package/dist/server/pages-node-compat.d.ts +5 -3
  148. package/dist/server/pages-node-compat.js +35 -16
  149. package/dist/server/pages-request-pipeline.d.ts +6 -1
  150. package/dist/server/pages-request-pipeline.js +31 -35
  151. package/dist/server/pages-request-stage-entry.js +16 -6
  152. package/dist/server/pages-response-stage-entry.js +1 -1
  153. package/dist/server/pages-revalidate.js +1 -0
  154. package/dist/server/pages-router-entry.js +1 -1
  155. package/dist/server/prod-server.d.ts +2 -2
  156. package/dist/server/prod-server.js +71 -33
  157. package/dist/server/proxy-trust.d.ts +6 -0
  158. package/dist/server/proxy-trust.js +12 -6
  159. package/dist/server/request-pipeline.d.ts +5 -0
  160. package/dist/server/request-pipeline.js +12 -1
  161. package/dist/server/server-reference-loader.js +10 -1
  162. package/dist/server/static-file-cache.js +15 -3
  163. package/dist/server/worker-utils.js +1 -1
  164. package/dist/shims/cache-handler.js +3 -2
  165. package/dist/shims/cache-request-state.d.ts +40 -3
  166. package/dist/shims/cache-request-state.js +70 -5
  167. package/dist/shims/cache-runtime.js +47 -19
  168. package/dist/shims/cache.d.ts +2 -2
  169. package/dist/shims/cache.js +17 -8
  170. package/dist/shims/cdn-purge-routes.d.ts +24 -0
  171. package/dist/shims/cdn-purge-routes.js +77 -0
  172. package/dist/shims/dynamic.js +17 -4
  173. package/dist/shims/form.js +8 -3
  174. package/dist/shims/image-props.d.ts +93 -0
  175. package/dist/shims/image-props.js +323 -0
  176. package/dist/shims/image.d.ts +4 -18
  177. package/dist/shims/image.js +4 -319
  178. package/dist/shims/internal/headers-state.d.ts +7 -0
  179. package/dist/shims/internal/headers-state.js +14 -2
  180. package/dist/shims/internal/hybrid-client-route-owner-direct.d.ts +4 -1
  181. package/dist/shims/internal/hybrid-client-route-owner-direct.js +31 -14
  182. package/dist/shims/internal/hybrid-client-route-owner.js +8 -8
  183. package/dist/shims/link.js +5 -3
  184. package/dist/shims/navigation.d.ts +1 -1
  185. package/dist/shims/navigation.js +17 -5
  186. package/dist/shims/og.js +35 -10
  187. package/dist/shims/request-context.d.ts +13 -0
  188. package/dist/shims/router.js +19 -40
  189. package/dist/shims/server.d.ts +31 -4
  190. package/dist/shims/server.js +58 -10
  191. package/dist/shims/thenable-params.d.ts +6 -1
  192. package/dist/shims/thenable-params.js +11 -2
  193. package/dist/shims/unified-request-context.d.ts +5 -0
  194. package/dist/shims/unified-request-context.js +2 -0
  195. package/dist/utils/asset-prefix.d.ts +7 -0
  196. package/dist/utils/asset-prefix.js +10 -1
  197. package/dist/utils/client-build-manifest.js +12 -5
  198. package/dist/utils/client-runtime-metadata.d.ts +1 -0
  199. package/dist/utils/client-runtime-metadata.js +15 -2
  200. package/dist/utils/lazy-chunks.d.ts +4 -0
  201. package/dist/utils/manifest-paths.d.ts +14 -0
  202. package/dist/utils/manifest-paths.js +22 -1
  203. package/dist/utils/path-to-regexp.d.ts +21 -0
  204. package/dist/{server/middleware-path-to-regexp.js → utils/path-to-regexp.js} +14 -11
  205. package/dist/utils/plugin-react-version.d.ts +15 -0
  206. package/dist/utils/plugin-react-version.js +64 -0
  207. package/dist/utils/public-routes.d.ts +2 -0
  208. package/dist/utils/public-routes.js +18 -7
  209. package/package.json +1 -1
  210. package/dist/server/middleware-path-to-regexp.d.ts +0 -13
  211. package/dist/utils/regex-safety.d.ts +0 -17
  212. package/dist/utils/regex-safety.js +0 -789
@@ -7,11 +7,12 @@ import { notFoundResponse } from "./http-error-responses.js";
7
7
  import { getRepeatedSlashRedirect, isOpenRedirectShaped, sendRepeatedSlashRedirect } from "./open-redirect.js";
8
8
  import { readStaticFileSignal } from "./static-file-signal.js";
9
9
  import { canonicalizeRequestPathname, filterInternalHeaders } from "./request-pipeline.js";
10
- import { ASSET_PREFIX_URL_DIR, assetPrefixPathname, isAbsoluteAssetPrefix } from "../utils/asset-prefix.js";
10
+ import { ASSET_PREFIX_URL_DIR, assetPrefixPathname, isAbsoluteAssetPrefix, isAssetPrefixBuildAsset } from "../utils/asset-prefix.js";
11
11
  import { StaticFileCache, contentTypeForPath, etagFromFilenameHash } from "./static-file-cache.js";
12
12
  import { normalizePathnameForRouteMatchStrict } from "../routing/utils.js";
13
- import { resolveRequestHost, resolveRequestProtocol, trustProxy, trustedHosts } from "./proxy-trust.js";
13
+ import { resolveRequestHost, resolveRequestProtocol, resolveTrustedForwardedHost, trustProxy, trustedHosts } from "./proxy-trust.js";
14
14
  import { normalizePath } from "./normalize-path.js";
15
+ import { shouldRestoreLocaleRootTrailingSlash } from "./pages-i18n.js";
15
16
  import { buildNextDataNotFoundResponse, encodeUrlParserIgnoredCharacters, isNextDataPathname, normalizeNextDataPagePathname, parseNextDataPathname, shouldAddTrailingSlashToPagesDataPath, urlParserCreatesPagesDataPath } from "./pages-data-route.js";
16
17
  import { buildCacheStateHeaders } from "./cache-headers.js";
17
18
  import { parseHttpDate } from "./http-date.js";
@@ -378,6 +379,19 @@ function isVinextStreamedHtmlResponse(response) {
378
379
  function isVinextStreamedApiResponse(response) {
379
380
  return response.__vinextStreamedApiResponse === true;
380
381
  }
382
+ function disablePrerenderKeepAliveTimeout(server, purpose) {
383
+ if (purpose === "prerender") server.keepAliveTimeout = 0;
384
+ }
385
+ function listen(server, port, host) {
386
+ return new Promise((resolve, reject) => {
387
+ server.once("error", reject);
388
+ server.listen(port, host, () => {
389
+ server.off("error", reject);
390
+ const addr = server.address();
391
+ resolve(typeof addr === "object" && addr ? addr.port : port);
392
+ });
393
+ });
394
+ }
381
395
  function logProdServerStarted(host, port, purpose) {
382
396
  const url = `http://${host}:${port}`;
383
397
  if (purpose === "prerender") {
@@ -925,14 +939,16 @@ async function startProdServer(options = {}) {
925
939
  silent
926
940
  });
927
941
  }
928
- function createNodeExecutionContext(trustedRevalidateOrigin) {
942
+ function createNodeExecutionContext(trustedRevalidateOrigin, { middlewareOrigin, requestSignal } = {}) {
929
943
  return {
930
944
  hostRuntime: "node",
945
+ requestSignal,
931
946
  waitUntil(promise) {
932
947
  Promise.resolve(promise).catch(() => {});
933
948
  },
934
949
  passThroughOnException() {},
935
- trustedRevalidateOrigin
950
+ trustedRevalidateOrigin,
951
+ middlewareOrigin
936
952
  };
937
953
  }
938
954
  /**
@@ -953,8 +969,26 @@ function markPrerenderSpecialError(response, marker) {
953
969
  });
954
970
  }
955
971
  function resolveTrustedNodeRevalidateOrigin(req, configuredHost, configuredPort) {
972
+ return `http://${resolveNodeServerHost(req, configuredHost, configuredPort)}`;
973
+ }
974
+ /**
975
+ * The origin middleware runs against. The Host header is client-controlled,
976
+ * so, like Next.js, which builds the middleware URL from its own hostname and
977
+ * port, it never counts as the server's origin. Otherwise a client could send
978
+ * the host of an external middleware rewrite target and turn that rewrite into
979
+ * an internal one, skipping middleware's checks for the target path. A trusted
980
+ * `X-Forwarded-Host` is operator-approved, so it keeps the request origin, and
981
+ * rewrites to that host stay internal.
982
+ */
983
+ function resolveNodeMiddlewareOrigin(req, requestUrl, configuredHost, configuredPort) {
984
+ const url = new URL(requestUrl);
985
+ if (resolveTrustedForwardedHost(req) !== void 0) return url.origin;
986
+ return `${url.protocol}//${resolveNodeServerHost(req, configuredHost, configuredPort)}`;
987
+ }
988
+ /** The `host:port` this server is reachable at locally. */
989
+ function resolveNodeServerHost(req, configuredHost, configuredPort) {
956
990
  const port = req.socket.localPort ?? configuredPort;
957
- return `http://${normalizeInternalFetchHost(configuredHost)}:${port}`;
991
+ return `${normalizeInternalFetchHost(configuredHost)}:${port}`;
958
992
  }
959
993
  function normalizeInternalFetchHost(host) {
960
994
  if (!host || host === "0.0.0.0" || host === "::") return "localhost";
@@ -1058,6 +1092,7 @@ function installPagesClientAssets(options) {
1058
1092
  clientEntry: metadata.clientEntryFile,
1059
1093
  appBootstrapPreinitModules: metadata.appBootstrapPreinitModules,
1060
1094
  ssrManifest: Object.keys(ssrManifest).length > 0 ? ssrManifest : void 0,
1095
+ sharedChunks: metadata.sharedChunks,
1061
1096
  cssGraph: metadata.cssGraph,
1062
1097
  lazyChunks: metadata.lazyChunks,
1063
1098
  dynamicPreloads: metadata.dynamicPreloads,
@@ -1154,7 +1189,7 @@ async function startAppRouterServer(options) {
1154
1189
  const assetLookupPath = sourcePathname !== null ? resolveAppRouterAssetPath(sourcePathname, appAssetPathPrefix, appRouterAssetPrefix) : null;
1155
1190
  if (assetLookupPath && await serveSource(assetLookupPath)) return;
1156
1191
  if (sourcePathname !== null) {
1157
- const sourceResponse = await rscHandler(new Request(sourceUrl, { signal: request.signal }), createNodeExecutionContext(resolveTrustedNodeRevalidateOrigin(req, host, port)));
1192
+ const sourceResponse = await rscHandler(new Request(sourceUrl, { signal: request.signal }), createNodeExecutionContext(resolveTrustedNodeRevalidateOrigin(req, host, port), { middlewareOrigin: resolveNodeMiddlewareOrigin(req, request.url, host, port) }));
1158
1193
  const sourceSignal = isImageSourceBodyStatus(sourceResponse.status) ? readStaticFileSignal(sourceResponse) : null;
1159
1194
  cancelResponseBody(sourceResponse, request.signal.reason);
1160
1195
  if (request.signal.aborted) return;
@@ -1211,8 +1246,12 @@ async function startAppRouterServer(options) {
1211
1246
  if (clientBuildFile && await tryServeStatic(req, res, clientDir, clientBuildFile, compress, staticCache)) return;
1212
1247
  }
1213
1248
  try {
1214
- const request = nodeToWebRequest(req, rawUrl, prerenderSecret, appRouterI18nConfig, appRouterAuthorizeOnDemandRevalidate, signalFromNodeResponse(res));
1215
- const ctx = createNodeExecutionContext(resolveTrustedNodeRevalidateOrigin(req, host, port));
1249
+ const signal = signalFromNodeResponse(res);
1250
+ const request = nodeToWebRequest(req, rawUrl, prerenderSecret, appRouterI18nConfig, appRouterAuthorizeOnDemandRevalidate, signal);
1251
+ const ctx = createNodeExecutionContext(resolveTrustedNodeRevalidateOrigin(req, host, port), {
1252
+ middlewareOrigin: resolveNodeMiddlewareOrigin(req, request.url, host, port),
1253
+ requestSignal: signal
1254
+ });
1216
1255
  const recorded = {};
1217
1256
  if (purpose === "prerender") ctx.recordPrerenderSpecialError = (marker) => {
1218
1257
  recorded.marker = marker;
@@ -1282,18 +1321,12 @@ async function startAppRouterServer(options) {
1282
1321
  const server = createServer((req, res) => {
1283
1322
  runWithServerEntryRequire(rscEntryRequire, () => handleRequest(req, res));
1284
1323
  });
1285
- await new Promise((resolve) => {
1286
- server.listen(port, host, () => {
1287
- const addr = server.address();
1288
- const actualPort = typeof addr === "object" && addr ? addr.port : port;
1289
- if (!silent) logProdServerStarted(host, actualPort, purpose);
1290
- resolve();
1291
- });
1292
- });
1293
- const addr = server.address();
1324
+ disablePrerenderKeepAliveTimeout(server, purpose);
1325
+ const actualPort = await listen(server, port, host);
1326
+ if (!silent) logProdServerStarted(host, actualPort, purpose);
1294
1327
  return {
1295
1328
  server,
1296
- port: typeof addr === "object" && addr ? addr.port : port
1329
+ port: actualPort
1297
1330
  };
1298
1331
  }
1299
1332
  function isPagesServerEntryPageRoute(value) {
@@ -1323,18 +1356,12 @@ async function startPagesRouterServer(options) {
1323
1356
  const { port, host, purpose, silent } = options;
1324
1357
  const handler = await createPagesRouterRequestHandler(options);
1325
1358
  const server = createServer(handler);
1326
- await new Promise((resolve) => {
1327
- server.listen(port, host, () => {
1328
- const addr = server.address();
1329
- const actualPort = typeof addr === "object" && addr ? addr.port : port;
1330
- if (!silent) logProdServerStarted(host, actualPort, purpose);
1331
- resolve();
1332
- });
1333
- });
1334
- const addr = server.address();
1359
+ disablePrerenderKeepAliveTimeout(server, purpose);
1360
+ const actualPort = await listen(server, port, host);
1361
+ if (!silent) logProdServerStarted(host, actualPort, purpose);
1335
1362
  return {
1336
1363
  server,
1337
- port: typeof addr === "object" && addr ? addr.port : port
1364
+ port: actualPort
1338
1365
  };
1339
1366
  }
1340
1367
  /**
@@ -1481,6 +1508,10 @@ async function createPagesRouterRequestHandler(options) {
1481
1508
  }
1482
1509
  try {
1483
1510
  const hadBasePath = !basePath || hasBasePath(requestPathname, basePath);
1511
+ const restoreLocaleRootTrailingSlash = shouldRestoreLocaleRootTrailingSlash(requestPathname, {
1512
+ trailingSlash,
1513
+ skipProxyUrlNormalize
1514
+ });
1484
1515
  let configMatchPathname = stripBasePath(requestPathname, basePath);
1485
1516
  {
1486
1517
  const strippedPathname = stripBasePath(pathname, basePath);
@@ -1543,6 +1574,8 @@ async function createPagesRouterRequestHandler(options) {
1543
1574
  duplex: hasBody ? "half" : void 0
1544
1575
  });
1545
1576
  const middlewareRequest = isDataReq && skipProxyUrlNormalize ? new Request(new URL(originalRenderUrl, webRequest.url), webRequest) : void 0;
1577
+ const middlewareCtx = createNodeExecutionContext(void 0, { middlewareOrigin: resolveNodeMiddlewareOrigin(req, webRequest.url, host, port) });
1578
+ const runNodeMiddleware = typeof runMiddleware === "function" ? (request, _ctx, opts) => runMiddleware(request, middlewareCtx, opts) : null;
1546
1579
  const resolvePublicImageSource = async (sourceUrl) => {
1547
1580
  const rawSourcePathname = sourceUrl.pathname;
1548
1581
  if (getRepeatedSlashRedirect(rawSourcePathname) || isOpenRedirectShaped(rawSourcePathname)) return null;
@@ -1561,11 +1594,15 @@ async function createPagesRouterRequestHandler(options) {
1561
1594
  recordCacheability: false,
1562
1595
  rawSearch: sourceUrl.search,
1563
1596
  configMatchPathname: strippedSourcePathname,
1564
- runMiddleware: typeof runMiddleware === "function" ? wrapMiddlewareWithBasePath(runMiddleware, basePath, sourceHadBasePath) : null,
1597
+ restoreLocaleRootTrailingSlash: shouldRestoreLocaleRootTrailingSlash(sourceRequestPathname, {
1598
+ trailingSlash,
1599
+ skipProxyUrlNormalize
1600
+ }),
1601
+ runMiddleware: runNodeMiddleware ? wrapMiddlewareWithBasePath(runNodeMiddleware, basePath, sourceHadBasePath) : null,
1565
1602
  renderPage: null,
1566
1603
  handleApi: null,
1567
- serveFilesystemRoute: async (candidate, _stagedHeaders, phase) => {
1568
- if (isImageOptimizationPath(candidate) || isPagesFilesystemExcludedPath(candidate, phase)) return false;
1604
+ serveFilesystemRoute: async (candidate, _stagedHeaders, phase, _resolvedUrl, _request, candidateHasBasePath) => {
1605
+ if (!candidateHasBasePath && !isAssetPrefixBuildAsset(candidate, pagesAssetPathPrefix) || isImageOptimizationPath(candidate) || isPagesFilesystemExcludedPath(candidate, phase)) return false;
1569
1606
  const lookupPath = staticCacheLookupPath(candidate);
1570
1607
  if (lookupPath === null || lookupPath === "/" || !staticCache.lookup(lookupPath)) return false;
1571
1608
  sourcePath = candidate;
@@ -1595,9 +1632,10 @@ async function createPagesRouterRequestHandler(options) {
1595
1632
  rawSearch: rawQs,
1596
1633
  authorizeOnDemandRevalidate: typeof authorizeOnDemandRevalidate === "function" ? authorizeOnDemandRevalidate : void 0,
1597
1634
  configMatchPathname,
1635
+ restoreLocaleRootTrailingSlash,
1598
1636
  matchPageRoute: matchPageRoute ?? null,
1599
1637
  matchApiRoute: matchApiRoute ?? null,
1600
- runMiddleware: typeof runMiddleware === "function" ? wrapMiddlewareWithBasePath(runMiddleware, basePath, hadBasePath) : null,
1638
+ runMiddleware: runNodeMiddleware ? wrapMiddlewareWithBasePath(runNodeMiddleware, basePath, hadBasePath) : null,
1601
1639
  renderPage: typeof renderPage === "function" ? (request, resolvedUrl, options, stagedHeaders) => renderPage(request, resolvedUrl, ssrManifest, void 0, stagedHeaders, {
1602
1640
  ...options,
1603
1641
  originalUrl: originalRenderUrl
@@ -1648,7 +1686,7 @@ async function createPagesRouterRequestHandler(options) {
1648
1686
  res.end(INVALID_IMAGE_SOURCE_MESSAGE);
1649
1687
  return true;
1650
1688
  }
1651
- if (isPagesFilesystemExcludedPath(requestPathname, phase)) return false;
1689
+ if (!resolvedPathnameHasBasePath && !isAssetPrefixBuildAsset(requestPathname, pagesAssetPathPrefix) || isPagesFilesystemExcludedPath(requestPathname, phase)) return false;
1652
1690
  return tryServeStatic(req, res, clientDir, requestPathname, compress, staticCache, stagedHeaders);
1653
1691
  }
1654
1692
  };
@@ -35,4 +35,10 @@ export declare function resolveRequestProtocol(source: IncomingMessage | Headers
35
35
  * against `request.url`.
36
36
  */
37
37
  export declare function resolveRequestHost(source: IncomingMessage | Headers, fallback: string): string;
38
+ /**
39
+ * The `X-Forwarded-Host` value when it matches the `trustedHosts` allow-list,
40
+ * otherwise undefined. Unlike the raw `Host` header, this host is
41
+ * operator-approved.
42
+ */
43
+ export declare function resolveTrustedForwardedHost(source: IncomingMessage | Headers): string | undefined;
38
44
  //#endregion
@@ -42,12 +42,18 @@ function resolveRequestProtocol(source) {
42
42
  * against `request.url`.
43
43
  */
44
44
  function resolveRequestHost(source, fallback) {
45
+ return resolveTrustedForwardedHost(source) ?? (readHost(source) || fallback);
46
+ }
47
+ /**
48
+ * The `X-Forwarded-Host` value when it matches the `trustedHosts` allow-list,
49
+ * otherwise undefined. Unlike the raw `Host` header, this host is
50
+ * operator-approved.
51
+ */
52
+ function resolveTrustedForwardedHost(source) {
45
53
  const rawForwarded = readForwardedHost(source);
46
- if (rawForwarded && trustedHosts.size > 0) {
47
- const forwardedHost = rawForwarded.split(",")[0]?.trim().toLowerCase();
48
- if (forwardedHost && trustedHosts.has(forwardedHost)) return forwardedHost;
49
- }
50
- return readHost(source) || fallback;
54
+ if (!rawForwarded || trustedHosts.size === 0) return void 0;
55
+ const forwardedHost = rawForwarded.split(",")[0]?.trim().toLowerCase();
56
+ return forwardedHost && trustedHosts.has(forwardedHost) ? forwardedHost : void 0;
51
57
  }
52
58
  function readForwardedProto(source) {
53
59
  if (isWebHeaders(source)) return source.get("x-forwarded-proto") ?? void 0;
@@ -65,4 +71,4 @@ function isWebHeaders(source) {
65
71
  return typeof source.get === "function";
66
72
  }
67
73
  //#endregion
68
- export { resolveRequestHost, resolveRequestProtocol, trustProxy, trustedHosts };
74
+ export { resolveRequestHost, resolveRequestProtocol, resolveTrustedForwardedHost, trustProxy, trustedHosts };
@@ -143,6 +143,11 @@ export declare function isOriginAllowed(origin: string, allowed: string[]): bool
143
143
  *
144
144
  * @param headers - The Headers object to modify in place
145
145
  */
146
+ /**
147
+ * Next.js drops each empty middleware Set-Cookie value when it converts
148
+ * middleware's response headers, so blank values never reach the response.
149
+ */
150
+ export declare function dropEmptyMiddlewareSetCookie(headers: Headers): void;
146
151
  export declare function processMiddlewareHeaders(headers: Headers): void;
147
152
  /**
148
153
  * Strip internal headers from an inbound request so they cannot be forged by
@@ -313,7 +313,18 @@ function isOriginAllowed(origin, allowed) {
313
313
  *
314
314
  * @param headers - The Headers object to modify in place
315
315
  */
316
+ /**
317
+ * Next.js drops each empty middleware Set-Cookie value when it converts
318
+ * middleware's response headers, so blank values never reach the response.
319
+ */
320
+ function dropEmptyMiddlewareSetCookie(headers) {
321
+ const cookies = headers.getSetCookie();
322
+ if (!cookies.includes("")) return;
323
+ headers.delete("set-cookie");
324
+ for (const cookie of cookies) if (cookie) headers.append("set-cookie", cookie);
325
+ }
316
326
  function processMiddlewareHeaders(headers) {
327
+ dropEmptyMiddlewareSetCookie(headers);
317
328
  const keysToDelete = [];
318
329
  const unconsumedRequestHeaders = getUnconsumedMiddlewareRequestHeaders(headers);
319
330
  for (const key of headers.keys()) if (key.startsWith("x-middleware-") && key !== "x-middleware-cache" && !unconsumedRequestHeaders.has(key)) keysToDelete.push(key);
@@ -433,4 +444,4 @@ function cloneRequestWithUrl(request, url) {
433
444
  return attachRequestCfMetadata(cloned, request);
434
445
  }
435
446
  //#endregion
436
- export { INTERNAL_HEADERS, VINEXT_INTERNAL_HEADERS, attachRequestCfMetadata, canonicalizeRequestPathname, canonicalizeRequestUrlPathname, cloneRequestWithHeaders, cloneRequestWithUrl, createStaticFileSignal, filterInternalHeaders, getRepeatedSlashRedirect, guardProtocolRelativeUrl, hasBasePath, isOpenRedirectShaped, isOriginAllowed, normalizeTrailingSlash, normalizeTrailingSlashPathname, processMiddlewareHeaders, resolvePublicFileRoute, sendRepeatedSlashRedirect, stripBasePath, validateCsrfOrigin, validateServerActionPayload };
447
+ export { INTERNAL_HEADERS, VINEXT_INTERNAL_HEADERS, attachRequestCfMetadata, canonicalizeRequestPathname, canonicalizeRequestUrlPathname, cloneRequestWithHeaders, cloneRequestWithUrl, createStaticFileSignal, dropEmptyMiddlewareSetCookie, filterInternalHeaders, getRepeatedSlashRedirect, guardProtocolRelativeUrl, hasBasePath, isOpenRedirectShaped, isOriginAllowed, normalizeTrailingSlash, normalizeTrailingSlashPathname, processMiddlewareHeaders, resolvePublicFileRoute, sendRepeatedSlashRedirect, stripBasePath, validateCsrfOrigin, validateServerActionPayload };
@@ -1,4 +1,6 @@
1
1
  import { runOutsideRequestScopes } from "../shims/internal/als-registry.js";
2
+ import { getRequestExecutionContext } from "../shims/request-context.js";
3
+ import { shareIsolatePromise } from "./isolate-shared-promise.js";
2
4
  //#region src/server/server-reference-loader.ts
3
5
  /**
4
6
  * Keep server-reference module evaluation out of the request that first
@@ -21,7 +23,14 @@ const ISOLATED = Symbol.for("vinext.serverReferenceRequire.isolated");
21
23
  function isolateServerReferenceLoads() {
22
24
  const load = globalThis.__vite_rsc_server_require__;
23
25
  if (typeof load !== "function" || ISOLATED in load) return;
24
- const isolated = (id) => runOutsideRequestScopes(() => load(id));
26
+ const started = /* @__PURE__ */ new WeakSet();
27
+ const isolated = (id) => {
28
+ const ctx = getRequestExecutionContext();
29
+ const loaded = runOutsideRequestScopes(() => load(id));
30
+ if (!(loaded instanceof Promise) || started.has(loaded)) return loaded;
31
+ started.add(loaded);
32
+ return shareIsolatePromise(loaded, ctx);
33
+ };
25
34
  Object.defineProperty(isolated, ISOLATED, { value: true });
26
35
  globalThis.__vite_rsc_server_require__ = isolated;
27
36
  }
@@ -178,6 +178,15 @@ var StaticFileCache = class StaticFileCache {
178
178
  return this.entries.get(pathname);
179
179
  }
180
180
  };
181
+ const MANAGED_CHUNKS_SEGMENT = `${ASSET_PREFIX_URL_DIR}/chunks/`;
182
+ const MANAGED_CSS_SEGMENT = `${ASSET_PREFIX_URL_DIR}/css/`;
183
+ const MANAGED_WORKERS_SEGMENT = `${ASSET_PREFIX_URL_DIR}/workers/`;
184
+ const MANAGED_MEDIA_SEGMENT = `${ASSET_PREFIX_URL_DIR}/media/`;
185
+ const HASH_ONLY_BASENAME_RE = /^[A-Za-z0-9_-]{8}$/;
186
+ const WORKER_BASENAME_RE = /^[0-9a-f]{8}-[A-Za-z0-9_-]{8}$/;
187
+ function isInManagedDir(normalizedPath, segment) {
188
+ return normalizedPath.startsWith(segment) || normalizedPath.includes(`/${segment}`);
189
+ }
181
190
  /**
182
191
  * Extract a stable weak ETag from a Vite hashed filename (e.g. `app-DqZc3R4n.js`).
183
192
  * The hash is a content hash computed by the bundler — deterministic across
@@ -190,14 +199,17 @@ var StaticFileCache = class StaticFileCache {
190
199
  */
191
200
  function etagFromFilenameHash(relativePath, ext) {
192
201
  const basename = path.basename(relativePath, ext);
202
+ if (basename.length === 8 && HASH_ONLY_BASENAME_RE.test(basename)) {
203
+ const normalizedPath = toSlash(relativePath);
204
+ if (isInManagedDir(normalizedPath, MANAGED_CHUNKS_SEGMENT) || isInManagedDir(normalizedPath, MANAGED_CSS_SEGMENT)) return `W/"${basename}"`;
205
+ }
206
+ if (basename.length === 17 && WORKER_BASENAME_RE.test(basename) && isInManagedDir(toSlash(relativePath), MANAGED_WORKERS_SEGMENT)) return `W/"${basename}"`;
193
207
  const lastDash = basename.lastIndexOf("-");
194
208
  if (lastDash !== -1 && lastDash !== basename.length - 1) {
195
209
  const suffix = basename.slice(lastDash + 1);
196
210
  if (suffix.length >= 6 && suffix.length <= 12 && /^[A-Za-z0-9_-]+$/.test(suffix)) return `W/"${suffix}"`;
197
211
  }
198
- const normalizedPath = toSlash(relativePath);
199
- const managedMediaSegment = `${ASSET_PREFIX_URL_DIR}/media/`;
200
- if (normalizedPath.startsWith(managedMediaSegment) || normalizedPath.includes(`/${managedMediaSegment}`)) {
212
+ if (isInManagedDir(toSlash(relativePath), MANAGED_MEDIA_SEGMENT)) {
201
213
  const lastDot = basename.lastIndexOf(".");
202
214
  if (lastDot !== -1) {
203
215
  const suffix = basename.slice(lastDot + 1);
@@ -108,7 +108,7 @@ async function resolveStaticAssetSignal(signalResponse, options) {
108
108
  * overrides, so a removed `Range` or replaced validator reaches the asset fetch.
109
109
  */
110
110
  function createStaticAssetRequest(assetPath, sourceRequest, headers = null) {
111
- const assetUrl = new URL(assetPath, sourceRequest.url);
111
+ const assetUrl = new URL(assetPath.replace(/[?#]/g, (character) => encodeURIComponent(character)), sourceRequest.url);
112
112
  if (sourceRequest.method === "GET" || sourceRequest.method === "HEAD") return headers ? new Request(new Request(assetUrl, sourceRequest), { headers }) : new Request(assetUrl, sourceRequest);
113
113
  return new Request(assetUrl, {
114
114
  method: sourceRequest.method,
@@ -1,3 +1,4 @@
1
+ import { shareIsolatePromise } from "../server/isolate-shared-promise.js";
1
2
  import { readCacheControlNumberField, readCacheControlRevalidateField } from "../utils/cache-control-metadata.js";
2
3
  //#region src/shims/cache-handler.ts
3
4
  var NoOpCacheHandler = class {
@@ -167,7 +168,7 @@ var LazyDataCacheHandler = class {
167
168
  this.load = load;
168
169
  }
169
170
  resolve() {
170
- return this.resolved ??= this.load().then(() => {
171
+ return this.resolved ??= shareIsolatePromise(this.load().then(() => {
171
172
  const registered = globalHandlers[HANDLER_KEY];
172
173
  if (registered && registered !== this) {
173
174
  this.loadedHandler = registered;
@@ -179,7 +180,7 @@ var LazyDataCacheHandler = class {
179
180
  delete globalHandlers[LAZY_HANDLER_KEY];
180
181
  this.loadedHandler = fallback;
181
182
  return fallback;
182
- });
183
+ }));
183
184
  }
184
185
  async get(key, ctx) {
185
186
  return (await this.resolve()).get(key, ctx);
@@ -23,9 +23,19 @@ export type UnstableCacheObservation = Readonly<{
23
23
  export type CacheLifeSink = {
24
24
  cacheLife: CacheLifeConfig | null;
25
25
  };
26
+ type TagInvalidationDurations = {
27
+ expire?: number;
28
+ } | undefined;
29
+ /** A CDN purge waiting for the request boundary, after its data-cache invalidation. */
30
+ export type PendingCdnTagInvalidation = Readonly<{
31
+ tag: string;
32
+ durations: TagInvalidationDurations;
33
+ dataInvalidation: Promise<void>;
34
+ }>;
26
35
  export type CacheState = {
27
36
  actionRevalidationKind: ActionRevalidationKind;
28
37
  cacheLifeSink: CacheLifeSink | null;
38
+ pendingCdnTagInvalidations: PendingCdnTagInvalidation[];
29
39
  pendingRevalidatedTags: Set<string>;
30
40
  pendingRevalidations: Set<Promise<void>>;
31
41
  requestScopedCacheLife: CacheLifeConfig | null;
@@ -56,9 +66,36 @@ export declare function _hasPendingRevalidatedTag(tags: readonly string[]): bool
56
66
  */
57
67
  export declare function _queuePendingRevalidation(promise: Promise<void>): boolean;
58
68
  /**
59
- * Await and clear every cache invalidation queued in the current request.
60
- * Clearing before awaiting also lets a later drain observe work enqueued by
61
- * an async continuation while this batch is settling.
69
+ * Defer the CDN purge for `tag` to the current Server Action or Route Handler
70
+ * boundary, so the request sends one adapter call per cacheLife profile like
71
+ * Next.js' `executeRevalidates`. Edge purges are rate limited (Workers Cache
72
+ * allows 5 requests a minute per account), so per-call purges run out fast.
73
+ *
74
+ * Only those two phases defer: their executors always drain before the
75
+ * request finishes. Once the response has closed, `after()` callbacks run
76
+ * past the last drain, so they purge immediately too. Everywhere else returns
77
+ * false and the caller purges immediately.
78
+ *
79
+ * @internal
80
+ */
81
+ export declare function _queuePendingCdnTagInvalidation(tag: string, durations: TagInvalidationDurations, dataInvalidation: Promise<void>): boolean;
82
+ /**
83
+ * Ask the CDN adapter to invalidate `tags`, logging rather than rethrowing a
84
+ * failure. The data cache is already invalidated by then, so a failed edge
85
+ * purge leaves edge-cached responses stale until they expire, and failing the
86
+ * request would not change that. It would only report a committed Server
87
+ * Action write as a failure.
88
+ *
89
+ * @internal
90
+ */
91
+ export declare function _revalidateCdnTags(tags: string | string[], durations?: {
92
+ expire?: number;
93
+ }): Promise<void>;
94
+ /**
95
+ * Await and clear every cache invalidation queued in the current request,
96
+ * then send the deferred CDN purges in batches. Clearing before awaiting also
97
+ * lets a later drain observe work enqueued by an async continuation while
98
+ * this batch is settling.
62
99
  *
63
100
  * @internal
64
101
  */
@@ -1,5 +1,6 @@
1
1
  import { getOrCreateAls } from "./internal/als-registry.js";
2
2
  import { getRequestContext, isInsideUnifiedScope, runWithUnifiedStateMutation } from "./unified-request-context.js";
3
+ import { getCdnCacheAdapter } from "./cdn-cache.js";
3
4
  import { getHeadersAccessPhase } from "./internal/headers-state.js";
4
5
  import { _recordUseCacheRootParamRead, _registerCacheContextAccessor, getRegisteredCacheContext } from "./internal/cache-context-accessor.js";
5
6
  //#region src/shims/cache-request-state.ts
@@ -48,6 +49,7 @@ const ACTION_DID_REVALIDATE_DYNAMIC_ONLY = 2;
48
49
  const fallbackState = globalState[FALLBACK_KEY] ??= {
49
50
  actionRevalidationKind: ACTION_DID_NOT_REVALIDATE,
50
51
  cacheLifeSink: null,
52
+ pendingCdnTagInvalidations: [],
51
53
  pendingRevalidatedTags: /* @__PURE__ */ new Set(),
52
54
  pendingRevalidations: /* @__PURE__ */ new Set(),
53
55
  requestScopedCacheLife: null,
@@ -69,6 +71,7 @@ function _runWithCacheState(fn) {
69
71
  const state = {
70
72
  actionRevalidationKind: ACTION_DID_NOT_REVALIDATE,
71
73
  cacheLifeSink: null,
74
+ pendingCdnTagInvalidations: [],
72
75
  pendingRevalidatedTags: /* @__PURE__ */ new Set(),
73
76
  pendingRevalidations: /* @__PURE__ */ new Set(),
74
77
  requestScopedCacheLife: null,
@@ -128,9 +131,69 @@ function _queuePendingRevalidation(promise) {
128
131
  return true;
129
132
  }
130
133
  /**
131
- * Await and clear every cache invalidation queued in the current request.
132
- * Clearing before awaiting also lets a later drain observe work enqueued by
133
- * an async continuation while this batch is settling.
134
+ * Defer the CDN purge for `tag` to the current Server Action or Route Handler
135
+ * boundary, so the request sends one adapter call per cacheLife profile like
136
+ * Next.js' `executeRevalidates`. Edge purges are rate limited (Workers Cache
137
+ * allows 5 requests a minute per account), so per-call purges run out fast.
138
+ *
139
+ * Only those two phases defer: their executors always drain before the
140
+ * request finishes. Once the response has closed, `after()` callbacks run
141
+ * past the last drain, so they purge immediately too. Everywhere else returns
142
+ * false and the caller purges immediately.
143
+ *
144
+ * @internal
145
+ */
146
+ function _queuePendingCdnTagInvalidation(tag, durations, dataInvalidation) {
147
+ const phase = getHeadersAccessPhase();
148
+ if (phase !== "action" && phase !== "route-handler") return false;
149
+ if (isInsideUnifiedScope() && getRequestContext().afterContext.responseClosed) return false;
150
+ getCacheState().pendingCdnTagInvalidations.push({
151
+ tag,
152
+ durations,
153
+ dataInvalidation
154
+ });
155
+ return true;
156
+ }
157
+ /**
158
+ * Ask the CDN adapter to invalidate `tags`, logging rather than rethrowing a
159
+ * failure. The data cache is already invalidated by then, so a failed edge
160
+ * purge leaves edge-cached responses stale until they expire, and failing the
161
+ * request would not change that. It would only report a committed Server
162
+ * Action write as a failure.
163
+ *
164
+ * @internal
165
+ */
166
+ async function _revalidateCdnTags(tags, durations) {
167
+ try {
168
+ await getCdnCacheAdapter().revalidateTag(tags, durations);
169
+ } catch (error) {
170
+ console.error("[vinext] CDN cache invalidation failed; edge-cached responses may stay stale until they expire:", error);
171
+ }
172
+ }
173
+ async function flushCdnTagInvalidations(invalidations) {
174
+ if (invalidations.length === 0) return;
175
+ const settled = await Promise.allSettled(invalidations.map(({ dataInvalidation }) => dataInvalidation));
176
+ const batches = /* @__PURE__ */ new Map();
177
+ invalidations.forEach(({ tag, durations }, index) => {
178
+ if (settled[index].status === "rejected") return;
179
+ const key = durations === void 0 ? "" : JSON.stringify(durations);
180
+ let batch = batches.get(key);
181
+ if (!batch) {
182
+ batch = {
183
+ durations,
184
+ tags: /* @__PURE__ */ new Set()
185
+ };
186
+ batches.set(key, batch);
187
+ }
188
+ batch.tags.add(tag);
189
+ });
190
+ await Promise.all([...batches.values()].map(({ durations, tags }) => _revalidateCdnTags([...tags], durations)));
191
+ }
192
+ /**
193
+ * Await and clear every cache invalidation queued in the current request,
194
+ * then send the deferred CDN purges in batches. Clearing before awaiting also
195
+ * lets a later drain observe work enqueued by an async continuation while
196
+ * this batch is settling.
134
197
  *
135
198
  * @internal
136
199
  */
@@ -138,14 +201,16 @@ async function _drainPendingRevalidations() {
138
201
  const state = getCacheState();
139
202
  let didReject = false;
140
203
  let firstRejection;
141
- while (state.pendingRevalidations.size > 0) {
204
+ while (state.pendingRevalidations.size > 0 || state.pendingCdnTagInvalidations.length > 0) {
142
205
  const pending = [...state.pendingRevalidations];
143
206
  state.pendingRevalidations.clear();
207
+ const cdnInvalidations = state.pendingCdnTagInvalidations.splice(0);
144
208
  const results = await Promise.allSettled(pending);
145
209
  for (const result of results) if (result.status === "rejected" && !didReject) {
146
210
  didReject = true;
147
211
  firstRejection = result.reason;
148
212
  }
213
+ await flushCdnTagInvalidations(cdnInvalidations);
149
214
  }
150
215
  if (didReject) throw firstRejection;
151
216
  }
@@ -220,4 +285,4 @@ function shouldServeStaleUnstableCacheEntry() {
220
285
  return getCacheState().unstableCacheRevalidation === "background";
221
286
  }
222
287
  //#endregion
223
- export { ACTION_DID_REVALIDATE_DYNAMIC_ONLY, ACTION_DID_REVALIDATE_STATIC_AND_DYNAMIC, _captureRequestScopedCacheLifeAccessors, _consumeRequestScopedCacheLife, _drainPendingRevalidations, _hasPendingRevalidatedTag, _initRequestScopedCacheState, _markPendingRevalidatedTag, _peekRequestScopedCacheLife, _peekUnstableCacheObservations, _queuePendingRevalidation, _recordUseCacheRootParamRead, _registerCacheContextAccessor, _runWithCacheState, _setRequestScopedCacheLife, cacheLifeProfiles, getAndClearActionRevalidationKind, getRegisteredCacheContext, markActionRevalidation, recordUnstableCacheObservation, runWithDetachedCacheObservations, shouldServeStaleUnstableCacheEntry };
288
+ export { ACTION_DID_REVALIDATE_DYNAMIC_ONLY, ACTION_DID_REVALIDATE_STATIC_AND_DYNAMIC, _captureRequestScopedCacheLifeAccessors, _consumeRequestScopedCacheLife, _drainPendingRevalidations, _hasPendingRevalidatedTag, _initRequestScopedCacheState, _markPendingRevalidatedTag, _peekRequestScopedCacheLife, _peekUnstableCacheObservations, _queuePendingCdnTagInvalidation, _queuePendingRevalidation, _recordUseCacheRootParamRead, _registerCacheContextAccessor, _revalidateCdnTags, _runWithCacheState, _setRequestScopedCacheLife, cacheLifeProfiles, getAndClearActionRevalidationKind, getRegisteredCacheContext, markActionRevalidation, recordUnstableCacheObservation, runWithDetachedCacheObservations, shouldServeStaleUnstableCacheEntry };