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.
- package/dist/build/client-build-config.d.ts +11 -2
- package/dist/build/client-build-config.js +17 -6
- package/dist/build/prerender.d.ts +9 -1
- package/dist/build/prerender.js +42 -12
- package/dist/build/run-prerender.d.ts +10 -2
- package/dist/build/run-prerender.js +15 -1
- package/dist/client/app-nav-failure-handler.d.ts +8 -0
- package/dist/client/app-nav-failure-handler.js +44 -0
- package/dist/client/pages-router-link-navigation.d.ts +33 -7
- package/dist/client/pages-router-link-navigation.js +32 -2
- package/dist/client/vinext-next-data.d.ts +18 -1
- package/dist/client/vinext-next-data.js +2 -0
- package/dist/client/window-next.d.ts +2 -1
- package/dist/client/window-next.js +12 -1
- package/dist/cloudflare/src/cache/cdn-adapter.runtime.js +6 -1
- package/dist/config/config-matchers.d.ts +11 -1
- package/dist/config/config-matchers.js +87 -16
- package/dist/config/next-config.d.ts +46 -4
- package/dist/config/next-config.js +147 -48
- package/dist/config/tsconfig-paths.js +14 -1
- package/dist/deploy.d.ts +30 -11
- package/dist/deploy.js +200 -112
- package/dist/entries/app-browser-entry.d.ts +9 -3
- package/dist/entries/app-browser-entry.js +21 -3
- package/dist/entries/app-rsc-entry.d.ts +2 -0
- package/dist/entries/app-rsc-entry.js +65 -5
- package/dist/entries/app-rsc-manifest.js +2 -0
- package/dist/entries/app-ssr-entry.js +1 -1
- package/dist/entries/pages-client-entry.js +66 -20
- package/dist/entries/pages-server-entry.js +47 -31
- package/dist/index.js +417 -102
- package/dist/plugins/dynamic-preload-metadata.js +2 -4
- package/dist/plugins/extensionless-dynamic-import.d.ts +6 -0
- package/dist/plugins/extensionless-dynamic-import.js +152 -0
- package/dist/plugins/fonts.js +5 -4
- package/dist/plugins/optimize-imports.d.ts +2 -1
- package/dist/plugins/optimize-imports.js +11 -9
- package/dist/plugins/postcss.js +7 -7
- package/dist/plugins/strip-server-exports.d.ts +9 -7
- package/dist/plugins/strip-server-exports.js +493 -46
- package/dist/plugins/typeof-window.d.ts +14 -0
- package/dist/plugins/typeof-window.js +150 -0
- package/dist/routing/app-route-graph.d.ts +2 -1
- package/dist/routing/app-route-graph.js +46 -16
- package/dist/routing/file-matcher.d.ts +10 -1
- package/dist/routing/file-matcher.js +22 -1
- package/dist/routing/pages-router.js +3 -3
- package/dist/routing/utils.d.ts +35 -6
- package/dist/routing/utils.js +59 -7
- package/dist/server/api-handler.d.ts +6 -1
- package/dist/server/api-handler.js +21 -15
- package/dist/server/app-browser-action-result.d.ts +19 -6
- package/dist/server/app-browser-action-result.js +20 -11
- package/dist/server/app-browser-entry.js +175 -91
- package/dist/server/app-browser-error.d.ts +10 -6
- package/dist/server/app-browser-error.js +43 -8
- package/dist/server/app-browser-hydration.d.ts +2 -0
- package/dist/server/app-browser-hydration.js +1 -0
- package/dist/server/app-browser-navigation-controller.d.ts +5 -3
- package/dist/server/app-browser-navigation-controller.js +23 -2
- package/dist/server/app-browser-server-action-navigation.d.ts +6 -0
- package/dist/server/app-browser-server-action-navigation.js +9 -0
- package/dist/server/app-browser-state.d.ts +1 -1
- package/dist/server/app-browser-state.js +19 -11
- package/dist/server/app-browser-stream.js +86 -43
- package/dist/server/app-browser-visible-commit.d.ts +1 -1
- package/dist/server/app-elements-wire.d.ts +6 -1
- package/dist/server/app-elements-wire.js +14 -4
- package/dist/server/app-elements.d.ts +2 -2
- package/dist/server/app-elements.js +2 -2
- package/dist/server/app-fallback-renderer.d.ts +1 -0
- package/dist/server/app-fallback-renderer.js +3 -1
- package/dist/server/app-optimistic-routing.js +2 -2
- package/dist/server/app-page-boundary-render.d.ts +1 -0
- package/dist/server/app-page-boundary-render.js +27 -14
- package/dist/server/app-page-cache-render.d.ts +53 -0
- package/dist/server/app-page-cache-render.js +91 -0
- package/dist/server/app-page-cache.d.ts +16 -2
- package/dist/server/app-page-cache.js +62 -1
- package/dist/server/app-page-dispatch.d.ts +26 -0
- package/dist/server/app-page-dispatch.js +149 -92
- package/dist/server/app-page-element-builder.d.ts +1 -0
- package/dist/server/app-page-element-builder.js +5 -2
- package/dist/server/app-page-execution.d.ts +6 -1
- package/dist/server/app-page-execution.js +21 -1
- package/dist/server/app-page-probe.d.ts +1 -0
- package/dist/server/app-page-probe.js +4 -0
- package/dist/server/app-page-render-observation.d.ts +3 -1
- package/dist/server/app-page-render-observation.js +17 -1
- package/dist/server/app-page-render.d.ts +12 -1
- package/dist/server/app-page-render.js +42 -4
- package/dist/server/app-page-request.d.ts +2 -0
- package/dist/server/app-page-request.js +2 -1
- package/dist/server/app-page-route-wiring.d.ts +3 -1
- package/dist/server/app-page-route-wiring.js +14 -5
- package/dist/server/app-page-stream.d.ts +15 -3
- package/dist/server/app-page-stream.js +11 -5
- package/dist/server/app-pages-bridge.d.ts +23 -1
- package/dist/server/app-pages-bridge.js +26 -17
- package/dist/server/app-ppr-fallback-shell-render.d.ts +17 -0
- package/dist/server/app-ppr-fallback-shell-render.js +26 -0
- package/dist/server/app-ppr-fallback-shell.d.ts +13 -1
- package/dist/server/app-ppr-fallback-shell.js +8 -1
- package/dist/server/app-route-handler-dispatch.js +9 -2
- package/dist/server/app-route-handler-policy.d.ts +1 -0
- package/dist/server/app-router-entry.js +5 -0
- package/dist/server/app-rsc-cache-busting.js +2 -0
- package/dist/server/app-rsc-handler.d.ts +28 -0
- package/dist/server/app-rsc-handler.js +195 -59
- package/dist/server/app-rsc-route-matching.d.ts +3 -0
- package/dist/server/app-rsc-route-matching.js +8 -2
- package/dist/server/app-segment-config.d.ts +9 -1
- package/dist/server/app-segment-config.js +12 -3
- package/dist/server/app-server-action-execution.d.ts +1 -0
- package/dist/server/app-server-action-execution.js +47 -15
- package/dist/server/app-ssr-entry.d.ts +2 -0
- package/dist/server/app-ssr-entry.js +84 -39
- package/dist/server/before-interactive-head.d.ts +17 -0
- package/dist/server/before-interactive-head.js +35 -0
- package/dist/server/cache-control.js +4 -0
- package/dist/server/csp.js +1 -4
- package/dist/server/dev-server.d.ts +2 -2
- package/dist/server/dev-server.js +321 -83
- package/dist/server/hybrid-route-priority.d.ts +22 -0
- package/dist/server/hybrid-route-priority.js +33 -0
- package/dist/server/image-optimization.d.ts +18 -9
- package/dist/server/image-optimization.js +37 -23
- package/dist/server/implicit-tags.d.ts +2 -1
- package/dist/server/implicit-tags.js +4 -1
- package/dist/server/middleware-matcher.js +12 -3
- package/dist/server/middleware-runtime.d.ts +3 -4
- package/dist/server/middleware-runtime.js +2 -0
- package/dist/server/navigation-planner.d.ts +135 -41
- package/dist/server/navigation-planner.js +138 -0
- package/dist/server/navigation-trace.d.ts +9 -1
- package/dist/server/navigation-trace.js +9 -1
- package/dist/server/operation-token.d.ts +40 -0
- package/dist/server/operation-token.js +85 -0
- package/dist/server/pages-api-route.d.ts +6 -0
- package/dist/server/pages-api-route.js +13 -2
- package/dist/server/pages-asset-tags.d.ts +2 -1
- package/dist/server/pages-asset-tags.js +6 -2
- package/dist/server/pages-data-route.d.ts +9 -2
- package/dist/server/pages-data-route.js +18 -6
- package/dist/server/pages-dev-module-url.d.ts +4 -0
- package/dist/server/pages-dev-module-url.js +15 -0
- package/dist/server/pages-document-initial-props.d.ts +4 -15
- package/dist/server/pages-document-initial-props.js +27 -56
- package/dist/server/pages-get-initial-props.d.ts +54 -4
- package/dist/server/pages-get-initial-props.js +43 -1
- package/dist/server/pages-i18n.js +2 -2
- package/dist/server/pages-node-compat.js +2 -2
- package/dist/server/pages-page-data.d.ts +11 -2
- package/dist/server/pages-page-data.js +207 -34
- package/dist/server/pages-page-handler.d.ts +4 -2
- package/dist/server/pages-page-handler.js +62 -23
- package/dist/server/pages-page-response.d.ts +4 -1
- package/dist/server/pages-page-response.js +11 -8
- package/dist/server/pages-readiness.js +1 -1
- package/dist/server/pages-request-pipeline.d.ts +8 -7
- package/dist/server/pages-request-pipeline.js +126 -47
- package/dist/server/pregenerated-concrete-paths.d.ts +1 -17
- package/dist/server/pregenerated-concrete-paths.js +2 -19
- package/dist/server/prerender-manifest.d.ts +33 -0
- package/dist/server/prerender-manifest.js +54 -0
- package/dist/server/prerender-route-params.d.ts +1 -2
- package/dist/server/prod-server.d.ts +3 -1
- package/dist/server/prod-server.js +50 -13
- package/dist/server/request-pipeline.d.ts +3 -15
- package/dist/server/request-pipeline.js +58 -47
- package/dist/server/rsc-stream-hints.d.ts +5 -1
- package/dist/server/rsc-stream-hints.js +6 -1
- package/dist/server/seed-cache.js +10 -18
- package/dist/server/static-file-cache.js +16 -4
- package/dist/shims/app-router-scroll-state.d.ts +3 -1
- package/dist/shims/app-router-scroll-state.js +14 -2
- package/dist/shims/app-router-scroll.d.ts +3 -0
- package/dist/shims/app-router-scroll.js +28 -18
- package/dist/shims/before-interactive-context.d.ts +14 -3
- package/dist/shims/cache-runtime.js +3 -2
- package/dist/shims/cache.d.ts +1 -0
- package/dist/shims/cache.js +1 -1
- package/dist/shims/cdn-cache.d.ts +5 -5
- package/dist/shims/document.d.ts +15 -20
- package/dist/shims/document.js +5 -8
- package/dist/shims/dynamic-preload-chunks.js +6 -4
- package/dist/shims/error-boundary.d.ts +2 -0
- package/dist/shims/error-boundary.js +7 -0
- package/dist/shims/error.js +3 -2
- package/dist/shims/error.react-server.d.ts +9 -0
- package/dist/shims/error.react-server.js +6 -0
- package/dist/shims/fetch-cache.d.ts +3 -1
- package/dist/shims/fetch-cache.js +45 -20
- package/dist/shims/hash-scroll.js +6 -1
- package/dist/shims/headers.js +29 -4
- package/dist/shims/image.js +9 -2
- package/dist/shims/internal/als-registry.js +28 -1
- package/dist/shims/internal/app-route-detection.js +8 -17
- package/dist/shims/internal/hybrid-client-route-owner.d.ts +31 -0
- package/dist/shims/internal/hybrid-client-route-owner.js +143 -0
- package/dist/shims/internal/navigation-untracked.d.ts +35 -0
- package/dist/shims/internal/navigation-untracked.js +55 -0
- package/dist/shims/internal/pages-data-fetch-dedup.d.ts +6 -7
- package/dist/shims/internal/pages-data-fetch-dedup.js +67 -14
- package/dist/shims/internal/pages-data-target.d.ts +7 -2
- package/dist/shims/internal/pages-data-target.js +17 -8
- package/dist/shims/internal/pages-router-accessor.d.ts +19 -0
- package/dist/shims/internal/pages-router-accessor.js +13 -0
- package/dist/shims/internal/router-context.d.ts +2 -1
- package/dist/shims/internal/router-context.js +3 -1
- package/dist/shims/link.js +47 -19
- package/dist/shims/metadata.js +4 -4
- package/dist/shims/navigation.d.ts +8 -2
- package/dist/shims/navigation.js +63 -31
- package/dist/shims/ppr-fallback-shell.d.ts +5 -1
- package/dist/shims/ppr-fallback-shell.js +28 -7
- package/dist/shims/router.d.ts +18 -3
- package/dist/shims/router.js +512 -142
- package/dist/shims/script.js +8 -4
- package/dist/shims/server.d.ts +16 -1
- package/dist/shims/server.js +44 -12
- package/dist/shims/unified-request-context.js +1 -0
- package/dist/utils/built-asset-url.d.ts +4 -0
- package/dist/utils/built-asset-url.js +11 -0
- package/dist/utils/commonjs-loader.d.ts +16 -0
- package/dist/utils/commonjs-loader.js +100 -0
- package/dist/utils/deployment-id.d.ts +8 -0
- package/dist/utils/deployment-id.js +22 -0
- package/dist/utils/has-trailing-comma.d.ts +24 -0
- package/dist/utils/has-trailing-comma.js +62 -0
- package/dist/utils/html-limited-bots.d.ts +18 -1
- package/dist/utils/html-limited-bots.js +23 -1
- package/dist/utils/parse-cookie.d.ts +13 -0
- package/dist/utils/parse-cookie.js +52 -0
- package/dist/utils/path.d.ts +7 -1
- package/dist/utils/path.js +9 -1
- package/dist/utils/text-stream.d.ts +1 -1
- package/dist/utils/text-stream.js +2 -2
- package/dist/utils/vite-version.d.ts +12 -1
- package/dist/utils/vite-version.js +9 -1
- package/package.json +2 -2
- package/dist/shims/internal/parse-cookie-header.d.ts +0 -14
- 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
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
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
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
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 `
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
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
|
-
|
|
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
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
renderPage,
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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 (!
|
|
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)
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
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 {
|
|
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:
|
|
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: (
|
|
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
|
-
|
|
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
|