vinext 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (243) hide show
  1. package/dist/build/client-build-config.d.ts +11 -2
  2. package/dist/build/client-build-config.js +17 -6
  3. package/dist/build/prerender.d.ts +9 -1
  4. package/dist/build/prerender.js +42 -12
  5. package/dist/build/run-prerender.d.ts +10 -2
  6. package/dist/build/run-prerender.js +15 -1
  7. package/dist/client/app-nav-failure-handler.d.ts +8 -0
  8. package/dist/client/app-nav-failure-handler.js +44 -0
  9. package/dist/client/pages-router-link-navigation.d.ts +33 -7
  10. package/dist/client/pages-router-link-navigation.js +32 -2
  11. package/dist/client/vinext-next-data.d.ts +18 -1
  12. package/dist/client/vinext-next-data.js +2 -0
  13. package/dist/client/window-next.d.ts +2 -1
  14. package/dist/client/window-next.js +12 -1
  15. package/dist/cloudflare/src/cache/cdn-adapter.runtime.js +6 -1
  16. package/dist/config/config-matchers.d.ts +11 -1
  17. package/dist/config/config-matchers.js +87 -16
  18. package/dist/config/next-config.d.ts +46 -4
  19. package/dist/config/next-config.js +147 -48
  20. package/dist/config/tsconfig-paths.js +14 -1
  21. package/dist/deploy.d.ts +30 -11
  22. package/dist/deploy.js +200 -112
  23. package/dist/entries/app-browser-entry.d.ts +9 -3
  24. package/dist/entries/app-browser-entry.js +21 -3
  25. package/dist/entries/app-rsc-entry.d.ts +2 -0
  26. package/dist/entries/app-rsc-entry.js +65 -5
  27. package/dist/entries/app-rsc-manifest.js +2 -0
  28. package/dist/entries/app-ssr-entry.js +1 -1
  29. package/dist/entries/pages-client-entry.js +66 -20
  30. package/dist/entries/pages-server-entry.js +47 -31
  31. package/dist/index.js +417 -102
  32. package/dist/plugins/dynamic-preload-metadata.js +2 -4
  33. package/dist/plugins/extensionless-dynamic-import.d.ts +6 -0
  34. package/dist/plugins/extensionless-dynamic-import.js +152 -0
  35. package/dist/plugins/fonts.js +5 -4
  36. package/dist/plugins/optimize-imports.d.ts +2 -1
  37. package/dist/plugins/optimize-imports.js +11 -9
  38. package/dist/plugins/postcss.js +7 -7
  39. package/dist/plugins/strip-server-exports.d.ts +9 -7
  40. package/dist/plugins/strip-server-exports.js +493 -46
  41. package/dist/plugins/typeof-window.d.ts +14 -0
  42. package/dist/plugins/typeof-window.js +150 -0
  43. package/dist/routing/app-route-graph.d.ts +2 -1
  44. package/dist/routing/app-route-graph.js +46 -16
  45. package/dist/routing/file-matcher.d.ts +10 -1
  46. package/dist/routing/file-matcher.js +22 -1
  47. package/dist/routing/pages-router.js +3 -3
  48. package/dist/routing/utils.d.ts +35 -6
  49. package/dist/routing/utils.js +59 -7
  50. package/dist/server/api-handler.d.ts +6 -1
  51. package/dist/server/api-handler.js +21 -15
  52. package/dist/server/app-browser-action-result.d.ts +19 -6
  53. package/dist/server/app-browser-action-result.js +20 -11
  54. package/dist/server/app-browser-entry.js +175 -91
  55. package/dist/server/app-browser-error.d.ts +10 -6
  56. package/dist/server/app-browser-error.js +43 -8
  57. package/dist/server/app-browser-hydration.d.ts +2 -0
  58. package/dist/server/app-browser-hydration.js +1 -0
  59. package/dist/server/app-browser-navigation-controller.d.ts +5 -3
  60. package/dist/server/app-browser-navigation-controller.js +23 -2
  61. package/dist/server/app-browser-server-action-navigation.d.ts +6 -0
  62. package/dist/server/app-browser-server-action-navigation.js +9 -0
  63. package/dist/server/app-browser-state.d.ts +1 -1
  64. package/dist/server/app-browser-state.js +19 -11
  65. package/dist/server/app-browser-stream.js +86 -43
  66. package/dist/server/app-browser-visible-commit.d.ts +1 -1
  67. package/dist/server/app-elements-wire.d.ts +6 -1
  68. package/dist/server/app-elements-wire.js +14 -4
  69. package/dist/server/app-elements.d.ts +2 -2
  70. package/dist/server/app-elements.js +2 -2
  71. package/dist/server/app-fallback-renderer.d.ts +1 -0
  72. package/dist/server/app-fallback-renderer.js +3 -1
  73. package/dist/server/app-optimistic-routing.js +2 -2
  74. package/dist/server/app-page-boundary-render.d.ts +1 -0
  75. package/dist/server/app-page-boundary-render.js +27 -14
  76. package/dist/server/app-page-cache-render.d.ts +53 -0
  77. package/dist/server/app-page-cache-render.js +91 -0
  78. package/dist/server/app-page-cache.d.ts +16 -2
  79. package/dist/server/app-page-cache.js +62 -1
  80. package/dist/server/app-page-dispatch.d.ts +26 -0
  81. package/dist/server/app-page-dispatch.js +149 -92
  82. package/dist/server/app-page-element-builder.d.ts +1 -0
  83. package/dist/server/app-page-element-builder.js +5 -2
  84. package/dist/server/app-page-execution.d.ts +6 -1
  85. package/dist/server/app-page-execution.js +21 -1
  86. package/dist/server/app-page-probe.d.ts +1 -0
  87. package/dist/server/app-page-probe.js +4 -0
  88. package/dist/server/app-page-render-observation.d.ts +3 -1
  89. package/dist/server/app-page-render-observation.js +17 -1
  90. package/dist/server/app-page-render.d.ts +12 -1
  91. package/dist/server/app-page-render.js +42 -4
  92. package/dist/server/app-page-request.d.ts +2 -0
  93. package/dist/server/app-page-request.js +2 -1
  94. package/dist/server/app-page-route-wiring.d.ts +3 -1
  95. package/dist/server/app-page-route-wiring.js +14 -5
  96. package/dist/server/app-page-stream.d.ts +15 -3
  97. package/dist/server/app-page-stream.js +11 -5
  98. package/dist/server/app-pages-bridge.d.ts +23 -1
  99. package/dist/server/app-pages-bridge.js +26 -17
  100. package/dist/server/app-ppr-fallback-shell-render.d.ts +17 -0
  101. package/dist/server/app-ppr-fallback-shell-render.js +26 -0
  102. package/dist/server/app-ppr-fallback-shell.d.ts +13 -1
  103. package/dist/server/app-ppr-fallback-shell.js +8 -1
  104. package/dist/server/app-route-handler-dispatch.js +9 -2
  105. package/dist/server/app-route-handler-policy.d.ts +1 -0
  106. package/dist/server/app-router-entry.js +5 -0
  107. package/dist/server/app-rsc-cache-busting.js +2 -0
  108. package/dist/server/app-rsc-handler.d.ts +28 -0
  109. package/dist/server/app-rsc-handler.js +195 -59
  110. package/dist/server/app-rsc-route-matching.d.ts +3 -0
  111. package/dist/server/app-rsc-route-matching.js +8 -2
  112. package/dist/server/app-segment-config.d.ts +9 -1
  113. package/dist/server/app-segment-config.js +12 -3
  114. package/dist/server/app-server-action-execution.d.ts +1 -0
  115. package/dist/server/app-server-action-execution.js +47 -15
  116. package/dist/server/app-ssr-entry.d.ts +2 -0
  117. package/dist/server/app-ssr-entry.js +84 -39
  118. package/dist/server/before-interactive-head.d.ts +17 -0
  119. package/dist/server/before-interactive-head.js +35 -0
  120. package/dist/server/cache-control.js +4 -0
  121. package/dist/server/csp.js +1 -4
  122. package/dist/server/dev-server.d.ts +2 -2
  123. package/dist/server/dev-server.js +321 -83
  124. package/dist/server/hybrid-route-priority.d.ts +22 -0
  125. package/dist/server/hybrid-route-priority.js +33 -0
  126. package/dist/server/image-optimization.d.ts +18 -9
  127. package/dist/server/image-optimization.js +37 -23
  128. package/dist/server/implicit-tags.d.ts +2 -1
  129. package/dist/server/implicit-tags.js +4 -1
  130. package/dist/server/middleware-matcher.js +12 -3
  131. package/dist/server/middleware-runtime.d.ts +3 -4
  132. package/dist/server/middleware-runtime.js +2 -0
  133. package/dist/server/navigation-planner.d.ts +135 -41
  134. package/dist/server/navigation-planner.js +138 -0
  135. package/dist/server/navigation-trace.d.ts +9 -1
  136. package/dist/server/navigation-trace.js +9 -1
  137. package/dist/server/operation-token.d.ts +40 -0
  138. package/dist/server/operation-token.js +85 -0
  139. package/dist/server/pages-api-route.d.ts +6 -0
  140. package/dist/server/pages-api-route.js +13 -2
  141. package/dist/server/pages-asset-tags.d.ts +2 -1
  142. package/dist/server/pages-asset-tags.js +6 -2
  143. package/dist/server/pages-data-route.d.ts +9 -2
  144. package/dist/server/pages-data-route.js +18 -6
  145. package/dist/server/pages-dev-module-url.d.ts +4 -0
  146. package/dist/server/pages-dev-module-url.js +15 -0
  147. package/dist/server/pages-document-initial-props.d.ts +4 -15
  148. package/dist/server/pages-document-initial-props.js +27 -56
  149. package/dist/server/pages-get-initial-props.d.ts +54 -4
  150. package/dist/server/pages-get-initial-props.js +43 -1
  151. package/dist/server/pages-i18n.js +2 -2
  152. package/dist/server/pages-node-compat.js +2 -2
  153. package/dist/server/pages-page-data.d.ts +11 -2
  154. package/dist/server/pages-page-data.js +207 -34
  155. package/dist/server/pages-page-handler.d.ts +4 -2
  156. package/dist/server/pages-page-handler.js +62 -23
  157. package/dist/server/pages-page-response.d.ts +4 -1
  158. package/dist/server/pages-page-response.js +11 -8
  159. package/dist/server/pages-readiness.js +1 -1
  160. package/dist/server/pages-request-pipeline.d.ts +8 -7
  161. package/dist/server/pages-request-pipeline.js +126 -47
  162. package/dist/server/pregenerated-concrete-paths.d.ts +1 -17
  163. package/dist/server/pregenerated-concrete-paths.js +2 -19
  164. package/dist/server/prerender-manifest.d.ts +33 -0
  165. package/dist/server/prerender-manifest.js +54 -0
  166. package/dist/server/prerender-route-params.d.ts +1 -2
  167. package/dist/server/prod-server.d.ts +3 -1
  168. package/dist/server/prod-server.js +50 -13
  169. package/dist/server/request-pipeline.d.ts +3 -15
  170. package/dist/server/request-pipeline.js +58 -47
  171. package/dist/server/rsc-stream-hints.d.ts +5 -1
  172. package/dist/server/rsc-stream-hints.js +6 -1
  173. package/dist/server/seed-cache.js +10 -18
  174. package/dist/server/static-file-cache.js +16 -4
  175. package/dist/shims/app-router-scroll-state.d.ts +3 -1
  176. package/dist/shims/app-router-scroll-state.js +14 -2
  177. package/dist/shims/app-router-scroll.d.ts +3 -0
  178. package/dist/shims/app-router-scroll.js +28 -18
  179. package/dist/shims/before-interactive-context.d.ts +14 -3
  180. package/dist/shims/cache-runtime.js +3 -2
  181. package/dist/shims/cache.d.ts +1 -0
  182. package/dist/shims/cache.js +1 -1
  183. package/dist/shims/cdn-cache.d.ts +5 -5
  184. package/dist/shims/document.d.ts +15 -20
  185. package/dist/shims/document.js +5 -8
  186. package/dist/shims/dynamic-preload-chunks.js +6 -4
  187. package/dist/shims/error-boundary.d.ts +2 -0
  188. package/dist/shims/error-boundary.js +7 -0
  189. package/dist/shims/error.js +3 -2
  190. package/dist/shims/error.react-server.d.ts +9 -0
  191. package/dist/shims/error.react-server.js +6 -0
  192. package/dist/shims/fetch-cache.d.ts +3 -1
  193. package/dist/shims/fetch-cache.js +45 -20
  194. package/dist/shims/hash-scroll.js +6 -1
  195. package/dist/shims/headers.js +29 -4
  196. package/dist/shims/image.js +9 -2
  197. package/dist/shims/internal/als-registry.js +28 -1
  198. package/dist/shims/internal/app-route-detection.js +8 -17
  199. package/dist/shims/internal/hybrid-client-route-owner.d.ts +31 -0
  200. package/dist/shims/internal/hybrid-client-route-owner.js +143 -0
  201. package/dist/shims/internal/navigation-untracked.d.ts +35 -0
  202. package/dist/shims/internal/navigation-untracked.js +55 -0
  203. package/dist/shims/internal/pages-data-fetch-dedup.d.ts +6 -7
  204. package/dist/shims/internal/pages-data-fetch-dedup.js +67 -14
  205. package/dist/shims/internal/pages-data-target.d.ts +7 -2
  206. package/dist/shims/internal/pages-data-target.js +17 -8
  207. package/dist/shims/internal/pages-router-accessor.d.ts +19 -0
  208. package/dist/shims/internal/pages-router-accessor.js +13 -0
  209. package/dist/shims/internal/router-context.d.ts +2 -1
  210. package/dist/shims/internal/router-context.js +3 -1
  211. package/dist/shims/link.js +47 -19
  212. package/dist/shims/metadata.js +4 -4
  213. package/dist/shims/navigation.d.ts +8 -2
  214. package/dist/shims/navigation.js +63 -31
  215. package/dist/shims/ppr-fallback-shell.d.ts +5 -1
  216. package/dist/shims/ppr-fallback-shell.js +28 -7
  217. package/dist/shims/router.d.ts +18 -3
  218. package/dist/shims/router.js +512 -142
  219. package/dist/shims/script.js +8 -4
  220. package/dist/shims/server.d.ts +16 -1
  221. package/dist/shims/server.js +44 -12
  222. package/dist/shims/unified-request-context.js +1 -0
  223. package/dist/utils/built-asset-url.d.ts +4 -0
  224. package/dist/utils/built-asset-url.js +11 -0
  225. package/dist/utils/commonjs-loader.d.ts +16 -0
  226. package/dist/utils/commonjs-loader.js +100 -0
  227. package/dist/utils/deployment-id.d.ts +8 -0
  228. package/dist/utils/deployment-id.js +22 -0
  229. package/dist/utils/has-trailing-comma.d.ts +24 -0
  230. package/dist/utils/has-trailing-comma.js +62 -0
  231. package/dist/utils/html-limited-bots.d.ts +18 -1
  232. package/dist/utils/html-limited-bots.js +23 -1
  233. package/dist/utils/parse-cookie.d.ts +13 -0
  234. package/dist/utils/parse-cookie.js +52 -0
  235. package/dist/utils/path.d.ts +7 -1
  236. package/dist/utils/path.js +9 -1
  237. package/dist/utils/text-stream.d.ts +1 -1
  238. package/dist/utils/text-stream.js +2 -2
  239. package/dist/utils/vite-version.d.ts +12 -1
  240. package/dist/utils/vite-version.js +9 -1
  241. package/package.json +2 -2
  242. package/dist/shims/internal/parse-cookie-header.d.ts +0 -14
  243. package/dist/shims/internal/parse-cookie-header.js +0 -30
@@ -19,19 +19,19 @@ import React from "react";
19
19
  * https://github.com/vercel/next.js/blob/canary/packages/next/src/server/render.tsx
20
20
  * (search for `loadDocumentInitialProps` and `documentElement`).
21
21
  *
22
- * vinext only forwards `docProps`. The full `DocumentContext`
23
- * (`renderPage`, `defaultGetInitialProps`, `pathname`, `query`, `req`, `res`,
24
- * `err`, `asPath`) is not yet plumbed through. The common upstream pattern
22
+ * `runDocumentRenderPage()` supplies `renderPage`, `defaultGetInitialProps`,
23
+ * and the request pathname/query/asPath fields needed by the common upstream
24
+ * pattern:
25
25
  *
26
26
  * static async getInitialProps(ctx) {
27
27
  * const initialProps = await Document.getInitialProps(ctx)
28
28
  * return { ...initialProps, docValue }
29
29
  * }
30
30
  *
31
- * works because the base `Document.getInitialProps` shim in
32
- * `shims/document.tsx` returns `{ html: "" }` and ignores `ctx`. User
33
- * overrides that *only* read `ctx` will see `undefined` fields — that is a
34
- * separate gap tracked alongside the shim TODO.
31
+ * The standalone `loadUserDocumentInitialProps()` compatibility path supplies
32
+ * an empty default render result because it is only used after the body has
33
+ * already been produced. Request-only fields such as req/res remain outside
34
+ * that compatibility helper.
35
35
  *
36
36
  * Returns `null` when the user did not override the base shim (the static
37
37
  * `getInitialProps` reference still points at the shim's stub) so callers
@@ -47,7 +47,7 @@ async function loadUserDocumentInitialProps(DocumentComponent) {
47
47
  const getInitialProps = DocumentComponent.getInitialProps;
48
48
  if (typeof getInitialProps !== "function") return null;
49
49
  if (getInitialProps === BASE_GET_INITIAL_PROPS) return null;
50
- const result = await getInitialProps({});
50
+ const result = await getInitialProps({ defaultGetInitialProps: async () => ({ html: "" }) });
51
51
  return result && typeof result === "object" ? result : null;
52
52
  }
53
53
  /**
@@ -60,11 +60,10 @@ async function loadUserDocumentInitialProps(DocumentComponent) {
60
60
  * prod (`pages-page-response.ts`) and dev (`dev-server.ts`) SSR pipelines so
61
61
  * the `getInitialProps` + `renderPage` contract lives in one place.
62
62
  *
63
- * `getInitialProps` is invoked at most once here. When this returns `consumed`
64
- * or `rendered`, callers MUST treat that as the single invocation and must not
65
- * call `loadUserDocumentInitialProps` (which would invoke it again — and, for a
66
- * throwing override, surface the error as a 500 rather than the clean fallback
67
- * this contract guarantees).
63
+ * `getInitialProps` is invoked at most once here. When this returns `rendered`,
64
+ * callers MUST treat that as the single invocation and must not call
65
+ * `loadUserDocumentInitialProps` again. Errors intentionally propagate to the
66
+ * Pages Router's normal error-page pipeline, matching Next.js.
68
67
  *
69
68
  * @see .nextjs-ref/packages/next/src/server/render.tsx (search `renderPage`)
70
69
  */
@@ -74,58 +73,30 @@ async function runDocumentRenderPage(input) {
74
73
  if (DocCtor.getInitialProps === BASE_GET_INITIAL_PROPS) return { status: "skipped" };
75
74
  if (!input.enhancePageElement) return { status: "skipped" };
76
75
  const enhancePageElement = input.enhancePageElement;
77
- let renderPageCalled = false;
78
76
  const renderPage = async (opts = {}) => {
79
- renderPageCalled = true;
80
- const wrapped = withScriptNonce(enhancePageElement(opts), input.scriptNonce);
77
+ const wrapped = withScriptNonce(enhancePageElement(typeof opts === "function" ? { enhanceComponent: opts } : opts), input.scriptNonce);
81
78
  return {
82
79
  html: await readStreamAsText(await input.renderToReadableStream(wrapped)),
83
80
  head: []
84
81
  };
85
82
  };
86
- let docInitialProps;
87
- try {
88
- docInitialProps = await DocCtor.getInitialProps({
89
- renderPage,
90
- defaultGetInitialProps: async (ctx) => {
91
- const result = await (ctx.renderPage ?? renderPage)({ enhanceApp: (App) => (props) => React.createElement(App, props) });
92
- return {
93
- html: result.html,
94
- head: result.head ?? [],
95
- styles: void 0
96
- };
97
- },
98
- ...input.context
99
- });
100
- } catch (err) {
101
- console.error("[vinext] _document.getInitialProps() threw:", err);
102
- return {
103
- status: "consumed",
104
- docProps: {},
105
- head: []
106
- };
107
- }
83
+ const docInitialProps = await DocCtor.getInitialProps({
84
+ renderPage,
85
+ defaultGetInitialProps: async (ctx) => {
86
+ const result = await ctx.renderPage({ enhanceApp: (App) => (props) => React.createElement(App, props) });
87
+ return {
88
+ html: result.html,
89
+ head: result.head ?? [],
90
+ styles: void 0
91
+ };
92
+ },
93
+ ...input.context
94
+ });
108
95
  const { html: _html, head: rawHead, styles: _styles, ...docProps } = docInitialProps ?? {};
109
96
  const head = Array.isArray(rawHead) ? rawHead : [];
110
- if (!renderPageCalled) return {
111
- status: "consumed",
112
- docProps,
113
- head
114
- };
115
- if (!docInitialProps || typeof docInitialProps.html !== "string") {
116
- console.error(`[vinext] "${DocCtor.displayName ?? DocCtor.name ?? "Document"}.getInitialProps()" did not return an object with a string "html" prop`);
117
- return {
118
- status: "consumed",
119
- docProps,
120
- head
121
- };
122
- }
97
+ if (!docInitialProps || typeof docInitialProps.html !== "string") throw new Error(`"${DocCtor.displayName ?? DocCtor.name ?? "Document"}.getInitialProps()" should resolve to an object with a "html" prop set with a valid html string`);
123
98
  let stylesHTML = "";
124
- if (docInitialProps.styles != null) try {
125
- stylesHTML = await input.renderStylesToString(React.createElement(React.Fragment, null, docInitialProps.styles));
126
- } catch (err) {
127
- console.error("[vinext] Failed to render _document.getInitialProps() styles:", err);
128
- }
99
+ if (docInitialProps.styles != null) stylesHTML = await input.renderStylesToString(React.createElement(React.Fragment, null, docInitialProps.styles));
129
100
  return {
130
101
  status: "rendered",
131
102
  bodyHtml: docInitialProps.html,
@@ -3,6 +3,48 @@ type PagesGetInitialPropsContext = {
3
3
  req?: unknown;
4
4
  res?: unknown;
5
5
  err?: unknown;
6
+ pathname?: string;
7
+ query?: Record<string, unknown>;
8
+ asPath?: string;
9
+ locale?: string;
10
+ locales?: string[];
11
+ defaultLocale?: string;
12
+ } & Record<string, unknown>;
13
+ declare function hasPagesGetInitialProps(component: unknown): boolean;
14
+ declare function isResponseSent(res: unknown): boolean;
15
+ declare function loadPagesGetInitialProps(component: unknown, context: PagesGetInitialPropsContext): Promise<Record<string, unknown> | null>;
16
+ /**
17
+ * Decision returned by {@link loadDevAppInitialProps}.
18
+ *
19
+ * - `skip`: the custom `App` has no `getInitialProps`; the caller renders with
20
+ * its existing props unchanged.
21
+ * - `response-sent`: `_app.getInitialProps` ended the response itself (wrote
22
+ * headers / body); the caller must stop and not render.
23
+ * - `render`: the caller should render with the returned `pageProps` /
24
+ * `renderProps`.
25
+ */
26
+ type DevAppInitialPropsResult = {
27
+ kind: "skip";
28
+ } | {
29
+ kind: "response-sent";
30
+ } | {
31
+ kind: "render";
32
+ pageProps: Record<string, unknown>;
33
+ renderProps: Record<string, unknown> & {
34
+ pageProps: unknown;
35
+ };
36
+ };
37
+ type DevAppInitialPropsContext = {
38
+ appComponent: unknown;
39
+ /**
40
+ * Builds the `AppTree` element passed to `getInitialProps`. Injected so this
41
+ * module stays free of React; the dev SSR handler supplies the real
42
+ * `React.createElement` closure.
43
+ */
44
+ appTree: (appTreeProps: Record<string, unknown>) => unknown;
45
+ component: unknown;
46
+ req: unknown;
47
+ res: unknown;
6
48
  pathname: string;
7
49
  query: Record<string, unknown>;
8
50
  asPath: string;
@@ -10,8 +52,16 @@ type PagesGetInitialPropsContext = {
10
52
  locales?: string[];
11
53
  defaultLocale?: string;
12
54
  };
13
- declare function hasPagesGetInitialProps(component: unknown): boolean;
14
- declare function isResponseSent(res: unknown): boolean;
15
- declare function loadPagesGetInitialProps(component: unknown, context: PagesGetInitialPropsContext): Promise<Record<string, unknown> | null>;
55
+ /**
56
+ * Run the custom `App`'s `getInitialProps` for the dev SSR render path and
57
+ * return a decision the caller applies.
58
+ *
59
+ * This is the dev-server counterpart to the production page-data resolver's
60
+ * app-initial-props loading. It is invoked lazily — only when a request is
61
+ * actually going to render (cache miss / on-demand revalidation), never on an
62
+ * ISR cache HIT/STALE that serves cached HTML verbatim — so userland `App`
63
+ * data code does not run on the cache hot path.
64
+ */
65
+ declare function loadDevAppInitialProps(ctx: DevAppInitialPropsContext): Promise<DevAppInitialPropsResult>;
16
66
  //#endregion
17
- export { hasPagesGetInitialProps, isResponseSent, loadPagesGetInitialProps };
67
+ export { DevAppInitialPropsContext, DevAppInitialPropsResult, hasPagesGetInitialProps, isResponseSent, loadDevAppInitialProps, loadPagesGetInitialProps };
@@ -46,5 +46,47 @@ async function loadPagesGetInitialProps(component, context) {
46
46
  if (!isPropsObject(result)) throw new Error(`"${getDisplayName(component)}.getInitialProps()" should resolve to an object. But found "${describeInitialPropsValue(result)}" instead.`);
47
47
  return result;
48
48
  }
49
+ /**
50
+ * Run the custom `App`'s `getInitialProps` for the dev SSR render path and
51
+ * return a decision the caller applies.
52
+ *
53
+ * This is the dev-server counterpart to the production page-data resolver's
54
+ * app-initial-props loading. It is invoked lazily — only when a request is
55
+ * actually going to render (cache miss / on-demand revalidation), never on an
56
+ * ISR cache HIT/STALE that serves cached HTML verbatim — so userland `App`
57
+ * data code does not run on the cache hot path.
58
+ */
59
+ async function loadDevAppInitialProps(ctx) {
60
+ if (!hasPagesGetInitialProps(ctx.appComponent)) return { kind: "skip" };
61
+ const initialProps = await loadPagesGetInitialProps(ctx.appComponent, {
62
+ AppTree: ctx.appTree,
63
+ Component: ctx.component,
64
+ router: {
65
+ pathname: ctx.pathname,
66
+ query: ctx.query,
67
+ asPath: ctx.asPath
68
+ },
69
+ ctx: {
70
+ req: ctx.req,
71
+ res: ctx.res,
72
+ pathname: ctx.pathname,
73
+ query: ctx.query,
74
+ asPath: ctx.asPath,
75
+ locale: ctx.locale,
76
+ locales: ctx.locales,
77
+ defaultLocale: ctx.defaultLocale
78
+ }
79
+ });
80
+ if (isResponseSent(ctx.res)) return { kind: "response-sent" };
81
+ const initialPageProps = isPropsObject(initialProps) ? initialProps.pageProps : void 0;
82
+ return {
83
+ kind: "render",
84
+ pageProps: isPropsObject(initialPageProps) ? initialPageProps : {},
85
+ renderProps: isPropsObject(initialProps) ? {
86
+ ...initialProps,
87
+ pageProps: initialPageProps
88
+ } : { pageProps: initialPageProps }
89
+ };
90
+ }
49
91
  //#endregion
50
- export { hasPagesGetInitialProps, isResponseSent, loadPagesGetInitialProps };
92
+ export { hasPagesGetInitialProps, isResponseSent, loadDevAppInitialProps, loadPagesGetInitialProps };
@@ -127,8 +127,8 @@ function parseCookieLocaleFromHeader(cookieHeader, i18nConfig) {
127
127
  } catch {
128
128
  return null;
129
129
  }
130
- if (i18nConfig.locales.includes(value)) return value;
131
- return null;
130
+ const lowerValue = value.toLowerCase();
131
+ return i18nConfig.locales.find((locale) => locale.toLowerCase() === lowerValue) ?? null;
132
132
  }
133
133
  function formatLocalizedRootPath(locale, defaultLocale, basePath = "", trailingSlash = false, search = "") {
134
134
  if (locale.toLowerCase() === defaultLocale.toLowerCase()) return void 0;
@@ -1,4 +1,4 @@
1
- import { parseCookies } from "../config/config-matchers.js";
1
+ import { parseCookieHeader } from "../utils/parse-cookie.js";
2
2
  import { readStreamAsTextWithLimit } from "../utils/text-stream.js";
3
3
  import { PagesBodyParseError, getMediaType, isJsonMediaType } from "./pages-media-type.js";
4
4
  import { DEFAULT_PAGES_API_BODY_SIZE_LIMIT } from "./pages-body-parser-config.js";
@@ -217,7 +217,7 @@ function createPagesReqRes(options) {
217
217
  headers: headersObj,
218
218
  query: options.query,
219
219
  body: options.body,
220
- cookies: parseCookies(options.request.headers.get("cookie"))
220
+ cookies: parseCookieHeader(options.request.headers.get("cookie"))
221
221
  });
222
222
  let resolveResponse;
223
223
  let rejectResponse;
@@ -33,6 +33,9 @@ type PagesGsspContextResponse = {
33
33
  res: PagesMutableGsspResponse;
34
34
  responsePromise: Promise<Response>;
35
35
  };
36
+ type PagesRenderProps = Record<string, unknown> & {
37
+ pageProps: unknown;
38
+ };
36
39
  type PagesPageModule = {
37
40
  default?: unknown;
38
41
  getStaticPaths?: (context: {
@@ -82,9 +85,10 @@ type PagesPageModule = {
82
85
  type RenderPagesIsrHtmlOptions = {
83
86
  buildId: string | null;
84
87
  cachedHtml: string;
85
- createPageElement: (pageProps: Record<string, unknown>) => ReactNode;
88
+ createPageElement: (props: Record<string, unknown>) => ReactNode;
86
89
  i18n: PagesI18nRenderContext;
87
90
  pageProps: Record<string, unknown>;
91
+ props?: Record<string, unknown>;
88
92
  params: Record<string, unknown>;
89
93
  renderIsrPassToStringAsync: (element: ReactNode) => Promise<string>;
90
94
  routePattern: string;
@@ -106,7 +110,8 @@ type ResolvePagesPageDataOptions = {
106
110
  isDataReq?: boolean;
107
111
  err?: unknown;
108
112
  createGsspReqRes: () => PagesGsspContextResponse;
109
- createPageElement: (pageProps: Record<string, unknown>) => ReactNode;
113
+ createAppTree?: (props: Record<string, unknown>) => ReactNode;
114
+ createPageElement: (props: Record<string, unknown>) => ReactNode;
110
115
  fontLinkHeader: string;
111
116
  i18n: PagesI18nRenderContext;
112
117
  isrCacheKey: (router: string, pathname: string) => string;
@@ -145,10 +150,13 @@ type ResolvePagesPageDataOptions = {
145
150
  * Typically sourced from `process.env.__VINEXT_DEPLOYMENT_ID || process.env.NEXT_DEPLOYMENT_ID`.
146
151
  */
147
152
  deploymentId?: string;
153
+ htmlLimitedBots?: string;
148
154
  pageModule: PagesPageModule;
155
+ AppComponent?: unknown;
149
156
  params: Record<string, unknown>;
150
157
  query: Record<string, unknown>;
151
158
  asPath?: string;
159
+ resolvedUrl?: string;
152
160
  route: Pick<Route, "isDynamic">;
153
161
  routePattern: string;
154
162
  routeUrl: string;
@@ -192,6 +200,7 @@ type ResolvePagesPageDataRenderResult = {
192
200
  gsspRes: PagesGsspResponse | null;
193
201
  isrRevalidateSeconds: number | null;
194
202
  pageProps: Record<string, unknown>;
203
+ props: PagesRenderProps;
195
204
  /**
196
205
  * True when `getStaticPaths` returned `fallback: true` AND the requested path
197
206
  * is not in the pre-rendered list. The caller renders a loading shell with