vinext 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -9
- package/dist/build/client-build-config.d.ts +10 -0
- package/dist/build/client-build-config.js +18 -2
- 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 +5 -3
- 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 +7 -6
- package/dist/cli.js +2 -1
- 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 +78 -81
- 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 +134 -43
- 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 +1 -0
- package/dist/init.js +67 -3
- package/dist/plugins/ast-scope.d.ts +7 -0
- package/dist/plugins/ast-scope.js +59 -3
- package/dist/plugins/cache-flight-codec.d.ts +1 -1
- package/dist/plugins/dynamic-preload-metadata.d.ts +1 -1
- package/dist/plugins/dynamic-preload-metadata.js +9 -8
- package/dist/plugins/ignore-dynamic-requests.d.ts +1 -1
- package/dist/plugins/ignore-dynamic-requests.js +3 -4
- package/dist/plugins/middleware-server-only.d.ts +5 -4
- package/dist/plugins/middleware-server-only.js +8 -5
- package/dist/plugins/pages-node-externals.js +1 -1
- 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 +262 -98
- 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.js +8 -2
- 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 +129 -0
- package/dist/server/api-handler.d.ts +1 -0
- package/dist/server/api-handler.js +2 -1
- 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-navigation-controller.js +1 -1
- package/dist/server/app-browser-server-action-client.js +1 -1
- package/dist/server/app-middleware.d.ts +11 -0
- package/dist/server/app-middleware.js +17 -2
- 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 +4 -3
- 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-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 +2 -3
- package/dist/server/app-prerender-endpoints.js +9 -6
- package/dist/server/app-request-stage-dispatch.js +6 -2
- package/dist/server/app-request-stage-independent-entry.js +25 -5
- package/dist/server/app-response-stage-entry.js +10 -2
- 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 +45 -24
- package/dist/server/app-router-entry.js +24 -5
- package/dist/server/app-rsc-cache-busting.js +1 -1
- 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 +85 -35
- package/dist/server/app-rsc-response-stage.js +4 -2
- 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 +61 -22
- package/dist/server/app-ssr-entry.js +2 -1
- 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/dev-server.js +38 -27
- 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 +93 -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 +9 -8
- package/dist/server/middleware-matcher.d.ts +2 -0
- package/dist/server/middleware-matcher.js +23 -2
- package/dist/server/middleware-runtime.d.ts +13 -0
- package/dist/server/middleware-runtime.js +33 -20
- 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/normalize-path.d.ts +0 -13
- package/dist/server/normalize-path.js +1 -34
- package/dist/server/pages-api-route.d.ts +3 -2
- package/dist/server/pages-api-route.js +4 -3
- 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 +19 -2
- 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 +50 -120
- package/dist/server/pages-page-handler.d.ts +0 -6
- package/dist/server/pages-page-handler.js +188 -126
- package/dist/server/pages-page-response.d.ts +12 -6
- package/dist/server/pages-page-response.js +41 -34
- package/dist/server/pages-request-pipeline.d.ts +10 -2
- package/dist/server/pages-request-pipeline.js +37 -18
- package/dist/server/pages-request-stage-entry.d.ts +6 -0
- package/dist/server/pages-request-stage-entry.js +71 -12
- package/dist/server/pages-response-stage-entry.js +4 -0
- package/dist/server/pages-revalidate.js +1 -1
- package/dist/server/pages-router-entry.js +4 -3
- 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 +199 -69
- 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.js +31 -2
- 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 +86 -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 +15 -13
- package/dist/shims/image.js +2 -1
- package/dist/shims/internal/work-store-scope.d.ts +5 -0
- package/dist/shims/internal/work-store-scope.js +24 -0
- package/dist/shims/navigation.js +31 -5
- package/dist/shims/request-context.d.ts +2 -0
- package/dist/shims/request-state-types.d.ts +2 -1
- package/dist/shims/router.js +12 -20
- package/dist/shims/server.d.ts +16 -0
- package/dist/shims/server.js +24 -4
- package/dist/shims/unified-request-context.d.ts +1 -1
- package/dist/shims/url-utils.d.ts +2 -0
- package/dist/shims/url-utils.js +3 -1
- package/dist/utils/client-runtime-metadata.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 +4 -0
- package/dist/utils/plugin-rsc-version.js +15 -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 +3 -0
- package/dist/utils/react-version.js +1 -1
- package/package.json +7 -3
|
@@ -4,17 +4,17 @@ import { normalizePathnameForRouteMatch } from "../routing/utils.js";
|
|
|
4
4
|
import { NEXTJS_CACHE_HEADER, NEXTJS_DEPLOYMENT_ID_HEADER } from "./headers.js";
|
|
5
5
|
import { isDangerousScheme } from "../shims/url-safety.js";
|
|
6
6
|
import { extractLocaleFromUrl } from "./pages-i18n.js";
|
|
7
|
+
import { buildNextDataPropsJsonResponse } from "./pages-data-route.js";
|
|
7
8
|
import { recordRouteCacheability } from "../shims/cacheability-classification.js";
|
|
8
9
|
import { applyCdnResponseHeaders } from "./cache-control.js";
|
|
9
10
|
import { buildMissIsrCacheControl, decideIsr } from "./isr-decision.js";
|
|
10
|
-
import {
|
|
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. */
|