vinext 1.0.1 → 1.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 (334) hide show
  1. package/README.md +93 -10
  2. package/dist/build/app-page-static-eligibility.d.ts +15 -0
  3. package/dist/build/app-page-static-eligibility.js +82 -0
  4. package/dist/build/client-build-config.d.ts +10 -0
  5. package/dist/build/client-build-config.js +18 -2
  6. package/dist/build/pages-client-assets-module.d.ts +8 -0
  7. package/dist/build/pages-client-assets-module.js +21 -1
  8. package/dist/build/prerender-paths.js +8 -81
  9. package/dist/build/prerender.js +33 -8
  10. package/dist/build/run-prerender.js +1 -1
  11. package/dist/build/server-manifest.d.ts +7 -0
  12. package/dist/build/server-manifest.js +11 -1
  13. package/dist/build/ssr-manifest.d.ts +2 -0
  14. package/dist/build/ssr-manifest.js +6 -2
  15. package/dist/cache/cache-adapters-virtual.d.ts +7 -1
  16. package/dist/cache/cache-adapters-virtual.js +3 -3
  17. package/dist/check.js +7 -6
  18. package/dist/cli.js +2 -1
  19. package/dist/client/client-redirect-matcher.d.ts +14 -0
  20. package/dist/client/client-redirect-matcher.js +37 -0
  21. package/dist/client/client-redirects.d.ts +27 -0
  22. package/dist/client/client-redirects.js +28 -0
  23. package/dist/client/client-rewrites.d.ts +2 -1
  24. package/dist/client/client-rewrites.js +1 -1
  25. package/dist/client/navigation-runtime.d.ts +11 -0
  26. package/dist/client/navigation-runtime.js +1 -1
  27. package/dist/config/config-matchers.d.ts +26 -11
  28. package/dist/config/config-matchers.js +81 -82
  29. package/dist/config/destination-params.d.ts +47 -0
  30. package/dist/config/destination-params.js +116 -0
  31. package/dist/config/next-config.d.ts +14 -0
  32. package/dist/config/next-config.js +21 -3
  33. package/dist/entries/app-rsc-entry.d.ts +6 -0
  34. package/dist/entries/app-rsc-entry.js +84 -49
  35. package/dist/entries/pages-client-entry.js +3 -1
  36. package/dist/entries/pages-server-entry.js +13 -37
  37. package/dist/index.d.ts +7 -2
  38. package/dist/index.js +193 -73
  39. package/dist/init-cloudflare.d.ts +9 -0
  40. package/dist/init-cloudflare.js +107 -31
  41. package/dist/init-platform.d.ts +4 -0
  42. package/dist/init-platform.js +27 -2
  43. package/dist/init.d.ts +1 -0
  44. package/dist/init.js +67 -3
  45. package/dist/plugins/ast-scope.d.ts +7 -0
  46. package/dist/plugins/ast-scope.js +59 -3
  47. package/dist/plugins/cache-flight-codec.d.ts +19 -0
  48. package/dist/plugins/cache-flight-codec.js +68 -0
  49. package/dist/plugins/commonjs-esm-facade.d.ts +35 -0
  50. package/dist/plugins/commonjs-esm-facade.js +80 -0
  51. package/dist/plugins/dynamic-preload-metadata.d.ts +1 -1
  52. package/dist/plugins/dynamic-preload-metadata.js +9 -8
  53. package/dist/plugins/fonts.d.ts +8 -11
  54. package/dist/plugins/fonts.js +71 -34
  55. package/dist/plugins/ignore-dynamic-requests.d.ts +1 -1
  56. package/dist/plugins/ignore-dynamic-requests.js +3 -4
  57. package/dist/plugins/middleware-server-only.d.ts +5 -4
  58. package/dist/plugins/middleware-server-only.js +8 -5
  59. package/dist/plugins/pages-node-externals.js +1 -1
  60. package/dist/plugins/rsc-scan-glob-imports.d.ts +19 -0
  61. package/dist/plugins/rsc-scan-glob-imports.js +50 -0
  62. package/dist/plugins/strip-server-exports.js +262 -98
  63. package/dist/plugins/transform-result.d.ts +9 -5
  64. package/dist/plugins/transitive-externals.js +1 -1
  65. package/dist/plugins/typeof-window.d.ts +2 -2
  66. package/dist/plugins/use-cache-callable.js +8 -2
  67. package/dist/plugins/worker-server-only-imports.d.ts +20 -0
  68. package/dist/plugins/worker-server-only-imports.js +31 -0
  69. package/dist/plugins/worker-use-server.d.ts +25 -0
  70. package/dist/plugins/worker-use-server.js +129 -0
  71. package/dist/routing/file-matcher.d.ts +1 -0
  72. package/dist/routing/file-matcher.js +1 -1
  73. package/dist/server/api-handler.d.ts +1 -0
  74. package/dist/server/api-handler.js +19 -8
  75. package/dist/server/app-browser-action-result.d.ts +1 -1
  76. package/dist/server/app-browser-action-result.js +9 -2
  77. package/dist/server/app-browser-entry.js +11 -7
  78. package/dist/server/app-browser-history-controller.d.ts +2 -0
  79. package/dist/server/app-browser-history-controller.js +8 -0
  80. package/dist/server/app-browser-interception-context.js +26 -2
  81. package/dist/server/app-browser-navigation-controller.d.ts +7 -1
  82. package/dist/server/app-browser-navigation-controller.js +94 -11
  83. package/dist/server/app-browser-server-action-client.js +1 -1
  84. package/dist/server/app-fallback-renderer.d.ts +2 -0
  85. package/dist/server/app-fallback-renderer.js +1 -0
  86. package/dist/server/app-history-state.d.ts +3 -0
  87. package/dist/server/app-history-state.js +7 -0
  88. package/dist/server/app-middleware.d.ts +11 -0
  89. package/dist/server/app-middleware.js +19 -3
  90. package/dist/server/app-optimistic-routing.js +1 -1
  91. package/dist/server/app-page-boundary-render.d.ts +5 -0
  92. package/dist/server/app-page-boundary-render.js +6 -4
  93. package/dist/server/app-page-cache-finalizer.d.ts +11 -0
  94. package/dist/server/app-page-cache-finalizer.js +41 -7
  95. package/dist/server/app-page-cache-render.d.ts +18 -0
  96. package/dist/server/app-page-cache-render.js +63 -43
  97. package/dist/server/app-page-cache.d.ts +6 -1
  98. package/dist/server/app-page-cache.js +28 -8
  99. package/dist/server/app-page-dispatch.d.ts +12 -2
  100. package/dist/server/app-page-dispatch.js +51 -33
  101. package/dist/server/app-page-element-builder.d.ts +7 -0
  102. package/dist/server/app-page-element-builder.js +27 -42
  103. package/dist/server/app-page-execution.d.ts +15 -12
  104. package/dist/server/app-page-execution.js +30 -40
  105. package/dist/server/app-page-head.d.ts +5 -0
  106. package/dist/server/app-page-head.js +9 -3
  107. package/dist/server/app-page-ppr-runtime.js +1 -1
  108. package/dist/server/app-page-probe.d.ts +0 -109
  109. package/dist/server/app-page-probe.js +3 -136
  110. package/dist/server/app-page-render-identity.d.ts +0 -1
  111. package/dist/server/app-page-render-identity.js +1 -1
  112. package/dist/server/app-page-render-observation.js +3 -3
  113. package/dist/server/app-page-render.d.ts +13 -5
  114. package/dist/server/app-page-render.js +219 -119
  115. package/dist/server/app-page-request.d.ts +0 -1
  116. package/dist/server/app-page-request.js +54 -17
  117. package/dist/server/app-page-response.d.ts +4 -3
  118. package/dist/server/app-page-response.js +4 -3
  119. package/dist/server/app-page-route-wiring.d.ts +17 -5
  120. package/dist/server/app-page-route-wiring.js +57 -35
  121. package/dist/server/app-page-rsc-render-status.d.ts +48 -0
  122. package/dist/server/app-page-rsc-render-status.js +54 -0
  123. package/dist/server/app-page-stream.d.ts +15 -8
  124. package/dist/server/app-page-stream.js +6 -0
  125. package/dist/server/app-pages-bridge.d.ts +1 -1
  126. package/dist/server/app-pages-bridge.js +2 -3
  127. package/dist/server/app-prerender-endpoints.js +9 -6
  128. package/dist/server/app-request-stage-dispatch.js +7 -3
  129. package/dist/server/app-request-stage-independent-entry.js +29 -9
  130. package/dist/server/app-response-header-provenance.d.ts +2 -0
  131. package/dist/server/app-response-header-provenance.js +10 -4
  132. package/dist/server/app-response-stage-entry.js +10 -2
  133. package/dist/server/app-route-handler-cache.d.ts +1 -0
  134. package/dist/server/app-route-handler-cache.js +1 -0
  135. package/dist/server/app-route-handler-dispatch.d.ts +1 -0
  136. package/dist/server/app-route-handler-dispatch.js +6 -3
  137. package/dist/server/app-route-handler-execution.d.ts +1 -0
  138. package/dist/server/app-route-handler-execution.js +1 -0
  139. package/dist/server/app-route-handler-runtime.d.ts +4 -1
  140. package/dist/server/app-route-handler-runtime.js +45 -24
  141. package/dist/server/app-router-entry.js +27 -8
  142. package/dist/server/app-rsc-cache-busting.js +1 -1
  143. package/dist/server/app-rsc-errors.js +20 -16
  144. package/dist/server/app-rsc-handler.d.ts +11 -0
  145. package/dist/server/app-rsc-handler.js +291 -125
  146. package/dist/server/app-rsc-request-normalization.d.ts +3 -1
  147. package/dist/server/app-rsc-request-normalization.js +4 -2
  148. package/dist/server/app-rsc-response-stage.d.ts +1 -1
  149. package/dist/server/app-rsc-response-stage.js +10 -6
  150. package/dist/server/app-rsc-route-matching.d.ts +9 -1
  151. package/dist/server/app-rsc-route-matching.js +36 -19
  152. package/dist/server/app-segment-config.d.ts +2 -1
  153. package/dist/server/app-server-action-execution.d.ts +2 -1
  154. package/dist/server/app-server-action-execution.js +62 -23
  155. package/dist/server/app-ssr-entry.d.ts +3 -2
  156. package/dist/server/app-ssr-entry.js +8 -5
  157. package/dist/server/app-ssr-stream.d.ts +6 -1
  158. package/dist/server/app-ssr-stream.js +34 -15
  159. package/dist/server/app-worker-stages.d.ts +7 -2
  160. package/dist/server/app-worker-stages.js +4 -4
  161. package/dist/server/cacheability-request.js +11 -7
  162. package/dist/server/client-build-files.d.ts +16 -0
  163. package/dist/server/client-build-files.js +36 -0
  164. package/dist/server/client-reuse-manifest.js +1 -1
  165. package/dist/server/config-headers.js +2 -0
  166. package/dist/server/dev-server.js +50 -29
  167. package/dist/server/dev-stack-sourcemap.js +18 -23
  168. package/dist/server/document-initial-head.d.ts +0 -11
  169. package/dist/server/document-initial-head.js +1 -1
  170. package/dist/server/forwarded-middleware-context.d.ts +5 -0
  171. package/dist/server/forwarded-middleware-context.js +22 -0
  172. package/dist/server/headers.d.ts +18 -1
  173. package/dist/server/headers.js +19 -2
  174. package/dist/server/http-conditional.d.ts +11 -0
  175. package/dist/server/http-conditional.js +10 -1
  176. package/dist/server/http-error-responses.d.ts +1 -1
  177. package/dist/server/image-optimization.d.ts +54 -0
  178. package/dist/server/image-optimization.js +118 -9
  179. package/dist/server/isr-cache.d.ts +10 -0
  180. package/dist/server/isr-cache.js +43 -8
  181. package/dist/server/metadata-route-response.js +9 -8
  182. package/dist/server/middleware-matcher-pattern.js +8 -4
  183. package/dist/server/middleware-matcher.d.ts +2 -0
  184. package/dist/server/middleware-matcher.js +23 -2
  185. package/dist/server/middleware-response-headers.js +2 -0
  186. package/dist/server/middleware-runtime.d.ts +13 -0
  187. package/dist/server/middleware-runtime.js +33 -20
  188. package/dist/server/middleware.d.ts +1 -1
  189. package/dist/server/middleware.js +3 -1
  190. package/dist/server/multi-stage.d.ts +19 -0
  191. package/dist/server/navigation-planner.js +1 -1
  192. package/dist/server/node-response-signal.d.ts +16 -0
  193. package/dist/server/node-response-signal.js +26 -0
  194. package/dist/server/normalize-path.d.ts +0 -13
  195. package/dist/server/normalize-path.js +1 -34
  196. package/dist/server/open-redirect.d.ts +47 -0
  197. package/dist/server/open-redirect.js +74 -1
  198. package/dist/server/pages-api-route.d.ts +3 -2
  199. package/dist/server/pages-api-route.js +4 -3
  200. package/dist/server/pages-cache-tag.d.ts +12 -0
  201. package/dist/server/pages-cache-tag.js +19 -0
  202. package/dist/server/pages-client-assets.d.ts +2 -0
  203. package/dist/server/pages-data-route.d.ts +10 -0
  204. package/dist/server/pages-data-route.js +19 -2
  205. package/dist/server/pages-document-asset-props.d.ts +5 -1
  206. package/dist/server/pages-document-asset-props.js +13 -5
  207. package/dist/server/pages-document-splice.d.ts +19 -0
  208. package/dist/server/pages-document-splice.js +55 -0
  209. package/dist/server/pages-i18n.d.ts +12 -1
  210. package/dist/server/pages-i18n.js +18 -4
  211. package/dist/server/pages-node-compat.d.ts +16 -5
  212. package/dist/server/pages-node-compat.js +20 -12
  213. package/dist/server/pages-page-data.d.ts +32 -24
  214. package/dist/server/pages-page-data.js +50 -120
  215. package/dist/server/pages-page-handler.d.ts +0 -6
  216. package/dist/server/pages-page-handler.js +209 -130
  217. package/dist/server/pages-page-response.d.ts +12 -6
  218. package/dist/server/pages-page-response.js +41 -34
  219. package/dist/server/pages-request-pipeline.d.ts +10 -2
  220. package/dist/server/pages-request-pipeline.js +37 -18
  221. package/dist/server/pages-request-stage-entry.d.ts +6 -0
  222. package/dist/server/pages-request-stage-entry.js +79 -16
  223. package/dist/server/pages-response-stage-entry.js +4 -0
  224. package/dist/server/pages-revalidate.js +1 -1
  225. package/dist/server/pages-router-entry.js +4 -3
  226. package/dist/server/prerender-manifest.d.ts +3 -3
  227. package/dist/server/prerender-manifest.js +4 -3
  228. package/dist/server/prerender-work-unit-setup.js +4 -0
  229. package/dist/server/prod-server.d.ts +20 -7
  230. package/dist/server/prod-server.js +343 -129
  231. package/dist/server/proper-error.d.ts +4 -0
  232. package/dist/server/proper-error.js +31 -0
  233. package/dist/server/request-pipeline.d.ts +24 -9
  234. package/dist/server/request-pipeline.js +24 -9
  235. package/dist/server/response-compression.d.ts +43 -0
  236. package/dist/server/response-compression.js +111 -0
  237. package/dist/server/revalidation-request.d.ts +1 -0
  238. package/dist/server/revalidation-request.js +1 -1
  239. package/dist/server/rsc-stream-hints.js +31 -2
  240. package/dist/server/seed-cache.d.ts +1 -0
  241. package/dist/server/seed-cache.js +15 -11
  242. package/dist/server/server-reference-loader.d.ts +4 -0
  243. package/dist/server/server-reference-loader.js +29 -0
  244. package/dist/server/socket-error-backstop.d.ts +23 -1
  245. package/dist/server/socket-error-backstop.js +69 -17
  246. package/dist/server/static-file-signal.d.ts +15 -4
  247. package/dist/server/static-file-signal.js +46 -12
  248. package/dist/server/worker-image-optimization.d.ts +34 -0
  249. package/dist/server/worker-image-optimization.js +86 -0
  250. package/dist/server/worker-stages.d.ts +1 -1
  251. package/dist/server/worker-stages.js +2 -2
  252. package/dist/server/worker-utils.d.ts +8 -3
  253. package/dist/server/worker-utils.js +12 -7
  254. package/dist/shims/app-router-scroll.js +4 -1
  255. package/dist/shims/app-router-tree-context.d.ts +5 -0
  256. package/dist/shims/app-router-tree-context.js +27 -0
  257. package/dist/shims/cache-adapter-instantiate.d.ts +50 -0
  258. package/dist/shims/cache-adapter-instantiate.js +118 -0
  259. package/dist/shims/cache-callable-runtime.d.ts +6 -42
  260. package/dist/shims/cache-callable-runtime.js +65 -174
  261. package/dist/shims/cache-flight-arguments.d.ts +22 -0
  262. package/dist/shims/cache-flight-arguments.js +56 -0
  263. package/dist/shims/cache-handler.js +1 -9
  264. package/dist/shims/cache-request-state.d.ts +15 -0
  265. package/dist/shims/cache-request-state.js +31 -8
  266. package/dist/shims/cache-runtime.d.ts +12 -20
  267. package/dist/shims/cache-runtime.js +166 -225
  268. package/dist/shims/cache.d.ts +4 -4
  269. package/dist/shims/cache.js +44 -16
  270. package/dist/shims/cacheability-classification.d.ts +7 -0
  271. package/dist/shims/cdn-cache.d.ts +8 -0
  272. package/dist/shims/cdn-cache.js +17 -1
  273. package/dist/shims/disable-smooth-scroll.d.ts +3 -0
  274. package/dist/shims/disable-smooth-scroll.js +36 -0
  275. package/dist/shims/document-placeholders.d.ts +19 -0
  276. package/dist/shims/document-placeholders.js +45 -0
  277. package/dist/shims/document.js +21 -5
  278. package/dist/shims/dynamic-preload-chunks.d.ts +1 -0
  279. package/dist/shims/dynamic-preload-chunks.js +13 -9
  280. package/dist/shims/dynamic.d.ts +1 -1
  281. package/dist/shims/dynamic.js +60 -8
  282. package/dist/shims/error-boundary-navigation.d.ts +7 -0
  283. package/dist/shims/error-boundary-navigation.js +19 -1
  284. package/dist/shims/error-boundary.d.ts +10 -10
  285. package/dist/shims/error-boundary.js +26 -7
  286. package/dist/shims/fetch-cache-state.d.ts +66 -0
  287. package/dist/shims/fetch-cache-state.js +92 -0
  288. package/dist/shims/fetch-cache.d.ts +3 -61
  289. package/dist/shims/fetch-cache.js +161 -108
  290. package/dist/shims/form.js +1 -1
  291. package/dist/shims/head.d.ts +10 -6
  292. package/dist/shims/head.js +15 -13
  293. package/dist/shims/headers.d.ts +13 -0
  294. package/dist/shims/headers.js +47 -4
  295. package/dist/shims/image.js +2 -1
  296. package/dist/shims/internal/app-page-props-cache-key.d.ts +5 -2
  297. package/dist/shims/internal/app-page-props-cache-key.js +24 -15
  298. package/dist/shims/internal/headers-state.d.ts +0 -1
  299. package/dist/shims/internal/work-store-scope.d.ts +5 -0
  300. package/dist/shims/internal/work-store-scope.js +24 -0
  301. package/dist/shims/metadata.js +3 -3
  302. package/dist/shims/navigation-errors.d.ts +6 -0
  303. package/dist/shims/navigation-errors.js +11 -1
  304. package/dist/shims/navigation.d.ts +7 -0
  305. package/dist/shims/navigation.js +45 -9
  306. package/dist/shims/request-context.d.ts +11 -0
  307. package/dist/shims/request-state-types.d.ts +2 -1
  308. package/dist/shims/router.js +12 -20
  309. package/dist/shims/server.d.ts +16 -0
  310. package/dist/shims/server.js +24 -4
  311. package/dist/shims/thenable-params.d.ts +4 -0
  312. package/dist/shims/thenable-params.js +25 -3
  313. package/dist/shims/unified-request-context.d.ts +1 -1
  314. package/dist/shims/unified-request-context.js +1 -0
  315. package/dist/shims/url-utils.d.ts +2 -0
  316. package/dist/shims/url-utils.js +3 -1
  317. package/dist/utils/client-runtime-metadata.js +1 -1
  318. package/dist/utils/hash.d.ts +7 -0
  319. package/dist/utils/hash.js +11 -1
  320. package/dist/utils/mdx-scan.d.ts +5 -0
  321. package/dist/utils/mdx-scan.js +8 -1
  322. package/dist/utils/package-name.d.ts +6 -0
  323. package/dist/utils/package-name.js +12 -1
  324. package/dist/utils/plugin-rsc-version.d.ts +4 -0
  325. package/dist/utils/plugin-rsc-version.js +15 -0
  326. package/dist/utils/prerender-output-paths.js +15 -4
  327. package/dist/utils/public-file-path.d.ts +10 -2
  328. package/dist/utils/public-file-path.js +13 -9
  329. package/dist/utils/public-routes.js +2 -2
  330. package/dist/utils/react-version.d.ts +3 -0
  331. package/dist/utils/react-version.js +1 -1
  332. package/dist/utils/regex-safety.d.ts +10 -0
  333. package/dist/utils/regex-safety.js +70 -18
  334. package/package.json +9 -5
@@ -4,17 +4,17 @@ import { normalizePathnameForRouteMatch } from "../routing/utils.js";
4
4
  import { NEXTJS_CACHE_HEADER, NEXTJS_DEPLOYMENT_ID_HEADER } from "./headers.js";
5
5
  import { isDangerousScheme } from "../shims/url-safety.js";
6
6
  import { extractLocaleFromUrl } from "./pages-i18n.js";
7
+ import { buildNextDataPropsJsonResponse } from "./pages-data-route.js";
7
8
  import { recordRouteCacheability } from "../shims/cacheability-classification.js";
8
9
  import { applyCdnResponseHeaders } from "./cache-control.js";
9
10
  import { buildMissIsrCacheControl, decideIsr } from "./isr-decision.js";
10
- import { buildPagesCacheValue, isrCacheControl } from "./isr-cache.js";
11
- import { encodeCacheTag } from "../utils/encode-cache-tag.js";
11
+ import { isrCacheControl } from "./isr-cache.js";
12
12
  import { normalizeStaticPathname } from "../routing/route-pattern.js";
13
13
  import { buildCacheStateHeaders } from "./cache-headers.js";
14
- import { matchesIfNoneMatch } from "./http-conditional.js";
15
- import { buildPagesNextDataScript, generatePagesETag, isPagesStreamingBot, requestsNoCache } from "./pages-page-response.js";
14
+ import { pagesPathCacheTag } from "./pages-cache-tag.js";
15
+ import { isPageNotModified } from "./http-conditional.js";
16
+ import { generatePagesETag, isPagesStreamingBot, rendersPagesNotModified } from "./pages-page-response.js";
16
17
  import { createPagesGetInitialPropsRouter, hasPagesGetInitialProps, isResponseSent, loadPagesGetInitialProps } from "./pages-get-initial-props.js";
17
- import { buildNextDataPropsJsonResponse } from "./pages-data-route.js";
18
18
  import { isSerializableProps } from "./pages-serializable-props.js";
19
19
  import { tracePagesData, tracePagesDocument } from "./pages-execution-tracing.js";
20
20
  //#region src/server/pages-page-data.ts
@@ -43,6 +43,16 @@ function assertPages404DoesNotReturnNotFound(routePattern, result) {
43
43
  * - packages/next/src/server/render.tsx (`metadata.cacheControl`)
44
44
  * - packages/next/src/server/route-modules/pages/pages-handler.ts
45
45
  */
46
+ /**
47
+ * Next.js renders a shared getStaticProps status page (/404, /500) for its own
48
+ * pathname, never for the request that reached it. Only the original
49
+ * request's trailing slash carries over under `trailingSlash`, read before
50
+ * rewrites and locale stripping.
51
+ * https://github.com/vercel/next.js/blob/canary/packages/next/src/server/route-modules/pages/pages-handler.ts
52
+ */
53
+ function resolvePagesStatusPageRenderPath(statusPathname, trailingSlash, requestPathname) {
54
+ return trailingSlash && requestPathname.endsWith("/") ? statusPathname + "/" : statusPathname;
55
+ }
46
56
  function resolvePagesRevalidateSeconds(result, routeUrl = "") {
47
57
  const revalidate = result.revalidate;
48
58
  if (revalidate === true) return 1;
@@ -103,14 +113,13 @@ function mergePagesNotFoundSourceHeaders(response, sourceHeaders) {
103
113
  });
104
114
  }
105
115
  function applyPagesTerminalMissHeaders(response, revalidateSeconds, isrCachePathname, expireSeconds) {
106
- const stem = isrCachePathname.endsWith("/") ? isrCachePathname.slice(0, -1) : isrCachePathname;
107
116
  recordRouteCacheability({
108
117
  cacheable: revalidateSeconds !== 0,
109
118
  cacheControl: buildMissIsrCacheControl(revalidateSeconds, expireSeconds)
110
119
  });
111
120
  applyCdnResponseHeaders(response.headers, {
112
121
  cacheControl: buildMissIsrCacheControl(revalidateSeconds, expireSeconds),
113
- tags: [encodeCacheTag(`_N_T_${stem || "/"}`)]
122
+ tags: [pagesPathCacheTag(isrCachePathname)]
114
123
  });
115
124
  for (const [name, value] of Object.entries(buildCacheStateHeaders("MISS"))) response.headers.set(name, value);
116
125
  return response;
@@ -216,7 +225,7 @@ async function loadPagesAppInitialRenderProps(options, getSharedReqRes) {
216
225
  defaultLocale: options.i18n.defaultLocale
217
226
  }
218
227
  });
219
- if (isResponseSent(res)) return {
228
+ if (isResponseSent(res) && typeof options.pageModule.getStaticProps !== "function") return {
220
229
  kind: "response",
221
230
  response: responsePromise
222
231
  };
@@ -367,7 +376,7 @@ function matchesPagesStaticPath(pathEntry, params, routeParams, routeUrl, i18n)
367
376
  const actual = params[key];
368
377
  if (Array.isArray(value)) {
369
378
  if (optional && value.length === 0 && actual === void 0) return true;
370
- return Array.isArray(actual) && value.join("/") === actual.join("/");
379
+ return Array.isArray(actual) && value.length === actual.length && actual.every((part, index) => part === value[index]);
371
380
  }
372
381
  return String(value) === String(actual);
373
382
  });
@@ -408,7 +417,11 @@ function finalizeCachedPagesResponse(response, options, html) {
408
417
  if (html !== void 0 && options.userAgent && isPagesStreamingBot(options.userAgent)) {
409
418
  const etag = generatePagesETag(html);
410
419
  response.headers.set("ETag", etag);
411
- if (!requestsNoCache(options.requestCacheControl) && options.ifNoneMatch && matchesIfNoneMatch(options.ifNoneMatch, etag)) response = new Response(null, {
420
+ if (isPageNotModified({
421
+ cacheControl: options.requestCacheControl,
422
+ ifModifiedSince: options.ifModifiedSince,
423
+ ifNoneMatch: options.ifNoneMatch
424
+ }, etag) && rendersPagesNotModified(response.status)) response = new Response(null, {
412
425
  status: 304,
413
426
  headers: response.headers
414
427
  });
@@ -418,92 +431,6 @@ function finalizeCachedPagesResponse(response, options, html) {
418
431
  response
419
432
  };
420
433
  }
421
- /**
422
- * Matches one serialized `next/head` tag. `getSSRHeadHTML()` stamps every tag
423
- * it emits with `data-next-head=""` (see `shims/head.ts`), which is the same
424
- * marker Next.js uses to reconcile the head on the client — so it is a stable
425
- * anchor for finding the collector's output inside an already-rendered shell.
426
- *
427
- * Raw-content tags are safe to match non-greedily: `headChildToHTML()` escapes
428
- * closing-tag sequences in `<style>`/`<script>` bodies, so the first `</style>`
429
- * encountered is always the real terminator.
430
- */
431
- const SSR_HEAD_TAG_PATTERN = /<(title|meta|link|style|script|base|noscript)\b[^>]*?\sdata-next-head=""[^>]*?(?:\/>|>[\s\S]*?<\/\1>)/g;
432
- /**
433
- * Matches a whole head element whose body may contain markup-looking text.
434
- * Script/style are raw-text elements, title is RCDATA, and noscript is raw
435
- * text while scripting is enabled. In all four, a literal `</head>` does not
436
- * close the document head. `headChildToHTML()` only escapes the element's own
437
- * closing sequence for script/style, while `dangerouslySetInnerHTML` may leave
438
- * `</head>` intact in any of them.
439
- */
440
- const HEAD_TEXT_ELEMENT_PATTERN = /<(script|style|title|noscript)\b[^>]*>[\s\S]*?<\/\1>/gi;
441
- /**
442
- * Replace the `next/head` region of a cached shell with a freshly collected
443
- * one.
444
- *
445
- * ISR regeneration re-renders the page body but reuses the cached shell, so
446
- * without this the `<head>` stays frozen at whatever the first cache-filling
447
- * render produced — a page whose `<title>`/meta derive from `getStaticProps`
448
- * data would serve an updated body under permanently stale metadata.
449
- *
450
- * The collector emits its tags as one contiguous run (`ssrHeadHTML` is
451
- * concatenated ahead of trace meta and `_document` styles in
452
- * `buildPagesShellHtml`), so replacing first-match-start through
453
- * last-match-end swaps exactly that run and leaves `_document`-owned head
454
- * markup either side of it untouched.
455
- *
456
- * Only the `next/head` run refreshes. `_document`-rendered head children and
457
- * CSS-in-JS `styles` still come from the cached shell, because regeneration
458
- * never re-renders `_document` — refreshing those means running the full
459
- * document pipeline on regeneration the way Next.js does.
460
- */
461
- function refreshCachedHeadTags(cachedHtml, freshHead) {
462
- if (!freshHead) return cachedHtml;
463
- const headEnd = cachedHtml.replace(HEAD_TEXT_ELEMENT_PATTERN, (element) => " ".repeat(element.length)).indexOf("</head>");
464
- if (headEnd < 0) return cachedHtml;
465
- const matches = [...cachedHtml.slice(0, headEnd).matchAll(SSR_HEAD_TAG_PATTERN)];
466
- const first = matches[0];
467
- const last = matches[matches.length - 1];
468
- if (!first || !last || first.index === void 0 || last.index === void 0) return cachedHtml;
469
- return cachedHtml.slice(0, first.index) + freshHead + cachedHtml.slice(last.index + last[0].length);
470
- }
471
- function rewritePagesCachedHtml(cachedHtml, freshBody, nextDataScript) {
472
- const bodyStart = cachedHtml.indexOf("<div id=\"__next\">");
473
- const contentStart = bodyStart >= 0 ? bodyStart + 17 : -1;
474
- const canonicalNextDataStart = cachedHtml.search(/<script\b(?=[^>]*\bid=["']__NEXT_DATA__["'])(?=[^>]*\btype=["']application\/json["'])[^>]*>/);
475
- const legacyNextDataStart = cachedHtml.indexOf("<script>window.__NEXT_DATA__");
476
- const nextDataStart = canonicalNextDataStart >= 0 ? canonicalNextDataStart : legacyNextDataStart;
477
- if (contentStart >= 0 && nextDataStart >= 0) {
478
- const region = cachedHtml.slice(contentStart, nextDataStart);
479
- const lastCloseDiv = region.lastIndexOf("</div>");
480
- const gap = lastCloseDiv >= 0 ? region.slice(lastCloseDiv + 6) : "";
481
- const nextDataEnd = cachedHtml.indexOf("<\/script>", nextDataStart) + 9;
482
- const tail = cachedHtml.slice(nextDataEnd);
483
- return cachedHtml.slice(0, contentStart) + freshBody + "</div>" + gap + nextDataScript + tail;
484
- }
485
- return "<!DOCTYPE html>\n<html>\n<head>\n</head>\n<body>\n <div id=\"__next\">" + freshBody + "</div>\n " + nextDataScript + "\n</body>\n</html>";
486
- }
487
- async function renderPagesIsrHtml(options) {
488
- const renderProps = options.props ?? { pageProps: options.pageProps };
489
- const collectHead = options.collectIsrHeadHTML;
490
- let freshHead = "";
491
- const freshBody = await options.renderIsrPassToStringAsync(options.createPageElement(renderProps), collectHead && (async () => {
492
- freshHead = collectHead();
493
- }));
494
- const nextDataScript = buildPagesNextDataScript({
495
- buildId: options.buildId,
496
- i18n: options.i18n,
497
- pageProps: options.pageProps,
498
- props: renderProps,
499
- params: options.params,
500
- routePattern: options.routePattern,
501
- safeJsonStringify: options.safeJsonStringify,
502
- nextData: options.nextData,
503
- vinext: options.vinext
504
- });
505
- return rewritePagesCachedHtml(refreshCachedHeadTags(options.cachedHtml, freshHead), freshBody, nextDataScript);
506
- }
507
434
  async function resolvePagesPageData(options) {
508
435
  const userFacingParams = options.route.isDynamic ? options.params : null;
509
436
  let isFallback = false;
@@ -515,13 +442,13 @@ async function resolvePagesPageData(options) {
515
442
  const value = cached?.value.value;
516
443
  if (cached && !cached.isStale && !cached.isExpired && value?.kind === "PAGES") return finalizeCachedPagesResponse(options.isDataReq ? applyCachedPagesRepresentationHeaders(buildNextDataPropsJsonResponse(normalizePagesRenderProps(value.pageData), options.safeJsonStringify, options.deploymentId ? { headers: { [NEXTJS_DEPLOYMENT_ID_HEADER]: options.deploymentId } } : void 0), "HIT", cached.value, options) : buildPagesCacheResponse(value.html, "HIT", options.fontLinkHeader, void 0, options.expireSeconds, cached.value.cacheControl, options.statusCode ?? value.status, value.headers), options, options.isDataReq ? void 0 : value.html);
517
444
  }
518
- let hasFreshPrerenderedEntry = false;
519
- if (options.hasPrerenderedPages && options.route.isDynamic && typeof options.pageModule.getStaticProps === "function" && typeof options.pageModule.getServerSideProps !== "function" && !options.isOnDemandRevalidate && previewData === false) {
445
+ let hasStoredEntry = options.regeneratesStoredEntry === true;
446
+ if (options.route.isDynamic && typeof options.pageModule.getStaticProps === "function" && typeof options.pageModule.getServerSideProps !== "function" && !hasStoredEntry && !options.isOnDemandRevalidate && previewData === false) {
520
447
  previousCacheEntry = await options.isrGet(options.isrCacheKey("pages", options.isrCachePathname ?? options.routeUrl.split("?")[0]));
521
448
  const value = previousCacheEntry?.value.value;
522
- hasFreshPrerenderedEntry = !!previousCacheEntry && !previousCacheEntry.isStale && !previousCacheEntry.isExpired && (value === null || value?.kind === "PAGES" || value?.kind === "REDIRECT");
449
+ hasStoredEntry = !!previousCacheEntry && !previousCacheEntry.isExpired && (value === null || value?.kind === "PAGES" || value?.kind === "REDIRECT");
523
450
  }
524
- if (!hasFreshPrerenderedEntry && typeof options.pageModule.getStaticPaths === "function" && options.route.isDynamic) {
451
+ if (!hasStoredEntry && previewData === false && typeof options.pageModule.getStaticPaths === "function" && options.route.isDynamic) {
525
452
  const staticPathsI18n = {
526
453
  ...options.i18n,
527
454
  defaultLocale: options.staticPathsDefaultLocale ?? options.i18n.defaultLocale
@@ -534,7 +461,7 @@ async function resolvePagesPageData(options) {
534
461
  const paths = pathsResult?.paths ?? [];
535
462
  const routeParams = getPagesRouteParams(options.routePattern);
536
463
  const isValidPath = paths.some((pathEntry) => matchesPagesStaticPath(pathEntry, options.params, routeParams, options.routeUrl, staticPathsI18n));
537
- if (fallback === false && !isValidPath && previewData === false) {
464
+ if (fallback === false && !isValidPath) {
538
465
  if (options.isOnDemandRevalidate && !options.revalidateOnlyGenerated) return {
539
466
  kind: "response",
540
467
  response: new Response("This page could not be found", { status: 404 }),
@@ -543,7 +470,7 @@ async function resolvePagesPageData(options) {
543
470
  return buildPagesNotFoundResult(options);
544
471
  }
545
472
  const isBotRequest = !!options.userAgent && isBotUserAgent(options.userAgent, options.htmlLimitedBots);
546
- if (fallback === true && !isValidPath && !options.isDataReq && !isBotRequest && previewData === false) isFallback = true;
473
+ if (fallback === true && !isValidPath && !options.isDataReq && !isBotRequest) isFallback = true;
547
474
  shouldPersistFallbackData = fallback === true && !isValidPath && options.isDataReq === true;
548
475
  }
549
476
  if (typeof options.pageModule.getStaticProps === "function" && options.isOnDemandRevalidate && options.revalidateOnlyGenerated) {
@@ -571,6 +498,13 @@ async function resolvePagesPageData(options) {
571
498
  }
572
499
  let renderProps = { pageProps };
573
500
  if (previewData !== false) renderProps.__N_PREVIEW = true;
501
+ async function takeSentResponse() {
502
+ if (options.isOnDemandRevalidate || !sharedReqRes || !isResponseSent(sharedReqRes.res)) return null;
503
+ return {
504
+ kind: "response",
505
+ response: await sharedReqRes.responsePromise
506
+ };
507
+ }
574
508
  async function loadForegroundAppInitialRenderProps() {
575
509
  const result = await loadPagesAppInitialRenderProps(options, getSharedReqRes);
576
510
  if (result.kind === "response") return {
@@ -583,7 +517,7 @@ async function resolvePagesPageData(options) {
583
517
  }
584
518
  if (isFallback) {
585
519
  const pathname = options.isrCachePathname ?? options.routeUrl.split("?")[0];
586
- if ((await options.isrGet(options.isrCacheKey("pages", pathname)))?.value.value?.kind !== "PAGES") {
520
+ if ((previousCacheEntry !== void 0 ? previousCacheEntry : await options.isrGet(options.isrCacheKey("pages", pathname)))?.value.value?.kind !== "PAGES") {
587
521
  const appShortCircuit = await loadForegroundAppInitialRenderProps();
588
522
  if (appShortCircuit) return appShortCircuit;
589
523
  pageProps = {};
@@ -656,7 +590,8 @@ async function resolvePagesPageData(options) {
656
590
  options.triggerBackgroundRegeneration(cacheKey, async function() {
657
591
  return options.runInFreshUnifiedContext(async () => {
658
592
  options.applyRequestContexts();
659
- const freshAppResult = await loadPagesAppInitialRenderProps(options, () => options.createGsspReqRes());
593
+ const reqRes = (options.createRegenerationReqRes ?? options.createGsspReqRes)();
594
+ const freshAppResult = await loadPagesAppInitialRenderProps(options, () => reqRes);
660
595
  if (freshAppResult.kind === "response") return;
661
596
  let freshPageProps = freshAppResult.pageProps;
662
597
  let freshRenderProps = freshAppResult.renderProps;
@@ -696,22 +631,13 @@ async function resolvePagesPageData(options) {
696
631
  };
697
632
  if (options.validatePropsSerialization !== false) isSerializableProps(options.routePattern, "getStaticProps", freshPageProps);
698
633
  if (cachedValue?.kind === "PAGES" && !cachedValue.generatedFromDataRequest) {
699
- const freshHtml = await tracePagesDocument(options.routePattern, () => renderPagesIsrHtml({
700
- buildId: options.buildId,
701
- cachedHtml: cachedValue.html,
702
- createPageElement: options.createPageElement,
703
- i18n: options.i18n,
634
+ await tracePagesDocument(options.routePattern, () => options.renderIsrDocument({
635
+ documentReqRes: reqRes,
636
+ expireSeconds,
704
637
  pageProps: freshPageProps,
705
638
  props: freshRenderProps,
706
- params: options.params,
707
- renderIsrPassToStringAsync: options.renderIsrPassToStringAsync,
708
- collectIsrHeadHTML: options.collectIsrHeadHTML,
709
- routePattern: options.routePattern,
710
- safeJsonStringify: options.safeJsonStringify,
711
- nextData: options.nextData,
712
- vinext: options.vinext
639
+ revalidateSeconds
713
640
  }));
714
- await options.isrSet(cacheKey, buildPagesCacheValue(freshHtml, freshRenderProps, options.statusCode), { cacheControl: isrCacheControl(revalidateSeconds, { expireSeconds }) });
715
641
  return;
716
642
  }
717
643
  await options.isrSet(cacheKey, {
@@ -788,7 +714,7 @@ async function resolvePagesPageData(options) {
788
714
  }, { cacheControl: isrCacheControl(revalidateSeconds, { expireSeconds }) });
789
715
  applyPagesTerminalMissHeaders(response, revalidateSeconds, pathname, expireSeconds);
790
716
  }
791
- return {
717
+ return await takeSentResponse() ?? {
792
718
  kind: "response",
793
719
  response
794
720
  };
@@ -799,7 +725,7 @@ async function resolvePagesPageData(options) {
799
725
  if (previewData === false) await options.isrSet(cacheKey, null, { cacheControl: isrCacheControl(revalidateSeconds, { expireSeconds }) });
800
726
  const notFoundResult = buildPagesNotFoundResult(options, revalidateSeconds, previewData === false ? "MISS" : void 0, expireSeconds);
801
727
  if (notFoundResult.kind === "response" && previewData === false) applyPagesTerminalMissHeaders(notFoundResult.response, revalidateSeconds, pathname, expireSeconds);
802
- return notFoundResult;
728
+ return await takeSentResponse() ?? notFoundResult;
803
729
  }
804
730
  if (result?.props !== void 0 && options.validatePropsSerialization !== false) isSerializableProps(options.routePattern, "getStaticProps", pageProps);
805
731
  if (previewData === false && result) {
@@ -854,6 +780,10 @@ async function resolvePagesPageData(options) {
854
780
  };
855
781
  }
856
782
  }
783
+ if (options.isDataReq) {
784
+ const sentResponse = await takeSentResponse();
785
+ if (sentResponse) return sentResponse;
786
+ }
857
787
  return {
858
788
  kind: "render",
859
789
  documentReqRes: sharedReqRes,
@@ -866,4 +796,4 @@ async function resolvePagesPageData(options) {
866
796
  };
867
797
  }
868
798
  //#endregion
869
- export { assertPages404DoesNotReturnNotFound, buildPagesRedirectProps, getPagesRouteParams, matchesPagesStaticPath, mergePagesDataProps, mergePagesNotFoundSourceHeaders, renderPagesIsrHtml, resolvePagesPageData, resolvePagesRedirect, resolvePagesRedirectLocation, resolvePagesRevalidateSeconds };
799
+ export { assertPages404DoesNotReturnNotFound, buildPagesRedirectProps, getPagesRouteParams, matchesPagesStaticPath, mergePagesDataProps, mergePagesNotFoundSourceHeaders, resolvePagesPageData, resolvePagesRedirect, resolvePagesRedirectLocation, resolvePagesRevalidateSeconds, resolvePagesStatusPageRenderPath };
@@ -99,12 +99,6 @@ export type CreatePagesPageHandlerOptions = {
99
99
  }>;
100
100
  /** `renderToReadableStream` from `react-dom/server.edge`. */
101
101
  renderToReadableStream: (element: ReactNode) => Promise<ReadableStream<Uint8Array>>;
102
- /**
103
- * Render a second ISR pass to a string (wraps renderToReadableStream).
104
- * `onHeadReady` runs inside the pass's head scope, after the render and
105
- * before the scope unwinds, so callers can read the collected `<head>`.
106
- */
107
- renderIsrPassToStringAsync: (element: ReactNode, onHeadReady?: () => Promise<void>) => Promise<string>;
108
102
  /** `safeJsonStringify` from `vinext/html`. */
109
103
  safeJsonStringify: (value: unknown) => string;
110
104
  /** `sanitizeDestination` from the config-matchers module. */