vinext 0.1.8 → 0.2.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 (237) hide show
  1. package/README.md +51 -30
  2. package/dist/build/inject-pregenerated-paths.d.ts +4 -0
  3. package/dist/build/inject-pregenerated-paths.js +18 -0
  4. package/dist/build/layout-classification.js +1 -1
  5. package/dist/build/nitro-route-rules.js +1 -1
  6. package/dist/build/pages-client-assets-module.d.ts +11 -0
  7. package/dist/build/pages-client-assets-module.js +27 -0
  8. package/dist/build/prerender.d.ts +2 -1
  9. package/dist/build/prerender.js +13 -6
  10. package/dist/build/report.d.ts +13 -2
  11. package/dist/build/report.js +99 -2
  12. package/dist/build/run-prerender.d.ts +7 -0
  13. package/dist/build/run-prerender.js +10 -1
  14. package/dist/build/standalone.js +2 -0
  15. package/dist/cache/cache-adapters-virtual.js +3 -3
  16. package/dist/check.js +40 -2
  17. package/dist/cli-args.d.ts +1 -2
  18. package/dist/cli-args.js +1 -1
  19. package/dist/cli-dev-config.d.ts +12 -0
  20. package/dist/cli-dev-config.js +23 -0
  21. package/dist/cli.js +111 -95
  22. package/dist/{server → client}/dev-error-overlay-store.d.ts +1 -1
  23. package/dist/{server → client}/dev-error-overlay-store.js +1 -1
  24. package/dist/{server → client}/dev-error-overlay.d.ts +1 -1
  25. package/dist/{server → client}/dev-error-overlay.js +2 -2
  26. package/dist/client/navigation-runtime.d.ts +2 -0
  27. package/dist/client/navigation-runtime.js +3 -1
  28. package/dist/client/window-next.d.ts +2 -1
  29. package/dist/cloudflare/index.d.ts +2 -2
  30. package/dist/cloudflare/index.js +2 -2
  31. package/dist/config/config-matchers.js +14 -10
  32. package/dist/config/next-config.d.ts +5 -3
  33. package/dist/config/next-config.js +44 -1
  34. package/dist/config/prerender.d.ts +34 -0
  35. package/dist/config/prerender.js +55 -0
  36. package/dist/entries/app-rsc-entry.d.ts +2 -1
  37. package/dist/entries/app-rsc-entry.js +40 -10
  38. package/dist/entries/app-rsc-manifest.js +2 -0
  39. package/dist/entries/pages-client-entry.d.ts +3 -0
  40. package/dist/entries/pages-client-entry.js +15 -1
  41. package/dist/entries/pages-server-entry.js +5 -2
  42. package/dist/image/image-adapters-virtual.d.ts +59 -0
  43. package/dist/image/image-adapters-virtual.js +59 -0
  44. package/dist/index.d.ts +33 -0
  45. package/dist/index.js +167 -100
  46. package/dist/init-cloudflare.d.ts +43 -0
  47. package/dist/init-cloudflare.js +839 -0
  48. package/dist/init-platform.d.ts +40 -0
  49. package/dist/init-platform.js +195 -0
  50. package/dist/init.d.ts +16 -38
  51. package/dist/init.js +209 -99
  52. package/dist/node_modules/.pnpm/am-i-vibing@0.5.0/node_modules/am-i-vibing/dist/detector-1yx2Hoe0.js +294 -0
  53. package/dist/node_modules/.pnpm/process-ancestry@0.1.0/node_modules/process-ancestry/dist/index.js +94 -0
  54. package/dist/{cloudflare → packages/cloudflare}/src/cache/cdn-adapter.runtime.js +1 -1
  55. package/dist/{cloudflare → packages/cloudflare}/src/cache/kv-data-adapter.runtime.d.ts +2 -2
  56. package/dist/{cloudflare → packages/cloudflare}/src/cache/kv-data-adapter.runtime.js +1 -1
  57. package/dist/packages/cloudflare/src/deploy-config.js +150 -0
  58. package/dist/packages/cloudflare/src/deploy-help.js +55 -0
  59. package/dist/packages/cloudflare/src/deploy.js +276 -0
  60. package/dist/{cloudflare → packages/cloudflare/src}/tpr.d.ts +4 -41
  61. package/dist/{cloudflare → packages/cloudflare/src}/tpr.js +18 -15
  62. package/dist/plugins/ast-scope.d.ts +16 -0
  63. package/dist/plugins/ast-scope.js +62 -0
  64. package/dist/plugins/ast-utils.d.ts +27 -1
  65. package/dist/plugins/ast-utils.js +32 -1
  66. package/dist/plugins/css-module-imports.d.ts +14 -0
  67. package/dist/plugins/css-module-imports.js +59 -0
  68. package/dist/plugins/extensionless-dynamic-import.js +2 -2
  69. package/dist/plugins/ignore-dynamic-requests.d.ts +11 -0
  70. package/dist/plugins/ignore-dynamic-requests.js +530 -0
  71. package/dist/plugins/typeof-window.d.ts +1 -1
  72. package/dist/plugins/typeof-window.js +28 -56
  73. package/dist/routing/app-route-graph.d.ts +23 -2
  74. package/dist/routing/app-route-graph.js +126 -32
  75. package/dist/routing/file-matcher.d.ts +3 -0
  76. package/dist/routing/file-matcher.js +3 -0
  77. package/dist/routing/pages-router.js +2 -2
  78. package/dist/server/api-handler.js +9 -14
  79. package/dist/server/app-browser-action-result.d.ts +4 -1
  80. package/dist/server/app-browser-action-result.js +8 -1
  81. package/dist/server/app-browser-entry.js +161 -52
  82. package/dist/server/app-browser-interception-context.d.ts +1 -0
  83. package/dist/server/app-browser-interception-context.js +4 -2
  84. package/dist/server/app-browser-navigation-controller.d.ts +2 -0
  85. package/dist/server/app-browser-navigation-controller.js +60 -31
  86. package/dist/server/app-browser-server-action-client.d.ts +1 -1
  87. package/dist/server/app-browser-server-action-client.js +3 -4
  88. package/dist/server/app-browser-state.d.ts +11 -1
  89. package/dist/server/app-browser-state.js +25 -8
  90. package/dist/server/app-browser-visible-commit.d.ts +6 -1
  91. package/dist/server/app-browser-visible-commit.js +43 -25
  92. package/dist/server/app-elements-wire.d.ts +9 -2
  93. package/dist/server/app-elements-wire.js +8 -1
  94. package/dist/server/app-elements.d.ts +2 -2
  95. package/dist/server/app-elements.js +4 -3
  96. package/dist/server/app-fallback-renderer.d.ts +2 -1
  97. package/dist/server/app-fallback-renderer.js +10 -6
  98. package/dist/server/app-hydration-cache-publication.d.ts +11 -0
  99. package/dist/server/app-hydration-cache-publication.js +43 -0
  100. package/dist/server/app-middleware.d.ts +4 -3
  101. package/dist/server/app-middleware.js +8 -3
  102. package/dist/server/app-optimistic-routing.js +11 -4
  103. package/dist/server/app-page-cache-finalizer.js +2 -1
  104. package/dist/server/app-page-cache-render.d.ts +1 -0
  105. package/dist/server/app-page-cache-render.js +8 -4
  106. package/dist/server/app-page-cache.d.ts +1 -0
  107. package/dist/server/app-page-cache.js +5 -2
  108. package/dist/server/app-page-dispatch.js +1 -0
  109. package/dist/server/app-page-element-builder.d.ts +2 -1
  110. package/dist/server/app-page-element-builder.js +58 -4
  111. package/dist/server/app-page-probe.js +5 -0
  112. package/dist/server/app-page-render-identity.d.ts +1 -0
  113. package/dist/server/app-page-render-identity.js +1 -1
  114. package/dist/server/app-page-render.js +18 -0
  115. package/dist/server/app-page-request.d.ts +14 -0
  116. package/dist/server/app-page-request.js +69 -4
  117. package/dist/server/app-page-route-wiring.d.ts +8 -1
  118. package/dist/server/app-page-route-wiring.js +32 -18
  119. package/dist/server/app-page-segment-state.d.ts +2 -1
  120. package/dist/server/app-page-segment-state.js +3 -1
  121. package/dist/server/app-page-stream.d.ts +5 -0
  122. package/dist/server/app-page-stream.js +3 -1
  123. package/dist/server/app-route-handler-execution.js +5 -1
  124. package/dist/server/app-route-handler-response.js +1 -0
  125. package/dist/server/app-route-handler-runtime.js +1 -1
  126. package/dist/server/app-router-entry.js +9 -2
  127. package/dist/server/app-rsc-handler.d.ts +1 -0
  128. package/dist/server/app-rsc-handler.js +62 -31
  129. package/dist/server/app-rsc-request-normalization.d.ts +3 -2
  130. package/dist/server/app-rsc-request-normalization.js +6 -3
  131. package/dist/server/app-segment-config.d.ts +11 -0
  132. package/dist/server/app-segment-config.js +62 -6
  133. package/dist/server/app-server-action-execution.d.ts +1 -0
  134. package/dist/server/app-server-action-execution.js +58 -28
  135. package/dist/server/app-ssr-entry.d.ts +3 -0
  136. package/dist/server/app-ssr-entry.js +15 -7
  137. package/dist/server/app-ssr-stream.d.ts +7 -3
  138. package/dist/server/app-ssr-stream.js +10 -6
  139. package/dist/server/app-visited-response-cache.d.ts +6 -0
  140. package/dist/server/app-visited-response-cache.js +3 -1
  141. package/dist/server/client-trace-metadata.js +26 -0
  142. package/dist/server/default-global-not-found-module.d.ts +14 -0
  143. package/dist/server/default-global-not-found-module.js +14 -0
  144. package/dist/server/dev-route-files.js +4 -0
  145. package/dist/server/dev-server.js +19 -18
  146. package/dist/server/dev-stack-sourcemap.d.ts +1 -1
  147. package/dist/server/dev-stack-sourcemap.js +1 -1
  148. package/dist/server/fetch-handler.d.ts +2 -0
  149. package/dist/server/fetch-handler.js +18 -0
  150. package/dist/server/headers.d.ts +3 -15
  151. package/dist/server/headers.js +2 -15
  152. package/dist/server/image-optimization.d.ts +51 -1
  153. package/dist/server/image-optimization.js +52 -2
  154. package/dist/server/implicit-tags.js +1 -1
  155. package/dist/server/isr-cache.d.ts +1 -1
  156. package/dist/server/isr-cache.js +2 -2
  157. package/dist/server/metadata-routes.d.ts +3 -1
  158. package/dist/server/metadata-routes.js +12 -2
  159. package/dist/server/middleware-runtime.js +6 -1
  160. package/dist/server/navigation-planner.d.ts +1 -0
  161. package/dist/server/navigation-planner.js +14 -3
  162. package/dist/server/pages-api-route.js +2 -2
  163. package/dist/server/pages-asset-tags.d.ts +4 -6
  164. package/dist/server/pages-asset-tags.js +12 -12
  165. package/dist/server/pages-client-assets.d.ts +12 -0
  166. package/dist/server/pages-client-assets.js +10 -0
  167. package/dist/server/pages-node-compat.d.ts +8 -1
  168. package/dist/server/pages-node-compat.js +32 -4
  169. package/dist/server/pages-page-data.d.ts +24 -1
  170. package/dist/server/pages-page-data.js +45 -24
  171. package/dist/server/pages-page-handler.d.ts +2 -1
  172. package/dist/server/pages-page-handler.js +19 -12
  173. package/dist/server/pages-page-response.d.ts +7 -0
  174. package/dist/server/pages-page-response.js +4 -1
  175. package/dist/server/pages-request-pipeline.d.ts +2 -0
  176. package/dist/server/pages-request-pipeline.js +25 -1
  177. package/dist/server/pages-router-entry.d.ts +30 -0
  178. package/dist/server/pages-router-entry.js +108 -0
  179. package/dist/server/prerender-manifest.d.ts +3 -1
  180. package/dist/server/prerender-route-params.js +1 -1
  181. package/dist/server/prod-server.d.ts +1 -1
  182. package/dist/server/prod-server.js +33 -20
  183. package/dist/server/request-pipeline.js +1 -0
  184. package/dist/server/seed-cache.js +4 -4
  185. package/dist/shims/app-router-scroll-state.d.ts +1 -0
  186. package/dist/shims/app-router-scroll-state.js +1 -0
  187. package/dist/shims/app-router-scroll.js +2 -1
  188. package/dist/shims/cache.js +19 -15
  189. package/dist/shims/cdn-cache.js +1 -1
  190. package/dist/shims/dynamic-preload-chunks.js +2 -1
  191. package/dist/shims/form.d.ts +3 -1
  192. package/dist/shims/form.js +37 -43
  193. package/dist/shims/headers.d.ts +7 -1
  194. package/dist/shims/headers.js +17 -3
  195. package/dist/shims/image.js +75 -14
  196. package/dist/shims/internal/app-route-detection.d.ts +2 -17
  197. package/dist/shims/internal/app-route-detection.js +4 -17
  198. package/dist/shims/internal/hybrid-client-route-owner-direct.d.ts +23 -0
  199. package/dist/shims/internal/hybrid-client-route-owner-direct.js +51 -0
  200. package/dist/shims/internal/hybrid-client-route-owner.d.ts +2 -15
  201. package/dist/shims/internal/hybrid-client-route-owner.js +9 -60
  202. package/dist/shims/internal/pages-data-fetch-dedup.d.ts +9 -5
  203. package/dist/shims/internal/pages-data-fetch-dedup.js +73 -14
  204. package/dist/shims/internal/pages-data-target.d.ts +10 -9
  205. package/dist/shims/internal/pages-data-target.js +91 -12
  206. package/dist/shims/internal/pages-router-components.d.ts +7 -0
  207. package/dist/shims/internal/pages-router-components.js +13 -0
  208. package/dist/shims/layout-segment-context.d.ts +4 -1
  209. package/dist/shims/layout-segment-context.js +18 -4
  210. package/dist/shims/link.js +55 -26
  211. package/dist/shims/navigation.d.ts +5 -1
  212. package/dist/shims/navigation.js +45 -10
  213. package/dist/shims/navigation.react-server.js +1 -1
  214. package/dist/shims/root-params.d.ts +15 -1
  215. package/dist/shims/root-params.js +21 -1
  216. package/dist/shims/router.d.ts +5 -7
  217. package/dist/shims/router.js +362 -93
  218. package/dist/shims/server.js +3 -2
  219. package/dist/shims/slot.js +3 -6
  220. package/dist/utils/client-runtime-metadata.d.ts +2 -18
  221. package/dist/utils/client-runtime-metadata.js +31 -22
  222. package/dist/utils/dev-stack-sourcemap-endpoint.d.ts +4 -0
  223. package/dist/{server → utils}/dev-stack-sourcemap-endpoint.js +1 -1
  224. package/dist/utils/domain-locale.d.ts +6 -3
  225. package/dist/{server → utils}/middleware-request-headers.d.ts +1 -1
  226. package/dist/{server → utils}/middleware-request-headers.js +2 -2
  227. package/dist/utils/project.d.ts +48 -2
  228. package/dist/utils/project.js +225 -4
  229. package/dist/utils/protocol-headers.d.ts +17 -0
  230. package/dist/utils/protocol-headers.js +17 -0
  231. package/dist/utils/react-version.d.ts +4 -0
  232. package/dist/utils/react-version.js +44 -0
  233. package/package.json +47 -2
  234. package/dist/deploy.d.ts +0 -197
  235. package/dist/deploy.js +0 -1040
  236. package/dist/server/dev-stack-sourcemap-endpoint.d.ts +0 -4
  237. /package/dist/{cloudflare → packages/cloudflare}/src/utils/cache-control-metadata.js +0 -0
@@ -1,22 +1,24 @@
1
1
  import { normalizePathnameForRouteMatchStrict } from "../routing/utils.js";
2
2
  import { hasBasePath, stripBasePath } from "../utils/base-path.js";
3
- import { VINEXT_PRERENDER_ROUTE_PARAMS_HEADER, VINEXT_PRERENDER_SECRET_HEADER, VINEXT_STATIC_FILE_HEADER } from "./headers.js";
3
+ import { VINEXT_PRERENDER_ROUTE_PARAMS_HEADER, VINEXT_PRERENDER_SECRET_HEADER } from "../utils/protocol-headers.js";
4
+ import { VINEXT_STATIC_FILE_HEADER } from "./headers.js";
4
5
  import { normalizePath } from "./normalize-path.js";
5
6
  import { notFoundResponse } from "./http-error-responses.js";
6
7
  import { isOpenRedirectShaped } from "./open-redirect.js";
7
8
  import { filterInternalHeaders } from "./request-pipeline.js";
8
9
  import { isUnknownRecord } from "../utils/record.js";
10
+ import { buildNextDataNotFoundResponse, isNextDataPathname, parseNextDataPathname } from "./pages-data-route.js";
9
11
  import { resolveRequestHost, resolveRequestProtocol, trustProxy, trustedHosts } from "./proxy-trust.js";
10
12
  import { DEFAULT_DEVICE_SIZES, DEFAULT_IMAGE_SIZES, isImageOptimizationPath, isSafeImageContentType, parseImageParams } from "./image-optimization.js";
11
13
  import { installSocketErrorBackstop } from "./socket-error-backstop.js";
12
14
  import { ASSET_PREFIX_URL_DIR, assetPrefixPathname, isAbsoluteAssetPrefix } from "../utils/asset-prefix.js";
13
15
  import { CONTENT_TYPES, StaticFileCache, etagFromFilenameHash } from "./static-file-cache.js";
14
- import { buildNextDataNotFoundResponse, isNextDataPathname, parseNextDataPathname } from "./pages-data-route.js";
15
16
  import { collectInlineCssManifest } from "../build/inline-css.js";
16
17
  import { mergeHeaders } from "./worker-utils.js";
17
18
  import { runPagesRequest, wrapMiddlewareWithBasePath } from "./pages-request-pipeline.js";
18
- import { readTrustedPrerenderRouteParamsFromHeaders, serializePrerenderRouteParamsHeader } from "./prerender-route-params.js";
19
19
  import { computeClientRuntimeMetadata } from "../utils/client-runtime-metadata.js";
20
+ import { readTrustedPrerenderRouteParamsFromHeaders, serializePrerenderRouteParamsHeader } from "./prerender-route-params.js";
21
+ import { setPagesClientAssets } from "./pages-client-assets.js";
20
22
  import { readPrerenderSecret } from "../build/server-manifest.js";
21
23
  import { seedMemoryCacheFromPrerender } from "./seed-cache.js";
22
24
  import { negotiateEncoding, parseAcceptedEncodings, selectContentEncoding } from "./accept-encoding.js";
@@ -24,9 +26,9 @@ import fs from "node:fs";
24
26
  import path from "node:path";
25
27
  import fs$1 from "node:fs/promises";
26
28
  import { pathToFileURL } from "node:url";
29
+ import { Readable, pipeline } from "node:stream";
27
30
  import zlib from "node:zlib";
28
31
  import { createServer } from "node:http";
29
- import { Readable, pipeline } from "node:stream";
30
32
  //#region src/server/prod-server.ts
31
33
  /**
32
34
  * Production server for vinext.
@@ -275,8 +277,11 @@ function installClientBuildManifestGlobals(clientDir, assetBase, assetPrefix) {
275
277
  assetBase,
276
278
  assetPrefix
277
279
  });
278
- globalThis.__VINEXT_LAZY_CHUNKS__ = metadata.lazyChunks;
279
- globalThis.__VINEXT_DYNAMIC_PRELOADS__ = metadata.dynamicPreloads;
280
+ setPagesClientAssets({
281
+ appBootstrapPreinitModules: metadata.appBootstrapPreinitModules,
282
+ lazyChunks: metadata.lazyChunks,
283
+ dynamicPreloads: metadata.dynamicPreloads
284
+ });
280
285
  }
281
286
  function isNoBodyResponseStatus(status) {
282
287
  return NO_BODY_RESPONSE_STATUSES.has(status);
@@ -305,7 +310,7 @@ function logProdServerStarted(host, port, purpose) {
305
310
  * arguments in (headers, response) order. The request path now calls
306
311
  * `runPagesRequest`, which uses `mergeHeaders` directly; this wrapper is retained
307
312
  * only for its existing tests and any external callers, so there is a single
308
- * implementation to keep in sync. (deploy.ts still emits its own generated copy.)
313
+ * implementation to keep in sync. The init-owned Cloudflare Worker template delegates here.
309
314
  */
310
315
  function mergeWebResponse(middlewareHeaders, response, statusOverride) {
311
316
  return mergeHeaders(response, middlewareHeaders, statusOverride);
@@ -736,18 +741,21 @@ function readSsrManifest(clientDir) {
736
741
  }
737
742
  return parsed;
738
743
  }
739
- function installPagesClientAssetGlobals(options) {
744
+ function installPagesClientAssets(options) {
740
745
  const ssrManifest = readSsrManifest(options.clientDir);
741
- globalThis.__VINEXT_SSR_MANIFEST__ = Object.keys(ssrManifest).length > 0 ? ssrManifest : void 0;
742
746
  const metadata = computeClientRuntimeMetadata({
743
747
  clientDir: options.clientDir,
744
748
  assetBase: options.assetBase,
745
749
  assetPrefix: options.assetPrefix,
746
750
  includeClientEntry: options.clientEntryLookup === "pages-client-entry" ? "pages-client-entry" : true
747
751
  });
748
- globalThis.__VINEXT_CLIENT_ENTRY__ = metadata.clientEntryFile;
749
- globalThis.__VINEXT_LAZY_CHUNKS__ = metadata.lazyChunks;
750
- globalThis.__VINEXT_DYNAMIC_PRELOADS__ = metadata.dynamicPreloads;
752
+ setPagesClientAssets({
753
+ clientEntry: metadata.clientEntryFile,
754
+ appBootstrapPreinitModules: metadata.appBootstrapPreinitModules,
755
+ ssrManifest: Object.keys(ssrManifest).length > 0 ? ssrManifest : void 0,
756
+ lazyChunks: metadata.lazyChunks,
757
+ dynamicPreloads: metadata.dynamicPreloads
758
+ });
751
759
  return ssrManifest;
752
760
  }
753
761
  /**
@@ -769,11 +777,6 @@ function installPagesClientAssetGlobals(options) {
769
777
  */
770
778
  async function startAppRouterServer(options) {
771
779
  const { port, host, clientDir, rscEntryPath, compress, purpose } = options;
772
- let imageConfig;
773
- const imageConfigPath = path.join(path.dirname(rscEntryPath), "image-config.json");
774
- if (fs.existsSync(imageConfigPath)) try {
775
- imageConfig = JSON.parse(fs.readFileSync(imageConfigPath, "utf-8"));
776
- } catch {}
777
780
  const prerenderSecret = readPrerenderSecret(path.dirname(rscEntryPath));
778
781
  const rscModule = await importServerEntryModule(rscEntryPath);
779
782
  const rscHandler = resolveAppRouterHandler(rscModule.default);
@@ -781,10 +784,18 @@ async function startAppRouterServer(options) {
781
784
  const appRouterBasePath = typeof rscModule.__basePath === "string" ? rscModule.__basePath : "";
782
785
  const appRouterInlineCss = rscModule.__inlineCss === true;
783
786
  const appRouterHasPagesDir = rscModule.__hasPagesDir === true;
787
+ const appImageAllowedWidths = Array.isArray(rscModule.__imageAllowedWidths) ? rscModule.__imageAllowedWidths : [...DEFAULT_DEVICE_SIZES, ...DEFAULT_IMAGE_SIZES];
788
+ let imageConfig = typeof rscModule.__imageConfig === "object" && rscModule.__imageConfig !== null ? rscModule.__imageConfig : void 0;
789
+ if (imageConfig === void 0) {
790
+ const imageConfigPath = path.join(path.dirname(rscEntryPath), "image-config.json");
791
+ if (fs.existsSync(imageConfigPath)) try {
792
+ imageConfig = JSON.parse(fs.readFileSync(imageConfigPath, "utf-8"));
793
+ } catch {}
794
+ }
784
795
  globalThis.__VINEXT_INLINE_CSS__ = appRouterInlineCss ? collectInlineCssManifest(clientDir, appRouterAssetPrefix) : void 0;
785
796
  const appAssetPathPrefix = assetPrefixPathname(appRouterAssetPrefix);
786
797
  const appAssetBase = appRouterBasePath ? `${appRouterBasePath}/` : "/";
787
- if (appRouterHasPagesDir) installPagesClientAssetGlobals({
798
+ if (appRouterHasPagesDir) installPagesClientAssets({
788
799
  clientDir,
789
800
  assetPrefix: appRouterAssetPrefix,
790
801
  assetBase: appAssetBase,
@@ -828,7 +839,7 @@ async function startAppRouterServer(options) {
828
839
  }
829
840
  }
830
841
  if (isImageOptimizationPath(pathname)) {
831
- const params = parseImageParams(new URL(rawUrl, "http://localhost"), [...imageConfig?.deviceSizes ?? DEFAULT_DEVICE_SIZES, ...imageConfig?.imageSizes ?? DEFAULT_IMAGE_SIZES], imageConfig?.qualities);
842
+ const params = parseImageParams(new URL(rawUrl, "http://localhost"), appImageAllowedWidths, imageConfig?.qualities);
832
843
  if (!params) {
833
844
  res.writeHead(400);
834
845
  res.end("Bad Request");
@@ -923,6 +934,7 @@ async function startPagesRouterServer(options) {
923
934
  const serverEntry = await importServerEntryModule(serverEntryPath);
924
935
  const { renderPage, handleApiRoute: handleApi, runMiddleware, vinextConfig, buildId: pagesBuildId } = serverEntry;
925
936
  const matchPageRoute = typeof serverEntry.matchPageRoute === "function" ? serverEntry.matchPageRoute : void 0;
937
+ const hasMiddleware = serverEntry.hasMiddleware === true;
926
938
  const pageRoutes = readPagesServerEntryPageRoutes(serverEntry.pageRoutes);
927
939
  const prerenderSecret = readPrerenderSecret(path.dirname(serverEntryPath));
928
940
  const basePath = vinextConfig?.basePath ?? "";
@@ -946,7 +958,7 @@ async function startPagesRouterServer(options) {
946
958
  contentDispositionType: vinextConfig.images.contentDispositionType,
947
959
  contentSecurityPolicy: vinextConfig.images.contentSecurityPolicy
948
960
  } : void 0;
949
- const ssrManifest = installPagesClientAssetGlobals({
961
+ const ssrManifest = installPagesClientAssets({
950
962
  clientDir,
951
963
  assetPrefix,
952
964
  assetBase,
@@ -1075,6 +1087,7 @@ async function startPagesRouterServer(options) {
1075
1087
  hadBasePath,
1076
1088
  isDataReq,
1077
1089
  isDataRequest,
1090
+ hasMiddleware,
1078
1091
  ctx: void 0,
1079
1092
  rawSearch: rawQs,
1080
1093
  matchPageRoute: matchPageRoute ?? null,
@@ -1,4 +1,5 @@
1
1
  import { hasBasePath, removeTrailingSlash, stripBasePath } from "../utils/base-path.js";
2
+ import "../utils/protocol-headers.js";
2
3
  import { INTERNAL_HEADERS, VINEXT_INTERNAL_HEADERS, VINEXT_STATIC_FILE_HEADER } from "./headers.js";
3
4
  import { matchHeaders } from "../config/config-matchers.js";
4
5
  import { forbiddenResponse, notFoundResponse } from "./http-error-responses.js";
@@ -1,8 +1,8 @@
1
1
  import { isrCacheKey, isrSetPrerenderedAppPage } from "./isr-cache.js";
2
+ import { getRenderedAppRoutes, isFallbackShellArtifactPath, readPrerenderManifest } from "./prerender-manifest.js";
2
3
  import { buildAppPageCacheTags } from "./app-page-cache.js";
3
4
  import { getOutputPath, getRscOutputPath } from "../utils/prerender-output-paths.js";
4
5
  import { addPregeneratedConcretePath, clearPregeneratedConcretePaths, normalizePregeneratedPathname } from "./pregenerated-concrete-paths.js";
5
- import { getRenderedAppRoutes, isFallbackShellArtifactPath, readPrerenderManifest } from "./prerender-manifest.js";
6
6
  import fs from "node:fs";
7
7
  import path from "node:path";
8
8
  //#region src/server/seed-cache.ts
@@ -67,7 +67,7 @@ async function seedMemoryCacheFromPrerender(serverDir, options) {
67
67
  const revalidateSeconds = typeof route.revalidate === "number" ? route.revalidate : void 0;
68
68
  const expireSeconds = typeof route.expire === "number" ? route.expire : void 0;
69
69
  const tags = buildAppPageCacheTags(cachePathname, []);
70
- if (await seedHtml(writeAppPageEntry, prerenderDir, htmlKey, artifactPathname, trailingSlash, revalidateSeconds, expireSeconds, tags)) {
70
+ if (await seedHtml(writeAppPageEntry, prerenderDir, htmlKey, artifactPathname, trailingSlash, route.headers, revalidateSeconds, expireSeconds, tags)) {
71
71
  await seedRsc(writeAppPageEntry, prerenderDir, rscKey, artifactPathname, revalidateSeconds, expireSeconds, tags);
72
72
  seeded++;
73
73
  }
@@ -81,7 +81,7 @@ function createDefaultAppPageEntryWriter() {
81
81
  * Seed the HTML cache entry for a single route.
82
82
  * Returns true if the file existed and was seeded.
83
83
  */
84
- async function seedHtml(writeAppPageEntry, prerenderDir, key, pathname, trailingSlash, revalidateSeconds, expireSeconds, tags) {
84
+ async function seedHtml(writeAppPageEntry, prerenderDir, key, pathname, trailingSlash, headers, revalidateSeconds, expireSeconds, tags) {
85
85
  const relPath = getOutputPath(pathname, trailingSlash);
86
86
  const fullPath = path.join(prerenderDir, relPath);
87
87
  if (!fs.existsSync(fullPath)) return false;
@@ -89,7 +89,7 @@ async function seedHtml(writeAppPageEntry, prerenderDir, key, pathname, trailing
89
89
  kind: "APP_PAGE",
90
90
  html: fs.readFileSync(fullPath, "utf-8"),
91
91
  rscData: void 0,
92
- headers: void 0,
92
+ headers,
93
93
  postponed: void 0,
94
94
  status: void 0
95
95
  }, {
@@ -2,6 +2,7 @@
2
2
  type AppRouterScrollIntent = Readonly<{
3
3
  commitId: number | null;
4
4
  hash: string | null;
5
+ headElements: ReadonlySet<Element> | null;
5
6
  id: number;
6
7
  targetHoistedInHead: boolean;
7
8
  }>;
@@ -14,6 +14,7 @@ function beginAppRouterScrollIntent(hash) {
14
14
  const intent = {
15
15
  commitId: null,
16
16
  hash,
17
+ headElements: typeof document === "undefined" ? null : new Set(document.head?.children ?? []),
17
18
  id: store.nextId,
18
19
  targetHoistedInHead: false
19
20
  };
@@ -99,7 +99,8 @@ var AppRouterScrollTargetInner = class extends React$1.Component {
99
99
  else node = null;
100
100
  if (node === null) {
101
101
  node = findDOMNode(this);
102
- if (node !== null && isInDocumentHead(node)) {
102
+ const headElement = node instanceof Element ? node : node?.parentElement;
103
+ if (node !== null && headElement != null && isInDocumentHead(node) && !intent.headElements?.has(headElement)) {
103
104
  markAppRouterScrollIntentHeadHoisted(intent, this.props.commitId);
104
105
  return;
105
106
  }
@@ -5,7 +5,7 @@ import { MemoryCacheHandler, NoOpCacheHandler, configureMemoryCacheHandler, getC
5
5
  import { getCdnCacheAdapter } from "./cdn-cache.js";
6
6
  import { fnv1a64 } from "../utils/hash.js";
7
7
  import { makeHangingPromise } from "./internal/make-hanging-promise.js";
8
- import { getHeadersAccessPhase, markDynamicUsage } from "./headers.js";
8
+ import { getHeadersAccessPhase, isDraftModeEnabled, markDynamicUsage } from "./headers.js";
9
9
  import { ACTION_DID_REVALIDATE_DYNAMIC_ONLY, ACTION_DID_REVALIDATE_STATIC_AND_DYNAMIC, _consumeRequestScopedCacheLife, _initRequestScopedCacheState, _peekRequestScopedCacheLife, _peekUnstableCacheObservations, _registerCacheContextAccessor, _runWithCacheState, _setRequestScopedCacheLife, cacheLifeProfiles, getAndClearActionRevalidationKind, getRegisteredCacheContext, markActionRevalidation, recordUnstableCacheObservation, shouldServeStaleUnstableCacheEntry } from "./cache-request-state.js";
10
10
  import { encodeCacheTag, encodeCacheTags } from "../utils/encode-cache-tag.js";
11
11
  import { workUnitAsyncStorage } from "./internal/work-unit-async-storage.js";
@@ -110,10 +110,10 @@ function refresh() {
110
110
  *
111
111
  * @see https://nextjs.org/docs/app/api-reference/functions/updateTag
112
112
  */
113
- async function updateTag(tag) {
113
+ function updateTag(tag) {
114
114
  if (getHeadersAccessPhase() !== "action") throw new Error("updateTag can only be called from within a Server Action. To invalidate cache tags in Route Handlers or other contexts, use revalidateTag instead. See more info here: https://nextjs.org/docs/app/api-reference/functions/updateTag");
115
115
  markActionRevalidation(1);
116
- await _invalidateEncodedTag(encodeCacheTag(tag));
116
+ return _invalidateEncodedTag(encodeCacheTag(tag));
117
117
  }
118
118
  /**
119
119
  * Opt out of static rendering and indicate a particular component should not be cached.
@@ -380,19 +380,23 @@ function unstable_cache(fn, keyParts, options) {
380
380
  tagCount: tags.length,
381
381
  tagHash: tags.length > 0 ? fnv1a64(JSON.stringify(tags)) : null
382
382
  });
383
- const existing = await getDataCacheHandler().get(cacheKey, {
384
- kind: "FETCH",
385
- tags
386
- });
387
- if (existing?.value && existing.value.kind === "FETCH") {
388
- const cached = tryDeserializeUnstableCacheResult(existing.value.data.body);
389
- if (cached.ok) if (existing.cacheState === "stale") {
390
- if (shouldServeStaleUnstableCacheEntry()) {
391
- scheduleUnstableCacheBackgroundRevalidation(cacheKey, () => refreshUnstableCacheResult(fn, args, cacheKey, tags, revalidateSeconds));
392
- return cached.value;
393
- }
394
- } else return cached.value;
383
+ const isDraftMode = isDraftModeEnabled();
384
+ if (!isDraftMode) {
385
+ const existing = await getDataCacheHandler().get(cacheKey, {
386
+ kind: "FETCH",
387
+ tags
388
+ });
389
+ if (existing?.value && existing.value.kind === "FETCH") {
390
+ const cached = tryDeserializeUnstableCacheResult(existing.value.data.body);
391
+ if (cached.ok) if (existing.cacheState === "stale") {
392
+ if (shouldServeStaleUnstableCacheEntry()) {
393
+ scheduleUnstableCacheBackgroundRevalidation(cacheKey, () => refreshUnstableCacheResult(fn, args, cacheKey, tags, revalidateSeconds));
394
+ return cached.value;
395
+ }
396
+ } else return cached.value;
397
+ }
395
398
  }
399
+ if (isDraftMode) return await _unstableCacheAls.run(true, () => fn(...args));
396
400
  return await refreshUnstableCacheResult(fn, args, cacheKey, tags, revalidateSeconds);
397
401
  };
398
402
  return cachedFn;
@@ -1,6 +1,6 @@
1
1
  import { getRequestExecutionContext } from "./request-context.js";
2
2
  import { getDataCacheHandler } from "./cache-handler.js";
3
- import { CloudflareCdnCacheAdapter } from "../cloudflare/src/cache/cdn-adapter.runtime.js";
3
+ import { CloudflareCdnCacheAdapter } from "../packages/cloudflare/src/cache/cdn-adapter.runtime.js";
4
4
  //#region src/shims/cdn-cache.ts
5
5
  /**
6
6
  * CDN cache adapter — owns the *page-level ISR serving strategy*.
@@ -3,6 +3,7 @@ import { appendAssetDeploymentIdQuery } from "../utils/deployment-id.js";
3
3
  import { useScriptNonce } from "./script-nonce-context.js";
4
4
  import React from "react";
5
5
  import * as ReactDOM from "react-dom";
6
+ import { getPagesClientAssets } from "vinext/server/pages-client-assets";
6
7
  //#region src/shims/dynamic-preload-chunks.tsx
7
8
  /**
8
9
  * Preload links for rendered next/dynamic() boundaries.
@@ -34,7 +35,7 @@ function dynamicPreloadHref(file) {
34
35
  }
35
36
  function resolveDynamicPreloadFiles(moduleIds) {
36
37
  if (!moduleIds || moduleIds.length === 0) return [];
37
- const preloadMap = globalThis.__VINEXT_DYNAMIC_PRELOADS__;
38
+ const preloadMap = getPagesClientAssets().dynamicPreloads;
38
39
  if (!preloadMap) return [];
39
40
  const files = [];
40
41
  const seen = /* @__PURE__ */ new Set();
@@ -1,6 +1,8 @@
1
1
  import { FormHTMLAttributes, useActionState } from "react";
2
2
 
3
3
  //#region src/shims/form.d.ts
4
+ type FormSubmitter = HTMLButtonElement | HTMLInputElement;
5
+ declare function createFormSubmitDestinationUrl(action: string, form: HTMLFormElement, submitter: FormSubmitter | null): string;
4
6
  declare const Form: import("react").ForwardRefExoticComponent<{
5
7
  /** Target URL for GET forms, or server action for POST forms */action: string | ((formData: FormData) => void | Promise<void>); /** Replace instead of push in history (default: false) */
6
8
  replace?: boolean; /** Scroll to top after navigation (default: true) */
@@ -16,4 +18,4 @@ declare const Form: import("react").ForwardRefExoticComponent<{
16
18
  prefetch?: false | null;
17
19
  } & Omit<FormHTMLAttributes<HTMLFormElement>, "method" | "encType" | "target"> & import("react").RefAttributes<HTMLFormElement>>;
18
20
  //#endregion
19
- export { Form as default, useActionState };
21
+ export { createFormSubmitDestinationUrl, Form as default, useActionState };
@@ -1,9 +1,11 @@
1
1
  "use client";
2
2
  import { VINEXT_MOUNTED_SLOTS_HEADER } from "../server/headers.js";
3
- import { isDangerousScheme } from "./url-safety.js";
3
+ import { assertSafeNavigationUrl } from "./url-safety.js";
4
4
  import { AppElementsWire } from "../server/app-elements-wire.js";
5
+ import { APP_RSC_RENDER_MODE_PREFETCH_LOADING_SHELL } from "../server/app-rsc-render-mode.js";
5
6
  import "../server/app-elements.js";
6
- import { toSameOriginPath, withBasePath } from "./url-utils.js";
7
+ import { withBasePath } from "./url-utils.js";
8
+ import { isBotUserAgent } from "../utils/html-limited-bots.js";
7
9
  import { createRscRequestHeaders, createRscRequestUrl } from "../server/app-rsc-cache-busting.js";
8
10
  import { hasAppNavigationRuntime } from "../client/navigation-runtime.js";
9
11
  import { getMountedSlotsHeader, getPrefetchInterceptionContext, getPrefetchedUrls, hasPrefetchCacheEntryForNavigation, navigateClientSide, prefetchRscResponse } from "./navigation.js";
@@ -37,18 +39,13 @@ const DISALLOWED_FORM_PROPS = [
37
39
  const SUPPORTED_FORM_ENCTYPE = "application/x-www-form-urlencoded";
38
40
  const SUPPORTED_FORM_METHOD = "GET";
39
41
  const SUPPORTED_FORM_TARGET = "_self";
40
- function isSafeAction(action) {
41
- if (isDangerousScheme(action)) return false;
42
- if (action.startsWith("//")) return false;
43
- if (/^https?:\/\//i.test(action)) {
44
- if (typeof window !== "undefined") try {
45
- return new URL(action).origin === window.location.origin;
46
- } catch {
47
- return false;
48
- }
42
+ function isPrefetchableAction(action) {
43
+ try {
44
+ const actionUrl = new URL(action, window.location.href);
45
+ return (actionUrl.protocol === "http:" || actionUrl.protocol === "https:") && actionUrl.origin === window.location.origin;
46
+ } catch {
49
47
  return false;
50
48
  }
51
- return true;
52
49
  }
53
50
  function getSubmitter(nativeEvent) {
54
51
  const submitter = nativeEvent && typeof nativeEvent === "object" && "submitter" in nativeEvent && nativeEvent.submitter instanceof Element ? nativeEvent.submitter : null;
@@ -103,7 +100,7 @@ function createFormSubmitDestinationUrl(action, form, submitter) {
103
100
  if (process.env.NODE_ENV !== "production") console.warn("<Form> only supports file inputs if `action` is a function. File inputs cannot be used if `action` is a string, because files cannot be encoded as search params.");
104
101
  targetUrl.searchParams.append(name, value.name);
105
102
  } else targetUrl.searchParams.append(name, value);
106
- return toSameOriginPath(targetUrl.href) ?? targetUrl.href;
103
+ return targetUrl.href;
107
104
  }
108
105
  function buildFormData(form, submitter) {
109
106
  if (!submitter) return new FormData(form);
@@ -137,7 +134,7 @@ const Form = forwardRef(function Form(props, ref) {
137
134
  useEffect(() => {
138
135
  if (typeof action !== "string") return;
139
136
  if (prefetch === false || process.env.NODE_ENV !== "production") return;
140
- if (!isSafeAction(action)) return;
137
+ if (!isPrefetchableAction(actionHref)) return;
141
138
  if (!hasAppNavigationRuntime()) return;
142
139
  const node = formRef.current;
143
140
  if (!node) return;
@@ -145,9 +142,13 @@ const Form = forwardRef(function Form(props, ref) {
145
142
  const observer = new IntersectionObserver((entries) => {
146
143
  for (const entry of entries) if (entry.isIntersecting || entry.intersectionRatio > 0) {
147
144
  (async () => {
145
+ if (isBotUserAgent(window.navigator?.userAgent ?? "")) return;
148
146
  const interceptionContext = getPrefetchInterceptionContext(actionHref);
149
147
  const mountedSlotsHeader = getMountedSlotsHeader();
150
- const headers = createRscRequestHeaders({ interceptionContext });
148
+ const headers = createRscRequestHeaders({
149
+ interceptionContext,
150
+ renderMode: APP_RSC_RENDER_MODE_PREFETCH_LOADING_SHELL
151
+ });
151
152
  if (mountedSlotsHeader) headers.set(VINEXT_MOUNTED_SLOTS_HEADER, mountedSlotsHeader);
152
153
  const rscUrl = await createRscRequestUrl(actionHref, headers);
153
154
  const cacheKey = AppElementsWire.encodeCacheKey(rscUrl, interceptionContext);
@@ -161,8 +162,8 @@ const Form = forwardRef(function Form(props, ref) {
161
162
  priority: "low",
162
163
  purpose: "prefetch"
163
164
  }), interceptionContext, mountedSlotsHeader, void 0, {
164
- cacheForNavigation: true,
165
- optimisticRouteShell: false
165
+ cacheForNavigation: false,
166
+ optimisticRouteShell: true
166
167
  });
167
168
  })();
168
169
  observer.unobserve(node);
@@ -183,15 +184,7 @@ const Form = forwardRef(function Form(props, ref) {
183
184
  onSubmit,
184
185
  ...cleanRest
185
186
  });
186
- if (!isSafeAction(action)) {
187
- if (process.env.NODE_ENV !== "production") console.warn(`<Form> blocked unsafe action: ${action}`);
188
- return /* @__PURE__ */ jsx("form", {
189
- ref: setRefs,
190
- onSubmit,
191
- ...cleanRest
192
- });
193
- }
194
- async function handleSubmit(e) {
187
+ function handleSubmit(e) {
195
188
  if (onSubmit) {
196
189
  onSubmit(e);
197
190
  if (e.defaultPrevented) return;
@@ -204,23 +197,24 @@ const Form = forwardRef(function Form(props, ref) {
204
197
  }
205
198
  const effectiveAction = getEffectiveAction(submitter, actionHref);
206
199
  if (process.env.NODE_ENV !== "production" && submitter?.getAttribute("formaction") !== null) checkFormActionUrl(effectiveAction, "formAction");
207
- if (!isSafeAction(effectiveAction)) {
208
- if (process.env.NODE_ENV !== "production") console.warn(`<Form> blocked unsafe action: ${effectiveAction}`);
209
- e.preventDefault();
210
- return;
211
- }
212
- e.preventDefault();
213
200
  const url = createFormSubmitDestinationUrl(effectiveAction, e.currentTarget, submitter);
214
- if (hasAppNavigationRuntime()) await navigateClientSide(url, replace ? "replace" : "push", scroll);
215
- else try {
216
- const Router = (await import("./router.js")).default;
217
- if (replace) await Router.replace(url, void 0, { scroll });
218
- else await Router.push(url, void 0, { scroll });
219
- } catch {
220
- if (replace) window.history.replaceState({}, "", url);
221
- else window.history.pushState({}, "", url);
222
- window.dispatchEvent(new PopStateEvent("popstate"));
223
- if (scroll) window.scrollTo(0, 0);
201
+ e.preventDefault();
202
+ if (hasAppNavigationRuntime()) {
203
+ assertSafeNavigationUrl(url);
204
+ navigateClientSide(url, replace ? "replace" : "push", scroll);
205
+ } else {
206
+ assertSafeNavigationUrl(url);
207
+ (async () => {
208
+ let Router;
209
+ try {
210
+ Router = (await import("./router.js")).default;
211
+ if (replace) await Router.replace(url, void 0, { scroll });
212
+ else await Router.push(url, void 0, { scroll });
213
+ } catch {
214
+ if (replace) window.location.replace(url);
215
+ else window.location.assign(url);
216
+ }
217
+ })();
224
218
  }
225
219
  }
226
220
  return /* @__PURE__ */ jsx("form", {
@@ -233,4 +227,4 @@ const Form = forwardRef(function Form(props, ref) {
233
227
  });
234
228
  });
235
229
  //#endregion
236
- export { Form as default, useActionState };
230
+ export { createFormSubmitDestinationUrl, Form as default, useActionState };
@@ -179,6 +179,12 @@ declare function getAndClearPendingCookies(): string[];
179
179
  */
180
180
  declare function getDraftModeCookieHeader(): string | null;
181
181
  declare function isDraftModeRequest(request: Request, draftModeSecret: string): boolean;
182
+ /**
183
+ * Read the active request's draft-mode state without recording request API usage.
184
+ * Internal cache implementations use this to bypass persistent reads and writes,
185
+ * matching Next.js's request-level `workStore.isDraftMode` guard.
186
+ */
187
+ declare function isDraftModeEnabled(): boolean;
182
188
  type DraftModeResult = {
183
189
  readonly isEnabled: boolean;
184
190
  enable(): void;
@@ -252,4 +258,4 @@ declare class RequestCookies {
252
258
  toString(): string;
253
259
  }
254
260
  //#endregion
255
- export { HeadersAccessPhase, HeadersContext, type RequestCookies, VinextHeadersShimState, applyMiddlewareRequestHeaders, consumeDynamicUsage, consumeInvalidDynamicUsageError, consumeRenderRequestApiUsage, cookies, draftMode, getAndClearPendingCookies, getDraftModeCookieHeader, getHeadersAccessPhase, getHeadersContext, headers, headersContextFromRequest, isDraftModeRequest, markDynamicUsage, markRenderRequestApiUsage, peekDynamicUsage, peekRenderRequestApiUsage, runWithConnectionProbe, runWithHeadersContext, setHeadersAccessPhase, setHeadersContext, suspendConnectionProbe, throwIfInsideCacheScope, throwIfStaticGenerationAccessError };
261
+ export { HeadersAccessPhase, HeadersContext, type RequestCookies, VinextHeadersShimState, applyMiddlewareRequestHeaders, consumeDynamicUsage, consumeInvalidDynamicUsageError, consumeRenderRequestApiUsage, cookies, draftMode, getAndClearPendingCookies, getDraftModeCookieHeader, getHeadersAccessPhase, getHeadersContext, headers, headersContextFromRequest, isDraftModeEnabled, isDraftModeRequest, markDynamicUsage, markRenderRequestApiUsage, peekDynamicUsage, peekRenderRequestApiUsage, runWithConnectionProbe, runWithHeadersContext, setHeadersAccessPhase, setHeadersContext, suspendConnectionProbe, throwIfInsideCacheScope, throwIfStaticGenerationAccessError };
@@ -1,7 +1,8 @@
1
1
  import { getOrCreateAls } from "./internal/als-registry.js";
2
2
  import { getRequestContext, isInsideUnifiedScope, runWithUnifiedStateMutation } from "./unified-request-context.js";
3
- import { FLIGHT_HEADERS, MIDDLEWARE_SET_COOKIE_HEADER, NEXT_HTML_REQUEST_ID_HEADER, NEXT_REQUEST_ID_HEADER } from "../server/headers.js";
4
- import { buildRequestHeadersFromMiddlewareResponse } from "../server/middleware-request-headers.js";
3
+ import { MIDDLEWARE_SET_COOKIE_HEADER } from "../utils/protocol-headers.js";
4
+ import { FLIGHT_HEADERS, NEXT_HTML_REQUEST_ID_HEADER, NEXT_REQUEST_ID_HEADER } from "../server/headers.js";
5
+ import { buildRequestHeadersFromMiddlewareResponse } from "../utils/middleware-request-headers.js";
5
6
  import { serializeSetCookie, validateCookieAttributeValue, validateCookieName } from "./internal/cookie-serialize.js";
6
7
  import { parseEdgeRequestCookieHeader } from "../utils/parse-cookie.js";
7
8
  import { createPprFallbackShellSuspensePromise } from "./ppr-fallback-shell.js";
@@ -609,6 +610,19 @@ function isDraftModeRequest(request, draftModeSecret) {
609
610
  if (!cookieHeader) return false;
610
611
  return parseEdgeRequestCookieHeader(cookieHeader).get(DRAFT_MODE_COOKIE) === validateDraftModeSecret(draftModeSecret);
611
612
  }
613
+ /**
614
+ * Read the active request's draft-mode state without recording request API usage.
615
+ * Internal cache implementations use this to bypass persistent reads and writes,
616
+ * matching Next.js's request-level `workStore.isDraftMode` guard.
617
+ */
618
+ function isDraftModeEnabled() {
619
+ const context = _getState().headersContext;
620
+ if (!context) return false;
621
+ if (context.draftModeEnabled !== void 0) return context.draftModeEnabled;
622
+ const secret = context.draftModeSecret;
623
+ if (secret === void 0) return false;
624
+ return context.cookies.get(DRAFT_MODE_COOKIE) === validateDraftModeSecret(secret);
625
+ }
612
626
  function draftModeCookieAttributes() {
613
627
  if (typeof process !== "undefined" && process.env?.NODE_ENV === "development") return "Path=/; HttpOnly; SameSite=Lax";
614
628
  return "Path=/; HttpOnly; SameSite=None; Secure";
@@ -762,4 +776,4 @@ var RequestCookies = class {
762
776
  }
763
777
  };
764
778
  //#endregion
765
- export { applyMiddlewareRequestHeaders, consumeDynamicUsage, consumeInvalidDynamicUsageError, consumeRenderRequestApiUsage, cookies, draftMode, getAndClearPendingCookies, getDraftModeCookieHeader, getHeadersAccessPhase, getHeadersContext, headers, headersContextFromRequest, isDraftModeRequest, markDynamicUsage, markRenderRequestApiUsage, peekDynamicUsage, peekRenderRequestApiUsage, runWithConnectionProbe, runWithHeadersContext, setHeadersAccessPhase, setHeadersContext, suspendConnectionProbe, throwIfInsideCacheScope, throwIfStaticGenerationAccessError };
779
+ export { applyMiddlewareRequestHeaders, consumeDynamicUsage, consumeInvalidDynamicUsageError, consumeRenderRequestApiUsage, cookies, draftMode, getAndClearPendingCookies, getDraftModeCookieHeader, getHeadersAccessPhase, getHeadersContext, headers, headersContextFromRequest, isDraftModeEnabled, isDraftModeRequest, markDynamicUsage, markRenderRequestApiUsage, peekDynamicUsage, peekRenderRequestApiUsage, runWithConnectionProbe, runWithHeadersContext, setHeadersAccessPhase, setHeadersContext, suspendConnectionProbe, throwIfInsideCacheScope, throwIfStaticGenerationAccessError };