vinext 0.0.52 → 0.0.54

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 (330) hide show
  1. package/README.md +1 -1
  2. package/dist/build/clean-output.d.ts +14 -0
  3. package/dist/build/clean-output.js +36 -0
  4. package/dist/build/clean-output.js.map +1 -0
  5. package/dist/build/inline-css.d.ts +7 -0
  6. package/dist/build/inline-css.js +50 -0
  7. package/dist/build/inline-css.js.map +1 -0
  8. package/dist/build/prerender.d.ts +6 -2
  9. package/dist/build/prerender.js +51 -12
  10. package/dist/build/prerender.js.map +1 -1
  11. package/dist/build/run-prerender.js +10 -1
  12. package/dist/build/run-prerender.js.map +1 -1
  13. package/dist/build/static-export.d.ts +5 -0
  14. package/dist/build/static-export.js +8 -3
  15. package/dist/build/static-export.js.map +1 -1
  16. package/dist/check.js +4 -0
  17. package/dist/check.js.map +1 -1
  18. package/dist/cli.js +19 -4
  19. package/dist/cli.js.map +1 -1
  20. package/dist/client/instrumentation-client-inject.d.ts +34 -0
  21. package/dist/client/instrumentation-client-inject.js +57 -0
  22. package/dist/client/instrumentation-client-inject.js.map +1 -0
  23. package/dist/client/navigation-runtime.d.ts +16 -2
  24. package/dist/client/navigation-runtime.js +16 -1
  25. package/dist/client/navigation-runtime.js.map +1 -1
  26. package/dist/client/vinext-next-data.d.ts +2 -1
  27. package/dist/client/vinext-next-data.js.map +1 -1
  28. package/dist/client/window-next.d.ts +17 -2
  29. package/dist/client/window-next.js.map +1 -1
  30. package/dist/cloudflare/tpr.js +1 -1
  31. package/dist/cloudflare/tpr.js.map +1 -1
  32. package/dist/config/config-matchers.js +2 -1
  33. package/dist/config/config-matchers.js.map +1 -1
  34. package/dist/config/next-config.d.ts +95 -4
  35. package/dist/config/next-config.js +173 -14
  36. package/dist/config/next-config.js.map +1 -1
  37. package/dist/deploy.js +42 -7
  38. package/dist/deploy.js.map +1 -1
  39. package/dist/entries/app-browser-entry.d.ts +11 -1
  40. package/dist/entries/app-browser-entry.js +16 -6
  41. package/dist/entries/app-browser-entry.js.map +1 -1
  42. package/dist/entries/app-rsc-entry.d.ts +12 -3
  43. package/dist/entries/app-rsc-entry.js +41 -8
  44. package/dist/entries/app-rsc-entry.js.map +1 -1
  45. package/dist/entries/app-rsc-manifest.d.ts +21 -1
  46. package/dist/entries/app-rsc-manifest.js +6 -4
  47. package/dist/entries/app-rsc-manifest.js.map +1 -1
  48. package/dist/entries/pages-client-entry.d.ts +4 -1
  49. package/dist/entries/pages-client-entry.js +40 -3
  50. package/dist/entries/pages-client-entry.js.map +1 -1
  51. package/dist/entries/pages-server-entry.js +292 -34
  52. package/dist/entries/pages-server-entry.js.map +1 -1
  53. package/dist/entries/runtime-entry-module.d.ts +1 -10
  54. package/dist/entries/runtime-entry-module.js +2 -12
  55. package/dist/entries/runtime-entry-module.js.map +1 -1
  56. package/dist/index.js +91 -10
  57. package/dist/index.js.map +1 -1
  58. package/dist/plugins/fonts.js +25 -2
  59. package/dist/plugins/fonts.js.map +1 -1
  60. package/dist/plugins/remove-console.d.ts +16 -0
  61. package/dist/plugins/remove-console.js +176 -0
  62. package/dist/plugins/remove-console.js.map +1 -0
  63. package/dist/routing/app-route-graph.d.ts +24 -1
  64. package/dist/routing/app-route-graph.js +52 -4
  65. package/dist/routing/app-route-graph.js.map +1 -1
  66. package/dist/routing/app-router.d.ts +2 -2
  67. package/dist/routing/app-router.js +2 -2
  68. package/dist/routing/app-router.js.map +1 -1
  69. package/dist/routing/file-matcher.d.ts +21 -1
  70. package/dist/routing/file-matcher.js +39 -1
  71. package/dist/routing/file-matcher.js.map +1 -1
  72. package/dist/routing/pages-router.d.ts +1 -1
  73. package/dist/routing/pages-router.js +10 -3
  74. package/dist/routing/pages-router.js.map +1 -1
  75. package/dist/routing/route-trie.js +13 -18
  76. package/dist/routing/route-trie.js.map +1 -1
  77. package/dist/routing/utils.d.ts +11 -1
  78. package/dist/routing/utils.js +15 -1
  79. package/dist/routing/utils.js.map +1 -1
  80. package/dist/server/api-handler.js +19 -10
  81. package/dist/server/api-handler.js.map +1 -1
  82. package/dist/server/app-browser-action-result.d.ts +16 -1
  83. package/dist/server/app-browser-action-result.js +15 -1
  84. package/dist/server/app-browser-action-result.js.map +1 -1
  85. package/dist/server/app-browser-entry.js +47 -28
  86. package/dist/server/app-browser-entry.js.map +1 -1
  87. package/dist/server/app-browser-navigation-controller.d.ts +2 -0
  88. package/dist/server/app-browser-navigation-controller.js +4 -0
  89. package/dist/server/app-browser-navigation-controller.js.map +1 -1
  90. package/dist/server/app-elements-wire.d.ts +13 -4
  91. package/dist/server/app-elements-wire.js +10 -1
  92. package/dist/server/app-elements-wire.js.map +1 -1
  93. package/dist/server/app-elements.d.ts +2 -2
  94. package/dist/server/app-elements.js +2 -2
  95. package/dist/server/app-elements.js.map +1 -1
  96. package/dist/server/app-fallback-renderer.d.ts +27 -8
  97. package/dist/server/app-fallback-renderer.js +19 -8
  98. package/dist/server/app-fallback-renderer.js.map +1 -1
  99. package/dist/server/app-history-state.js +6 -2
  100. package/dist/server/app-history-state.js.map +1 -1
  101. package/dist/server/app-inline-css-client.d.ts +7 -0
  102. package/dist/server/app-inline-css-client.js +37 -0
  103. package/dist/server/app-inline-css-client.js.map +1 -0
  104. package/dist/server/app-interception-context-header.d.ts +33 -0
  105. package/dist/server/app-interception-context-header.js +44 -0
  106. package/dist/server/app-interception-context-header.js.map +1 -0
  107. package/dist/server/app-mounted-slots-header.d.ts +19 -0
  108. package/dist/server/app-mounted-slots-header.js +40 -1
  109. package/dist/server/app-mounted-slots-header.js.map +1 -1
  110. package/dist/server/app-optimistic-routing.js +26 -18
  111. package/dist/server/app-optimistic-routing.js.map +1 -1
  112. package/dist/server/app-page-boundary-render.d.ts +1 -0
  113. package/dist/server/app-page-boundary-render.js +2 -0
  114. package/dist/server/app-page-boundary-render.js.map +1 -1
  115. package/dist/server/app-page-boundary.d.ts +22 -1
  116. package/dist/server/app-page-boundary.js +30 -3
  117. package/dist/server/app-page-boundary.js.map +1 -1
  118. package/dist/server/app-page-cache.d.ts +9 -3
  119. package/dist/server/app-page-cache.js +14 -8
  120. package/dist/server/app-page-cache.js.map +1 -1
  121. package/dist/server/app-page-dispatch.d.ts +13 -1
  122. package/dist/server/app-page-dispatch.js +136 -82
  123. package/dist/server/app-page-dispatch.js.map +1 -1
  124. package/dist/server/app-page-element-builder.d.ts +2 -1
  125. package/dist/server/app-page-element-builder.js +17 -30
  126. package/dist/server/app-page-element-builder.js.map +1 -1
  127. package/dist/server/app-page-execution.d.ts +1 -0
  128. package/dist/server/app-page-execution.js +2 -0
  129. package/dist/server/app-page-execution.js.map +1 -1
  130. package/dist/server/app-page-head.d.ts +1 -0
  131. package/dist/server/app-page-head.js +8 -0
  132. package/dist/server/app-page-head.js.map +1 -1
  133. package/dist/server/app-page-render-identity.d.ts +22 -0
  134. package/dist/server/app-page-render-identity.js +42 -0
  135. package/dist/server/app-page-render-identity.js.map +1 -0
  136. package/dist/server/app-page-render-observation.js +1 -1
  137. package/dist/server/app-page-render.d.ts +9 -1
  138. package/dist/server/app-page-render.js +8 -2
  139. package/dist/server/app-page-render.js.map +1 -1
  140. package/dist/server/app-page-request.d.ts +6 -3
  141. package/dist/server/app-page-request.js +5 -2
  142. package/dist/server/app-page-request.js.map +1 -1
  143. package/dist/server/app-page-response.d.ts +11 -1
  144. package/dist/server/app-page-response.js +16 -4
  145. package/dist/server/app-page-response.js.map +1 -1
  146. package/dist/server/app-page-route-wiring.d.ts +16 -0
  147. package/dist/server/app-page-route-wiring.js +25 -10
  148. package/dist/server/app-page-route-wiring.js.map +1 -1
  149. package/dist/server/app-page-stream.d.ts +12 -0
  150. package/dist/server/app-page-stream.js +3 -0
  151. package/dist/server/app-page-stream.js.map +1 -1
  152. package/dist/server/app-route-handler-dispatch.d.ts +1 -0
  153. package/dist/server/app-route-handler-dispatch.js +3 -0
  154. package/dist/server/app-route-handler-dispatch.js.map +1 -1
  155. package/dist/server/app-route-handler-execution.d.ts +1 -0
  156. package/dist/server/app-route-handler-execution.js +1 -0
  157. package/dist/server/app-route-handler-execution.js.map +1 -1
  158. package/dist/server/app-route-handler-response.js +38 -6
  159. package/dist/server/app-route-handler-response.js.map +1 -1
  160. package/dist/server/app-rsc-handler.d.ts +16 -3
  161. package/dist/server/app-rsc-handler.js +60 -11
  162. package/dist/server/app-rsc-handler.js.map +1 -1
  163. package/dist/server/app-rsc-request-normalization.d.ts +2 -1
  164. package/dist/server/app-rsc-request-normalization.js +6 -4
  165. package/dist/server/app-rsc-request-normalization.js.map +1 -1
  166. package/dist/server/app-segment-config.d.ts +4 -1
  167. package/dist/server/app-segment-config.js +6 -1
  168. package/dist/server/app-segment-config.js.map +1 -1
  169. package/dist/server/app-server-action-execution.d.ts +22 -3
  170. package/dist/server/app-server-action-execution.js +46 -7
  171. package/dist/server/app-server-action-execution.js.map +1 -1
  172. package/dist/server/app-ssr-entry.d.ts +6 -0
  173. package/dist/server/app-ssr-entry.js +57 -6
  174. package/dist/server/app-ssr-entry.js.map +1 -1
  175. package/dist/server/app-ssr-error-meta.js +3 -3
  176. package/dist/server/app-ssr-error-meta.js.map +1 -1
  177. package/dist/server/app-ssr-stream.d.ts +25 -1
  178. package/dist/server/app-ssr-stream.js +237 -19
  179. package/dist/server/app-ssr-stream.js.map +1 -1
  180. package/dist/server/app-static-generation.d.ts +1 -0
  181. package/dist/server/app-static-generation.js +2 -1
  182. package/dist/server/app-static-generation.js.map +1 -1
  183. package/dist/server/client-trace-metadata.d.ts +31 -0
  184. package/dist/server/client-trace-metadata.js +83 -0
  185. package/dist/server/client-trace-metadata.js.map +1 -0
  186. package/dist/server/cookie-utils.d.ts +13 -0
  187. package/dist/server/cookie-utils.js +20 -0
  188. package/dist/server/cookie-utils.js.map +1 -0
  189. package/dist/server/default-not-found-module.d.ts +20 -0
  190. package/dist/server/default-not-found-module.js +20 -0
  191. package/dist/server/default-not-found-module.js.map +1 -0
  192. package/dist/server/dev-server.d.ts +8 -1
  193. package/dist/server/dev-server.js +56 -11
  194. package/dist/server/dev-server.js.map +1 -1
  195. package/dist/server/headers.d.ts +5 -1
  196. package/dist/server/headers.js +5 -1
  197. package/dist/server/headers.js.map +1 -1
  198. package/dist/server/html.d.ts +2 -1
  199. package/dist/server/html.js +6 -1
  200. package/dist/server/html.js.map +1 -1
  201. package/dist/server/image-optimization.d.ts +13 -4
  202. package/dist/server/image-optimization.js +15 -4
  203. package/dist/server/image-optimization.js.map +1 -1
  204. package/dist/server/isr-cache.d.ts +7 -5
  205. package/dist/server/isr-cache.js +17 -6
  206. package/dist/server/isr-cache.js.map +1 -1
  207. package/dist/server/middleware-runtime.js +1 -2
  208. package/dist/server/middleware-runtime.js.map +1 -1
  209. package/dist/server/middleware.js +1 -1
  210. package/dist/server/middleware.js.map +1 -1
  211. package/dist/server/pages-api-route.d.ts +18 -0
  212. package/dist/server/pages-api-route.js +3 -1
  213. package/dist/server/pages-api-route.js.map +1 -1
  214. package/dist/server/pages-body-parser-config.d.ts +60 -0
  215. package/dist/server/pages-body-parser-config.js +79 -0
  216. package/dist/server/pages-body-parser-config.js.map +1 -0
  217. package/dist/server/pages-data-route.js +1 -0
  218. package/dist/server/pages-data-route.js.map +1 -1
  219. package/dist/server/pages-default-404.d.ts +31 -0
  220. package/dist/server/pages-default-404.js +40 -0
  221. package/dist/server/pages-default-404.js.map +1 -0
  222. package/dist/server/pages-document-initial-props.d.ts +7 -0
  223. package/dist/server/pages-document-initial-props.js +14 -0
  224. package/dist/server/pages-document-initial-props.js.map +1 -0
  225. package/dist/server/pages-node-compat.d.ts +10 -0
  226. package/dist/server/pages-node-compat.js +12 -1
  227. package/dist/server/pages-node-compat.js.map +1 -1
  228. package/dist/server/pages-page-data.d.ts +40 -0
  229. package/dist/server/pages-page-data.js +19 -14
  230. package/dist/server/pages-page-data.js.map +1 -1
  231. package/dist/server/pages-page-method.d.ts +48 -0
  232. package/dist/server/pages-page-method.js +19 -0
  233. package/dist/server/pages-page-method.js.map +1 -0
  234. package/dist/server/pages-page-response.d.ts +8 -0
  235. package/dist/server/pages-page-response.js +21 -11
  236. package/dist/server/pages-page-response.js.map +1 -1
  237. package/dist/server/pages-serializable-props.d.ts +25 -0
  238. package/dist/server/pages-serializable-props.js +69 -0
  239. package/dist/server/pages-serializable-props.js.map +1 -0
  240. package/dist/server/prerender-route-params.d.ts +14 -0
  241. package/dist/server/prerender-route-params.js +94 -0
  242. package/dist/server/prerender-route-params.js.map +1 -0
  243. package/dist/server/prod-server.d.ts +3 -23
  244. package/dist/server/prod-server.js +43 -57
  245. package/dist/server/prod-server.js.map +1 -1
  246. package/dist/server/proxy-trust.d.ts +41 -0
  247. package/dist/server/proxy-trust.js +70 -0
  248. package/dist/server/proxy-trust.js.map +1 -0
  249. package/dist/server/request-pipeline.d.ts +3 -3
  250. package/dist/server/request-pipeline.js +5 -4
  251. package/dist/server/request-pipeline.js.map +1 -1
  252. package/dist/server/seed-cache.js +12 -6
  253. package/dist/server/seed-cache.js.map +1 -1
  254. package/dist/server/server-action-not-found.js +3 -2
  255. package/dist/server/server-action-not-found.js.map +1 -1
  256. package/dist/server/static-file-cache.js +2 -1
  257. package/dist/server/static-file-cache.js.map +1 -1
  258. package/dist/server/streaming-metadata.d.ts +5 -0
  259. package/dist/server/streaming-metadata.js +10 -0
  260. package/dist/server/streaming-metadata.js.map +1 -0
  261. package/dist/shims/app-router-scroll-state.d.ts +14 -0
  262. package/dist/shims/app-router-scroll-state.js +51 -0
  263. package/dist/shims/app-router-scroll-state.js.map +1 -0
  264. package/dist/shims/app-router-scroll.d.ts +28 -0
  265. package/dist/shims/app-router-scroll.js +115 -0
  266. package/dist/shims/app-router-scroll.js.map +1 -0
  267. package/dist/shims/before-interactive-context.d.ts +30 -0
  268. package/dist/shims/before-interactive-context.js +10 -0
  269. package/dist/shims/before-interactive-context.js.map +1 -0
  270. package/dist/shims/cache-runtime.d.ts +1 -1
  271. package/dist/shims/cache-runtime.js +14 -1
  272. package/dist/shims/cache-runtime.js.map +1 -1
  273. package/dist/shims/cache.d.ts +6 -0
  274. package/dist/shims/cache.js +7 -0
  275. package/dist/shims/cache.js.map +1 -1
  276. package/dist/shims/default-not-found.d.ts +12 -0
  277. package/dist/shims/default-not-found.js +61 -0
  278. package/dist/shims/default-not-found.js.map +1 -0
  279. package/dist/shims/error.js +3 -0
  280. package/dist/shims/error.js.map +1 -1
  281. package/dist/shims/font-local.d.ts +5 -0
  282. package/dist/shims/font-local.js +6 -2
  283. package/dist/shims/font-local.js.map +1 -1
  284. package/dist/shims/head.js +4 -4
  285. package/dist/shims/head.js.map +1 -1
  286. package/dist/shims/headers.d.ts +13 -2
  287. package/dist/shims/headers.js +73 -22
  288. package/dist/shims/headers.js.map +1 -1
  289. package/dist/shims/image.d.ts +1 -1
  290. package/dist/shims/image.js +4 -4
  291. package/dist/shims/image.js.map +1 -1
  292. package/dist/shims/internal/app-route-detection.d.ts +37 -0
  293. package/dist/shims/internal/app-route-detection.js +69 -0
  294. package/dist/shims/internal/app-route-detection.js.map +1 -0
  295. package/dist/shims/internal/pages-data-target.d.ts +58 -0
  296. package/dist/shims/internal/pages-data-target.js +91 -0
  297. package/dist/shims/internal/pages-data-target.js.map +1 -0
  298. package/dist/shims/internal/pages-data-url.d.ts +42 -0
  299. package/dist/shims/internal/pages-data-url.js +73 -0
  300. package/dist/shims/internal/pages-data-url.js.map +1 -0
  301. package/dist/shims/link.d.ts +18 -2
  302. package/dist/shims/link.js +129 -15
  303. package/dist/shims/link.js.map +1 -1
  304. package/dist/shims/metadata.d.ts +9 -7
  305. package/dist/shims/metadata.js +70 -7
  306. package/dist/shims/metadata.js.map +1 -1
  307. package/dist/shims/navigation.d.ts +1 -2
  308. package/dist/shims/navigation.js +94 -20
  309. package/dist/shims/navigation.js.map +1 -1
  310. package/dist/shims/router.d.ts +5 -0
  311. package/dist/shims/router.js +389 -80
  312. package/dist/shims/router.js.map +1 -1
  313. package/dist/shims/script.d.ts +11 -1
  314. package/dist/shims/script.js +158 -15
  315. package/dist/shims/script.js.map +1 -1
  316. package/dist/shims/server.js +1 -0
  317. package/dist/shims/server.js.map +1 -1
  318. package/dist/shims/url-utils.d.ts +2 -1
  319. package/dist/shims/url-utils.js +15 -4
  320. package/dist/shims/url-utils.js.map +1 -1
  321. package/dist/utils/html-limited-bots.d.ts +5 -0
  322. package/dist/utils/html-limited-bots.js +15 -0
  323. package/dist/utils/html-limited-bots.js.map +1 -0
  324. package/dist/utils/path.d.ts +13 -0
  325. package/dist/utils/path.js +16 -0
  326. package/dist/utils/path.js.map +1 -0
  327. package/dist/utils/query.d.ts +6 -0
  328. package/dist/utils/query.js +10 -1
  329. package/dist/utils/query.js.map +1 -1
  330. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"pages-page-data.js","names":[],"sources":["../../src/server/pages-page-data.ts"],"sourcesContent":["import type { ReactNode } from \"react\";\nimport type { Route } from \"../routing/pages-router.js\";\nimport { normalizeStaticPathname } from \"../routing/route-pattern.js\";\nimport type { CachedPagesValue, CacheControlMetadata } from \"vinext/shims/cache\";\nimport { buildCachedRevalidateCacheControl } from \"./cache-control.js\";\nimport { buildCacheStateHeaders } from \"./cache-headers.js\";\nimport { buildPagesCacheValue, type ISRCacheEntry } from \"./isr-cache.js\";\nimport {\n buildPagesNextDataScript,\n type PagesGsspResponse,\n type PagesI18nRenderContext,\n} from \"./pages-page-response.js\";\n\ntype PagesRedirectResult = {\n destination: string;\n permanent?: boolean;\n statusCode?: number;\n};\n\n// Next.js allows `paths` entries to be either an object with a `params` key\n// or a raw string path. We keep a local variant of `StaticPathsEntry` here\n// because at request time we compare against the actual request `params`\n// (whose value type is `unknown` from the route matcher) rather than the\n// `string | string[]` shape used at build time. The shared\n// `normalizeStaticPathname` helper from `../routing/route-pattern.js` is used\n// to canonicalize the string-entry comparison.\ntype PagesStaticPathsEntry = string | { params?: Record<string, unknown>; locale?: string };\n\ntype PagesStaticPathsResult = {\n fallback?: boolean | \"blocking\";\n paths?: PagesStaticPathsEntry[];\n};\n\ntype PagesPagePropsResult = {\n props?: Record<string, unknown>;\n redirect?: PagesRedirectResult;\n notFound?: boolean;\n revalidate?: number;\n};\n\nexport type PagesMutableGsspResponse = {\n headersSent: boolean;\n} & PagesGsspResponse;\n\nexport type PagesGsspContextResponse = {\n req: unknown;\n res: PagesMutableGsspResponse;\n responsePromise: Promise<Response>;\n};\n\nexport type PagesPageModule = {\n default?: unknown;\n getStaticPaths?: (context: {\n locales: string[];\n defaultLocale: string;\n }) => Promise<PagesStaticPathsResult> | PagesStaticPathsResult;\n /**\n * Pages Router data-fetching context.\n *\n * `params` is `null` for non-dynamic routes (no `[param]` segments) to\n * match Next.js. User code typically falls back via `params || null`, so\n * passing `null` (rather than `{}`) is required for the value to be\n * observable as `null` once the data flows through to the page props.\n *\n * See: test/e2e/edge-pages-support/index.test.ts in Next.js for the\n * authoritative assertion (`expect(props.params).toBe(null)`).\n */\n getServerSideProps?: (context: {\n params: Record<string, unknown> | null;\n req: unknown;\n res: PagesMutableGsspResponse;\n query: Record<string, unknown>;\n resolvedUrl: string;\n locale?: string;\n locales?: string[];\n defaultLocale?: string;\n }) => Promise<PagesPagePropsResult> | PagesPagePropsResult;\n getStaticProps?: (context: {\n params: Record<string, unknown> | null;\n locale?: string;\n locales?: string[];\n defaultLocale?: string;\n }) => Promise<PagesPagePropsResult> | PagesPagePropsResult;\n};\n\ntype RenderPagesIsrHtmlOptions = {\n buildId: string | null;\n cachedHtml: string;\n createPageElement: (pageProps: Record<string, unknown>) => ReactNode;\n i18n: PagesI18nRenderContext;\n pageProps: Record<string, unknown>;\n params: Record<string, unknown>;\n renderIsrPassToStringAsync: (element: ReactNode) => Promise<string>;\n routePattern: string;\n safeJsonStringify: (value: unknown) => string;\n};\n\nexport type ResolvePagesPageDataOptions = {\n applyRequestContexts: () => void;\n buildId: string | null;\n /**\n * When true, this is a `/_next/data/<buildId>/<page>.json` request. Callers\n * that respond with a JSON envelope (`{ pageProps }`) instead of HTML must\n * bypass the HTML ISR cache: a cached HTML body cannot be reshaped into the\n * expected JSON shape, and storing JSON in the HTML cache would corrupt\n * subsequent HTML hits. Next.js handles this the same way — see\n * `isNextDataRequest` checks in `packages/next/src/server/base-server.ts`.\n */\n isDataReq?: boolean;\n createGsspReqRes: () => PagesGsspContextResponse;\n createPageElement: (pageProps: Record<string, unknown>) => ReactNode;\n fontLinkHeader: string;\n i18n: PagesI18nRenderContext;\n isrCacheKey: (router: string, pathname: string) => string;\n isrGet: (key: string) => Promise<ISRCacheEntry | null>;\n isrSet: (\n key: string,\n data: CachedPagesValue,\n revalidateSeconds: number,\n tags?: string[],\n expireSeconds?: number,\n ) => Promise<void>;\n expireSeconds?: number;\n pageModule: PagesPageModule;\n params: Record<string, unknown>;\n query: Record<string, unknown>;\n route: Pick<Route, \"isDynamic\">;\n routePattern: string;\n routeUrl: string;\n runInFreshUnifiedContext: <T>(callback: () => Promise<T>) => Promise<T>;\n safeJsonStringify: (value: unknown) => string;\n sanitizeDestination: (destination: string) => string;\n scriptNonce?: string;\n triggerBackgroundRegeneration: (\n key: string,\n renderFn: () => Promise<void>,\n errorContext?: { routerKind: \"Pages Router\"; routePath: string; routeType: \"render\" },\n ) => void;\n renderIsrPassToStringAsync: (element: ReactNode) => Promise<string>;\n};\n\ntype ResolvePagesPageDataRenderResult = {\n kind: \"render\";\n gsspRes: PagesGsspResponse | null;\n isrRevalidateSeconds: number | null;\n pageProps: Record<string, unknown>;\n /**\n * True when `getStaticPaths` returned `fallback: true` AND the requested path\n * is not in the pre-rendered list. The caller renders a loading shell with\n * empty props and `useRouter().isFallback === true` (matching Next.js's\n * `render.tsx` — `getStaticProps` is skipped on the fallback render).\n */\n isFallback: boolean;\n};\n\ntype ResolvePagesPageDataResponseResult = {\n kind: \"response\";\n response: Response;\n};\n\ntype ResolvePagesPageDataResult =\n | ResolvePagesPageDataRenderResult\n | ResolvePagesPageDataResponseResult;\n\nfunction buildPagesNotFoundResponse(): Response {\n return new Response(\"<!DOCTYPE html><html><body><h1>404 - Page not found</h1></body></html>\", {\n status: 404,\n headers: { \"Content-Type\": \"text/html\" },\n });\n}\n\nfunction buildPagesDataNotFoundResponse(): Response {\n // Matches Next.js: `/_next/data/<buildId>/<page>.json` 404 responses use\n // application/json with an empty object body so clients can call\n // `res.json()` without throwing before inspecting the status code.\n return new Response(\"{}\", {\n status: 404,\n headers: { \"Content-Type\": \"application/json\" },\n });\n}\n\nfunction resolvePagesRedirectStatus(redirect: PagesRedirectResult): number {\n return redirect.statusCode != null ? redirect.statusCode : redirect.permanent ? 308 : 307;\n}\n\n/**\n * Compare a `getStaticPaths` entry against the actual request params.\n *\n * Handles both shapes Next.js allows:\n * - { params: { ... } }\n * - \"string-path\"\n *\n * For a string entry, compare the entry against the current request URL using\n * the shared `normalizeStaticPathname` helper from\n * `../routing/route-pattern.ts` (which mirrors the Next.js\n * `removeTrailingSlash` behaviour in\n * `.nextjs-ref/packages/next/src/build/static-paths/pages.ts`). For an object\n * entry with a missing `params` key, return false rather than throwing — the\n * caller will respond with a 404 just like Next.js does for unlisted paths.\n */\nfunction matchesPagesStaticPath(\n pathEntry: PagesStaticPathsEntry,\n params: Record<string, unknown>,\n routeUrl: string,\n): boolean {\n if (typeof pathEntry === \"string\") {\n return normalizeStaticPathname(pathEntry) === normalizeStaticPathname(routeUrl);\n }\n const entryParams = pathEntry.params;\n if (entryParams === undefined || entryParams === null) {\n return false;\n }\n return Object.entries(entryParams).every(([key, value]) => {\n const actual = params[key];\n if (Array.isArray(value)) {\n return Array.isArray(actual) && value.join(\"/\") === actual.join(\"/\");\n }\n return String(value) === String(actual);\n });\n}\n\nfunction buildPagesCacheResponse(\n html: string,\n cacheState: \"HIT\" | \"STALE\",\n fontLinkHeader: string,\n revalidateSeconds?: number,\n expireSeconds?: number,\n cacheControl?: CacheControlMetadata,\n): Response {\n // Legacy cache entries written before cacheControl metadata existed can still\n // hit this path without a persisted revalidate value; keep the historic\n // 60-second fallback for that migration window.\n const effectiveRevalidateSeconds = cacheControl?.revalidate ?? revalidateSeconds ?? 60;\n const effectiveExpireSeconds =\n cacheControl === undefined ? undefined : (cacheControl.expire ?? expireSeconds);\n const headers: Record<string, string> = {\n \"Content-Type\": \"text/html\",\n ...buildCacheStateHeaders(cacheState),\n \"Cache-Control\": buildCachedRevalidateCacheControl(\n cacheState,\n effectiveRevalidateSeconds,\n effectiveExpireSeconds,\n ),\n };\n\n if (fontLinkHeader) {\n headers.Link = fontLinkHeader;\n }\n\n return new Response(html, {\n status: 200,\n headers,\n });\n}\n\nfunction rewritePagesCachedHtml(\n cachedHtml: string,\n freshBody: string,\n nextDataScript: string,\n): string {\n const bodyMarker = '<div id=\"__next\">';\n const bodyStart = cachedHtml.indexOf(bodyMarker);\n const contentStart = bodyStart >= 0 ? bodyStart + bodyMarker.length : -1;\n // This intentionally looks for the bare inline __NEXT_DATA__ marker.\n // Pages responses with scriptNonce are excluded from ISR writes, so cached\n // HTML should never contain nonce-prefixed __NEXT_DATA__ scripts here.\n const nextDataMarker = \"<script>window.__NEXT_DATA__\";\n const nextDataStart = cachedHtml.indexOf(nextDataMarker);\n\n if (contentStart >= 0 && nextDataStart >= 0) {\n const region = cachedHtml.slice(contentStart, nextDataStart);\n const lastCloseDiv = region.lastIndexOf(\"</div>\");\n const gap = lastCloseDiv >= 0 ? region.slice(lastCloseDiv + 6) : \"\";\n const nextDataEnd = cachedHtml.indexOf(\"</script>\", nextDataStart) + 9;\n const tail = cachedHtml.slice(nextDataEnd);\n\n return cachedHtml.slice(0, contentStart) + freshBody + \"</div>\" + gap + nextDataScript + tail;\n }\n\n return (\n '<!DOCTYPE html>\\n<html>\\n<head>\\n</head>\\n<body>\\n <div id=\"__next\">' +\n freshBody +\n \"</div>\\n \" +\n nextDataScript +\n \"\\n</body>\\n</html>\"\n );\n}\n\nexport async function renderPagesIsrHtml(options: RenderPagesIsrHtmlOptions): Promise<string> {\n const freshBody = await options.renderIsrPassToStringAsync(\n options.createPageElement(options.pageProps),\n );\n const nextDataScript = buildPagesNextDataScript({\n buildId: options.buildId,\n i18n: options.i18n,\n pageProps: options.pageProps,\n params: options.params,\n routePattern: options.routePattern,\n safeJsonStringify: options.safeJsonStringify,\n });\n\n return rewritePagesCachedHtml(options.cachedHtml, freshBody, nextDataScript);\n}\n\nexport async function resolvePagesPageData(\n options: ResolvePagesPageDataOptions,\n): Promise<ResolvePagesPageDataResult> {\n // Next.js passes `params: null` (effectively) to gSSP/gSP context for\n // non-dynamic routes — see render.tsx's `...(pageIsDynamic ? { params } : undefined)`.\n // Internal bookkeeping (route param hydration, ISR HTML, getStaticPaths\n // validation) still uses the matched-but-empty object — only user-facing\n // data-fetching contexts surface `null`.\n const userFacingParams: Record<string, unknown> | null = options.route.isDynamic\n ? options.params\n : null;\n\n // Set when `getStaticPaths: { fallback: true }` is configured and the\n // requested path is NOT in the pre-rendered list. When true, we render the\n // loading shell with empty props and `useRouter().isFallback === true`,\n // skipping `getStaticProps`. Matches Next.js `render.tsx`'s\n // `if (isSSG && !isFallback)` gate around `getStaticProps`. Data requests\n // (`/_next/data/...json`) still call `getStaticProps` so the client can\n // hydrate the page after the fallback shell ships.\n let isFallback = false;\n\n if (typeof options.pageModule.getStaticPaths === \"function\" && options.route.isDynamic) {\n const pathsResult = await options.pageModule.getStaticPaths({\n locales: options.i18n.locales ?? [],\n defaultLocale: options.i18n.defaultLocale ?? \"\",\n });\n const fallback = pathsResult?.fallback ?? false;\n const paths = pathsResult?.paths ?? [];\n const isValidPath = paths.some((pathEntry) =>\n matchesPagesStaticPath(pathEntry, options.params, options.routeUrl),\n );\n\n if (fallback === false && !isValidPath) {\n // For data requests (`/_next/data/...json`), return a JSON-shaped 404\n // so the client router can `res.json()` without blowing up — matches\n // Next.js' behavior. HTML navigations still get the HTML 404 page.\n return {\n kind: \"response\",\n response: options.isDataReq\n ? buildPagesDataNotFoundResponse()\n : buildPagesNotFoundResponse(),\n };\n }\n\n // Render the fallback shell for unlisted paths under `fallback: true`.\n // Data requests resolve props normally so the client can fill in after\n // the loading shell ships (`fallback: 'blocking'` keeps SSRing as before).\n if (fallback === true && !isValidPath && !options.isDataReq) {\n isFallback = true;\n }\n }\n\n let pageProps: Record<string, unknown> = {};\n let gsspRes: PagesMutableGsspResponse | null = null;\n\n if (isFallback) {\n return {\n kind: \"render\",\n gsspRes: null,\n isrRevalidateSeconds: null,\n pageProps,\n isFallback: true,\n };\n }\n\n if (typeof options.pageModule.getServerSideProps === \"function\") {\n const { req, res, responsePromise } = options.createGsspReqRes();\n const result = await options.pageModule.getServerSideProps({\n params: userFacingParams,\n req,\n res,\n query: options.query,\n resolvedUrl: options.routeUrl,\n locale: options.i18n.locale,\n locales: options.i18n.locales,\n defaultLocale: options.i18n.defaultLocale,\n });\n\n if (res.headersSent) {\n return {\n kind: \"response\",\n response: await responsePromise,\n };\n }\n\n if (result?.props) {\n pageProps = result.props;\n }\n\n if (result?.redirect) {\n return {\n kind: \"response\",\n response: new Response(null, {\n status: resolvePagesRedirectStatus(result.redirect),\n headers: { Location: options.sanitizeDestination(result.redirect.destination) },\n }),\n };\n }\n\n if (result?.notFound) {\n return {\n kind: \"response\",\n response: options.isDataReq\n ? buildPagesDataNotFoundResponse()\n : buildPagesNotFoundResponse(),\n };\n }\n\n gsspRes = res;\n }\n\n let isrRevalidateSeconds: number | null = null;\n\n if (typeof options.pageModule.getStaticProps === \"function\") {\n const pathname = options.routeUrl.split(\"?\")[0];\n const cacheKey = options.isrCacheKey(\"pages\", pathname);\n const cached = await options.isrGet(cacheKey);\n const cachedValue = cached?.value.value;\n\n if (\n cachedValue?.kind === \"PAGES\" &&\n cached &&\n !cached.isStale &&\n !options.scriptNonce &&\n !options.isDataReq\n ) {\n return {\n kind: \"response\",\n response: buildPagesCacheResponse(\n cachedValue.html,\n \"HIT\",\n options.fontLinkHeader,\n undefined,\n options.expireSeconds,\n cached.value.cacheControl,\n ),\n };\n }\n\n if (\n cachedValue?.kind === \"PAGES\" &&\n cached &&\n cached.isStale &&\n !options.scriptNonce &&\n !options.isDataReq\n ) {\n options.triggerBackgroundRegeneration(\n cacheKey,\n async function () {\n return options.runInFreshUnifiedContext(async () => {\n const freshResult = await options.pageModule.getStaticProps?.({\n params: userFacingParams,\n locale: options.i18n.locale,\n locales: options.i18n.locales,\n defaultLocale: options.i18n.defaultLocale,\n });\n\n if (\n freshResult?.props &&\n typeof freshResult.revalidate === \"number\" &&\n freshResult.revalidate > 0\n ) {\n options.applyRequestContexts();\n const freshHtml = await renderPagesIsrHtml({\n buildId: options.buildId,\n cachedHtml: cachedValue.html,\n createPageElement: options.createPageElement,\n i18n: options.i18n,\n pageProps: freshResult.props,\n params: options.params,\n renderIsrPassToStringAsync: options.renderIsrPassToStringAsync,\n routePattern: options.routePattern,\n safeJsonStringify: options.safeJsonStringify,\n });\n\n await options.isrSet(\n cacheKey,\n buildPagesCacheValue(freshHtml, freshResult.props),\n freshResult.revalidate,\n undefined,\n options.expireSeconds,\n );\n }\n });\n },\n {\n routerKind: \"Pages Router\",\n routePath: options.routePattern,\n routeType: \"render\",\n },\n );\n\n return {\n kind: \"response\",\n response: buildPagesCacheResponse(\n cachedValue.html,\n \"STALE\",\n options.fontLinkHeader,\n undefined,\n options.expireSeconds,\n cached.value.cacheControl,\n ),\n };\n }\n\n const result = await options.pageModule.getStaticProps({\n params: userFacingParams,\n locale: options.i18n.locale,\n locales: options.i18n.locales,\n defaultLocale: options.i18n.defaultLocale,\n });\n\n if (result?.props) {\n pageProps = result.props;\n }\n\n if (result?.redirect) {\n return {\n kind: \"response\",\n response: new Response(null, {\n status: resolvePagesRedirectStatus(result.redirect),\n headers: { Location: options.sanitizeDestination(result.redirect.destination) },\n }),\n };\n }\n\n if (result?.notFound) {\n return {\n kind: \"response\",\n response: options.isDataReq\n ? buildPagesDataNotFoundResponse()\n : buildPagesNotFoundResponse(),\n };\n }\n\n if (typeof result?.revalidate === \"number\" && result.revalidate > 0) {\n isrRevalidateSeconds = result.revalidate;\n }\n }\n\n return {\n kind: \"render\",\n gsspRes,\n isrRevalidateSeconds,\n pageProps,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,UACV,OAAO;GACL,MAAM;GACN,UAAU,IAAI,SAAS,MAAM;IAC3B,QAAQ,2BAA2B,OAAO,SAAS;IACnD,SAAS,EAAE,UAAU,QAAQ,oBAAoB,OAAO,SAAS,YAAY,EAAE;IAChF,CAAC;GACH;EAGH,IAAI,QAAQ,UACV,OAAO;GACL,MAAM;GACN,UAAU,QAAQ,YACd,gCAAgC,GAChC,4BAA4B;GACjC;EAGH,IAAI,OAAO,QAAQ,eAAe,YAAY,OAAO,aAAa,GAChE,uBAAuB,OAAO;;CAIlC,OAAO;EACL,MAAM;EACN;EACA;EACA;EACA,YAAY;EACb"}
1
+ {"version":3,"file":"pages-page-data.js","names":[],"sources":["../../src/server/pages-page-data.ts"],"sourcesContent":["import type { ReactNode } from \"react\";\nimport type { VinextNextData } from \"../client/vinext-next-data.js\";\nimport type { Route } from \"../routing/pages-router.js\";\nimport { normalizeStaticPathname } from \"../routing/route-pattern.js\";\nimport type { CachedPagesValue, CacheControlMetadata } from \"vinext/shims/cache\";\nimport { buildCachedRevalidateCacheControl } from \"./cache-control.js\";\nimport { buildCacheStateHeaders } from \"./cache-headers.js\";\nimport { buildPagesCacheValue, type ISRCacheEntry } from \"./isr-cache.js\";\nimport {\n buildPagesNextDataScript,\n type PagesGsspResponse,\n type PagesI18nRenderContext,\n} from \"./pages-page-response.js\";\nimport { buildDefaultPagesNotFoundResponse } from \"./pages-default-404.js\";\nimport { isSerializableProps } from \"./pages-serializable-props.js\";\n\ntype PagesRedirectResult = {\n destination: string;\n permanent?: boolean;\n statusCode?: number;\n};\n\n// Next.js allows `paths` entries to be either an object with a `params` key\n// or a raw string path. We keep a local variant of `StaticPathsEntry` here\n// because at request time we compare against the actual request `params`\n// (whose value type is `unknown` from the route matcher) rather than the\n// `string | string[]` shape used at build time. The shared\n// `normalizeStaticPathname` helper from `../routing/route-pattern.js` is used\n// to canonicalize the string-entry comparison.\ntype PagesStaticPathsEntry = string | { params?: Record<string, unknown>; locale?: string };\n\ntype PagesStaticPathsResult = {\n fallback?: boolean | \"blocking\";\n paths?: PagesStaticPathsEntry[];\n};\n\ntype PagesPagePropsResult = {\n props?: Record<string, unknown>;\n redirect?: PagesRedirectResult;\n notFound?: boolean;\n revalidate?: number;\n};\n\nexport type PagesMutableGsspResponse = {\n headersSent: boolean;\n} & PagesGsspResponse;\n\nexport type PagesGsspContextResponse = {\n req: unknown;\n res: PagesMutableGsspResponse;\n responsePromise: Promise<Response>;\n};\n\nexport type PagesPageModule = {\n default?: unknown;\n getStaticPaths?: (context: {\n locales: string[];\n defaultLocale: string;\n }) => Promise<PagesStaticPathsResult> | PagesStaticPathsResult;\n /**\n * Pages Router data-fetching context.\n *\n * `params` is `null` for non-dynamic routes (no `[param]` segments) to\n * match Next.js. User code typically falls back via `params || null`, so\n * passing `null` (rather than `{}`) is required for the value to be\n * observable as `null` once the data flows through to the page props.\n *\n * See: test/e2e/edge-pages-support/index.test.ts in Next.js for the\n * authoritative assertion (`expect(props.params).toBe(null)`).\n */\n getServerSideProps?: (context: {\n params: Record<string, unknown> | null;\n req: unknown;\n res: PagesMutableGsspResponse;\n query: Record<string, unknown>;\n resolvedUrl: string;\n locale?: string;\n locales?: string[];\n defaultLocale?: string;\n }) => Promise<PagesPagePropsResult> | PagesPagePropsResult;\n getStaticProps?: (context: {\n params: Record<string, unknown> | null;\n locale?: string;\n locales?: string[];\n defaultLocale?: string;\n /**\n * Indicates why `getStaticProps` was invoked.\n *\n * - `\"build\"`: initial build-time prerender (before runtime traffic).\n * - `\"on-demand\"`: triggered by `res.revalidate()` from an API route.\n * - `\"stale\"`: stale-while-revalidate background regeneration.\n *\n * Mirrors Next.js `render.tsx`'s `revalidateReason` on the\n * `GetStaticPropsContext` type — see\n * `.nextjs-ref/packages/next/src/types.ts`.\n */\n revalidateReason?: \"build\" | \"on-demand\" | \"stale\";\n }) => Promise<PagesPagePropsResult> | PagesPagePropsResult;\n};\n\ntype RenderPagesIsrHtmlOptions = {\n buildId: string | null;\n cachedHtml: string;\n createPageElement: (pageProps: Record<string, unknown>) => ReactNode;\n i18n: PagesI18nRenderContext;\n pageProps: Record<string, unknown>;\n params: Record<string, unknown>;\n renderIsrPassToStringAsync: (element: ReactNode) => Promise<string>;\n routePattern: string;\n safeJsonStringify: (value: unknown) => string;\n vinext?: VinextNextData[\"__vinext\"];\n};\n\nexport type ResolvePagesPageDataOptions = {\n applyRequestContexts: () => void;\n buildId: string | null;\n /**\n * When true, this is a `/_next/data/<buildId>/<page>.json` request. Callers\n * that respond with a JSON envelope (`{ pageProps }`) instead of HTML must\n * bypass the HTML ISR cache: a cached HTML body cannot be reshaped into the\n * expected JSON shape, and storing JSON in the HTML cache would corrupt\n * subsequent HTML hits. Next.js handles this the same way — see\n * `isNextDataRequest` checks in `packages/next/src/server/base-server.ts`.\n */\n isDataReq?: boolean;\n createGsspReqRes: () => PagesGsspContextResponse;\n createPageElement: (pageProps: Record<string, unknown>) => ReactNode;\n fontLinkHeader: string;\n i18n: PagesI18nRenderContext;\n isrCacheKey: (router: string, pathname: string) => string;\n isrGet: (key: string) => Promise<ISRCacheEntry | null>;\n isrSet: (\n key: string,\n data: CachedPagesValue,\n revalidateSeconds: number,\n tags?: string[],\n expireSeconds?: number,\n ) => Promise<void>;\n expireSeconds?: number;\n /**\n * When true, this dispatch corresponds to a build-time prerender (the\n * `vinext` build phase fetches each statically generated page through the\n * production server). Maps to `revalidateReason: \"build\"` when\n * `getStaticProps` is invoked. Mirrors Next.js's\n * `renderOpts.isBuildTimePrerendering` flag — see\n * `.nextjs-ref/packages/next/src/server/render.tsx`.\n */\n isBuildTimePrerendering?: boolean;\n /**\n * When true, this dispatch was triggered by an on-demand revalidation\n * request (e.g. `res.revalidate()` in a Pages Router API route, or an\n * equivalent webhook). Maps to `revalidateReason: \"on-demand\"` when\n * `getStaticProps` is invoked. Mirrors Next.js's\n * `renderOpts.isOnDemandRevalidate` flag — see\n * `.nextjs-ref/packages/next/src/server/render.tsx`.\n *\n * Forward-looking plumbing: no caller currently sets this — `res.revalidate()`\n * is not yet implemented in vinext. The `\"on-demand\"` branch in the\n * `revalidateReason` resolver is intentionally unreachable today; keeping the\n * typed contract here means wiring it up will be a one-line change once the\n * trigger lands.\n */\n isOnDemandRevalidate?: boolean;\n pageModule: PagesPageModule;\n params: Record<string, unknown>;\n query: Record<string, unknown>;\n route: Pick<Route, \"isDynamic\">;\n routePattern: string;\n routeUrl: string;\n runInFreshUnifiedContext: <T>(callback: () => Promise<T>) => Promise<T>;\n safeJsonStringify: (value: unknown) => string;\n sanitizeDestination: (destination: string) => string;\n scriptNonce?: string;\n statusCode?: number;\n triggerBackgroundRegeneration: (\n key: string,\n renderFn: () => Promise<void>,\n errorContext?: { routerKind: \"Pages Router\"; routePath: string; routeType: \"render\" },\n ) => void;\n renderIsrPassToStringAsync: (element: ReactNode) => Promise<string>;\n vinext?: VinextNextData[\"__vinext\"];\n};\n\ntype ResolvePagesPageDataRenderResult = {\n kind: \"render\";\n gsspRes: PagesGsspResponse | null;\n isrRevalidateSeconds: number | null;\n pageProps: Record<string, unknown>;\n /**\n * True when `getStaticPaths` returned `fallback: true` AND the requested path\n * is not in the pre-rendered list. The caller renders a loading shell with\n * empty props and `useRouter().isFallback === true` (matching Next.js's\n * `render.tsx` — `getStaticProps` is skipped on the fallback render).\n */\n isFallback: boolean;\n};\n\ntype ResolvePagesPageDataResponseResult = {\n kind: \"response\";\n response: Response;\n};\n\ntype ResolvePagesPageDataResult =\n | ResolvePagesPageDataRenderResult\n | ResolvePagesPageDataResponseResult;\n\nfunction buildPagesNotFoundResponse(): Response {\n return buildDefaultPagesNotFoundResponse();\n}\n\nfunction buildPagesDataNotFoundResponse(): Response {\n // Matches Next.js: `/_next/data/<buildId>/<page>.json` 404 responses use\n // application/json with an empty object body so clients can call\n // `res.json()` without throwing before inspecting the status code.\n return new Response(\"{}\", {\n status: 404,\n headers: { \"Content-Type\": \"application/json\" },\n });\n}\n\nfunction resolvePagesRedirectStatus(redirect: PagesRedirectResult): number {\n return redirect.statusCode != null ? redirect.statusCode : redirect.permanent ? 308 : 307;\n}\n\n/**\n * Compare a `getStaticPaths` entry against the actual request params.\n *\n * Handles both shapes Next.js allows:\n * - { params: { ... } }\n * - \"string-path\"\n *\n * For a string entry, compare the entry against the current request URL using\n * the shared `normalizeStaticPathname` helper from\n * `../routing/route-pattern.ts` (which mirrors the Next.js\n * `removeTrailingSlash` behaviour in\n * `.nextjs-ref/packages/next/src/build/static-paths/pages.ts`). For an object\n * entry with a missing `params` key, return false rather than throwing — the\n * caller will respond with a 404 just like Next.js does for unlisted paths.\n */\nfunction matchesPagesStaticPath(\n pathEntry: PagesStaticPathsEntry,\n params: Record<string, unknown>,\n routeUrl: string,\n): boolean {\n if (typeof pathEntry === \"string\") {\n return normalizeStaticPathname(pathEntry) === normalizeStaticPathname(routeUrl);\n }\n const entryParams = pathEntry.params;\n if (entryParams === undefined || entryParams === null) {\n return false;\n }\n return Object.entries(entryParams).every(([key, value]) => {\n const actual = params[key];\n if (Array.isArray(value)) {\n return Array.isArray(actual) && value.join(\"/\") === actual.join(\"/\");\n }\n return String(value) === String(actual);\n });\n}\n\nfunction buildPagesCacheResponse(\n html: string,\n cacheState: \"HIT\" | \"STALE\",\n fontLinkHeader: string,\n revalidateSeconds?: number,\n expireSeconds?: number,\n cacheControl?: CacheControlMetadata,\n status?: number,\n): Response {\n // Legacy cache entries written before cacheControl metadata existed can still\n // hit this path without a persisted revalidate value; keep the historic\n // 60-second fallback for that migration window.\n const effectiveRevalidateSeconds = cacheControl?.revalidate ?? revalidateSeconds ?? 60;\n const effectiveExpireSeconds =\n cacheControl === undefined ? undefined : (cacheControl.expire ?? expireSeconds);\n const headers: Record<string, string> = {\n \"Content-Type\": \"text/html\",\n ...buildCacheStateHeaders(cacheState),\n \"Cache-Control\": buildCachedRevalidateCacheControl(\n cacheState,\n effectiveRevalidateSeconds,\n effectiveExpireSeconds,\n ),\n };\n\n if (fontLinkHeader) {\n headers.Link = fontLinkHeader;\n }\n\n return new Response(html, {\n status: status ?? 200,\n headers,\n });\n}\n\nfunction rewritePagesCachedHtml(\n cachedHtml: string,\n freshBody: string,\n nextDataScript: string,\n): string {\n const bodyMarker = '<div id=\"__next\">';\n const bodyStart = cachedHtml.indexOf(bodyMarker);\n const contentStart = bodyStart >= 0 ? bodyStart + bodyMarker.length : -1;\n // This intentionally looks for the bare inline __NEXT_DATA__ marker.\n // Pages responses with scriptNonce are excluded from ISR writes, so cached\n // HTML should never contain nonce-prefixed __NEXT_DATA__ scripts here.\n const nextDataMarker = \"<script>window.__NEXT_DATA__\";\n const nextDataStart = cachedHtml.indexOf(nextDataMarker);\n\n if (contentStart >= 0 && nextDataStart >= 0) {\n const region = cachedHtml.slice(contentStart, nextDataStart);\n const lastCloseDiv = region.lastIndexOf(\"</div>\");\n const gap = lastCloseDiv >= 0 ? region.slice(lastCloseDiv + 6) : \"\";\n const nextDataEnd = cachedHtml.indexOf(\"</script>\", nextDataStart) + 9;\n const tail = cachedHtml.slice(nextDataEnd);\n\n return cachedHtml.slice(0, contentStart) + freshBody + \"</div>\" + gap + nextDataScript + tail;\n }\n\n return (\n '<!DOCTYPE html>\\n<html>\\n<head>\\n</head>\\n<body>\\n <div id=\"__next\">' +\n freshBody +\n \"</div>\\n \" +\n nextDataScript +\n \"\\n</body>\\n</html>\"\n );\n}\n\nexport async function renderPagesIsrHtml(options: RenderPagesIsrHtmlOptions): Promise<string> {\n const freshBody = await options.renderIsrPassToStringAsync(\n options.createPageElement(options.pageProps),\n );\n const nextDataScript = buildPagesNextDataScript({\n buildId: options.buildId,\n i18n: options.i18n,\n pageProps: options.pageProps,\n params: options.params,\n routePattern: options.routePattern,\n safeJsonStringify: options.safeJsonStringify,\n vinext: options.vinext,\n });\n\n return rewritePagesCachedHtml(options.cachedHtml, freshBody, nextDataScript);\n}\n\nexport async function resolvePagesPageData(\n options: ResolvePagesPageDataOptions,\n): Promise<ResolvePagesPageDataResult> {\n // Next.js passes `params: null` (effectively) to gSSP/gSP context for\n // non-dynamic routes — see render.tsx's `...(pageIsDynamic ? { params } : undefined)`.\n // Internal bookkeeping (route param hydration, ISR HTML, getStaticPaths\n // validation) still uses the matched-but-empty object — only user-facing\n // data-fetching contexts surface `null`.\n const userFacingParams: Record<string, unknown> | null = options.route.isDynamic\n ? options.params\n : null;\n\n // Set when `getStaticPaths: { fallback: true }` is configured and the\n // requested path is NOT in the pre-rendered list. When true, we render the\n // loading shell with empty props and `useRouter().isFallback === true`,\n // skipping `getStaticProps`. Matches Next.js `render.tsx`'s\n // `if (isSSG && !isFallback)` gate around `getStaticProps`. Data requests\n // (`/_next/data/...json`) still call `getStaticProps` so the client can\n // hydrate the page after the fallback shell ships.\n let isFallback = false;\n\n if (typeof options.pageModule.getStaticPaths === \"function\" && options.route.isDynamic) {\n const pathsResult = await options.pageModule.getStaticPaths({\n locales: options.i18n.locales ?? [],\n defaultLocale: options.i18n.defaultLocale ?? \"\",\n });\n const fallback = pathsResult?.fallback ?? false;\n const paths = pathsResult?.paths ?? [];\n const isValidPath = paths.some((pathEntry) =>\n matchesPagesStaticPath(pathEntry, options.params, options.routeUrl),\n );\n\n if (fallback === false && !isValidPath) {\n // For data requests (`/_next/data/...json`), return a JSON-shaped 404\n // so the client router can `res.json()` without blowing up — matches\n // Next.js' behavior. HTML navigations still get the HTML 404 page.\n return {\n kind: \"response\",\n response: options.isDataReq\n ? buildPagesDataNotFoundResponse()\n : buildPagesNotFoundResponse(),\n };\n }\n\n // Render the fallback shell for unlisted paths under `fallback: true`.\n // Data requests resolve props normally so the client can fill in after\n // the loading shell ships (`fallback: 'blocking'` keeps SSRing as before).\n if (fallback === true && !isValidPath && !options.isDataReq) {\n isFallback = true;\n }\n }\n\n let pageProps: Record<string, unknown> = {};\n let gsspRes: PagesMutableGsspResponse | null = null;\n\n if (isFallback) {\n return {\n kind: \"render\",\n gsspRes: null,\n isrRevalidateSeconds: null,\n pageProps,\n isFallback: true,\n };\n }\n\n if (typeof options.pageModule.getServerSideProps === \"function\") {\n const { req, res, responsePromise } = options.createGsspReqRes();\n const result = await options.pageModule.getServerSideProps({\n params: userFacingParams,\n req,\n res,\n query: options.query,\n resolvedUrl: options.routeUrl,\n locale: options.i18n.locale,\n locales: options.i18n.locales,\n defaultLocale: options.i18n.defaultLocale,\n });\n\n if (res.headersSent) {\n return {\n kind: \"response\",\n response: await responsePromise,\n };\n }\n\n if (result?.props) {\n // Next.js explicitly supports a Promise value for `props`. Await it\n // before serialising; otherwise pageProps would be a Promise and the\n // rendered page would receive empty props. See\n // packages/next/src/server/render.tsx (deferredContent).\n pageProps = (await Promise.resolve(result.props)) as Record<string, unknown>;\n }\n\n if (result?.redirect) {\n return {\n kind: \"response\",\n response: new Response(null, {\n status: resolvePagesRedirectStatus(result.redirect),\n headers: { Location: options.sanitizeDestination(result.redirect.destination) },\n }),\n };\n }\n\n if (result?.notFound) {\n return {\n kind: \"response\",\n response: options.isDataReq\n ? buildPagesDataNotFoundResponse()\n : buildPagesNotFoundResponse(),\n };\n }\n\n // Mirrors Next.js render.tsx's `isSerializableProps(pathname, \"getServerSideProps\", data.props)`\n // check, gated on `!metadata.isRedirect && !metadata.isNotFound` (both\n // short-circuit above). Throws a friendly `SerializableError` so the\n // caller's existing try/catch surfaces a clear 500 instead of rendering\n // an empty page. See\n // .nextjs-ref/packages/next/src/server/render.tsx (~line 1200) and\n // .nextjs-ref/packages/next/src/lib/is-serializable-props.ts. Tracked in\n // vinext#1478.\n if (result?.props !== undefined) {\n isSerializableProps(options.routePattern, \"getServerSideProps\", pageProps);\n }\n\n gsspRes = res;\n }\n\n let isrRevalidateSeconds: number | null = null;\n\n if (typeof options.pageModule.getStaticProps === \"function\") {\n const pathname = options.routeUrl.split(\"?\")[0];\n const cacheKey = options.isrCacheKey(\"pages\", pathname);\n const cached = await options.isrGet(cacheKey);\n const cachedValue = cached?.value.value;\n\n if (\n cachedValue?.kind === \"PAGES\" &&\n cached &&\n !cached.isStale &&\n !options.scriptNonce &&\n !options.isDataReq\n ) {\n return {\n kind: \"response\",\n response: buildPagesCacheResponse(\n cachedValue.html,\n \"HIT\",\n options.fontLinkHeader,\n undefined,\n options.expireSeconds,\n cached.value.cacheControl,\n cachedValue.status,\n ),\n };\n }\n\n if (\n cachedValue?.kind === \"PAGES\" &&\n cached &&\n cached.isStale &&\n !options.scriptNonce &&\n !options.isDataReq\n ) {\n options.triggerBackgroundRegeneration(\n cacheKey,\n async function () {\n return options.runInFreshUnifiedContext(async () => {\n const freshResult = await options.pageModule.getStaticProps?.({\n params: userFacingParams,\n locale: options.i18n.locale,\n locales: options.i18n.locales,\n defaultLocale: options.i18n.defaultLocale,\n // Background regeneration for an entry that is already in the\n // cache is always a stale-while-revalidate refresh — mirrors\n // Next.js `render.tsx` (`isBuildTimeSSG ? \"build\" : \"stale\"`,\n // and we're not at build time here).\n revalidateReason: \"stale\",\n });\n\n if (\n freshResult?.props &&\n typeof freshResult.revalidate === \"number\" &&\n freshResult.revalidate > 0\n ) {\n options.applyRequestContexts();\n const freshHtml = await renderPagesIsrHtml({\n buildId: options.buildId,\n cachedHtml: cachedValue.html,\n createPageElement: options.createPageElement,\n i18n: options.i18n,\n pageProps: freshResult.props,\n params: options.params,\n renderIsrPassToStringAsync: options.renderIsrPassToStringAsync,\n routePattern: options.routePattern,\n safeJsonStringify: options.safeJsonStringify,\n vinext: options.vinext,\n });\n\n await options.isrSet(\n cacheKey,\n buildPagesCacheValue(freshHtml, freshResult.props, options.statusCode),\n freshResult.revalidate,\n undefined,\n options.expireSeconds,\n );\n }\n });\n },\n {\n routerKind: \"Pages Router\",\n routePath: options.routePattern,\n routeType: \"render\",\n },\n );\n\n return {\n kind: \"response\",\n response: buildPagesCacheResponse(\n cachedValue.html,\n \"STALE\",\n options.fontLinkHeader,\n undefined,\n options.expireSeconds,\n cached.value.cacheControl,\n cachedValue.status,\n ),\n };\n }\n\n const result = await options.pageModule.getStaticProps({\n params: userFacingParams,\n locale: options.i18n.locale,\n locales: options.i18n.locales,\n defaultLocale: options.i18n.defaultLocale,\n // Maps Next.js's resolution in `render.tsx`:\n // isOnDemandRevalidate ? \"on-demand\"\n // : isBuildTimeSSG ? \"build\"\n // : \"stale\"\n // We pick \"stale\" as the default at runtime so existing-but-missing\n // (cache evicted) entries surface as a regeneration rather than a build.\n revalidateReason: options.isOnDemandRevalidate\n ? \"on-demand\"\n : options.isBuildTimePrerendering\n ? \"build\"\n : \"stale\",\n });\n\n if (result?.props) {\n pageProps = result.props;\n }\n\n if (result?.redirect) {\n return {\n kind: \"response\",\n response: new Response(null, {\n status: resolvePagesRedirectStatus(result.redirect),\n headers: { Location: options.sanitizeDestination(result.redirect.destination) },\n }),\n };\n }\n\n if (result?.notFound) {\n return {\n kind: \"response\",\n response: options.isDataReq\n ? buildPagesDataNotFoundResponse()\n : buildPagesNotFoundResponse(),\n };\n }\n\n // Mirrors Next.js render.tsx's `isSerializableProps(pathname, \"getStaticProps\", data.props)`\n // check, gated on `!metadata.isNotFound` (notFound + redirect both\n // short-circuit above). Throws a friendly `SerializableError` so the\n // caller's existing try/catch surfaces a clear 500 instead of rendering\n // an empty page. See\n // .nextjs-ref/packages/next/src/server/render.tsx (~line 982) and\n // .nextjs-ref/packages/next/src/lib/is-serializable-props.ts. Tracked in\n // vinext#1478.\n if (result?.props !== undefined) {\n isSerializableProps(options.routePattern, \"getStaticProps\", pageProps);\n }\n\n if (typeof result?.revalidate === \"number\" && result.revalidate > 0) {\n isrRevalidateSeconds = result.revalidate;\n }\n }\n\n return {\n kind: \"render\",\n gsspRes,\n isrRevalidateSeconds,\n pageProps,\n isFallback: false,\n };\n}\n"],"mappings":";;;;;;;;AA8MA,SAAS,6BAAuC;CAC9C,OAAO,mCAAmC;;AAG5C,SAAS,iCAA2C;CAIlD,OAAO,IAAI,SAAS,MAAM;EACxB,QAAQ;EACR,SAAS,EAAE,gBAAgB,oBAAoB;EAChD,CAAC;;AAGJ,SAAS,2BAA2B,UAAuC;CACzE,OAAO,SAAS,cAAc,OAAO,SAAS,aAAa,SAAS,YAA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ACnD,SAAS,EAAE,UAAU,QAAQ,oBAAoB,OAAO,SAAS,YAAY,EAAE;IAChF,CAAC;GACH;EAGH,IAAI,QAAQ,UACV,OAAO;GACL,MAAM;GACN,UAAU,QAAQ,YACd,gCAAgC,GAChC,4BAA4B;GACjC;EAWH,IAAI,QAAQ,UAAU,KAAA,GACpB,oBAAoB,QAAQ,cAAc,kBAAkB,UAAU;EAGxE,IAAI,OAAO,QAAQ,eAAe,YAAY,OAAO,aAAa,GAChE,uBAAuB,OAAO;;CAIlC,OAAO;EACL,MAAM;EACN;EACA;EACA;EACA,YAAY;EACb"}
@@ -0,0 +1,48 @@
1
+ //#region src/server/pages-page-method.d.ts
2
+ /**
3
+ * Pages Router method-allow policy.
4
+ *
5
+ * Mirrors Next.js's behavior in
6
+ * `.nextjs-ref/packages/next/src/server/base-server.ts` around L2277:
7
+ *
8
+ * if (
9
+ * !isPossibleServerAction &&
10
+ * !minimalPostponed &&
11
+ * !is404Page &&
12
+ * !is500Page &&
13
+ * pathname !== '/_error' &&
14
+ * req.method !== 'HEAD' &&
15
+ * req.method !== 'GET' &&
16
+ * (typeof components.Component === 'string' || isSSG)
17
+ * ) {
18
+ * res.statusCode = 405
19
+ * res.setHeader('Allow', ['GET', 'HEAD'])
20
+ * res.body('Method Not Allowed').send()
21
+ * return null
22
+ * }
23
+ *
24
+ * In vinext, a Pages Router route is "static" (no SSR per-request work) when
25
+ * it does not export `getServerSideProps`. Such routes — including plain
26
+ * components and `getStaticProps` (GSP) pages — must reject non-GET/HEAD
27
+ * requests with 405 + `Allow: GET, HEAD`.
28
+ *
29
+ * Server Actions (Pages Router supports `"use server"` for forms in newer
30
+ * Next.js versions) are out of scope here: vinext's Pages Router does not
31
+ * implement them, so there's no carve-out to add. If/when it does, this
32
+ * helper should grow an `isPossibleServerAction` opt-out parameter mirroring
33
+ * the App Router's `resolveAppPageMethodResponse`.
34
+ *
35
+ * Refs #1463.
36
+ */
37
+ type PagesPageMethodOptions = {
38
+ hasGetServerSideProps: boolean;
39
+ method: string;
40
+ };
41
+ /**
42
+ * Returns a 405 `Response` when the request method is not allowed for a
43
+ * static (no `getServerSideProps`) Pages Router page, otherwise `null`.
44
+ */
45
+ declare function resolvePagesPageMethodResponse(options: PagesPageMethodOptions): Response | null;
46
+ //#endregion
47
+ export { resolvePagesPageMethodResponse };
48
+ //# sourceMappingURL=pages-page-method.d.ts.map
@@ -0,0 +1,19 @@
1
+ import { methodNotAllowedResponse } from "./http-error-responses.js";
2
+ //#region src/server/pages-page-method.ts
3
+ function isNonGetOrHead(method) {
4
+ const normalizedMethod = method.toUpperCase();
5
+ return normalizedMethod !== "GET" && normalizedMethod !== "HEAD";
6
+ }
7
+ /**
8
+ * Returns a 405 `Response` when the request method is not allowed for a
9
+ * static (no `getServerSideProps`) Pages Router page, otherwise `null`.
10
+ */
11
+ function resolvePagesPageMethodResponse(options) {
12
+ if (!isNonGetOrHead(options.method)) return null;
13
+ if (options.hasGetServerSideProps) return null;
14
+ return methodNotAllowedResponse("GET, HEAD");
15
+ }
16
+ //#endregion
17
+ export { resolvePagesPageMethodResponse };
18
+
19
+ //# sourceMappingURL=pages-page-method.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pages-page-method.js","names":[],"sources":["../../src/server/pages-page-method.ts"],"sourcesContent":["import { methodNotAllowedResponse } from \"./http-error-responses.js\";\n\n/**\n * Pages Router method-allow policy.\n *\n * Mirrors Next.js's behavior in\n * `.nextjs-ref/packages/next/src/server/base-server.ts` around L2277:\n *\n * if (\n * !isPossibleServerAction &&\n * !minimalPostponed &&\n * !is404Page &&\n * !is500Page &&\n * pathname !== '/_error' &&\n * req.method !== 'HEAD' &&\n * req.method !== 'GET' &&\n * (typeof components.Component === 'string' || isSSG)\n * ) {\n * res.statusCode = 405\n * res.setHeader('Allow', ['GET', 'HEAD'])\n * res.body('Method Not Allowed').send()\n * return null\n * }\n *\n * In vinext, a Pages Router route is \"static\" (no SSR per-request work) when\n * it does not export `getServerSideProps`. Such routes — including plain\n * components and `getStaticProps` (GSP) pages — must reject non-GET/HEAD\n * requests with 405 + `Allow: GET, HEAD`.\n *\n * Server Actions (Pages Router supports `\"use server\"` for forms in newer\n * Next.js versions) are out of scope here: vinext's Pages Router does not\n * implement them, so there's no carve-out to add. If/when it does, this\n * helper should grow an `isPossibleServerAction` opt-out parameter mirroring\n * the App Router's `resolveAppPageMethodResponse`.\n *\n * Refs #1463.\n */\n\ntype PagesPageMethodOptions = {\n hasGetServerSideProps: boolean;\n method: string;\n};\n\nfunction isNonGetOrHead(method: string): boolean {\n const normalizedMethod = method.toUpperCase();\n return normalizedMethod !== \"GET\" && normalizedMethod !== \"HEAD\";\n}\n\n/**\n * Returns a 405 `Response` when the request method is not allowed for a\n * static (no `getServerSideProps`) Pages Router page, otherwise `null`.\n */\nexport function resolvePagesPageMethodResponse(options: PagesPageMethodOptions): Response | null {\n if (!isNonGetOrHead(options.method)) {\n return null;\n }\n\n if (options.hasGetServerSideProps) {\n return null;\n }\n\n return methodNotAllowedResponse(\"GET, HEAD\");\n}\n"],"mappings":";;AA2CA,SAAS,eAAe,QAAyB;CAC/C,MAAM,mBAAmB,OAAO,aAAa;CAC7C,OAAO,qBAAqB,SAAS,qBAAqB;;;;;;AAO5D,SAAgB,+BAA+B,SAAkD;CAC/F,IAAI,CAAC,eAAe,QAAQ,OAAO,EACjC,OAAO;CAGT,IAAI,QAAQ,uBACV,OAAO;CAGT,OAAO,yBAAyB,YAAY"}
@@ -29,6 +29,12 @@ type RenderPagesPageResponseOptions = {
29
29
  getFontLinks: () => string[];
30
30
  getFontStyles: () => string[];
31
31
  getSSRHeadHTML?: (() => string) | undefined;
32
+ /**
33
+ * Allow-list of OpenTelemetry propagation keys (from
34
+ * `experimental.clientTraceMetadata`) to emit as `<meta>` tags in the SSR
35
+ * head. Undefined or empty disables emission.
36
+ */
37
+ clientTraceMetadata?: readonly string[] | undefined;
32
38
  gsspRes: PagesGsspResponse | null;
33
39
  isrCacheKey: (router: string, pathname: string) => string;
34
40
  expireSeconds?: number;
@@ -51,6 +57,8 @@ type RenderPagesPageResponseOptions = {
51
57
  routeUrl: string;
52
58
  safeJsonStringify: (value: unknown) => string;
53
59
  scriptNonce?: string;
60
+ statusCode?: number;
61
+ vinext?: VinextNextData["__vinext"];
54
62
  };
55
63
  declare function buildPagesNextDataScript(options: Pick<RenderPagesPageResponseOptions, "buildId" | "i18n" | "isFallback" | "pageProps" | "params" | "routePattern" | "safeJsonStringify" | "scriptNonce"> & {
56
64
  vinext?: VinextNextData["__vinext"];
@@ -3,8 +3,10 @@ import { reportRequestError } from "./instrumentation.js";
3
3
  import { setCacheStateHeaders } from "./cache-headers.js";
4
4
  import { withScriptNonce } from "../shims/script-nonce-context.js";
5
5
  import { createInlineScriptTag, createNonceAttribute, escapeHtmlAttr } from "./html.js";
6
- import { buildRevalidateCacheControl } from "./cache-control.js";
6
+ import { getClientTraceMetadataHTML } from "./client-trace-metadata.js";
7
+ import { loadUserDocumentInitialProps } from "./pages-document-initial-props.js";
7
8
  import { readStreamAsText } from "../utils/text-stream.js";
9
+ import { buildRevalidateCacheControl } from "./cache-control.js";
8
10
  import React from "react";
9
11
  //#region src/server/pages-page-response.ts
10
12
  function buildPagesFontHeadHtml(fontLinks, fontPreloads, fontStyles, scriptNonce) {
@@ -35,7 +37,9 @@ function buildPagesNextDataScript(options) {
35
37
  }
36
38
  async function buildPagesShellHtml(bodyMarker, fontHeadHTML, nextDataScript, options) {
37
39
  if (options.DocumentComponent) {
38
- let html = await options.renderDocumentToString(React.createElement(options.DocumentComponent));
40
+ const docProps = await loadUserDocumentInitialProps(options.DocumentComponent);
41
+ const docElement = docProps ? React.createElement(options.DocumentComponent, docProps) : React.createElement(options.DocumentComponent);
42
+ let html = await options.renderDocumentToString(docElement);
39
43
  html = html.replace("__NEXT_MAIN__", bodyMarker);
40
44
  if (options.ssrHeadHTML || options.assetTags || fontHeadHTML) html = html.replace("</head>", ` ${fontHeadHTML}${options.ssrHeadHTML}\n ${options.assetTags}\n</head>`);
41
45
  html = html.replace("<!-- __NEXT_SCRIPTS__ -->", nextDataScript);
@@ -90,12 +94,12 @@ function schedulePagesIsrCacheWrite(options) {
90
94
  html: options.shellPrefix + bodyHtml + options.shellSuffix,
91
95
  pageData: options.pageData,
92
96
  headers: void 0,
93
- status: void 0
97
+ status: options.status
94
98
  }, options.revalidateSeconds, void 0, options.expireSeconds)).catch((error) => reportPagesIsrCacheWriteError(error, options.cacheKey, options.routePattern));
95
99
  getRequestExecutionContext()?.waitUntil(cacheWritePromise);
96
100
  }
97
- function applyGsspHeaders(headers, gsspRes) {
98
- if (!gsspRes) return 200;
101
+ function applyGsspHeaders(headers, gsspRes, statusCode) {
102
+ if (!gsspRes) return statusCode ?? 200;
99
103
  const gsspHeaders = gsspRes.getHeaders();
100
104
  for (const key of Object.keys(gsspHeaders)) {
101
105
  const value = gsspHeaders[key];
@@ -110,7 +114,7 @@ function applyGsspHeaders(headers, gsspRes) {
110
114
  if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") headers.set(key, String(value));
111
115
  }
112
116
  headers.set("Content-Type", "text/html");
113
- return gsspRes.statusCode;
117
+ return statusCode ?? gsspRes.statusCode;
114
118
  }
115
119
  async function renderPagesPageResponse(options) {
116
120
  const pageElement = withScriptNonce(React.createElement(React.Fragment, null, options.createPageElement(options.pageProps)), options.scriptNonce);
@@ -125,20 +129,26 @@ async function renderPagesPageResponse(options) {
125
129
  params: options.params,
126
130
  routePattern: options.routePattern,
127
131
  safeJsonStringify: options.safeJsonStringify,
128
- scriptNonce: options.scriptNonce
132
+ scriptNonce: options.scriptNonce,
133
+ vinext: options.vinext
129
134
  });
130
135
  const bodyMarker = "<!--VINEXT_STREAM_BODY-->";
131
136
  const bodyStream = await options.renderToReadableStream(pageElement);
137
+ const headFromShim = options.getSSRHeadHTML?.() ?? "";
138
+ const traceMetaHTML = getClientTraceMetadataHTML(options.clientTraceMetadata);
139
+ const ssrHeadHTML = traceMetaHTML ? `${headFromShim}\n ${traceMetaHTML}` : headFromShim;
132
140
  const shellHtml = await buildPagesShellHtml(bodyMarker, fontHeadHTML, nextDataScript, {
133
141
  assetTags: options.assetTags,
134
142
  DocumentComponent: options.DocumentComponent,
135
143
  renderDocumentToString: options.renderDocumentToString,
136
- ssrHeadHTML: options.getSSRHeadHTML?.() ?? ""
144
+ ssrHeadHTML
137
145
  });
138
146
  options.clearSsrContext();
139
147
  const markerIndex = shellHtml.indexOf(bodyMarker);
140
148
  const shellPrefix = shellHtml.slice(0, markerIndex);
141
149
  const shellSuffix = shellHtml.slice(markerIndex + 25);
150
+ const responseHeaders = new Headers({ "Content-Type": "text/html" });
151
+ const finalStatus = applyGsspHeaders(responseHeaders, options.gsspRes, options.statusCode);
142
152
  let responseBodyStream = bodyStream;
143
153
  if (!options.scriptNonce && options.isrRevalidateSeconds !== null && options.isrRevalidateSeconds > 0) {
144
154
  const cacheBodyStreamPair = bodyStream.tee();
@@ -154,17 +164,17 @@ async function renderPagesPageResponse(options) {
154
164
  setCache: options.isrSet,
155
165
  shellPrefix,
156
166
  shellSuffix,
167
+ status: finalStatus,
157
168
  stream: cacheBodyStream
158
169
  });
159
170
  }
160
171
  const compositeStream = await buildPagesCompositeStream(responseBodyStream, shellPrefix, shellSuffix);
161
- const responseHeaders = new Headers({ "Content-Type": "text/html" });
162
- const finalStatus = applyGsspHeaders(responseHeaders, options.gsspRes);
172
+ const userSetCacheControl = responseHeaders.has("Cache-Control");
163
173
  if (options.scriptNonce) responseHeaders.set("Cache-Control", "no-store, must-revalidate");
164
174
  else if (options.isrRevalidateSeconds) {
165
175
  responseHeaders.set("Cache-Control", buildRevalidateCacheControl(options.isrRevalidateSeconds, options.expireSeconds));
166
176
  setCacheStateHeaders(responseHeaders, "MISS");
167
- }
177
+ } else if (options.gsspRes && !userSetCacheControl) responseHeaders.set("Cache-Control", "private, no-cache, no-store, max-age=0, must-revalidate");
168
178
  if (options.fontLinkHeader) responseHeaders.set("Link", options.fontLinkHeader);
169
179
  return Object.assign(new Response(compositeStream, {
170
180
  status: finalStatus,
@@ -1 +1 @@
1
- {"version":3,"file":"pages-page-response.js","names":[],"sources":["../../src/server/pages-page-response.ts"],"sourcesContent":["import React, { type ComponentType, type ReactNode } from \"react\";\nimport type { VinextNextData } from \"../client/vinext-next-data.js\";\nimport type { CachedPagesValue } from \"vinext/shims/cache\";\nimport { withScriptNonce } from \"vinext/shims/script-nonce-context\";\nimport { getRequestExecutionContext } from \"vinext/shims/request-context\";\nimport { buildRevalidateCacheControl } from \"./cache-control.js\";\nimport { setCacheStateHeaders } from \"./cache-headers.js\";\nimport { createInlineScriptTag, createNonceAttribute, escapeHtmlAttr } from \"./html.js\";\nimport { reportRequestError } from \"./instrumentation.js\";\nimport { readStreamAsText } from \"../utils/text-stream.js\";\n\ntype PagesFontPreload = {\n href: string;\n type: string;\n};\n\nexport type PagesI18nRenderContext = {\n locale?: string;\n locales?: string[];\n defaultLocale?: string;\n domainLocales?: unknown;\n};\n\nexport type PagesGsspResponse = {\n statusCode: number;\n getHeaders(): Record<string, string | number | boolean | string[]>;\n};\n\ntype PagesStreamedHtmlResponse = {\n __vinextStreamedHtmlResponse?: boolean;\n} & Response;\n\ntype RenderPagesPageResponseOptions = {\n assetTags: string;\n buildId: string | null;\n clearSsrContext: () => void;\n createPageElement: (pageProps: Record<string, unknown>) => ReactNode;\n DocumentComponent: ComponentType | null;\n flushPreloads?: (() => Promise<void> | void) | undefined;\n fontLinkHeader: string;\n fontPreloads: PagesFontPreload[];\n getFontLinks: () => string[];\n getFontStyles: () => string[];\n getSSRHeadHTML?: (() => string) | undefined;\n gsspRes: PagesGsspResponse | null;\n isrCacheKey: (router: string, pathname: string) => string;\n expireSeconds?: number;\n isrRevalidateSeconds: number | null;\n isrSet: (\n key: string,\n data: CachedPagesValue,\n revalidateSeconds: number,\n tags?: string[],\n expireSeconds?: number,\n ) => Promise<void>;\n i18n: PagesI18nRenderContext;\n /**\n * True when rendering a `getStaticPaths` fallback shell for a path that\n * isn't pre-rendered (`fallback: true` + unlisted path). Forwarded to\n * `buildPagesNextDataScript` so the client serialises `isFallback: true`\n * into `__NEXT_DATA__`, then later hydrates by fetching the data URL.\n */\n isFallback?: boolean;\n pageProps: Record<string, unknown>;\n params: Record<string, unknown>;\n renderDocumentToString: (element: ReactNode) => Promise<string>;\n renderToReadableStream: (element: ReactNode) => Promise<ReadableStream<Uint8Array>>;\n resetSSRHead?: (() => void) | undefined;\n routePattern: string;\n routeUrl: string;\n safeJsonStringify: (value: unknown) => string;\n scriptNonce?: string;\n};\n\nfunction buildPagesFontHeadHtml(\n fontLinks: string[],\n fontPreloads: PagesFontPreload[],\n fontStyles: string[],\n scriptNonce?: string,\n): string {\n let html = \"\";\n const nonceAttr = createNonceAttribute(scriptNonce);\n\n for (const link of fontLinks) {\n html += `<link rel=\"stylesheet\"${nonceAttr} href=\"${escapeHtmlAttr(link)}\" />\\n `;\n }\n\n for (const preload of fontPreloads) {\n html += `<link rel=\"preload\"${nonceAttr} href=\"${escapeHtmlAttr(preload.href)}\" as=\"font\" type=\"${escapeHtmlAttr(preload.type)}\" crossorigin />\\n `;\n }\n\n if (fontStyles.length > 0) {\n html += `<style data-vinext-fonts${nonceAttr}>${fontStyles.join(\"\\n\")}</style>\\n `;\n }\n\n return html;\n}\n\nexport function buildPagesNextDataScript(\n options: Pick<\n RenderPagesPageResponseOptions,\n | \"buildId\"\n | \"i18n\"\n | \"isFallback\"\n | \"pageProps\"\n | \"params\"\n | \"routePattern\"\n | \"safeJsonStringify\"\n | \"scriptNonce\"\n > & {\n vinext?: VinextNextData[\"__vinext\"];\n },\n): string {\n const nextDataPayload: Record<string, unknown> = {\n props: { pageProps: options.pageProps },\n page: options.routePattern,\n query: options.params,\n buildId: options.buildId,\n isFallback: options.isFallback === true,\n };\n\n if (options.i18n.locales) {\n nextDataPayload.locale = options.i18n.locale;\n nextDataPayload.locales = options.i18n.locales;\n nextDataPayload.defaultLocale = options.i18n.defaultLocale;\n nextDataPayload.domainLocales = options.i18n.domainLocales;\n }\n\n if (options.vinext) {\n nextDataPayload.__vinext = options.vinext;\n }\n\n const localeGlobals = options.i18n.locales\n ? `;window.__VINEXT_LOCALE__=${options.safeJsonStringify(options.i18n.locale)}` +\n `;window.__VINEXT_LOCALES__=${options.safeJsonStringify(options.i18n.locales)}` +\n `;window.__VINEXT_DEFAULT_LOCALE__=${options.safeJsonStringify(options.i18n.defaultLocale)}`\n : \"\";\n\n return createInlineScriptTag(\n `window.__NEXT_DATA__ = ${options.safeJsonStringify(nextDataPayload)}${localeGlobals}`,\n options.scriptNonce,\n );\n}\n\nasync function buildPagesShellHtml(\n bodyMarker: string,\n fontHeadHTML: string,\n nextDataScript: string,\n options: Pick<\n RenderPagesPageResponseOptions,\n \"assetTags\" | \"DocumentComponent\" | \"renderDocumentToString\"\n > & {\n ssrHeadHTML: string;\n },\n): Promise<string> {\n if (options.DocumentComponent) {\n let html = await options.renderDocumentToString(React.createElement(options.DocumentComponent));\n html = html.replace(\"__NEXT_MAIN__\", bodyMarker);\n if (options.ssrHeadHTML || options.assetTags || fontHeadHTML) {\n html = html.replace(\n \"</head>\",\n ` ${fontHeadHTML}${options.ssrHeadHTML}\\n ${options.assetTags}\\n</head>`,\n );\n }\n html = html.replace(\"<!-- __NEXT_SCRIPTS__ -->\", nextDataScript);\n if (!html.includes(\"__NEXT_DATA__\")) {\n html = html.replace(\"</body>\", ` ${nextDataScript}\\n</body>`);\n }\n return html;\n }\n\n return (\n \"<!DOCTYPE html>\\n<html>\\n<head>\\n\" +\n ' <meta charset=\"utf-8\" />\\n' +\n ' <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\\n' +\n ` ${fontHeadHTML}${options.ssrHeadHTML}\\n` +\n ` ${options.assetTags}\\n` +\n \"</head>\\n<body>\\n\" +\n ` <div id=\"__next\">${bodyMarker}</div>\\n` +\n ` ${nextDataScript}\\n` +\n \"</body>\\n</html>\"\n );\n}\n\nasync function buildPagesCompositeStream(\n bodyStream: ReadableStream<Uint8Array>,\n shellPrefix: string,\n shellSuffix: string,\n): Promise<ReadableStream<Uint8Array>> {\n const encoder = new TextEncoder();\n\n return new ReadableStream({\n async start(controller) {\n controller.enqueue(encoder.encode(shellPrefix));\n const reader = bodyStream.getReader();\n try {\n for (;;) {\n const chunk = await reader.read();\n if (chunk.done) {\n break;\n }\n controller.enqueue(chunk.value);\n }\n } finally {\n reader.releaseLock();\n }\n controller.enqueue(encoder.encode(shellSuffix));\n controller.close();\n },\n });\n}\n\nasync function reportPagesIsrCacheWriteError(\n error: unknown,\n cacheKey: string,\n routePattern: string,\n): Promise<void> {\n console.error(`[vinext] Pages ISR cache write failed for ${cacheKey}:`, error);\n try {\n await reportRequestError(\n error instanceof Error ? error : new Error(String(error)),\n { path: cacheKey, method: \"GET\", headers: {} },\n {\n routerKind: \"Pages Router\",\n routePath: routePattern,\n routeType: \"render\",\n },\n );\n } catch {\n // Cache-write failure reporting must never make the background task reject.\n }\n}\n\nfunction schedulePagesIsrCacheWrite(options: {\n cacheKey: string;\n expireSeconds?: number;\n pageData: Record<string, unknown>;\n revalidateSeconds: number;\n routePattern: string;\n shellPrefix: string;\n shellSuffix: string;\n stream: ReadableStream<Uint8Array>;\n setCache: RenderPagesPageResponseOptions[\"isrSet\"];\n}): void {\n const cacheWritePromise = readStreamAsText(options.stream)\n .then((bodyHtml) =>\n options.setCache(\n options.cacheKey,\n {\n kind: \"PAGES\",\n html: options.shellPrefix + bodyHtml + options.shellSuffix,\n pageData: options.pageData,\n headers: undefined,\n status: undefined,\n },\n options.revalidateSeconds,\n undefined,\n options.expireSeconds,\n ),\n )\n .catch((error: unknown) =>\n reportPagesIsrCacheWriteError(error, options.cacheKey, options.routePattern),\n );\n\n getRequestExecutionContext()?.waitUntil(cacheWritePromise);\n}\n\nfunction applyGsspHeaders(headers: Headers, gsspRes: PagesGsspResponse | null): number {\n if (!gsspRes) {\n return 200;\n }\n\n const gsspHeaders = gsspRes.getHeaders();\n for (const key of Object.keys(gsspHeaders)) {\n const value = gsspHeaders[key];\n const lowerKey = key.toLowerCase();\n if (lowerKey === \"set-cookie\" && Array.isArray(value)) {\n for (const cookie of value) {\n headers.append(\"set-cookie\", String(cookie));\n }\n continue;\n }\n if (Array.isArray(value)) {\n headers.set(key, value.join(\", \"));\n continue;\n }\n if (typeof value === \"string\" || typeof value === \"number\" || typeof value === \"boolean\") {\n headers.set(key, String(value));\n }\n }\n headers.set(\"Content-Type\", \"text/html\");\n return gsspRes.statusCode;\n}\n\nexport async function renderPagesPageResponse(\n options: RenderPagesPageResponseOptions,\n): Promise<Response> {\n const pageElement = withScriptNonce(\n React.createElement(React.Fragment, null, options.createPageElement(options.pageProps)),\n options.scriptNonce,\n );\n\n options.resetSSRHead?.();\n await options.flushPreloads?.();\n\n const fontHeadHTML = buildPagesFontHeadHtml(\n options.getFontLinks(),\n options.fontPreloads,\n options.getFontStyles(),\n options.scriptNonce,\n );\n const nextDataScript = buildPagesNextDataScript({\n buildId: options.buildId,\n i18n: options.i18n,\n isFallback: options.isFallback,\n pageProps: options.pageProps,\n params: options.params,\n routePattern: options.routePattern,\n safeJsonStringify: options.safeJsonStringify,\n scriptNonce: options.scriptNonce,\n });\n const bodyMarker = \"<!--VINEXT_STREAM_BODY-->\";\n // Render the page FIRST so that <Head> and other SSR state collectors\n // (e.g. styled-jsx, useServerInsertedHTML) are populated before we read\n // them. This fixes a race condition where head styles were silently dropped\n // because they were collected before the page had finished rendering.\n // Mirrors Next.js fix: vercel/next.js@9853944\n const bodyStream = await options.renderToReadableStream(pageElement);\n\n const shellHtml = await buildPagesShellHtml(bodyMarker, fontHeadHTML, nextDataScript, {\n assetTags: options.assetTags,\n DocumentComponent: options.DocumentComponent,\n renderDocumentToString: options.renderDocumentToString,\n ssrHeadHTML: options.getSSRHeadHTML?.() ?? \"\",\n });\n\n options.clearSsrContext();\n\n const markerIndex = shellHtml.indexOf(bodyMarker);\n const shellPrefix = shellHtml.slice(0, markerIndex);\n const shellSuffix = shellHtml.slice(markerIndex + bodyMarker.length);\n\n let responseBodyStream = bodyStream;\n if (\n // Keep nonce-bearing pages out of ISR writes: rewritePagesCachedHtml()\n // later matches the cached __NEXT_DATA__ block via a bare <script> marker.\n !options.scriptNonce &&\n options.isrRevalidateSeconds !== null &&\n options.isrRevalidateSeconds > 0\n ) {\n const cacheBodyStreamPair = bodyStream.tee();\n responseBodyStream = cacheBodyStreamPair[0];\n const cacheBodyStream = cacheBodyStreamPair[1];\n const isrPathname = options.routeUrl.split(\"?\")[0];\n const cacheKey = options.isrCacheKey(\"pages\", isrPathname);\n\n schedulePagesIsrCacheWrite({\n cacheKey,\n expireSeconds: options.expireSeconds,\n pageData: options.pageProps,\n revalidateSeconds: options.isrRevalidateSeconds,\n routePattern: options.routePattern,\n setCache: options.isrSet,\n shellPrefix,\n shellSuffix,\n stream: cacheBodyStream,\n });\n }\n\n const compositeStream = await buildPagesCompositeStream(\n responseBodyStream,\n shellPrefix,\n shellSuffix,\n );\n\n const responseHeaders = new Headers({ \"Content-Type\": \"text/html\" });\n const finalStatus = applyGsspHeaders(responseHeaders, options.gsspRes);\n\n if (options.scriptNonce) {\n responseHeaders.set(\"Cache-Control\", \"no-store, must-revalidate\");\n } else if (options.isrRevalidateSeconds) {\n responseHeaders.set(\n \"Cache-Control\",\n buildRevalidateCacheControl(options.isrRevalidateSeconds, options.expireSeconds),\n );\n setCacheStateHeaders(responseHeaders, \"MISS\");\n }\n if (options.fontLinkHeader) {\n responseHeaders.set(\"Link\", options.fontLinkHeader);\n }\n\n const response: PagesStreamedHtmlResponse = Object.assign(\n new Response(compositeStream, {\n status: finalStatus,\n headers: responseHeaders,\n }),\n {\n __vinextStreamedHtmlResponse: true,\n },\n );\n // Mark the normal streamed HTML render so the Node prod server can strip\n // stale Content-Length only for this path, not for custom gSSP responses.\n return response;\n}\n"],"mappings":";;;;;;;;;AA0EA,SAAS,uBACP,WACA,cACA,YACA,aACQ;CACR,IAAI,OAAO;CACX,MAAM,YAAY,qBAAqB,YAAY;CAEnD,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-response.ts"],"sourcesContent":["import React, { type ComponentType, type ReactNode } from \"react\";\nimport type { VinextNextData } from \"../client/vinext-next-data.js\";\nimport type { CachedPagesValue } from \"vinext/shims/cache\";\nimport { withScriptNonce } from \"vinext/shims/script-nonce-context\";\nimport { getRequestExecutionContext } from \"vinext/shims/request-context\";\nimport { buildRevalidateCacheControl } from \"./cache-control.js\";\nimport { setCacheStateHeaders } from \"./cache-headers.js\";\nimport { createInlineScriptTag, createNonceAttribute, escapeHtmlAttr } from \"./html.js\";\nimport { getClientTraceMetadataHTML } from \"./client-trace-metadata.js\";\nimport { reportRequestError } from \"./instrumentation.js\";\nimport { loadUserDocumentInitialProps } from \"./pages-document-initial-props.js\";\nimport { readStreamAsText } from \"../utils/text-stream.js\";\n\ntype PagesFontPreload = {\n href: string;\n type: string;\n};\n\nexport type PagesI18nRenderContext = {\n locale?: string;\n locales?: string[];\n defaultLocale?: string;\n domainLocales?: unknown;\n};\n\nexport type PagesGsspResponse = {\n statusCode: number;\n getHeaders(): Record<string, string | number | boolean | string[]>;\n};\n\ntype PagesStreamedHtmlResponse = {\n __vinextStreamedHtmlResponse?: boolean;\n} & Response;\n\ntype RenderPagesPageResponseOptions = {\n assetTags: string;\n buildId: string | null;\n clearSsrContext: () => void;\n createPageElement: (pageProps: Record<string, unknown>) => ReactNode;\n DocumentComponent: ComponentType | null;\n flushPreloads?: (() => Promise<void> | void) | undefined;\n fontLinkHeader: string;\n fontPreloads: PagesFontPreload[];\n getFontLinks: () => string[];\n getFontStyles: () => string[];\n getSSRHeadHTML?: (() => string) | undefined;\n /**\n * Allow-list of OpenTelemetry propagation keys (from\n * `experimental.clientTraceMetadata`) to emit as `<meta>` tags in the SSR\n * head. Undefined or empty disables emission.\n */\n clientTraceMetadata?: readonly string[] | undefined;\n gsspRes: PagesGsspResponse | null;\n isrCacheKey: (router: string, pathname: string) => string;\n expireSeconds?: number;\n isrRevalidateSeconds: number | null;\n isrSet: (\n key: string,\n data: CachedPagesValue,\n revalidateSeconds: number,\n tags?: string[],\n expireSeconds?: number,\n ) => Promise<void>;\n i18n: PagesI18nRenderContext;\n /**\n * True when rendering a `getStaticPaths` fallback shell for a path that\n * isn't pre-rendered (`fallback: true` + unlisted path). Forwarded to\n * `buildPagesNextDataScript` so the client serialises `isFallback: true`\n * into `__NEXT_DATA__`, then later hydrates by fetching the data URL.\n */\n isFallback?: boolean;\n pageProps: Record<string, unknown>;\n params: Record<string, unknown>;\n renderDocumentToString: (element: ReactNode) => Promise<string>;\n renderToReadableStream: (element: ReactNode) => Promise<ReadableStream<Uint8Array>>;\n resetSSRHead?: (() => void) | undefined;\n routePattern: string;\n routeUrl: string;\n safeJsonStringify: (value: unknown) => string;\n scriptNonce?: string;\n statusCode?: number;\n vinext?: VinextNextData[\"__vinext\"];\n};\n\nfunction buildPagesFontHeadHtml(\n fontLinks: string[],\n fontPreloads: PagesFontPreload[],\n fontStyles: string[],\n scriptNonce?: string,\n): string {\n let html = \"\";\n const nonceAttr = createNonceAttribute(scriptNonce);\n\n for (const link of fontLinks) {\n html += `<link rel=\"stylesheet\"${nonceAttr} href=\"${escapeHtmlAttr(link)}\" />\\n `;\n }\n\n for (const preload of fontPreloads) {\n html += `<link rel=\"preload\"${nonceAttr} href=\"${escapeHtmlAttr(preload.href)}\" as=\"font\" type=\"${escapeHtmlAttr(preload.type)}\" crossorigin />\\n `;\n }\n\n if (fontStyles.length > 0) {\n html += `<style data-vinext-fonts${nonceAttr}>${fontStyles.join(\"\\n\")}</style>\\n `;\n }\n\n return html;\n}\n\nexport function buildPagesNextDataScript(\n options: Pick<\n RenderPagesPageResponseOptions,\n | \"buildId\"\n | \"i18n\"\n | \"isFallback\"\n | \"pageProps\"\n | \"params\"\n | \"routePattern\"\n | \"safeJsonStringify\"\n | \"scriptNonce\"\n > & {\n vinext?: VinextNextData[\"__vinext\"];\n },\n): string {\n const nextDataPayload: Record<string, unknown> = {\n props: { pageProps: options.pageProps },\n page: options.routePattern,\n query: options.params,\n buildId: options.buildId,\n isFallback: options.isFallback === true,\n };\n\n if (options.i18n.locales) {\n nextDataPayload.locale = options.i18n.locale;\n nextDataPayload.locales = options.i18n.locales;\n nextDataPayload.defaultLocale = options.i18n.defaultLocale;\n nextDataPayload.domainLocales = options.i18n.domainLocales;\n }\n\n if (options.vinext) {\n nextDataPayload.__vinext = options.vinext;\n }\n\n const localeGlobals = options.i18n.locales\n ? `;window.__VINEXT_LOCALE__=${options.safeJsonStringify(options.i18n.locale)}` +\n `;window.__VINEXT_LOCALES__=${options.safeJsonStringify(options.i18n.locales)}` +\n `;window.__VINEXT_DEFAULT_LOCALE__=${options.safeJsonStringify(options.i18n.defaultLocale)}`\n : \"\";\n\n return createInlineScriptTag(\n `window.__NEXT_DATA__ = ${options.safeJsonStringify(nextDataPayload)}${localeGlobals}`,\n options.scriptNonce,\n );\n}\n\nasync function buildPagesShellHtml(\n bodyMarker: string,\n fontHeadHTML: string,\n nextDataScript: string,\n options: Pick<\n RenderPagesPageResponseOptions,\n \"assetTags\" | \"DocumentComponent\" | \"renderDocumentToString\"\n > & {\n ssrHeadHTML: string;\n },\n): Promise<string> {\n if (options.DocumentComponent) {\n const docProps = await loadUserDocumentInitialProps(options.DocumentComponent);\n const docElement = docProps\n ? React.createElement(options.DocumentComponent, docProps)\n : React.createElement(options.DocumentComponent);\n let html = await options.renderDocumentToString(docElement);\n html = html.replace(\"__NEXT_MAIN__\", bodyMarker);\n if (options.ssrHeadHTML || options.assetTags || fontHeadHTML) {\n html = html.replace(\n \"</head>\",\n ` ${fontHeadHTML}${options.ssrHeadHTML}\\n ${options.assetTags}\\n</head>`,\n );\n }\n html = html.replace(\"<!-- __NEXT_SCRIPTS__ -->\", nextDataScript);\n if (!html.includes(\"__NEXT_DATA__\")) {\n html = html.replace(\"</body>\", ` ${nextDataScript}\\n</body>`);\n }\n return html;\n }\n\n return (\n \"<!DOCTYPE html>\\n<html>\\n<head>\\n\" +\n ' <meta charset=\"utf-8\" />\\n' +\n ' <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\\n' +\n ` ${fontHeadHTML}${options.ssrHeadHTML}\\n` +\n ` ${options.assetTags}\\n` +\n \"</head>\\n<body>\\n\" +\n ` <div id=\"__next\">${bodyMarker}</div>\\n` +\n ` ${nextDataScript}\\n` +\n \"</body>\\n</html>\"\n );\n}\n\nasync function buildPagesCompositeStream(\n bodyStream: ReadableStream<Uint8Array>,\n shellPrefix: string,\n shellSuffix: string,\n): Promise<ReadableStream<Uint8Array>> {\n const encoder = new TextEncoder();\n\n return new ReadableStream({\n async start(controller) {\n controller.enqueue(encoder.encode(shellPrefix));\n const reader = bodyStream.getReader();\n try {\n for (;;) {\n const chunk = await reader.read();\n if (chunk.done) {\n break;\n }\n controller.enqueue(chunk.value);\n }\n } finally {\n reader.releaseLock();\n }\n controller.enqueue(encoder.encode(shellSuffix));\n controller.close();\n },\n });\n}\n\nasync function reportPagesIsrCacheWriteError(\n error: unknown,\n cacheKey: string,\n routePattern: string,\n): Promise<void> {\n console.error(`[vinext] Pages ISR cache write failed for ${cacheKey}:`, error);\n try {\n await reportRequestError(\n error instanceof Error ? error : new Error(String(error)),\n { path: cacheKey, method: \"GET\", headers: {} },\n {\n routerKind: \"Pages Router\",\n routePath: routePattern,\n routeType: \"render\",\n },\n );\n } catch {\n // Cache-write failure reporting must never make the background task reject.\n }\n}\n\nfunction schedulePagesIsrCacheWrite(options: {\n cacheKey: string;\n expireSeconds?: number;\n pageData: Record<string, unknown>;\n revalidateSeconds: number;\n routePattern: string;\n shellPrefix: string;\n shellSuffix: string;\n status: number;\n stream: ReadableStream<Uint8Array>;\n setCache: RenderPagesPageResponseOptions[\"isrSet\"];\n}): void {\n const cacheWritePromise = readStreamAsText(options.stream)\n .then((bodyHtml) =>\n options.setCache(\n options.cacheKey,\n {\n kind: \"PAGES\",\n html: options.shellPrefix + bodyHtml + options.shellSuffix,\n pageData: options.pageData,\n headers: undefined,\n status: options.status,\n },\n options.revalidateSeconds,\n undefined,\n options.expireSeconds,\n ),\n )\n .catch((error: unknown) =>\n reportPagesIsrCacheWriteError(error, options.cacheKey, options.routePattern),\n );\n\n getRequestExecutionContext()?.waitUntil(cacheWritePromise);\n}\n\nfunction applyGsspHeaders(\n headers: Headers,\n gsspRes: PagesGsspResponse | null,\n statusCode?: number,\n): number {\n if (!gsspRes) {\n return statusCode ?? 200;\n }\n\n const gsspHeaders = gsspRes.getHeaders();\n for (const key of Object.keys(gsspHeaders)) {\n const value = gsspHeaders[key];\n const lowerKey = key.toLowerCase();\n if (lowerKey === \"set-cookie\" && Array.isArray(value)) {\n for (const cookie of value) {\n headers.append(\"set-cookie\", String(cookie));\n }\n continue;\n }\n if (Array.isArray(value)) {\n headers.set(key, value.join(\", \"));\n continue;\n }\n if (typeof value === \"string\" || typeof value === \"number\" || typeof value === \"boolean\") {\n headers.set(key, String(value));\n }\n }\n headers.set(\"Content-Type\", \"text/html\");\n return statusCode ?? gsspRes.statusCode;\n}\n\nexport async function renderPagesPageResponse(\n options: RenderPagesPageResponseOptions,\n): Promise<Response> {\n const pageElement = withScriptNonce(\n React.createElement(React.Fragment, null, options.createPageElement(options.pageProps)),\n options.scriptNonce,\n );\n\n options.resetSSRHead?.();\n await options.flushPreloads?.();\n\n const fontHeadHTML = buildPagesFontHeadHtml(\n options.getFontLinks(),\n options.fontPreloads,\n options.getFontStyles(),\n options.scriptNonce,\n );\n const nextDataScript = buildPagesNextDataScript({\n buildId: options.buildId,\n i18n: options.i18n,\n isFallback: options.isFallback,\n pageProps: options.pageProps,\n params: options.params,\n routePattern: options.routePattern,\n safeJsonStringify: options.safeJsonStringify,\n scriptNonce: options.scriptNonce,\n vinext: options.vinext,\n });\n const bodyMarker = \"<!--VINEXT_STREAM_BODY-->\";\n // Render the page FIRST so that <Head> and other SSR state collectors\n // (e.g. styled-jsx, useServerInsertedHTML) are populated before we read\n // them. This fixes a race condition where head styles were silently dropped\n // because they were collected before the page had finished rendering.\n // Mirrors Next.js fix: vercel/next.js@9853944\n const bodyStream = await options.renderToReadableStream(pageElement);\n\n const headFromShim = options.getSSRHeadHTML?.() ?? \"\";\n // Trace meta tags from the active OpenTelemetry context. When the\n // allow-list is unset (the common case) or OTel is not installed,\n // `getClientTraceMetadataHTML` returns \"\" and we forward the head HTML\n // verbatim — keeping the no-op path zero-overhead.\n const traceMetaHTML = getClientTraceMetadataHTML(options.clientTraceMetadata);\n const ssrHeadHTML = traceMetaHTML ? `${headFromShim}\\n ${traceMetaHTML}` : headFromShim;\n const shellHtml = await buildPagesShellHtml(bodyMarker, fontHeadHTML, nextDataScript, {\n assetTags: options.assetTags,\n DocumentComponent: options.DocumentComponent,\n renderDocumentToString: options.renderDocumentToString,\n ssrHeadHTML,\n });\n\n options.clearSsrContext();\n\n const markerIndex = shellHtml.indexOf(bodyMarker);\n const shellPrefix = shellHtml.slice(0, markerIndex);\n const shellSuffix = shellHtml.slice(markerIndex + bodyMarker.length);\n const responseHeaders = new Headers({ \"Content-Type\": \"text/html\" });\n const finalStatus = applyGsspHeaders(responseHeaders, options.gsspRes, options.statusCode);\n\n let responseBodyStream = bodyStream;\n if (\n // Keep nonce-bearing pages out of ISR writes: rewritePagesCachedHtml()\n // later matches the cached __NEXT_DATA__ block via a bare <script> marker.\n !options.scriptNonce &&\n options.isrRevalidateSeconds !== null &&\n options.isrRevalidateSeconds > 0\n ) {\n const cacheBodyStreamPair = bodyStream.tee();\n responseBodyStream = cacheBodyStreamPair[0];\n const cacheBodyStream = cacheBodyStreamPair[1];\n const isrPathname = options.routeUrl.split(\"?\")[0];\n const cacheKey = options.isrCacheKey(\"pages\", isrPathname);\n\n schedulePagesIsrCacheWrite({\n cacheKey,\n expireSeconds: options.expireSeconds,\n pageData: options.pageProps,\n revalidateSeconds: options.isrRevalidateSeconds,\n routePattern: options.routePattern,\n setCache: options.isrSet,\n shellPrefix,\n shellSuffix,\n status: finalStatus,\n stream: cacheBodyStream,\n });\n }\n\n const compositeStream = await buildPagesCompositeStream(\n responseBodyStream,\n shellPrefix,\n shellSuffix,\n );\n\n // Capture user-set Cache-Control (from getServerSideProps's res.setHeader)\n // so a downstream user override survives the gssp default below, and only\n // the default, never ISR/nonce Cache-Control which the runtime owns. Matches\n // Next.js's pages-handler.ts: `if (!res.getHeader('Cache-Control'))`.\n // responseHeaders/finalStatus are declared above so finalStatus can also feed\n // the ISR cache write; applyGsspHeaders is the only Cache-Control writer before\n // this point, so the captured value matches main's original capture site.\n const userSetCacheControl = responseHeaders.has(\"Cache-Control\");\n\n if (options.scriptNonce) {\n responseHeaders.set(\"Cache-Control\", \"no-store, must-revalidate\");\n } else if (options.isrRevalidateSeconds) {\n responseHeaders.set(\n \"Cache-Control\",\n buildRevalidateCacheControl(options.isrRevalidateSeconds, options.expireSeconds),\n );\n setCacheStateHeaders(responseHeaders, \"MISS\");\n } else if (options.gsspRes && !userSetCacheControl) {\n // Default for getServerSideProps responses, matching Next.js\n // pages-handler.ts (revalidate: 0 → getCacheControlHeader). Without this,\n // CDNs and browsers could cache per-request gssp responses.\n responseHeaders.set(\"Cache-Control\", \"private, no-cache, no-store, max-age=0, must-revalidate\");\n }\n if (options.fontLinkHeader) {\n responseHeaders.set(\"Link\", options.fontLinkHeader);\n }\n\n const response: PagesStreamedHtmlResponse = Object.assign(\n new Response(compositeStream, {\n status: finalStatus,\n headers: responseHeaders,\n }),\n {\n __vinextStreamedHtmlResponse: true,\n },\n );\n // Mark the normal streamed HTML render so the Node prod server can strip\n // stale Content-Length only for this path, not for custom gSSP responses.\n return response;\n}\n"],"mappings":";;;;;;;;;;;AAoFA,SAAS,uBACP,WACA,cACA,YACA,aACQ;CACR,IAAI,OAAO;CACX,MAAM,YAAY,qBAAqB,YAAY;CAEnD,KAAK,MAAM,QAAQ,WACjB,QAAQ,yBAAyB,UAAU,SAAS,eAAe,KAAK,CAAC;CAG3E,KAAK,MAAM,WAAW,cACpB,QAAQ,sBAAsB,UAAU,SAAS,eAAe,QAAQ,KAAK,CAAC,oBAAoB,eAAe,QAAQ,KAAK,CAAC;CAG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BAAgB,IAAI,QAAQ,QAAQ,eAAe;CAcrD,OAX4C,OAAO,OACjD,IAAI,SAAS,iBAAiB;EAC5B,QAAQ;EACR,SAAS;EACV,CAAC,EACF,EACE,8BAA8B,MAC/B,CAIY"}
@@ -0,0 +1,25 @@
1
+ //#region src/server/pages-serializable-props.d.ts
2
+ /**
3
+ * Validate that the value returned as `props` from `getStaticProps` /
4
+ * `getServerSideProps` is JSON-serializable. Throws a friendly
5
+ * `SerializableError` matching Next.js's error shape if it isn't.
6
+ *
7
+ * Ported from Next.js:
8
+ * .nextjs-ref/packages/next/src/lib/is-serializable-props.ts
9
+ * .nextjs-ref/packages/next/src/shared/lib/is-plain-object.ts
10
+ *
11
+ * Tested in Next.js by `test/unit/is-serializable-props.test.ts` and the
12
+ * `non-json` / `non-json-blocking` cases in `test/e2e/prerender.test.ts`.
13
+ *
14
+ * Next.js calls this from `packages/next/src/server/render.tsx` for both
15
+ * `getStaticProps` and `getServerSideProps`. We do the same in
16
+ * `pages-page-data.ts` so users see a clear error instead of an empty page
17
+ * when they accidentally return a `Date`, `Map`, or class instance.
18
+ */
19
+ declare class SerializableError extends Error {
20
+ constructor(page: string, method: string, path: string, message: string);
21
+ }
22
+ declare function isSerializableProps(page: string, method: string, input: unknown): true;
23
+ //#endregion
24
+ export { SerializableError, isSerializableProps };
25
+ //# sourceMappingURL=pages-serializable-props.d.ts.map
@@ -0,0 +1,69 @@
1
+ //#region src/server/pages-serializable-props.ts
2
+ /**
3
+ * Validate that the value returned as `props` from `getStaticProps` /
4
+ * `getServerSideProps` is JSON-serializable. Throws a friendly
5
+ * `SerializableError` matching Next.js's error shape if it isn't.
6
+ *
7
+ * Ported from Next.js:
8
+ * .nextjs-ref/packages/next/src/lib/is-serializable-props.ts
9
+ * .nextjs-ref/packages/next/src/shared/lib/is-plain-object.ts
10
+ *
11
+ * Tested in Next.js by `test/unit/is-serializable-props.test.ts` and the
12
+ * `non-json` / `non-json-blocking` cases in `test/e2e/prerender.test.ts`.
13
+ *
14
+ * Next.js calls this from `packages/next/src/server/render.tsx` for both
15
+ * `getStaticProps` and `getServerSideProps`. We do the same in
16
+ * `pages-page-data.ts` so users see a clear error instead of an empty page
17
+ * when they accidentally return a `Date`, `Map`, or class instance.
18
+ */
19
+ function getObjectClassLabel(value) {
20
+ return Object.prototype.toString.call(value);
21
+ }
22
+ function isPlainObject(value) {
23
+ if (getObjectClassLabel(value) !== "[object Object]") return false;
24
+ const prototype = Object.getPrototypeOf(value);
25
+ return prototype === null || Object.prototype.hasOwnProperty.call(prototype, "isPrototypeOf");
26
+ }
27
+ const REGEX_PLAIN_IDENTIFIER = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
28
+ var SerializableError = class extends Error {
29
+ constructor(page, method, path, message) {
30
+ super(path ? `Error serializing \`${path}\` returned from \`${method}\` in "${page}".\nReason: ${message}` : `Error serializing props returned from \`${method}\` in "${page}".\nReason: ${message}`);
31
+ this.name = "SerializableError";
32
+ }
33
+ };
34
+ function isSerializableProps(page, method, input) {
35
+ if (!isPlainObject(input)) throw new SerializableError(page, method, "", `Props must be returned as a plain object from ${method}: \`{ props: { ... } }\` (received: \`${getObjectClassLabel(input)}\`).`);
36
+ function visit(visited, value, path) {
37
+ if (visited.has(value)) throw new SerializableError(page, method, path, `Circular references cannot be expressed in JSON (references: \`${visited.get(value) || "(self)"}\`).`);
38
+ visited.set(value, path);
39
+ }
40
+ function isSerializable(refs, value, path) {
41
+ const type = typeof value;
42
+ if (value === null || type === "boolean" || type === "number" || type === "string") return true;
43
+ if (type === "undefined") throw new SerializableError(page, method, path, "`undefined` cannot be serialized as JSON. Please use `null` or omit this value.");
44
+ if (isPlainObject(value)) {
45
+ visit(refs, value, path);
46
+ const entries = Object.entries(value);
47
+ for (const [key, nestedValue] of entries) {
48
+ const nextPath = REGEX_PLAIN_IDENTIFIER.test(key) ? `${path}.${key}` : `${path}[${JSON.stringify(key)}]`;
49
+ const newRefs = new Map(refs);
50
+ isSerializable(newRefs, key, nextPath);
51
+ isSerializable(newRefs, nestedValue, nextPath);
52
+ }
53
+ return true;
54
+ }
55
+ if (Array.isArray(value)) {
56
+ visit(refs, value, path);
57
+ value.forEach((nestedValue, index) => {
58
+ isSerializable(new Map(refs), nestedValue, `${path}[${index}]`);
59
+ });
60
+ return true;
61
+ }
62
+ throw new SerializableError(page, method, path, `\`${type}\`${type === "object" ? ` ("${Object.prototype.toString.call(value)}")` : ""} cannot be serialized as JSON. Please only return JSON serializable data types.`);
63
+ }
64
+ return isSerializable(/* @__PURE__ */ new Map(), input, "");
65
+ }
66
+ //#endregion
67
+ export { SerializableError, isSerializableProps };
68
+
69
+ //# sourceMappingURL=pages-serializable-props.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pages-serializable-props.js","names":[],"sources":["../../src/server/pages-serializable-props.ts"],"sourcesContent":["/**\n * Validate that the value returned as `props` from `getStaticProps` /\n * `getServerSideProps` is JSON-serializable. Throws a friendly\n * `SerializableError` matching Next.js's error shape if it isn't.\n *\n * Ported from Next.js:\n * .nextjs-ref/packages/next/src/lib/is-serializable-props.ts\n * .nextjs-ref/packages/next/src/shared/lib/is-plain-object.ts\n *\n * Tested in Next.js by `test/unit/is-serializable-props.test.ts` and the\n * `non-json` / `non-json-blocking` cases in `test/e2e/prerender.test.ts`.\n *\n * Next.js calls this from `packages/next/src/server/render.tsx` for both\n * `getStaticProps` and `getServerSideProps`. We do the same in\n * `pages-page-data.ts` so users see a clear error instead of an empty page\n * when they accidentally return a `Date`, `Map`, or class instance.\n */\n\nfunction getObjectClassLabel(value: unknown): string {\n return Object.prototype.toString.call(value);\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n if (getObjectClassLabel(value) !== \"[object Object]\") {\n return false;\n }\n const prototype = Object.getPrototypeOf(value);\n\n // Mirrors Next.js's resilient prototype check — see the docstring in\n // .nextjs-ref/packages/next/src/shared/lib/is-plain-object.ts for the\n // explanation. `prototype.hasOwnProperty('isPrototypeOf')` lets us treat\n // cross-realm `Object` instances (vm boundaries, structuredClone) as plain.\n return prototype === null || Object.prototype.hasOwnProperty.call(prototype, \"isPrototypeOf\");\n}\n\nconst REGEX_PLAIN_IDENTIFIER = /^[A-Za-z_$][A-Za-z0-9_$]*$/;\n\nexport class SerializableError extends Error {\n constructor(page: string, method: string, path: string, message: string) {\n super(\n path\n ? `Error serializing \\`${path}\\` returned from \\`${method}\\` in \"${page}\".\\nReason: ${message}`\n : `Error serializing props returned from \\`${method}\\` in \"${page}\".\\nReason: ${message}`,\n );\n this.name = \"SerializableError\";\n }\n}\n\nexport function isSerializableProps(page: string, method: string, input: unknown): true {\n if (!isPlainObject(input)) {\n throw new SerializableError(\n page,\n method,\n \"\",\n `Props must be returned as a plain object from ${method}: \\`{ props: { ... } }\\` (received: \\`${getObjectClassLabel(\n input,\n )}\\`).`,\n );\n }\n\n function visit(visited: Map<unknown, string>, value: unknown, path: string): void {\n if (visited.has(value)) {\n throw new SerializableError(\n page,\n method,\n path,\n `Circular references cannot be expressed in JSON (references: \\`${\n visited.get(value) || \"(self)\"\n }\\`).`,\n );\n }\n visited.set(value, path);\n }\n\n function isSerializable(refs: Map<unknown, string>, value: unknown, path: string): true {\n const type = typeof value;\n if (\n // `null` is JSON-serializable, but `undefined` is not.\n value === null ||\n // `bigint`, `function`, `symbol`, and `undefined` are not serializable;\n // `object` is special-cased below.\n type === \"boolean\" ||\n type === \"number\" ||\n type === \"string\"\n ) {\n return true;\n }\n\n if (type === \"undefined\") {\n throw new SerializableError(\n page,\n method,\n path,\n \"`undefined` cannot be serialized as JSON. Please use `null` or omit this value.\",\n );\n }\n\n if (isPlainObject(value)) {\n visit(refs, value, path);\n\n const entries = Object.entries(value);\n for (const [key, nestedValue] of entries) {\n const nextPath = REGEX_PLAIN_IDENTIFIER.test(key)\n ? `${path}.${key}`\n : `${path}[${JSON.stringify(key)}]`;\n const newRefs = new Map(refs);\n isSerializable(newRefs, key, nextPath);\n isSerializable(newRefs, nestedValue, nextPath);\n }\n return true;\n }\n\n if (Array.isArray(value)) {\n visit(refs, value, path);\n\n value.forEach((nestedValue, index) => {\n const newRefs = new Map(refs);\n isSerializable(newRefs, nestedValue, `${path}[${index}]`);\n });\n return true;\n }\n\n throw new SerializableError(\n page,\n method,\n path,\n `\\`${type}\\`${\n type === \"object\" ? ` (\"${Object.prototype.toString.call(value)}\")` : \"\"\n } cannot be serialized as JSON. Please only return JSON serializable data types.`,\n );\n }\n\n return isSerializable(new Map(), input, \"\");\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAkBA,SAAS,oBAAoB,OAAwB;CACnD,OAAO,OAAO,UAAU,SAAS,KAAK,MAAM;;AAG9C,SAAS,cAAc,OAAkD;CACvE,IAAI,oBAAoB,MAAM,KAAK,mBACjC,OAAO;CAET,MAAM,YAAY,OAAO,eAAe,MAAM;CAM9C,OAAO,cAAc,QAAQ,OAAO,UAAU,eAAe,KAAK,WAAW,gBAAgB;;AAG/F,MAAM,yBAAyB;AAE/B,IAAa,oBAAb,cAAuC,MAAM;CAC3C,YAAY,MAAc,QAAgB,MAAc,SAAiB;EACvE,MACE,OACI,uBAAuB,KAAK,qBAAqB,OAAO,SAAS,KAAK,cAAc,YACpF,2CAA2C,OAAO,SAAS,KAAK,cAAc,UACnF;EACD,KAAK,OAAO;;;AAIhB,SAAgB,oBAAoB,MAAc,QAAgB,OAAsB;CACtF,IAAI,CAAC,cAAc,MAAM,EACvB,MAAM,IAAI,kBACR,MACA,QACA,IACA,iDAAiD,OAAO,wCAAwC,oBAC9F,MACD,CAAC,MACH;CAGH,SAAS,MAAM,SAA+B,OAAgB,MAAoB;EAChF,IAAI,QAAQ,IAAI,MAAM,EACpB,MAAM,IAAI,kBACR,MACA,QACA,MACA,kEACE,QAAQ,IAAI,MAAM,IAAI,SACvB,MACF;EAEH,QAAQ,IAAI,OAAO,KAAK;;CAG1B,SAAS,eAAe,MAA4B,OAAgB,MAAoB;EACtF,MAAM,OAAO,OAAO;EACpB,IAEE,UAAU,QAGV,SAAS,aACT,SAAS,YACT,SAAS,UAET,OAAO;EAGT,IAAI,SAAS,aACX,MAAM,IAAI,kBACR,MACA,QACA,MACA,kFACD;EAGH,IAAI,cAAc,MAAM,EAAE;GACxB,MAAM,MAAM,OAAO,KAAK;GAExB,MAAM,UAAU,OAAO,QAAQ,MAAM;GACrC,KAAK,MAAM,CAAC,KAAK,gBAAgB,SAAS;IACxC,MAAM,WAAW,uBAAuB,KAAK,IAAI,GAC7C,GAAG,KAAK,GAAG,QACX,GAAG,KAAK,GAAG,KAAK,UAAU,IAAI,CAAC;IACnC,MAAM,UAAU,IAAI,IAAI,KAAK;IAC7B,eAAe,SAAS,KAAK,SAAS;IACtC,eAAe,SAAS,aAAa,SAAS;;GAEhD,OAAO;;EAGT,IAAI,MAAM,QAAQ,MAAM,EAAE;GACxB,MAAM,MAAM,OAAO,KAAK;GAExB,MAAM,SAAS,aAAa,UAAU;IAEpC,eAAe,IADK,IAAI,KACF,EAAE,aAAa,GAAG,KAAK,GAAG,MAAM,GAAG;KACzD;GACF,OAAO;;EAGT,MAAM,IAAI,kBACR,MACA,QACA,MACA,KAAK,KAAK,IACR,SAAS,WAAW,MAAM,OAAO,UAAU,SAAS,KAAK,MAAM,CAAC,MAAM,GACvE,iFACF;;CAGH,OAAO,+BAAe,IAAI,KAAK,EAAE,OAAO,GAAG"}
@@ -0,0 +1,14 @@
1
+ //#region src/server/prerender-route-params.d.ts
2
+ type PrerenderRouteParams = Record<string, string | string[]>;
3
+ type PrerenderRouteParamsPayload = {
4
+ params: PrerenderRouteParams;
5
+ routePattern: string;
6
+ };
7
+ declare function serializePrerenderRouteParamsHeader(payload: PrerenderRouteParamsPayload | null): string | null;
8
+ declare function readTrustedPrerenderRouteParamsFromHeaders(headers: Headers, expectedSecret?: string): PrerenderRouteParamsPayload | null;
9
+ declare function readTrustedPrerenderRouteParams(request: Request): PrerenderRouteParamsPayload | null;
10
+ declare function prerenderRouteParamsPayloadMatchesRoute(payload: PrerenderRouteParamsPayload | null, routePattern: string, params: PrerenderRouteParams): payload is PrerenderRouteParamsPayload;
11
+ declare function encodePrerenderRouteParams(pattern: string, params: PrerenderRouteParams): PrerenderRouteParamsPayload | null;
12
+ //#endregion
13
+ export { PrerenderRouteParams, PrerenderRouteParamsPayload, encodePrerenderRouteParams, prerenderRouteParamsPayloadMatchesRoute, readTrustedPrerenderRouteParams, readTrustedPrerenderRouteParamsFromHeaders, serializePrerenderRouteParamsHeader };
14
+ //# sourceMappingURL=prerender-route-params.d.ts.map