vinext 1.1.0 → 1.2.1
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/README.md +22 -10
- package/dist/build/client-build-config.d.ts +10 -0
- package/dist/build/client-build-config.js +18 -2
- package/dist/build/output-root-externals.d.ts +21 -0
- package/dist/build/output-root-externals.js +40 -0
- package/dist/build/pages-client-assets-module.d.ts +8 -0
- package/dist/build/pages-client-assets-module.js +21 -1
- package/dist/build/prerender-paths.js +6 -4
- package/dist/build/prerender.js +1 -1
- package/dist/build/run-prerender.js +1 -1
- package/dist/build/ssr-manifest.d.ts +2 -0
- package/dist/build/ssr-manifest.js +6 -2
- package/dist/check.js +12 -12
- package/dist/cli-dev-config.js +3 -3
- package/dist/cli.js +3 -2
- package/dist/client/client-redirect-matcher.d.ts +14 -0
- package/dist/client/client-redirect-matcher.js +37 -0
- package/dist/client/client-redirects.d.ts +27 -0
- package/dist/client/client-redirects.js +28 -0
- package/dist/client/client-rewrites.d.ts +2 -1
- package/dist/client/client-rewrites.js +1 -1
- package/dist/config/config-matchers.d.ts +26 -11
- package/dist/config/config-matchers.js +90 -88
- package/dist/config/destination-params.d.ts +47 -0
- package/dist/config/destination-params.js +116 -0
- package/dist/config/next-config.d.ts +7 -0
- package/dist/config/next-config.js +3 -0
- package/dist/entries/app-rsc-entry.d.ts +4 -0
- package/dist/entries/app-rsc-entry.js +20 -6
- package/dist/entries/pages-client-entry.js +3 -1
- package/dist/entries/pages-server-entry.js +13 -37
- package/dist/index.d.ts +3 -1
- package/dist/index.js +246 -136
- package/dist/init-cloudflare.d.ts +9 -0
- package/dist/init-cloudflare.js +107 -31
- package/dist/init-platform.d.ts +4 -0
- package/dist/init-platform.js +27 -2
- package/dist/init.d.ts +2 -1
- package/dist/init.js +153 -9
- package/dist/plugins/ast-scope.d.ts +7 -0
- package/dist/plugins/ast-scope.js +59 -3
- package/dist/plugins/ast-utils.d.ts +53 -2
- package/dist/plugins/ast-utils.js +90 -2
- package/dist/plugins/cloudflare-dev-module-urls.d.ts +41 -0
- package/dist/plugins/cloudflare-dev-module-urls.js +271 -0
- package/dist/plugins/commonjs-esm-facade.js +2 -2
- package/dist/plugins/css-module-imports.js +13 -20
- package/dist/plugins/dynamic-preload-metadata.d.ts +1 -1
- package/dist/plugins/dynamic-preload-metadata.js +11 -11
- package/dist/plugins/extensionless-dynamic-import.js +2 -3
- package/dist/plugins/fonts.d.ts +1 -1
- package/dist/plugins/fonts.js +3 -3
- package/dist/plugins/ignore-dynamic-requests.d.ts +1 -1
- package/dist/plugins/ignore-dynamic-requests.js +5 -7
- package/dist/plugins/import-meta-url.js +3 -4
- package/dist/plugins/instrumentation-client.js +3 -2
- package/dist/plugins/middleware-export-validation.js +2 -3
- package/dist/plugins/middleware-server-only.d.ts +5 -4
- package/dist/plugins/middleware-server-only.js +8 -5
- package/dist/plugins/og-harfbuzz.js +2 -3
- package/dist/plugins/optimize-imports.js +3 -4
- package/dist/plugins/pages-node-externals.js +3 -4
- package/dist/plugins/remove-console.js +2 -18
- package/dist/plugins/require-condition-resolution.js +3 -3
- package/dist/plugins/require-context.js +2 -3
- package/dist/plugins/rsc-scan-glob-imports.d.ts +19 -0
- package/dist/plugins/rsc-scan-glob-imports.js +50 -0
- package/dist/plugins/strip-server-exports.js +265 -102
- package/dist/plugins/styled-jsx.js +2 -3
- package/dist/plugins/transform-result.d.ts +9 -5
- package/dist/plugins/transitive-externals.js +1 -1
- package/dist/plugins/typeof-window.d.ts +2 -2
- package/dist/plugins/use-cache-callable.d.ts +21 -2
- package/dist/plugins/use-cache-callable.js +84 -35
- package/dist/plugins/worker-image-imports.js +30 -33
- package/dist/plugins/worker-server-only-imports.d.ts +20 -0
- package/dist/plugins/worker-server-only-imports.js +31 -0
- package/dist/plugins/worker-use-server.d.ts +25 -0
- package/dist/plugins/worker-use-server.js +153 -0
- package/dist/server/api-handler.d.ts +1 -0
- package/dist/server/api-handler.js +3 -2
- package/dist/server/app-action-forwarding.js +2 -2
- package/dist/server/app-browser-action-result.d.ts +1 -1
- package/dist/server/app-browser-action-result.js +9 -2
- package/dist/server/app-browser-entry.js +3 -3
- package/dist/server/app-browser-interception-context.js +1 -1
- package/dist/server/app-browser-navigation-controller.js +1 -1
- package/dist/server/app-browser-prefetch-response.js +2 -2
- package/dist/server/app-browser-server-action-client.js +1 -1
- package/dist/server/app-browser-state.js +1 -1
- package/dist/server/app-browser-supplemental-refresh.js +1 -1
- package/dist/server/app-middleware.d.ts +11 -0
- package/dist/server/app-middleware.js +17 -2
- package/dist/server/app-optimistic-routing.js +1 -1
- package/dist/server/app-page-cache.d.ts +1 -1
- package/dist/server/app-page-cache.js +1 -1
- package/dist/server/app-page-dispatch.d.ts +3 -1
- package/dist/server/app-page-dispatch.js +5 -4
- package/dist/server/app-page-ppr-runtime.js +1 -1
- package/dist/server/app-page-render-observation.js +1 -1
- package/dist/server/app-page-render.js +1 -1
- package/dist/server/app-page-request.js +53 -15
- package/dist/server/app-page-route-wiring.js +2 -2
- package/dist/server/app-pages-bridge.d.ts +1 -1
- package/dist/server/app-pages-bridge.js +3 -4
- package/dist/server/app-prerender-endpoints.js +9 -6
- package/dist/server/app-render-abort-error.d.ts +19 -0
- package/dist/server/app-render-abort-error.js +31 -1
- package/dist/server/app-request-stage-dispatch.js +6 -2
- package/dist/server/app-request-stage-independent-entry.js +29 -9
- package/dist/server/app-response-stage-entry.js +11 -3
- package/dist/server/app-route-handler-cache.d.ts +1 -0
- package/dist/server/app-route-handler-cache.js +1 -0
- package/dist/server/app-route-handler-dispatch.d.ts +1 -0
- package/dist/server/app-route-handler-dispatch.js +5 -2
- package/dist/server/app-route-handler-execution.d.ts +1 -0
- package/dist/server/app-route-handler-execution.js +1 -0
- package/dist/server/app-route-handler-runtime.d.ts +4 -1
- package/dist/server/app-route-handler-runtime.js +46 -25
- package/dist/server/app-router-entry.js +29 -10
- package/dist/server/app-rsc-cache-busting.d.ts +16 -0
- package/dist/server/app-rsc-cache-busting.js +30 -13
- package/dist/server/app-rsc-errors.js +20 -16
- package/dist/server/app-rsc-handler.d.ts +7 -0
- package/dist/server/app-rsc-handler.js +89 -39
- package/dist/server/app-rsc-request-normalization.js +3 -3
- package/dist/server/app-rsc-response-stage.js +5 -3
- package/dist/server/app-segment-config.d.ts +2 -1
- package/dist/server/app-server-action-execution.d.ts +2 -1
- package/dist/server/app-server-action-execution.js +62 -23
- package/dist/server/app-ssr-entry.js +7 -5
- package/dist/server/app-visited-response-cache.js +2 -2
- package/dist/server/app-worker-stages.d.ts +5 -0
- package/dist/server/app-worker-stages.js +1 -1
- package/dist/server/cacheability-request.js +2 -2
- package/dist/server/client-build-files.d.ts +16 -0
- package/dist/server/client-build-files.js +36 -0
- package/dist/server/client-reuse-manifest.js +1 -1
- package/dist/server/config-headers.js +1 -1
- package/dist/server/defer-until-stream-consumed.d.ts +2 -1
- package/dist/server/defer-until-stream-consumed.js +3 -1
- package/dist/server/dev-server.js +39 -28
- package/dist/server/dev-stack-sourcemap.js +18 -23
- package/dist/server/document-initial-head.d.ts +0 -11
- package/dist/server/document-initial-head.js +1 -1
- package/dist/server/forwarded-middleware-context.d.ts +5 -0
- package/dist/server/forwarded-middleware-context.js +22 -0
- package/dist/server/headers.d.ts +4 -1
- package/dist/server/headers.js +4 -1
- package/dist/server/http-conditional.d.ts +11 -0
- package/dist/server/http-conditional.js +10 -1
- package/dist/server/http-error-responses.d.ts +1 -1
- package/dist/server/image-optimization.d.ts +38 -0
- package/dist/server/image-optimization.js +94 -4
- package/dist/server/isr-cache.d.ts +10 -0
- package/dist/server/isr-cache.js +41 -6
- package/dist/server/metadata-route-response.js +11 -10
- package/dist/server/middleware-matcher.d.ts +2 -0
- package/dist/server/middleware-matcher.js +23 -2
- package/dist/server/middleware-path-to-regexp.js +1 -1
- package/dist/server/middleware-runtime.d.ts +13 -0
- package/dist/server/middleware-runtime.js +38 -25
- package/dist/server/middleware.d.ts +1 -1
- package/dist/server/middleware.js +3 -1
- package/dist/server/multi-stage.d.ts +11 -0
- package/dist/server/navigation-planner.js +1 -1
- package/dist/server/normalize-path.d.ts +0 -13
- package/dist/server/normalize-path.js +1 -34
- package/dist/server/open-redirect.d.ts +11 -4
- package/dist/server/open-redirect.js +11 -4
- package/dist/server/pages-api-route.d.ts +3 -2
- package/dist/server/pages-api-route.js +6 -5
- package/dist/server/pages-cache-tag.d.ts +12 -0
- package/dist/server/pages-cache-tag.js +19 -0
- package/dist/server/pages-client-assets.d.ts +2 -0
- package/dist/server/pages-data-route.d.ts +10 -0
- package/dist/server/pages-data-route.js +21 -3
- package/dist/server/pages-document-asset-props.d.ts +5 -1
- package/dist/server/pages-document-asset-props.js +13 -5
- package/dist/server/pages-document-splice.d.ts +19 -0
- package/dist/server/pages-document-splice.js +55 -0
- package/dist/server/pages-i18n.d.ts +12 -1
- package/dist/server/pages-i18n.js +18 -4
- package/dist/server/pages-node-compat.d.ts +16 -5
- package/dist/server/pages-node-compat.js +20 -12
- package/dist/server/pages-page-data.d.ts +32 -24
- package/dist/server/pages-page-data.js +51 -121
- package/dist/server/pages-page-handler.d.ts +0 -6
- package/dist/server/pages-page-handler.js +189 -127
- package/dist/server/pages-page-response.d.ts +12 -6
- package/dist/server/pages-page-response.js +42 -35
- package/dist/server/pages-request-pipeline.d.ts +10 -2
- package/dist/server/pages-request-pipeline.js +41 -22
- package/dist/server/pages-request-stage-entry.d.ts +6 -0
- package/dist/server/pages-request-stage-entry.js +75 -16
- package/dist/server/pages-response-stage-entry.js +4 -0
- package/dist/server/pages-revalidate.js +3 -3
- package/dist/server/pages-router-entry.js +5 -4
- package/dist/server/prerender-manifest.d.ts +3 -3
- package/dist/server/prerender-manifest.js +4 -3
- package/dist/server/prerender-work-unit-setup.js +4 -0
- package/dist/server/prod-server.d.ts +12 -0
- package/dist/server/prod-server.js +204 -74
- package/dist/server/proper-error.d.ts +4 -0
- package/dist/server/proper-error.js +31 -0
- package/dist/server/request-pipeline.d.ts +4 -1
- package/dist/server/request-pipeline.js +3 -2
- package/dist/server/revalidation-request.d.ts +1 -0
- package/dist/server/revalidation-request.js +1 -1
- package/dist/server/rsc-stream-hints.d.ts +1 -1
- package/dist/server/rsc-stream-hints.js +52 -5
- package/dist/server/seed-cache.d.ts +1 -0
- package/dist/server/seed-cache.js +5 -4
- package/dist/server/server-reference-loader.d.ts +4 -0
- package/dist/server/server-reference-loader.js +29 -0
- package/dist/server/socket-error-backstop.d.ts +9 -1
- package/dist/server/socket-error-backstop.js +46 -17
- package/dist/server/static-file-signal.d.ts +15 -4
- package/dist/server/static-file-signal.js +46 -12
- package/dist/server/worker-image-optimization.d.ts +34 -0
- package/dist/server/worker-image-optimization.js +99 -0
- package/dist/server/worker-stages.d.ts +1 -1
- package/dist/server/worker-stages.js +2 -2
- package/dist/server/worker-utils.d.ts +8 -3
- package/dist/server/worker-utils.js +12 -7
- package/dist/shims/app-router-scroll.js +4 -1
- package/dist/shims/app-router-tree-context.d.ts +5 -0
- package/dist/shims/app-router-tree-context.js +27 -0
- package/dist/shims/cache-callable-runtime.d.ts +4 -2
- package/dist/shims/cache-callable-runtime.js +21 -12
- package/dist/shims/cache-handler.js +1 -9
- package/dist/shims/cache-runtime.d.ts +6 -1
- package/dist/shims/cache-runtime.js +2 -1
- package/dist/shims/cache.d.ts +2 -2
- package/dist/shims/cache.js +40 -13
- package/dist/shims/cdn-cache.d.ts +8 -0
- package/dist/shims/cdn-cache.js +17 -1
- package/dist/shims/disable-smooth-scroll.d.ts +3 -0
- package/dist/shims/disable-smooth-scroll.js +36 -0
- package/dist/shims/document-placeholders.d.ts +19 -0
- package/dist/shims/document-placeholders.js +45 -0
- package/dist/shims/document.js +21 -5
- package/dist/shims/dynamic-preload-chunks.d.ts +1 -0
- package/dist/shims/dynamic-preload-chunks.js +13 -9
- package/dist/shims/dynamic.d.ts +1 -1
- package/dist/shims/dynamic.js +60 -8
- package/dist/shims/fetch-cache-state.d.ts +66 -0
- package/dist/shims/fetch-cache-state.js +92 -0
- package/dist/shims/fetch-cache.d.ts +3 -67
- package/dist/shims/fetch-cache.js +160 -125
- package/dist/shims/head.d.ts +10 -6
- package/dist/shims/head.js +16 -14
- package/dist/shims/headers.js +2 -2
- package/dist/shims/image.js +2 -1
- package/dist/shims/internal/hybrid-client-route-owner-direct.js +1 -1
- package/dist/shims/internal/hybrid-client-route-owner.js +1 -0
- package/dist/shims/internal/work-store-scope.d.ts +5 -0
- package/dist/shims/internal/work-store-scope.js +24 -0
- package/dist/shims/link-prefetch.js +5 -4
- package/dist/shims/link.js +2 -2
- package/dist/shims/navigation.js +34 -9
- package/dist/shims/request-context.d.ts +2 -0
- package/dist/shims/request-state-types.d.ts +2 -1
- package/dist/shims/router.js +21 -32
- package/dist/shims/server.d.ts +27 -4
- package/dist/shims/server.js +65 -9
- package/dist/shims/unified-request-context.d.ts +1 -1
- package/dist/shims/url-utils.d.ts +9 -0
- package/dist/shims/url-utils.js +15 -4
- package/dist/utils/client-runtime-metadata.js +1 -1
- package/dist/utils/domain-locale.js +1 -1
- package/dist/utils/hash.d.ts +7 -0
- package/dist/utils/hash.js +11 -1
- package/dist/utils/package-name.d.ts +6 -0
- package/dist/utils/package-name.js +12 -1
- package/dist/utils/plugin-rsc-version.d.ts +6 -0
- package/dist/utils/plugin-rsc-version.js +41 -0
- package/dist/utils/prerender-output-paths.js +15 -4
- package/dist/utils/public-file-path.d.ts +10 -2
- package/dist/utils/public-file-path.js +13 -9
- package/dist/utils/public-routes.js +2 -2
- package/dist/utils/react-version.d.ts +10 -0
- package/dist/utils/react-version.js +39 -16
- package/package.json +11 -7
- package/dist/build/nitro-route-rules.d.ts +0 -47
- package/dist/build/nitro-route-rules.js +0 -79
- package/dist/plugins/cache-flight-codec.d.ts +0 -19
- package/dist/plugins/cache-flight-codec.js +0 -68
|
@@ -119,9 +119,6 @@ function attachPagesPreviewApi(req, res) {
|
|
|
119
119
|
var PagesResponseStream = class extends Writable {
|
|
120
120
|
resolveResponse;
|
|
121
121
|
rejectResponse;
|
|
122
|
-
requestHeaders;
|
|
123
|
-
trustedRevalidateOrigin;
|
|
124
|
-
allowedRevalidateHeaderKeys;
|
|
125
122
|
resStatusCode = 200;
|
|
126
123
|
resHeaders = {};
|
|
127
124
|
setCookieHeaders = [];
|
|
@@ -131,13 +128,10 @@ var PagesResponseStream = class extends Writable {
|
|
|
131
128
|
streamEnded = false;
|
|
132
129
|
pendingWrite = null;
|
|
133
130
|
discardBody = false;
|
|
134
|
-
constructor(resolveResponse, rejectResponse
|
|
131
|
+
constructor(resolveResponse, rejectResponse) {
|
|
135
132
|
super();
|
|
136
133
|
this.resolveResponse = resolveResponse;
|
|
137
134
|
this.rejectResponse = rejectResponse;
|
|
138
|
-
this.requestHeaders = requestHeaders;
|
|
139
|
-
this.trustedRevalidateOrigin = trustedRevalidateOrigin;
|
|
140
|
-
this.allowedRevalidateHeaderKeys = allowedRevalidateHeaderKeys;
|
|
141
135
|
this.once("error", (err) => {
|
|
142
136
|
if (!this.resolved) {
|
|
143
137
|
this.resolved = true;
|
|
@@ -206,9 +200,6 @@ var PagesResponseStream = class extends Writable {
|
|
|
206
200
|
if (this.setCookieHeaders.length > 0) headers["set-cookie"] = this.setCookieHeaders;
|
|
207
201
|
return headers;
|
|
208
202
|
}
|
|
209
|
-
async revalidate(urlPath, opts) {
|
|
210
|
-
await performOnDemandRevalidate(this.requestHeaders, urlPath, opts, this.trustedRevalidateOrigin, this.allowedRevalidateHeaderKeys);
|
|
211
|
-
}
|
|
212
203
|
setPreviewData(data, options = {}) {
|
|
213
204
|
setPagesPreviewData(this, data, options);
|
|
214
205
|
return this;
|
|
@@ -346,7 +337,7 @@ function createPagesReqRes(options) {
|
|
|
346
337
|
resolveResponse = resolve;
|
|
347
338
|
rejectResponse = reject;
|
|
348
339
|
});
|
|
349
|
-
const res = new PagesResponseStream(resolveResponse, rejectResponse
|
|
340
|
+
const res = new PagesResponseStream(resolveResponse, rejectResponse);
|
|
350
341
|
for (const [name, value] of options.initialResponseHeaders ?? []) {
|
|
351
342
|
if (name.toLowerCase() === "set-cookie") continue;
|
|
352
343
|
res.setHeader(name, value);
|
|
@@ -360,5 +351,22 @@ function createPagesReqRes(options) {
|
|
|
360
351
|
responsePromise
|
|
361
352
|
};
|
|
362
353
|
}
|
|
354
|
+
/**
|
|
355
|
+
* Create the req/res pair for a Pages API route. Only API responses get
|
|
356
|
+
* `res.revalidate()`: Next.js attaches it in apiResolver
|
|
357
|
+
* (`packages/next/src/server/api-utils/node/api-resolver.ts`), so a page's
|
|
358
|
+
* getServerSideProps `res` never carries the revalidation secret.
|
|
359
|
+
*/
|
|
360
|
+
function createPagesApiReqRes(options) {
|
|
361
|
+
const { req, res, responsePromise } = createPagesReqRes(options);
|
|
362
|
+
const trustedRevalidateOrigin = options.trustedRevalidateOrigin ?? new URL(options.request.url).origin;
|
|
363
|
+
return {
|
|
364
|
+
req,
|
|
365
|
+
res: Object.assign(res, { async revalidate(urlPath, opts) {
|
|
366
|
+
await performOnDemandRevalidate(options.request.headers, urlPath, opts, trustedRevalidateOrigin, options.allowedRevalidateHeaderKeys);
|
|
367
|
+
} }),
|
|
368
|
+
responsePromise
|
|
369
|
+
};
|
|
370
|
+
}
|
|
363
371
|
//#endregion
|
|
364
|
-
export { PagesBodyParseError as PagesApiBodyParseError, attachPagesPreviewApi, attachPagesRequestCookies, createPagesReqRes, isVinextStreamedApiResponse, markVinextStreamedApiResponse, parsePagesApiBody };
|
|
372
|
+
export { PagesBodyParseError as PagesApiBodyParseError, attachPagesPreviewApi, attachPagesRequestCookies, createPagesApiReqRes, createPagesReqRes, isVinextStreamedApiResponse, markVinextStreamedApiResponse, parsePagesApiBody };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Route } from "../routing/pages-router.js";
|
|
2
|
-
import { VinextNextData } from "../client/vinext-next-data.js";
|
|
3
2
|
import { CachedPagesValue, CachedRedirectValue } from "../shims/cache-handler.js";
|
|
4
3
|
import { ISRCacheEntry, IsrWritePolicy } from "./isr-cache.js";
|
|
5
4
|
import { PagesPreviewData } from "./pages-preview.js";
|
|
@@ -43,6 +42,14 @@ export declare function assertPages404DoesNotReturnNotFound(routePattern: string
|
|
|
43
42
|
* - packages/next/src/server/render.tsx (`metadata.cacheControl`)
|
|
44
43
|
* - packages/next/src/server/route-modules/pages/pages-handler.ts
|
|
45
44
|
*/
|
|
45
|
+
/**
|
|
46
|
+
* Next.js renders a shared getStaticProps status page (/404, /500) for its own
|
|
47
|
+
* pathname, never for the request that reached it. Only the original
|
|
48
|
+
* request's trailing slash carries over under `trailingSlash`, read before
|
|
49
|
+
* rewrites and locale stripping.
|
|
50
|
+
* https://github.com/vercel/next.js/blob/canary/packages/next/src/server/route-modules/pages/pages-handler.ts
|
|
51
|
+
*/
|
|
52
|
+
export declare function resolvePagesStatusPageRenderPath(statusPathname: string, trailingSlash: boolean, requestPathname: string): string;
|
|
46
53
|
export declare function resolvePagesRevalidateSeconds(result: PagesPagePropsResult, routeUrl?: string): number | false;
|
|
47
54
|
type PagesMutableGsspResponse = {
|
|
48
55
|
headersSent: boolean;
|
|
@@ -115,25 +122,9 @@ export type PagesPageModule = {
|
|
|
115
122
|
revalidateReason?: "build" | "on-demand" | "stale";
|
|
116
123
|
}) => Promise<PagesPagePropsResult> | PagesPagePropsResult;
|
|
117
124
|
};
|
|
118
|
-
type RenderPagesIsrHtmlOptions = {
|
|
119
|
-
buildId: string | null;
|
|
120
|
-
cachedHtml: string;
|
|
121
|
-
collectIsrHeadHTML?: (() => string) | undefined;
|
|
122
|
-
createPageElement: (props: Record<string, unknown>) => ReactNode;
|
|
123
|
-
i18n: PagesI18nRenderContext;
|
|
124
|
-
pageProps: Record<string, unknown>;
|
|
125
|
-
props?: Record<string, unknown>;
|
|
126
|
-
params: Record<string, unknown>;
|
|
127
|
-
renderIsrPassToStringAsync: (element: ReactNode, onHeadReady?: () => Promise<void>) => Promise<string>;
|
|
128
|
-
routePattern: string;
|
|
129
|
-
safeJsonStringify: (value: unknown) => string;
|
|
130
|
-
vinext?: VinextNextData["__vinext"];
|
|
131
|
-
nextData?: PagesNextDataExtras;
|
|
132
|
-
};
|
|
133
125
|
export type ResolvePagesPageDataOptions = {
|
|
134
126
|
applyRequestContexts: () => void;
|
|
135
127
|
basePath?: string;
|
|
136
|
-
buildId: string | null;
|
|
137
128
|
/**
|
|
138
129
|
* When true, this is a `/_next/data/<buildId>/<page>.json` request. Callers
|
|
139
130
|
* that respond with a JSON envelope (`{ pageProps }`) instead of HTML must
|
|
@@ -145,6 +136,8 @@ export type ResolvePagesPageDataOptions = {
|
|
|
145
136
|
isDataReq?: boolean;
|
|
146
137
|
err?: unknown;
|
|
147
138
|
createGsspReqRes: () => PagesGsspContextResponse;
|
|
139
|
+
/** The req/res for a stale regeneration's render; defaults to `createGsspReqRes`. */
|
|
140
|
+
createRegenerationReqRes?: () => PagesGsspContextResponse;
|
|
148
141
|
createAppTree?: (props: Record<string, unknown>) => ReactNode;
|
|
149
142
|
createPageElement: (props: Record<string, unknown>) => ReactNode;
|
|
150
143
|
fontLinkHeader: string;
|
|
@@ -188,6 +181,12 @@ export type ResolvePagesPageDataOptions = {
|
|
|
188
181
|
* fallback path. Mirrors Next.js `unstable_onlyGenerated`.
|
|
189
182
|
*/
|
|
190
183
|
revalidateOnlyGenerated?: boolean;
|
|
184
|
+
/**
|
|
185
|
+
* Set when a cache adapter regenerates an entry it stores for this build.
|
|
186
|
+
* The stored entry proves the path was admitted, so `getStaticPaths()` is
|
|
187
|
+
* skipped as it is for an entry read through `isrGet`.
|
|
188
|
+
*/
|
|
189
|
+
regeneratesStoredEntry?: boolean;
|
|
191
190
|
previewData?: PagesPreviewData | false;
|
|
192
191
|
/**
|
|
193
192
|
* The deployment ID used for deployment-skew protection. When set, it is
|
|
@@ -226,14 +225,19 @@ export type ResolvePagesPageDataOptions = {
|
|
|
226
225
|
routePath: string;
|
|
227
226
|
routeType: "render";
|
|
228
227
|
}) => void;
|
|
229
|
-
renderIsrPassToStringAsync: (element: ReactNode, onHeadReady?: () => Promise<void>) => Promise<string>;
|
|
230
228
|
/**
|
|
231
|
-
*
|
|
232
|
-
*
|
|
233
|
-
*
|
|
229
|
+
* Render the whole document for regenerated props and store it as the ISR
|
|
230
|
+
* entry, through the same pipeline (and with the same cache write) as a
|
|
231
|
+
* foreground MISS. Next.js re-runs its full render on regeneration too;
|
|
232
|
+
* resolves once the entry is written.
|
|
234
233
|
*/
|
|
235
|
-
|
|
236
|
-
|
|
234
|
+
renderIsrDocument: (input: {
|
|
235
|
+
documentReqRes: PagesGsspContextResponse;
|
|
236
|
+
expireSeconds: number | undefined;
|
|
237
|
+
pageProps: Record<string, unknown>;
|
|
238
|
+
props: Record<string, unknown>;
|
|
239
|
+
revalidateSeconds: number | false;
|
|
240
|
+
}) => Promise<void>;
|
|
237
241
|
nextData?: PagesNextDataExtras;
|
|
238
242
|
/**
|
|
239
243
|
* The request's User-Agent string. When this matches a known crawler/bot
|
|
@@ -250,6 +254,11 @@ export type ResolvePagesPageDataOptions = {
|
|
|
250
254
|
* response is a `304 Not Modified` with no body.
|
|
251
255
|
*/
|
|
252
256
|
ifNoneMatch?: string;
|
|
257
|
+
/**
|
|
258
|
+
* The incoming request's `If-Modified-Since` header value. As in Next.js,
|
|
259
|
+
* which gives a page no Last-Modified, a request with it gets the page.
|
|
260
|
+
*/
|
|
261
|
+
ifModifiedSince?: string;
|
|
253
262
|
/**
|
|
254
263
|
* The incoming request's `Cache-Control` header value. When it contains
|
|
255
264
|
* `no-cache`, the 304 short-circuit is skipped and a full response is
|
|
@@ -320,6 +329,5 @@ export type PagesRouteParam = {
|
|
|
320
329
|
};
|
|
321
330
|
export declare function getPagesRouteParams(routePattern: string): PagesRouteParam[];
|
|
322
331
|
export declare function matchesPagesStaticPath(pathEntry: PagesStaticPathsEntry, params: Record<string, unknown>, routeParams: PagesRouteParam[], routeUrl: string, i18n?: Pick<PagesI18nRenderContext, "locale" | "locales" | "defaultLocale">): boolean;
|
|
323
|
-
export declare function renderPagesIsrHtml(options: RenderPagesIsrHtmlOptions): Promise<string>;
|
|
324
332
|
export declare function resolvePagesPageData(options: ResolvePagesPageDataOptions): Promise<ResolvePagesPageDataResult>;
|
|
325
333
|
//#endregion
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { isUnknownRecord } from "../utils/record.js";
|
|
2
2
|
import { isBotUserAgent } from "../utils/html-limited-bots.js";
|
|
3
|
-
import { normalizePathnameForRouteMatch } from "../routing/utils.js";
|
|
4
3
|
import { NEXTJS_CACHE_HEADER, NEXTJS_DEPLOYMENT_ID_HEADER } from "./headers.js";
|
|
4
|
+
import { normalizePathnameForRouteMatch } from "../routing/utils.js";
|
|
5
5
|
import { isDangerousScheme } from "../shims/url-safety.js";
|
|
6
6
|
import { extractLocaleFromUrl } from "./pages-i18n.js";
|
|
7
|
+
import { buildNextDataPropsJsonResponse } from "./pages-data-route.js";
|
|
7
8
|
import { recordRouteCacheability } from "../shims/cacheability-classification.js";
|
|
8
9
|
import { applyCdnResponseHeaders } from "./cache-control.js";
|
|
9
10
|
import { buildMissIsrCacheControl, decideIsr } from "./isr-decision.js";
|
|
10
|
-
import {
|
|
11
|
-
import { encodeCacheTag } from "../utils/encode-cache-tag.js";
|
|
11
|
+
import { isrCacheControl } from "./isr-cache.js";
|
|
12
12
|
import { normalizeStaticPathname } from "../routing/route-pattern.js";
|
|
13
13
|
import { buildCacheStateHeaders } from "./cache-headers.js";
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
14
|
+
import { pagesPathCacheTag } from "./pages-cache-tag.js";
|
|
15
|
+
import { isPageNotModified } from "./http-conditional.js";
|
|
16
|
+
import { generatePagesETag, isPagesStreamingBot, rendersPagesNotModified } from "./pages-page-response.js";
|
|
16
17
|
import { createPagesGetInitialPropsRouter, hasPagesGetInitialProps, isResponseSent, loadPagesGetInitialProps } from "./pages-get-initial-props.js";
|
|
17
|
-
import { buildNextDataPropsJsonResponse } from "./pages-data-route.js";
|
|
18
18
|
import { isSerializableProps } from "./pages-serializable-props.js";
|
|
19
19
|
import { tracePagesData, tracePagesDocument } from "./pages-execution-tracing.js";
|
|
20
20
|
//#region src/server/pages-page-data.ts
|
|
@@ -43,6 +43,16 @@ function assertPages404DoesNotReturnNotFound(routePattern, result) {
|
|
|
43
43
|
* - packages/next/src/server/render.tsx (`metadata.cacheControl`)
|
|
44
44
|
* - packages/next/src/server/route-modules/pages/pages-handler.ts
|
|
45
45
|
*/
|
|
46
|
+
/**
|
|
47
|
+
* Next.js renders a shared getStaticProps status page (/404, /500) for its own
|
|
48
|
+
* pathname, never for the request that reached it. Only the original
|
|
49
|
+
* request's trailing slash carries over under `trailingSlash`, read before
|
|
50
|
+
* rewrites and locale stripping.
|
|
51
|
+
* https://github.com/vercel/next.js/blob/canary/packages/next/src/server/route-modules/pages/pages-handler.ts
|
|
52
|
+
*/
|
|
53
|
+
function resolvePagesStatusPageRenderPath(statusPathname, trailingSlash, requestPathname) {
|
|
54
|
+
return trailingSlash && requestPathname.endsWith("/") ? statusPathname + "/" : statusPathname;
|
|
55
|
+
}
|
|
46
56
|
function resolvePagesRevalidateSeconds(result, routeUrl = "") {
|
|
47
57
|
const revalidate = result.revalidate;
|
|
48
58
|
if (revalidate === true) return 1;
|
|
@@ -103,14 +113,13 @@ function mergePagesNotFoundSourceHeaders(response, sourceHeaders) {
|
|
|
103
113
|
});
|
|
104
114
|
}
|
|
105
115
|
function applyPagesTerminalMissHeaders(response, revalidateSeconds, isrCachePathname, expireSeconds) {
|
|
106
|
-
const stem = isrCachePathname.endsWith("/") ? isrCachePathname.slice(0, -1) : isrCachePathname;
|
|
107
116
|
recordRouteCacheability({
|
|
108
117
|
cacheable: revalidateSeconds !== 0,
|
|
109
118
|
cacheControl: buildMissIsrCacheControl(revalidateSeconds, expireSeconds)
|
|
110
119
|
});
|
|
111
120
|
applyCdnResponseHeaders(response.headers, {
|
|
112
121
|
cacheControl: buildMissIsrCacheControl(revalidateSeconds, expireSeconds),
|
|
113
|
-
tags: [
|
|
122
|
+
tags: [pagesPathCacheTag(isrCachePathname)]
|
|
114
123
|
});
|
|
115
124
|
for (const [name, value] of Object.entries(buildCacheStateHeaders("MISS"))) response.headers.set(name, value);
|
|
116
125
|
return response;
|
|
@@ -216,7 +225,7 @@ async function loadPagesAppInitialRenderProps(options, getSharedReqRes) {
|
|
|
216
225
|
defaultLocale: options.i18n.defaultLocale
|
|
217
226
|
}
|
|
218
227
|
});
|
|
219
|
-
if (isResponseSent(res)) return {
|
|
228
|
+
if (isResponseSent(res) && typeof options.pageModule.getStaticProps !== "function") return {
|
|
220
229
|
kind: "response",
|
|
221
230
|
response: responsePromise
|
|
222
231
|
};
|
|
@@ -367,7 +376,7 @@ function matchesPagesStaticPath(pathEntry, params, routeParams, routeUrl, i18n)
|
|
|
367
376
|
const actual = params[key];
|
|
368
377
|
if (Array.isArray(value)) {
|
|
369
378
|
if (optional && value.length === 0 && actual === void 0) return true;
|
|
370
|
-
return Array.isArray(actual) && value.
|
|
379
|
+
return Array.isArray(actual) && value.length === actual.length && actual.every((part, index) => part === value[index]);
|
|
371
380
|
}
|
|
372
381
|
return String(value) === String(actual);
|
|
373
382
|
});
|
|
@@ -408,7 +417,11 @@ function finalizeCachedPagesResponse(response, options, html) {
|
|
|
408
417
|
if (html !== void 0 && options.userAgent && isPagesStreamingBot(options.userAgent)) {
|
|
409
418
|
const etag = generatePagesETag(html);
|
|
410
419
|
response.headers.set("ETag", etag);
|
|
411
|
-
if (
|
|
420
|
+
if (isPageNotModified({
|
|
421
|
+
cacheControl: options.requestCacheControl,
|
|
422
|
+
ifModifiedSince: options.ifModifiedSince,
|
|
423
|
+
ifNoneMatch: options.ifNoneMatch
|
|
424
|
+
}, etag) && rendersPagesNotModified(response.status)) response = new Response(null, {
|
|
412
425
|
status: 304,
|
|
413
426
|
headers: response.headers
|
|
414
427
|
});
|
|
@@ -418,92 +431,6 @@ function finalizeCachedPagesResponse(response, options, html) {
|
|
|
418
431
|
response
|
|
419
432
|
};
|
|
420
433
|
}
|
|
421
|
-
/**
|
|
422
|
-
* Matches one serialized `next/head` tag. `getSSRHeadHTML()` stamps every tag
|
|
423
|
-
* it emits with `data-next-head=""` (see `shims/head.ts`), which is the same
|
|
424
|
-
* marker Next.js uses to reconcile the head on the client — so it is a stable
|
|
425
|
-
* anchor for finding the collector's output inside an already-rendered shell.
|
|
426
|
-
*
|
|
427
|
-
* Raw-content tags are safe to match non-greedily: `headChildToHTML()` escapes
|
|
428
|
-
* closing-tag sequences in `<style>`/`<script>` bodies, so the first `</style>`
|
|
429
|
-
* encountered is always the real terminator.
|
|
430
|
-
*/
|
|
431
|
-
const SSR_HEAD_TAG_PATTERN = /<(title|meta|link|style|script|base|noscript)\b[^>]*?\sdata-next-head=""[^>]*?(?:\/>|>[\s\S]*?<\/\1>)/g;
|
|
432
|
-
/**
|
|
433
|
-
* Matches a whole head element whose body may contain markup-looking text.
|
|
434
|
-
* Script/style are raw-text elements, title is RCDATA, and noscript is raw
|
|
435
|
-
* text while scripting is enabled. In all four, a literal `</head>` does not
|
|
436
|
-
* close the document head. `headChildToHTML()` only escapes the element's own
|
|
437
|
-
* closing sequence for script/style, while `dangerouslySetInnerHTML` may leave
|
|
438
|
-
* `</head>` intact in any of them.
|
|
439
|
-
*/
|
|
440
|
-
const HEAD_TEXT_ELEMENT_PATTERN = /<(script|style|title|noscript)\b[^>]*>[\s\S]*?<\/\1>/gi;
|
|
441
|
-
/**
|
|
442
|
-
* Replace the `next/head` region of a cached shell with a freshly collected
|
|
443
|
-
* one.
|
|
444
|
-
*
|
|
445
|
-
* ISR regeneration re-renders the page body but reuses the cached shell, so
|
|
446
|
-
* without this the `<head>` stays frozen at whatever the first cache-filling
|
|
447
|
-
* render produced — a page whose `<title>`/meta derive from `getStaticProps`
|
|
448
|
-
* data would serve an updated body under permanently stale metadata.
|
|
449
|
-
*
|
|
450
|
-
* The collector emits its tags as one contiguous run (`ssrHeadHTML` is
|
|
451
|
-
* concatenated ahead of trace meta and `_document` styles in
|
|
452
|
-
* `buildPagesShellHtml`), so replacing first-match-start through
|
|
453
|
-
* last-match-end swaps exactly that run and leaves `_document`-owned head
|
|
454
|
-
* markup either side of it untouched.
|
|
455
|
-
*
|
|
456
|
-
* Only the `next/head` run refreshes. `_document`-rendered head children and
|
|
457
|
-
* CSS-in-JS `styles` still come from the cached shell, because regeneration
|
|
458
|
-
* never re-renders `_document` — refreshing those means running the full
|
|
459
|
-
* document pipeline on regeneration the way Next.js does.
|
|
460
|
-
*/
|
|
461
|
-
function refreshCachedHeadTags(cachedHtml, freshHead) {
|
|
462
|
-
if (!freshHead) return cachedHtml;
|
|
463
|
-
const headEnd = cachedHtml.replace(HEAD_TEXT_ELEMENT_PATTERN, (element) => " ".repeat(element.length)).indexOf("</head>");
|
|
464
|
-
if (headEnd < 0) return cachedHtml;
|
|
465
|
-
const matches = [...cachedHtml.slice(0, headEnd).matchAll(SSR_HEAD_TAG_PATTERN)];
|
|
466
|
-
const first = matches[0];
|
|
467
|
-
const last = matches[matches.length - 1];
|
|
468
|
-
if (!first || !last || first.index === void 0 || last.index === void 0) return cachedHtml;
|
|
469
|
-
return cachedHtml.slice(0, first.index) + freshHead + cachedHtml.slice(last.index + last[0].length);
|
|
470
|
-
}
|
|
471
|
-
function rewritePagesCachedHtml(cachedHtml, freshBody, nextDataScript) {
|
|
472
|
-
const bodyStart = cachedHtml.indexOf("<div id=\"__next\">");
|
|
473
|
-
const contentStart = bodyStart >= 0 ? bodyStart + 17 : -1;
|
|
474
|
-
const canonicalNextDataStart = cachedHtml.search(/<script\b(?=[^>]*\bid=["']__NEXT_DATA__["'])(?=[^>]*\btype=["']application\/json["'])[^>]*>/);
|
|
475
|
-
const legacyNextDataStart = cachedHtml.indexOf("<script>window.__NEXT_DATA__");
|
|
476
|
-
const nextDataStart = canonicalNextDataStart >= 0 ? canonicalNextDataStart : legacyNextDataStart;
|
|
477
|
-
if (contentStart >= 0 && nextDataStart >= 0) {
|
|
478
|
-
const region = cachedHtml.slice(contentStart, nextDataStart);
|
|
479
|
-
const lastCloseDiv = region.lastIndexOf("</div>");
|
|
480
|
-
const gap = lastCloseDiv >= 0 ? region.slice(lastCloseDiv + 6) : "";
|
|
481
|
-
const nextDataEnd = cachedHtml.indexOf("<\/script>", nextDataStart) + 9;
|
|
482
|
-
const tail = cachedHtml.slice(nextDataEnd);
|
|
483
|
-
return cachedHtml.slice(0, contentStart) + freshBody + "</div>" + gap + nextDataScript + tail;
|
|
484
|
-
}
|
|
485
|
-
return "<!DOCTYPE html>\n<html>\n<head>\n</head>\n<body>\n <div id=\"__next\">" + freshBody + "</div>\n " + nextDataScript + "\n</body>\n</html>";
|
|
486
|
-
}
|
|
487
|
-
async function renderPagesIsrHtml(options) {
|
|
488
|
-
const renderProps = options.props ?? { pageProps: options.pageProps };
|
|
489
|
-
const collectHead = options.collectIsrHeadHTML;
|
|
490
|
-
let freshHead = "";
|
|
491
|
-
const freshBody = await options.renderIsrPassToStringAsync(options.createPageElement(renderProps), collectHead && (async () => {
|
|
492
|
-
freshHead = collectHead();
|
|
493
|
-
}));
|
|
494
|
-
const nextDataScript = buildPagesNextDataScript({
|
|
495
|
-
buildId: options.buildId,
|
|
496
|
-
i18n: options.i18n,
|
|
497
|
-
pageProps: options.pageProps,
|
|
498
|
-
props: renderProps,
|
|
499
|
-
params: options.params,
|
|
500
|
-
routePattern: options.routePattern,
|
|
501
|
-
safeJsonStringify: options.safeJsonStringify,
|
|
502
|
-
nextData: options.nextData,
|
|
503
|
-
vinext: options.vinext
|
|
504
|
-
});
|
|
505
|
-
return rewritePagesCachedHtml(refreshCachedHeadTags(options.cachedHtml, freshHead), freshBody, nextDataScript);
|
|
506
|
-
}
|
|
507
434
|
async function resolvePagesPageData(options) {
|
|
508
435
|
const userFacingParams = options.route.isDynamic ? options.params : null;
|
|
509
436
|
let isFallback = false;
|
|
@@ -515,13 +442,13 @@ async function resolvePagesPageData(options) {
|
|
|
515
442
|
const value = cached?.value.value;
|
|
516
443
|
if (cached && !cached.isStale && !cached.isExpired && value?.kind === "PAGES") return finalizeCachedPagesResponse(options.isDataReq ? applyCachedPagesRepresentationHeaders(buildNextDataPropsJsonResponse(normalizePagesRenderProps(value.pageData), options.safeJsonStringify, options.deploymentId ? { headers: { [NEXTJS_DEPLOYMENT_ID_HEADER]: options.deploymentId } } : void 0), "HIT", cached.value, options) : buildPagesCacheResponse(value.html, "HIT", options.fontLinkHeader, void 0, options.expireSeconds, cached.value.cacheControl, options.statusCode ?? value.status, value.headers), options, options.isDataReq ? void 0 : value.html);
|
|
517
444
|
}
|
|
518
|
-
let
|
|
519
|
-
if (options.
|
|
445
|
+
let hasStoredEntry = options.regeneratesStoredEntry === true;
|
|
446
|
+
if (options.route.isDynamic && typeof options.pageModule.getStaticProps === "function" && typeof options.pageModule.getServerSideProps !== "function" && !hasStoredEntry && !options.isOnDemandRevalidate && previewData === false) {
|
|
520
447
|
previousCacheEntry = await options.isrGet(options.isrCacheKey("pages", options.isrCachePathname ?? options.routeUrl.split("?")[0]));
|
|
521
448
|
const value = previousCacheEntry?.value.value;
|
|
522
|
-
|
|
449
|
+
hasStoredEntry = !!previousCacheEntry && !previousCacheEntry.isExpired && (value === null || value?.kind === "PAGES" || value?.kind === "REDIRECT");
|
|
523
450
|
}
|
|
524
|
-
if (!
|
|
451
|
+
if (!hasStoredEntry && previewData === false && typeof options.pageModule.getStaticPaths === "function" && options.route.isDynamic) {
|
|
525
452
|
const staticPathsI18n = {
|
|
526
453
|
...options.i18n,
|
|
527
454
|
defaultLocale: options.staticPathsDefaultLocale ?? options.i18n.defaultLocale
|
|
@@ -534,7 +461,7 @@ async function resolvePagesPageData(options) {
|
|
|
534
461
|
const paths = pathsResult?.paths ?? [];
|
|
535
462
|
const routeParams = getPagesRouteParams(options.routePattern);
|
|
536
463
|
const isValidPath = paths.some((pathEntry) => matchesPagesStaticPath(pathEntry, options.params, routeParams, options.routeUrl, staticPathsI18n));
|
|
537
|
-
if (fallback === false && !isValidPath
|
|
464
|
+
if (fallback === false && !isValidPath) {
|
|
538
465
|
if (options.isOnDemandRevalidate && !options.revalidateOnlyGenerated) return {
|
|
539
466
|
kind: "response",
|
|
540
467
|
response: new Response("This page could not be found", { status: 404 }),
|
|
@@ -543,7 +470,7 @@ async function resolvePagesPageData(options) {
|
|
|
543
470
|
return buildPagesNotFoundResult(options);
|
|
544
471
|
}
|
|
545
472
|
const isBotRequest = !!options.userAgent && isBotUserAgent(options.userAgent, options.htmlLimitedBots);
|
|
546
|
-
if (fallback === true && !isValidPath && !options.isDataReq && !isBotRequest
|
|
473
|
+
if (fallback === true && !isValidPath && !options.isDataReq && !isBotRequest) isFallback = true;
|
|
547
474
|
shouldPersistFallbackData = fallback === true && !isValidPath && options.isDataReq === true;
|
|
548
475
|
}
|
|
549
476
|
if (typeof options.pageModule.getStaticProps === "function" && options.isOnDemandRevalidate && options.revalidateOnlyGenerated) {
|
|
@@ -571,6 +498,13 @@ async function resolvePagesPageData(options) {
|
|
|
571
498
|
}
|
|
572
499
|
let renderProps = { pageProps };
|
|
573
500
|
if (previewData !== false) renderProps.__N_PREVIEW = true;
|
|
501
|
+
async function takeSentResponse() {
|
|
502
|
+
if (options.isOnDemandRevalidate || !sharedReqRes || !isResponseSent(sharedReqRes.res)) return null;
|
|
503
|
+
return {
|
|
504
|
+
kind: "response",
|
|
505
|
+
response: await sharedReqRes.responsePromise
|
|
506
|
+
};
|
|
507
|
+
}
|
|
574
508
|
async function loadForegroundAppInitialRenderProps() {
|
|
575
509
|
const result = await loadPagesAppInitialRenderProps(options, getSharedReqRes);
|
|
576
510
|
if (result.kind === "response") return {
|
|
@@ -583,7 +517,7 @@ async function resolvePagesPageData(options) {
|
|
|
583
517
|
}
|
|
584
518
|
if (isFallback) {
|
|
585
519
|
const pathname = options.isrCachePathname ?? options.routeUrl.split("?")[0];
|
|
586
|
-
if ((await options.isrGet(options.isrCacheKey("pages", pathname)))?.value.value?.kind !== "PAGES") {
|
|
520
|
+
if ((previousCacheEntry !== void 0 ? previousCacheEntry : await options.isrGet(options.isrCacheKey("pages", pathname)))?.value.value?.kind !== "PAGES") {
|
|
587
521
|
const appShortCircuit = await loadForegroundAppInitialRenderProps();
|
|
588
522
|
if (appShortCircuit) return appShortCircuit;
|
|
589
523
|
pageProps = {};
|
|
@@ -656,7 +590,8 @@ async function resolvePagesPageData(options) {
|
|
|
656
590
|
options.triggerBackgroundRegeneration(cacheKey, async function() {
|
|
657
591
|
return options.runInFreshUnifiedContext(async () => {
|
|
658
592
|
options.applyRequestContexts();
|
|
659
|
-
const
|
|
593
|
+
const reqRes = (options.createRegenerationReqRes ?? options.createGsspReqRes)();
|
|
594
|
+
const freshAppResult = await loadPagesAppInitialRenderProps(options, () => reqRes);
|
|
660
595
|
if (freshAppResult.kind === "response") return;
|
|
661
596
|
let freshPageProps = freshAppResult.pageProps;
|
|
662
597
|
let freshRenderProps = freshAppResult.renderProps;
|
|
@@ -696,22 +631,13 @@ async function resolvePagesPageData(options) {
|
|
|
696
631
|
};
|
|
697
632
|
if (options.validatePropsSerialization !== false) isSerializableProps(options.routePattern, "getStaticProps", freshPageProps);
|
|
698
633
|
if (cachedValue?.kind === "PAGES" && !cachedValue.generatedFromDataRequest) {
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
createPageElement: options.createPageElement,
|
|
703
|
-
i18n: options.i18n,
|
|
634
|
+
await tracePagesDocument(options.routePattern, () => options.renderIsrDocument({
|
|
635
|
+
documentReqRes: reqRes,
|
|
636
|
+
expireSeconds,
|
|
704
637
|
pageProps: freshPageProps,
|
|
705
638
|
props: freshRenderProps,
|
|
706
|
-
|
|
707
|
-
renderIsrPassToStringAsync: options.renderIsrPassToStringAsync,
|
|
708
|
-
collectIsrHeadHTML: options.collectIsrHeadHTML,
|
|
709
|
-
routePattern: options.routePattern,
|
|
710
|
-
safeJsonStringify: options.safeJsonStringify,
|
|
711
|
-
nextData: options.nextData,
|
|
712
|
-
vinext: options.vinext
|
|
639
|
+
revalidateSeconds
|
|
713
640
|
}));
|
|
714
|
-
await options.isrSet(cacheKey, buildPagesCacheValue(freshHtml, freshRenderProps, options.statusCode), { cacheControl: isrCacheControl(revalidateSeconds, { expireSeconds }) });
|
|
715
641
|
return;
|
|
716
642
|
}
|
|
717
643
|
await options.isrSet(cacheKey, {
|
|
@@ -788,7 +714,7 @@ async function resolvePagesPageData(options) {
|
|
|
788
714
|
}, { cacheControl: isrCacheControl(revalidateSeconds, { expireSeconds }) });
|
|
789
715
|
applyPagesTerminalMissHeaders(response, revalidateSeconds, pathname, expireSeconds);
|
|
790
716
|
}
|
|
791
|
-
return {
|
|
717
|
+
return await takeSentResponse() ?? {
|
|
792
718
|
kind: "response",
|
|
793
719
|
response
|
|
794
720
|
};
|
|
@@ -799,7 +725,7 @@ async function resolvePagesPageData(options) {
|
|
|
799
725
|
if (previewData === false) await options.isrSet(cacheKey, null, { cacheControl: isrCacheControl(revalidateSeconds, { expireSeconds }) });
|
|
800
726
|
const notFoundResult = buildPagesNotFoundResult(options, revalidateSeconds, previewData === false ? "MISS" : void 0, expireSeconds);
|
|
801
727
|
if (notFoundResult.kind === "response" && previewData === false) applyPagesTerminalMissHeaders(notFoundResult.response, revalidateSeconds, pathname, expireSeconds);
|
|
802
|
-
return notFoundResult;
|
|
728
|
+
return await takeSentResponse() ?? notFoundResult;
|
|
803
729
|
}
|
|
804
730
|
if (result?.props !== void 0 && options.validatePropsSerialization !== false) isSerializableProps(options.routePattern, "getStaticProps", pageProps);
|
|
805
731
|
if (previewData === false && result) {
|
|
@@ -854,6 +780,10 @@ async function resolvePagesPageData(options) {
|
|
|
854
780
|
};
|
|
855
781
|
}
|
|
856
782
|
}
|
|
783
|
+
if (options.isDataReq) {
|
|
784
|
+
const sentResponse = await takeSentResponse();
|
|
785
|
+
if (sentResponse) return sentResponse;
|
|
786
|
+
}
|
|
857
787
|
return {
|
|
858
788
|
kind: "render",
|
|
859
789
|
documentReqRes: sharedReqRes,
|
|
@@ -866,4 +796,4 @@ async function resolvePagesPageData(options) {
|
|
|
866
796
|
};
|
|
867
797
|
}
|
|
868
798
|
//#endregion
|
|
869
|
-
export { assertPages404DoesNotReturnNotFound, buildPagesRedirectProps, getPagesRouteParams, matchesPagesStaticPath, mergePagesDataProps, mergePagesNotFoundSourceHeaders,
|
|
799
|
+
export { assertPages404DoesNotReturnNotFound, buildPagesRedirectProps, getPagesRouteParams, matchesPagesStaticPath, mergePagesDataProps, mergePagesNotFoundSourceHeaders, resolvePagesPageData, resolvePagesRedirect, resolvePagesRedirectLocation, resolvePagesRevalidateSeconds, resolvePagesStatusPageRenderPath };
|
|
@@ -99,12 +99,6 @@ export type CreatePagesPageHandlerOptions = {
|
|
|
99
99
|
}>;
|
|
100
100
|
/** `renderToReadableStream` from `react-dom/server.edge`. */
|
|
101
101
|
renderToReadableStream: (element: ReactNode) => Promise<ReadableStream<Uint8Array>>;
|
|
102
|
-
/**
|
|
103
|
-
* Render a second ISR pass to a string (wraps renderToReadableStream).
|
|
104
|
-
* `onHeadReady` runs inside the pass's head scope, after the render and
|
|
105
|
-
* before the scope unwinds, so callers can read the collected `<head>`.
|
|
106
|
-
*/
|
|
107
|
-
renderIsrPassToStringAsync: (element: ReactNode, onHeadReady?: () => Promise<void>) => Promise<string>;
|
|
108
102
|
/** `safeJsonStringify` from `vinext/html`. */
|
|
109
103
|
safeJsonStringify: (value: unknown) => string;
|
|
110
104
|
/** `sanitizeDestination` from the config-matchers module. */
|