vinext 0.1.1 → 0.1.3
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 +2 -5
- package/dist/build/client-build-config.d.ts +7 -1
- package/dist/build/client-build-config.js +9 -1
- package/dist/build/prerender.d.ts +9 -1
- package/dist/build/prerender.js +41 -12
- package/dist/build/run-prerender.d.ts +10 -2
- package/dist/build/run-prerender.js +15 -1
- package/dist/check.js +4 -3
- package/dist/client/app-nav-failure-handler.d.ts +8 -0
- package/dist/client/app-nav-failure-handler.js +44 -0
- package/dist/client/navigation-runtime.d.ts +3 -2
- package/dist/client/vinext-next-data.d.ts +18 -1
- package/dist/client/window-next.d.ts +8 -5
- 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 -4
- package/dist/config/config-matchers.js +88 -16
- package/dist/config/next-config.d.ts +59 -4
- package/dist/config/next-config.js +149 -48
- package/dist/deploy.d.ts +30 -11
- package/dist/deploy.js +189 -101
- 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 +71 -6
- 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 +54 -9
- package/dist/entries/pages-server-entry.js +48 -11
- package/dist/index.d.ts +0 -2
- package/dist/index.js +285 -139
- package/dist/plugins/dynamic-preload-metadata.d.ts +13 -0
- package/dist/plugins/dynamic-preload-metadata.js +415 -0
- package/dist/plugins/extensionless-dynamic-import.d.ts +6 -0
- package/dist/plugins/extensionless-dynamic-import.js +152 -0
- package/dist/plugins/og-assets.js +2 -2
- package/dist/plugins/optimize-imports.d.ts +10 -5
- package/dist/plugins/optimize-imports.js +27 -21
- package/dist/plugins/postcss.js +7 -7
- package/dist/plugins/sass.d.ts +53 -24
- package/dist/plugins/sass.js +249 -1
- package/dist/plugins/typeof-window.d.ts +14 -0
- package/dist/plugins/typeof-window.js +150 -0
- package/dist/plugins/wasm-module-import.d.ts +15 -0
- package/dist/plugins/wasm-module-import.js +50 -0
- package/dist/routing/app-route-graph.d.ts +25 -2
- package/dist/routing/app-route-graph.js +91 -22
- package/dist/routing/file-matcher.d.ts +10 -1
- package/dist/routing/file-matcher.js +23 -2
- 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 +19 -10
- package/dist/server/app-browser-entry.js +269 -297
- package/dist/server/app-browser-error.d.ts +10 -3
- package/dist/server/app-browser-error.js +47 -6
- package/dist/server/app-browser-history-controller.d.ts +104 -0
- package/dist/server/app-browser-history-controller.js +210 -0
- 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 +7 -4
- package/dist/server/app-browser-navigation-controller.js +33 -9
- package/dist/server/app-browser-rsc-redirect.d.ts +11 -2
- package/dist/server/app-browser-rsc-redirect.js +30 -8
- 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.js +4 -7
- package/dist/server/app-browser-stream.js +86 -43
- package/dist/server/app-browser-visible-commit.js +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 +3 -1
- package/dist/server/app-fallback-renderer.js +6 -2
- package/dist/server/app-middleware.js +1 -0
- package/dist/server/app-optimistic-routing.js +24 -3
- package/dist/server/app-page-boundary-render.d.ts +3 -1
- package/dist/server/app-page-boundary-render.js +31 -16
- 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 +71 -8
- package/dist/server/app-page-dispatch.d.ts +34 -0
- package/dist/server/app-page-dispatch.js +167 -97
- package/dist/server/app-page-element-builder.d.ts +23 -2
- package/dist/server/app-page-element-builder.js +42 -10
- package/dist/server/app-page-execution.d.ts +7 -2
- package/dist/server/app-page-execution.js +53 -18
- 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 +13 -2
- package/dist/server/app-page-render.js +48 -17
- package/dist/server/app-page-request.d.ts +3 -0
- package/dist/server/app-page-request.js +5 -3
- package/dist/server/app-page-response.js +1 -1
- package/dist/server/app-page-route-wiring.d.ts +5 -1
- package/dist/server/app-page-route-wiring.js +21 -11
- package/dist/server/app-page-stream.d.ts +16 -9
- package/dist/server/app-page-stream.js +12 -9
- package/dist/server/app-pages-bridge.d.ts +18 -0
- package/dist/server/app-pages-bridge.js +22 -5
- 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-route-handler-response.js +11 -10
- package/dist/server/app-route-handler-runtime.js +12 -1
- 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 +25 -0
- package/dist/server/app-rsc-handler.js +153 -53
- package/dist/server/app-rsc-response-finalizer.js +1 -1
- package/dist/server/app-rsc-route-matching.d.ts +3 -0
- package/dist/server/app-rsc-route-matching.js +2 -0
- 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 +12 -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 +81 -8
- package/dist/server/app-ssr-stream.js +9 -1
- package/dist/server/cache-control.js +4 -0
- package/dist/server/dev-lockfile.js +2 -1
- package/dist/server/dev-server.d.ts +2 -2
- package/dist/server/dev-server.js +287 -63
- package/dist/server/headers.d.ts +8 -1
- package/dist/server/headers.js +8 -1
- 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/instrumentation-runtime.d.ts +6 -0
- package/dist/server/instrumentation-runtime.js +8 -0
- package/dist/server/isr-decision.d.ts +79 -0
- package/dist/server/isr-decision.js +70 -0
- package/dist/server/metadata-route-response.js +5 -3
- package/dist/server/middleware-runtime.d.ts +13 -0
- package/dist/server/middleware-runtime.js +11 -7
- package/dist/server/middleware.js +1 -0
- package/dist/server/navigation-planner.d.ts +186 -22
- package/dist/server/navigation-planner.js +302 -0
- package/dist/server/navigation-trace.d.ts +18 -1
- package/dist/server/navigation-trace.js +18 -1
- package/dist/server/normalize-path.d.ts +0 -8
- package/dist/server/normalize-path.js +3 -1
- package/dist/server/otel-tracer-extension.d.ts +45 -0
- package/dist/server/otel-tracer-extension.js +89 -0
- package/dist/server/pages-api-route.d.ts +20 -3
- package/dist/server/pages-api-route.js +19 -3
- package/dist/server/pages-asset-tags.d.ts +16 -4
- package/dist/server/pages-asset-tags.js +22 -12
- package/dist/server/pages-data-route.d.ts +8 -1
- package/dist/server/pages-data-route.js +16 -3
- 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-node-compat.d.ts +3 -11
- package/dist/server/pages-node-compat.js +175 -122
- package/dist/server/pages-page-data.d.ts +39 -2
- package/dist/server/pages-page-data.js +261 -46
- package/dist/server/pages-page-handler.d.ts +5 -2
- package/dist/server/pages-page-handler.js +78 -25
- package/dist/server/pages-page-response.d.ts +47 -2
- package/dist/server/pages-page-response.js +73 -9
- package/dist/server/pages-readiness.d.ts +1 -1
- package/dist/server/pages-request-pipeline.d.ts +16 -1
- package/dist/server/pages-request-pipeline.js +96 -38
- 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 +39 -1
- package/dist/server/prod-server.js +107 -37
- 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/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/cache-runtime.js +12 -4
- 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/dynamic-preload-chunks.d.ts +8 -0
- package/dist/shims/dynamic-preload-chunks.js +79 -0
- package/dist/shims/dynamic.d.ts +4 -0
- package/dist/shims/dynamic.js +4 -2
- package/dist/shims/error-boundary.d.ts +6 -4
- package/dist/shims/error-boundary.js +7 -0
- package/dist/shims/error.js +38 -11
- 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 +11 -1
- package/dist/shims/fetch-cache.js +55 -20
- package/dist/shims/hash-scroll.js +6 -1
- package/dist/shims/head.js +6 -1
- package/dist/shims/headers.d.ts +16 -2
- package/dist/shims/headers.js +66 -5
- package/dist/shims/image-config.js +7 -1
- package/dist/shims/internal/als-registry.js +28 -1
- package/dist/shims/internal/app-route-detection.d.ts +6 -3
- package/dist/shims/internal/app-route-detection.js +18 -23
- package/dist/shims/internal/app-router-context.d.ts +5 -0
- 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-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 +12 -5
- package/dist/shims/metadata.d.ts +6 -2
- package/dist/shims/metadata.js +32 -14
- package/dist/shims/navigation.d.ts +14 -17
- package/dist/shims/navigation.js +93 -46
- 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 +13 -2
- package/dist/shims/router.js +434 -116
- package/dist/shims/script-nonce-context.d.ts +1 -1
- package/dist/shims/script-nonce-context.js +11 -3
- package/dist/shims/server.d.ts +33 -2
- package/dist/shims/server.js +75 -18
- package/dist/shims/slot.js +1 -1
- package/dist/shims/unified-request-context.js +2 -0
- package/dist/typegen.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/client-build-manifest.js +15 -5
- package/dist/utils/client-runtime-metadata.d.ts +45 -0
- package/dist/utils/client-runtime-metadata.js +63 -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/hash.d.ts +17 -1
- package/dist/utils/hash.js +36 -1
- package/dist/utils/html-limited-bots.d.ts +18 -1
- package/dist/utils/html-limited-bots.js +23 -1
- package/dist/utils/lazy-chunks.d.ts +27 -1
- package/dist/utils/lazy-chunks.js +65 -1
- package/dist/utils/manifest-paths.d.ts +20 -2
- package/dist/utils/manifest-paths.js +38 -3
- package/dist/utils/parse-cookie.d.ts +13 -0
- package/dist/utils/parse-cookie.js +52 -0
- package/dist/utils/path.d.ts +8 -1
- package/dist/utils/path.js +13 -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
|
@@ -2,10 +2,14 @@ import { createRequestContext, runWithRequestContext } from "../shims/unified-re
|
|
|
2
2
|
import { createValidFileMatcher, findFileWithExtensions } from "../routing/file-matcher.js";
|
|
3
3
|
import { patternToNextFormat } from "../routing/route-validation.js";
|
|
4
4
|
import { matchRoute } from "../routing/pages-router.js";
|
|
5
|
+
import { NEXTJS_DEPLOYMENT_ID_HEADER } from "./headers.js";
|
|
5
6
|
import { normalizeStaticPathname } from "../routing/route-pattern.js";
|
|
6
7
|
import { importModule, reportRequestError } from "./instrumentation.js";
|
|
7
8
|
import { buildCacheStateHeaders } from "./cache-headers.js";
|
|
9
|
+
import { isUnknownRecord } from "../utils/record.js";
|
|
8
10
|
import { _runWithCacheState } from "../shims/cache.js";
|
|
11
|
+
import { NEVER_CACHE_CONTROL, NO_STORE_CACHE_CONTROL } from "./cache-control.js";
|
|
12
|
+
import { buildMissIsrCacheControl, decideIsr } from "./isr-decision.js";
|
|
9
13
|
import { PRERENDER_REVALIDATE_HEADER, buildPagesCacheValue, getRevalidateDuration, isOnDemandRevalidateRequest, isrCacheKey, isrGet, isrSet, setRevalidateDuration, triggerBackgroundRegeneration } from "./isr-cache.js";
|
|
10
14
|
import { ensureFetchPatch, runWithFetchCache } from "../shims/fetch-cache.js";
|
|
11
15
|
import { runWithPrivateCache } from "../shims/cache-runtime.js";
|
|
@@ -25,7 +29,8 @@ import { resolvePagesPageMethodResponse } from "./pages-page-method.js";
|
|
|
25
29
|
import { isSerializableProps } from "./pages-serializable-props.js";
|
|
26
30
|
import { loadUserDocumentInitialProps, runDocumentRenderPage } from "./pages-document-initial-props.js";
|
|
27
31
|
import { callDocumentGetInitialProps } from "./document-initial-head.js";
|
|
28
|
-
import { loadPagesGetInitialProps } from "./pages-get-initial-props.js";
|
|
32
|
+
import { hasPagesGetInitialProps, loadDevAppInitialProps, loadPagesGetInitialProps } from "./pages-get-initial-props.js";
|
|
33
|
+
import { isBotUserAgent } from "../utils/html-limited-bots.js";
|
|
29
34
|
import path from "node:path";
|
|
30
35
|
import React from "react";
|
|
31
36
|
import { renderToReadableStream } from "react-dom/server.edge";
|
|
@@ -57,16 +62,23 @@ async function renderIsrPassToStringAsync(element) {
|
|
|
57
62
|
* (`buildPagesRedirectResponse`) and Next.js's `render.tsx` `__N_REDIRECT`
|
|
58
63
|
* handling. See AGENTS.md "dev and prod server parity".
|
|
59
64
|
*/
|
|
60
|
-
function writeGsspRedirect(res, redirect, isDataReq) {
|
|
65
|
+
function writeGsspRedirect(res, redirect, isDataReq, props) {
|
|
61
66
|
const status = redirect.statusCode ?? (redirect.permanent ? 308 : 307);
|
|
62
67
|
let dest = redirect.destination;
|
|
63
68
|
if (!dest.startsWith("http://") && !dest.startsWith("https://")) dest = dest.replace(/^[\\/]+/, "/");
|
|
64
69
|
if (isDataReq) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
+
const deploymentId = process.env.__VINEXT_DEPLOYMENT_ID || process.env.NEXT_DEPLOYMENT_ID;
|
|
71
|
+
const dataHeaders = { "Content-Type": "application/json" };
|
|
72
|
+
if (deploymentId) dataHeaders[NEXTJS_DEPLOYMENT_ID_HEADER] = deploymentId;
|
|
73
|
+
res.writeHead(200, dataHeaders);
|
|
74
|
+
res.end(JSON.stringify({
|
|
75
|
+
...props,
|
|
76
|
+
pageProps: {
|
|
77
|
+
...isUnknownRecord(props.pageProps) ? props.pageProps : {},
|
|
78
|
+
__N_REDIRECT: dest,
|
|
79
|
+
__N_REDIRECT_STATUS: status
|
|
80
|
+
}
|
|
81
|
+
}));
|
|
70
82
|
return;
|
|
71
83
|
}
|
|
72
84
|
res.writeHead(status, { Location: dest });
|
|
@@ -184,12 +196,12 @@ function parseCookieLocale(req, i18nConfig) {
|
|
|
184
196
|
* 4. Render the component to HTML
|
|
185
197
|
* 5. Wrap in _document shell and send response
|
|
186
198
|
*/
|
|
187
|
-
function createSSRHandler(server, runner, routes, pagesDir, i18nConfig, fileMatcher, basePath = "", trailingSlash = false, hasMiddleware = false, hasRewrites = false, clientTraceMetadata) {
|
|
199
|
+
function createSSRHandler(server, runner, routes, pagesDir, i18nConfig, fileMatcher, basePath = "", trailingSlash = false, hasMiddleware = false, hasRewrites = false, clientTraceMetadata, htmlLimitedBots) {
|
|
188
200
|
const matcher = fileMatcher ?? createValidFileMatcher();
|
|
189
201
|
const pagePatterns = routes.map((r) => patternToNextFormat(r.pattern));
|
|
190
202
|
const _alsRegistration = Promise.all([runner.import("vinext/head-state"), runner.import("vinext/router-state")]);
|
|
191
203
|
_alsRegistration.catch(() => {});
|
|
192
|
-
return async (req, res, url, statusCode, isDataReq = false) => {
|
|
204
|
+
return async (req, res, url, statusCode, isDataReq = false, originalUrl = url) => {
|
|
193
205
|
const _reqStart = now();
|
|
194
206
|
let _compileEnd;
|
|
195
207
|
let _renderEnd;
|
|
@@ -228,7 +240,10 @@ function createSSRHandler(server, runner, routes, pagesDir, i18nConfig, fileMatc
|
|
|
228
240
|
const match = matchRoute(localeStrippedUrl, routes);
|
|
229
241
|
if (!match) {
|
|
230
242
|
if (isDataReq) {
|
|
231
|
-
|
|
243
|
+
const deploymentId = process.env.__VINEXT_DEPLOYMENT_ID || process.env.NEXT_DEPLOYMENT_ID;
|
|
244
|
+
const notFoundHeaders = { "Content-Type": "application/json" };
|
|
245
|
+
if (deploymentId) notFoundHeaders[NEXTJS_DEPLOYMENT_ID_HEADER] = deploymentId;
|
|
246
|
+
res.writeHead(404, notFoundHeaders);
|
|
232
247
|
res.end("{}");
|
|
233
248
|
return;
|
|
234
249
|
}
|
|
@@ -236,6 +251,11 @@ function createSSRHandler(server, runner, routes, pagesDir, i18nConfig, fileMatc
|
|
|
236
251
|
return;
|
|
237
252
|
}
|
|
238
253
|
const { route, params } = match;
|
|
254
|
+
req.url = originalUrl;
|
|
255
|
+
const parsedResolvedUrl = new URL(localeStrippedUrl, "http://vinext.local");
|
|
256
|
+
const originalRequestSearch = new URL(originalUrl, "http://vinext.local").search;
|
|
257
|
+
const gsspResolvedUrl = parsedResolvedUrl.pathname + originalRequestSearch;
|
|
258
|
+
const requestAsPath = isDataReq ? gsspResolvedUrl : originalUrl;
|
|
239
259
|
const userFacingParams = route.isDynamic ? params : null;
|
|
240
260
|
const query = mergeRouteParamsIntoQuery(parseQueryString(url), params);
|
|
241
261
|
return runWithRequestContext(createRequestContext(), async () => {
|
|
@@ -269,7 +289,7 @@ function createSSRHandler(server, runner, routes, pagesDir, i18nConfig, fileMatc
|
|
|
269
289
|
if (typeof routerShim.setSSRContext === "function") routerShim.setSSRContext({
|
|
270
290
|
pathname: patternToNextFormat(route.pattern),
|
|
271
291
|
query,
|
|
272
|
-
asPath:
|
|
292
|
+
asPath: requestAsPath,
|
|
273
293
|
navigationIsReady,
|
|
274
294
|
nextData: pagesNextData,
|
|
275
295
|
locale: locale ?? currentDefaultLocale,
|
|
@@ -303,8 +323,10 @@ function createSSRHandler(server, runner, routes, pagesDir, i18nConfig, fileMatc
|
|
|
303
323
|
}
|
|
304
324
|
}
|
|
305
325
|
let pageProps = {};
|
|
326
|
+
let renderProps = { pageProps };
|
|
306
327
|
let isrRevalidateSeconds = null;
|
|
307
328
|
let isFallbackRender = false;
|
|
329
|
+
let shouldPersistFallbackData = false;
|
|
308
330
|
if (typeof pageModule.getStaticPaths === "function" && route.isDynamic) {
|
|
309
331
|
const pathsResult = await pageModule.getStaticPaths({
|
|
310
332
|
locales: i18nConfig?.locales ?? [],
|
|
@@ -325,19 +347,25 @@ function createSSRHandler(server, runner, routes, pagesDir, i18nConfig, fileMatc
|
|
|
325
347
|
});
|
|
326
348
|
if (fallback === false && !isValidPath) {
|
|
327
349
|
if (isDataReq) {
|
|
328
|
-
|
|
350
|
+
const deploymentId = process.env.__VINEXT_DEPLOYMENT_ID || process.env.NEXT_DEPLOYMENT_ID;
|
|
351
|
+
const notFoundHeaders = { "Content-Type": "application/json" };
|
|
352
|
+
if (deploymentId) notFoundHeaders[NEXTJS_DEPLOYMENT_ID_HEADER] = deploymentId;
|
|
353
|
+
res.writeHead(404, notFoundHeaders);
|
|
329
354
|
res.end("{}");
|
|
330
355
|
return;
|
|
331
356
|
}
|
|
332
357
|
await renderErrorPage(server, runner, req, res, url, pagesDir, 404, routerShim.wrapWithRouterContext, matcher);
|
|
333
358
|
return;
|
|
334
359
|
}
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
360
|
+
const userAgentHeader = req.headers["user-agent"];
|
|
361
|
+
const userAgent = Array.isArray(userAgentHeader) ? userAgentHeader[0] : userAgentHeader;
|
|
362
|
+
const isBotRequest = !!userAgent && isBotUserAgent(userAgent, htmlLimitedBots);
|
|
363
|
+
if (fallback === true && !isValidPath && !isDataReq && !isBotRequest) {
|
|
364
|
+
isFallbackRender = (await isrGet(pagesIsrCacheKey(url.split("?")[0])))?.value.value?.kind !== "PAGES";
|
|
365
|
+
if (isFallbackRender && typeof routerShim.setSSRContext === "function") routerShim.setSSRContext({
|
|
338
366
|
pathname: patternToNextFormat(route.pattern),
|
|
339
367
|
query,
|
|
340
|
-
asPath:
|
|
368
|
+
asPath: requestAsPath,
|
|
341
369
|
navigationIsReady: false,
|
|
342
370
|
locale: locale ?? currentDefaultLocale,
|
|
343
371
|
locales: i18nConfig?.locales,
|
|
@@ -346,30 +374,79 @@ function createSSRHandler(server, runner, routes, pagesDir, i18nConfig, fileMatc
|
|
|
346
374
|
isFallback: true
|
|
347
375
|
});
|
|
348
376
|
}
|
|
377
|
+
shouldPersistFallbackData = fallback === true && !isValidPath && isDataReq;
|
|
349
378
|
}
|
|
350
379
|
const gsspExtraHeaders = {};
|
|
380
|
+
const hasAppGetInitialProps = hasPagesGetInitialProps(AppComponent);
|
|
381
|
+
async function loadAppInitialProps() {
|
|
382
|
+
if (!hasAppGetInitialProps) return false;
|
|
383
|
+
const appResult = await loadDevAppInitialProps({
|
|
384
|
+
appComponent: AppComponent,
|
|
385
|
+
appTree: (appTreeProps) => {
|
|
386
|
+
const appTree = React.createElement(AppComponent, {
|
|
387
|
+
...appTreeProps,
|
|
388
|
+
Component: PageComponent,
|
|
389
|
+
pageProps: appTreeProps.pageProps,
|
|
390
|
+
router: routerShim.default
|
|
391
|
+
});
|
|
392
|
+
return typeof routerShim.wrapWithRouterContext === "function" ? routerShim.wrapWithRouterContext(appTree) : appTree;
|
|
393
|
+
},
|
|
394
|
+
component: PageComponent,
|
|
395
|
+
req,
|
|
396
|
+
res,
|
|
397
|
+
pathname: patternToNextFormat(route.pattern),
|
|
398
|
+
query,
|
|
399
|
+
asPath: requestAsPath,
|
|
400
|
+
locale: locale ?? currentDefaultLocale,
|
|
401
|
+
locales: i18nConfig?.locales,
|
|
402
|
+
defaultLocale: currentDefaultLocale
|
|
403
|
+
});
|
|
404
|
+
if (appResult.kind === "response-sent") return true;
|
|
405
|
+
if (appResult.kind === "render") {
|
|
406
|
+
pageProps = appResult.pageProps;
|
|
407
|
+
renderProps = appResult.renderProps;
|
|
408
|
+
}
|
|
409
|
+
return false;
|
|
410
|
+
}
|
|
351
411
|
if (typeof pageModule.getServerSideProps === "function" && !isFallbackRender) {
|
|
412
|
+
if (await loadAppInitialProps()) return;
|
|
413
|
+
renderProps = {
|
|
414
|
+
...renderProps,
|
|
415
|
+
__N_SSP: true
|
|
416
|
+
};
|
|
352
417
|
const headersBeforeGSSP = new Set(Object.keys(res.getHeaders()));
|
|
353
418
|
const context = {
|
|
354
419
|
params: userFacingParams,
|
|
355
420
|
req,
|
|
356
421
|
res,
|
|
357
422
|
query,
|
|
358
|
-
resolvedUrl:
|
|
423
|
+
resolvedUrl: gsspResolvedUrl,
|
|
359
424
|
locale: locale ?? currentDefaultLocale,
|
|
360
425
|
locales: i18nConfig?.locales,
|
|
361
426
|
defaultLocale: currentDefaultLocale
|
|
362
427
|
};
|
|
363
428
|
const result = await pageModule.getServerSideProps(context);
|
|
364
429
|
if (res.writableEnded) return;
|
|
365
|
-
if (result && "props" in result)
|
|
430
|
+
if (result && "props" in result) {
|
|
431
|
+
pageProps = {
|
|
432
|
+
...pageProps,
|
|
433
|
+
...await Promise.resolve(result.props)
|
|
434
|
+
};
|
|
435
|
+
renderProps = {
|
|
436
|
+
...renderProps,
|
|
437
|
+
pageProps
|
|
438
|
+
};
|
|
439
|
+
}
|
|
366
440
|
if (result && "redirect" in result) {
|
|
367
|
-
writeGsspRedirect(res, result.redirect, isDataReq);
|
|
441
|
+
writeGsspRedirect(res, result.redirect, isDataReq, renderProps);
|
|
368
442
|
return;
|
|
369
443
|
}
|
|
370
444
|
if (result && "notFound" in result && result.notFound) {
|
|
371
445
|
if (isDataReq) {
|
|
372
|
-
|
|
446
|
+
const deploymentId = process.env.__VINEXT_DEPLOYMENT_ID || process.env.NEXT_DEPLOYMENT_ID;
|
|
447
|
+
const notFoundHeaders = { "Content-Type": "application/json" };
|
|
448
|
+
if (deploymentId) notFoundHeaders[NEXTJS_DEPLOYMENT_ID_HEADER] = deploymentId;
|
|
449
|
+
res.writeHead(404, notFoundHeaders);
|
|
373
450
|
res.end("{}");
|
|
374
451
|
return;
|
|
375
452
|
}
|
|
@@ -385,7 +462,7 @@ function createSSRHandler(server, runner, routes, pagesDir, i18nConfig, fileMatc
|
|
|
385
462
|
if (Array.isArray(val)) gsspExtraHeaders[key] = val.map(String);
|
|
386
463
|
else gsspExtraHeaders[key] = String(val);
|
|
387
464
|
}
|
|
388
|
-
if (!Object.keys(gsspExtraHeaders).some((k) => k.toLowerCase() === "cache-control")) gsspExtraHeaders["Cache-Control"] =
|
|
465
|
+
if (!Object.keys(gsspExtraHeaders).some((k) => k.toLowerCase() === "cache-control")) gsspExtraHeaders["Cache-Control"] = NEVER_CACHE_CONTROL;
|
|
389
466
|
}
|
|
390
467
|
const responseHeaders = typeof res.getHeaders === "function" ? res.getHeaders() : void 0;
|
|
391
468
|
const scriptNonce = getScriptNonceFromNodeHeaderSources(req.headers, responseHeaders);
|
|
@@ -402,26 +479,102 @@ function createSSRHandler(server, runner, routes, pagesDir, i18nConfig, fileMatc
|
|
|
402
479
|
const cacheKey = pagesIsrCacheKey(url.split("?")[0]);
|
|
403
480
|
const cached = await isrGet(cacheKey);
|
|
404
481
|
const isOnDemandRevalidate = isOnDemandRevalidateRequest(req.headers[PRERENDER_REVALIDATE_HEADER]);
|
|
405
|
-
if (!isOnDemandRevalidate && cached && !cached.isStale && cached.value.value?.kind === "PAGES" && !scriptNonce && !isDataReq) {
|
|
482
|
+
if (!isOnDemandRevalidate && cached && !cached.isStale && cached.value.value?.kind === "PAGES" && !cached.value.value.generatedFromDataRequest && !scriptNonce && !isDataReq) {
|
|
406
483
|
const cachedHtml = cached.value.value.html;
|
|
407
484
|
const transformedHtml = await server.transformIndexHtml(url, cachedHtml);
|
|
408
|
-
const
|
|
485
|
+
const { cacheControl: hitCacheControl } = decideIsr({
|
|
486
|
+
cacheState: "HIT",
|
|
487
|
+
kind: "dev",
|
|
488
|
+
revalidateSeconds: getRevalidateDuration(cacheKey) ?? 60
|
|
489
|
+
});
|
|
409
490
|
const hitHeaders = {
|
|
410
491
|
"Content-Type": "text/html",
|
|
411
492
|
...buildCacheStateHeaders("HIT"),
|
|
412
|
-
"Cache-Control":
|
|
493
|
+
"Cache-Control": hitCacheControl
|
|
413
494
|
};
|
|
414
495
|
if (earlyFontLinkHeader) hitHeaders["Link"] = earlyFontLinkHeader;
|
|
415
496
|
res.writeHead(200, hitHeaders);
|
|
416
497
|
res.end(transformedHtml);
|
|
417
498
|
return;
|
|
418
499
|
}
|
|
419
|
-
if (!isOnDemandRevalidate && cached && cached.isStale && cached.value.value?.kind === "PAGES" && !scriptNonce && !isDataReq) {
|
|
500
|
+
if (!isOnDemandRevalidate && cached && cached.isStale && cached.value.value?.kind === "PAGES" && !cached.value.value.generatedFromDataRequest && !scriptNonce && !isDataReq) {
|
|
420
501
|
const cachedHtml = cached.value.value.html;
|
|
421
502
|
const transformedHtml = await server.transformIndexHtml(url, cachedHtml);
|
|
422
503
|
triggerBackgroundRegeneration(cacheKey, async () => {
|
|
423
|
-
return runWithRequestContext(createRequestContext({
|
|
504
|
+
return runWithRequestContext(createRequestContext({
|
|
505
|
+
executionContext: null,
|
|
506
|
+
ssrContext: {
|
|
507
|
+
pathname: patternToNextFormat(route.pattern),
|
|
508
|
+
query,
|
|
509
|
+
asPath: requestAsPath,
|
|
510
|
+
navigationIsReady,
|
|
511
|
+
locale: locale ?? currentDefaultLocale,
|
|
512
|
+
locales: i18nConfig?.locales,
|
|
513
|
+
defaultLocale: currentDefaultLocale
|
|
514
|
+
},
|
|
515
|
+
i18nContext: i18nConfig ? {
|
|
516
|
+
locale: locale ?? currentDefaultLocale,
|
|
517
|
+
locales: i18nConfig.locales,
|
|
518
|
+
defaultLocale: currentDefaultLocale,
|
|
519
|
+
domainLocales,
|
|
520
|
+
hostname: req.headers.host?.split(":", 1)[0]
|
|
521
|
+
} : null
|
|
522
|
+
}), async () => {
|
|
424
523
|
ensureFetchPatch();
|
|
524
|
+
let freshPageProps = {};
|
|
525
|
+
let freshRenderProps = { pageProps: freshPageProps };
|
|
526
|
+
let RegenApp = null;
|
|
527
|
+
const appPath = path.join(pagesDir, "_app");
|
|
528
|
+
if (findFileWithExtensions(appPath, matcher)) try {
|
|
529
|
+
RegenApp = (await runner.import(appPath)).default ?? null;
|
|
530
|
+
} catch {}
|
|
531
|
+
if (RegenApp && hasPagesGetInitialProps(RegenApp)) {
|
|
532
|
+
const regenReq = {
|
|
533
|
+
url: req.url,
|
|
534
|
+
headers: req.headers,
|
|
535
|
+
method: req.method
|
|
536
|
+
};
|
|
537
|
+
const regenRes = {
|
|
538
|
+
headersSent: false,
|
|
539
|
+
writableEnded: false,
|
|
540
|
+
statusCode: 200,
|
|
541
|
+
getHeaders() {
|
|
542
|
+
return {};
|
|
543
|
+
}
|
|
544
|
+
};
|
|
545
|
+
const initialProps = await loadPagesGetInitialProps(RegenApp, {
|
|
546
|
+
AppTree: (appTreeProps) => {
|
|
547
|
+
const appTree = React.createElement(RegenApp, {
|
|
548
|
+
...appTreeProps,
|
|
549
|
+
Component: pageModule.default,
|
|
550
|
+
pageProps: appTreeProps.pageProps,
|
|
551
|
+
router: routerShim.default
|
|
552
|
+
});
|
|
553
|
+
return typeof routerShim.wrapWithRouterContext === "function" ? routerShim.wrapWithRouterContext(appTree) : appTree;
|
|
554
|
+
},
|
|
555
|
+
Component: pageModule.default,
|
|
556
|
+
router: {
|
|
557
|
+
pathname: patternToNextFormat(route.pattern),
|
|
558
|
+
query,
|
|
559
|
+
asPath: requestAsPath
|
|
560
|
+
},
|
|
561
|
+
ctx: {
|
|
562
|
+
req: regenReq,
|
|
563
|
+
res: regenRes,
|
|
564
|
+
pathname: patternToNextFormat(route.pattern),
|
|
565
|
+
query,
|
|
566
|
+
asPath: requestAsPath,
|
|
567
|
+
locale: locale ?? currentDefaultLocale,
|
|
568
|
+
locales: i18nConfig?.locales,
|
|
569
|
+
defaultLocale: currentDefaultLocale
|
|
570
|
+
}
|
|
571
|
+
});
|
|
572
|
+
if (regenRes.headersSent || regenRes.writableEnded) return;
|
|
573
|
+
if (initialProps) {
|
|
574
|
+
freshRenderProps = initialProps;
|
|
575
|
+
freshPageProps = isUnknownRecord(initialProps.pageProps) ? initialProps.pageProps : {};
|
|
576
|
+
}
|
|
577
|
+
}
|
|
425
578
|
const freshResult = await pageModule.getStaticProps({
|
|
426
579
|
params: userFacingParams,
|
|
427
580
|
locale: locale ?? currentDefaultLocale,
|
|
@@ -430,13 +583,20 @@ function createSSRHandler(server, runner, routes, pagesDir, i18nConfig, fileMatc
|
|
|
430
583
|
revalidateReason: "stale"
|
|
431
584
|
});
|
|
432
585
|
if (freshResult && "props" in freshResult) {
|
|
433
|
-
const revalidate = typeof freshResult.revalidate === "number" ? freshResult.revalidate : 0;
|
|
586
|
+
const revalidate = typeof freshResult.revalidate === "number" ? freshResult.revalidate : cached.value.cacheControl?.revalidate ?? 0;
|
|
434
587
|
if (revalidate > 0) {
|
|
435
|
-
|
|
588
|
+
freshPageProps = {
|
|
589
|
+
...freshPageProps,
|
|
590
|
+
...freshResult.props
|
|
591
|
+
};
|
|
592
|
+
freshRenderProps = {
|
|
593
|
+
...freshRenderProps,
|
|
594
|
+
pageProps: freshPageProps
|
|
595
|
+
};
|
|
436
596
|
if (typeof routerShim.setSSRContext === "function") routerShim.setSSRContext({
|
|
437
597
|
pathname: patternToNextFormat(route.pattern),
|
|
438
598
|
query,
|
|
439
|
-
asPath:
|
|
599
|
+
asPath: requestAsPath,
|
|
440
600
|
navigationIsReady,
|
|
441
601
|
locale: locale ?? currentDefaultLocale,
|
|
442
602
|
locales: i18nConfig?.locales,
|
|
@@ -454,15 +614,12 @@ function createSSRHandler(server, runner, routes, pagesDir, i18nConfig, fileMatc
|
|
|
454
614
|
hostname: req.headers.host?.split(":", 1)[0]
|
|
455
615
|
});
|
|
456
616
|
}
|
|
457
|
-
let RegenApp = null;
|
|
458
|
-
const appPath = path.join(pagesDir, "_app");
|
|
459
|
-
if (findFileWithExtensions(appPath, matcher)) try {
|
|
460
|
-
RegenApp = (await runner.import(appPath)).default ?? null;
|
|
461
|
-
} catch {}
|
|
462
617
|
let el = RegenApp ? React.createElement(RegenApp, {
|
|
618
|
+
...freshRenderProps,
|
|
463
619
|
Component: pageModule.default,
|
|
464
|
-
pageProps:
|
|
465
|
-
|
|
620
|
+
pageProps: freshRenderProps.pageProps,
|
|
621
|
+
router: routerShim.default
|
|
622
|
+
}) : React.createElement(pageModule.default, freshPageProps);
|
|
466
623
|
if (routerShim.wrapWithRouterContext) el = routerShim.wrapWithRouterContext(el);
|
|
467
624
|
const freshBody = await renderIsrPassToStringAsync(withScriptNonce(el, scriptNonce));
|
|
468
625
|
const viteRoot = server.config?.root;
|
|
@@ -478,7 +635,7 @@ function createSSRHandler(server, runner, routes, pagesDir, i18nConfig, fileMatc
|
|
|
478
635
|
}
|
|
479
636
|
};
|
|
480
637
|
await isrSet(cacheKey, buildPagesCacheValue(`<!DOCTYPE html><html><head></head><body><div id="__next">${freshBody}</div>${`<script>window.__NEXT_DATA__ = ${safeJsonStringify({
|
|
481
|
-
props:
|
|
638
|
+
props: freshRenderProps,
|
|
482
639
|
page: patternToNextFormat(route.pattern),
|
|
483
640
|
query: params,
|
|
484
641
|
buildId: process.env.__VINEXT_BUILD_ID,
|
|
@@ -488,7 +645,7 @@ function createSSRHandler(server, runner, routes, pagesDir, i18nConfig, fileMatc
|
|
|
488
645
|
defaultLocale: currentDefaultLocale,
|
|
489
646
|
domainLocales,
|
|
490
647
|
...freshPagesNextData
|
|
491
|
-
})}${i18nConfig ? `;window.__VINEXT_LOCALE__=${safeJsonStringify(locale ?? currentDefaultLocale)};window.__VINEXT_LOCALES__=${safeJsonStringify(i18nConfig.locales)};window.__VINEXT_DEFAULT_LOCALE__=${safeJsonStringify(currentDefaultLocale)}` : ""}<\/script>`}\n ${cachedHtml.match(/<script type="module">[\s\S]*?<\/script>/)?.[0] ?? ""}</body></html>`,
|
|
648
|
+
})}${i18nConfig ? `;window.__VINEXT_LOCALE__=${safeJsonStringify(locale ?? currentDefaultLocale)};window.__VINEXT_LOCALES__=${safeJsonStringify(i18nConfig.locales)};window.__VINEXT_DEFAULT_LOCALE__=${safeJsonStringify(currentDefaultLocale)}` : ""}<\/script>`}\n ${cachedHtml.match(/<script type="module">[\s\S]*?<\/script>/)?.[0] ?? ""}</body></html>`, freshRenderProps), revalidate);
|
|
492
649
|
setRevalidateDuration(cacheKey, revalidate);
|
|
493
650
|
}
|
|
494
651
|
}
|
|
@@ -498,11 +655,15 @@ function createSSRHandler(server, runner, routes, pagesDir, i18nConfig, fileMatc
|
|
|
498
655
|
routePath: route.pattern,
|
|
499
656
|
routeType: "render"
|
|
500
657
|
});
|
|
501
|
-
const
|
|
658
|
+
const { cacheControl: staleCacheControl } = decideIsr({
|
|
659
|
+
cacheState: "STALE",
|
|
660
|
+
kind: "dev",
|
|
661
|
+
revalidateSeconds: getRevalidateDuration(cacheKey) ?? 60
|
|
662
|
+
});
|
|
502
663
|
const staleHeaders = {
|
|
503
664
|
"Content-Type": "text/html",
|
|
504
665
|
...buildCacheStateHeaders("STALE"),
|
|
505
|
-
"Cache-Control":
|
|
666
|
+
"Cache-Control": staleCacheControl
|
|
506
667
|
};
|
|
507
668
|
if (earlyFontLinkHeader) staleHeaders["Link"] = earlyFontLinkHeader;
|
|
508
669
|
res.writeHead(200, staleHeaders);
|
|
@@ -516,15 +677,33 @@ function createSSRHandler(server, runner, routes, pagesDir, i18nConfig, fileMatc
|
|
|
516
677
|
defaultLocale: currentDefaultLocale,
|
|
517
678
|
revalidateReason: isOnDemandRevalidate ? "on-demand" : "stale"
|
|
518
679
|
};
|
|
519
|
-
const
|
|
520
|
-
if (
|
|
680
|
+
const generatedPageData = !isOnDemandRevalidate && cached?.isStale === false && cached?.value.value?.kind === "PAGES" && cached.value.value.generatedFromDataRequest && isUnknownRecord(cached.value.value.pageData) ? cached.value.value.pageData : null;
|
|
681
|
+
if (!generatedPageData && await loadAppInitialProps()) return;
|
|
682
|
+
const result = generatedPageData ? null : await pageModule.getStaticProps(context);
|
|
683
|
+
if (generatedPageData) {
|
|
684
|
+
renderProps = generatedPageData;
|
|
685
|
+
pageProps = isUnknownRecord(renderProps.pageProps) ? renderProps.pageProps : {};
|
|
686
|
+
}
|
|
687
|
+
if (result && "props" in result) {
|
|
688
|
+
pageProps = {
|
|
689
|
+
...pageProps,
|
|
690
|
+
...await Promise.resolve(result.props)
|
|
691
|
+
};
|
|
692
|
+
renderProps = {
|
|
693
|
+
...renderProps,
|
|
694
|
+
pageProps
|
|
695
|
+
};
|
|
696
|
+
}
|
|
521
697
|
if (result && "redirect" in result) {
|
|
522
|
-
writeGsspRedirect(res, result.redirect, isDataReq);
|
|
698
|
+
writeGsspRedirect(res, result.redirect, isDataReq, renderProps);
|
|
523
699
|
return;
|
|
524
700
|
}
|
|
525
701
|
if (result && "notFound" in result && result.notFound) {
|
|
526
702
|
if (isDataReq) {
|
|
527
|
-
|
|
703
|
+
const deploymentId = process.env.__VINEXT_DEPLOYMENT_ID || process.env.NEXT_DEPLOYMENT_ID;
|
|
704
|
+
const notFoundHeaders = { "Content-Type": "application/json" };
|
|
705
|
+
if (deploymentId) notFoundHeaders[NEXTJS_DEPLOYMENT_ID_HEADER] = deploymentId;
|
|
706
|
+
res.writeHead(404, notFoundHeaders);
|
|
528
707
|
res.end("{}");
|
|
529
708
|
return;
|
|
530
709
|
}
|
|
@@ -533,29 +712,57 @@ function createSSRHandler(server, runner, routes, pagesDir, i18nConfig, fileMatc
|
|
|
533
712
|
}
|
|
534
713
|
if (result && "props" in result) isSerializableProps(patternToNextFormat(route.pattern), "getStaticProps", pageProps);
|
|
535
714
|
if (typeof result?.revalidate === "number" && result.revalidate > 0) isrRevalidateSeconds = result.revalidate;
|
|
715
|
+
else if (cached?.value.value?.kind === "PAGES" && cached.value.value.generatedFromDataRequest) isrRevalidateSeconds = cached.value.cacheControl?.revalidate ?? 31536e3;
|
|
536
716
|
}
|
|
537
|
-
if (typeof pageModule.getServerSideProps !== "function" && typeof pageModule.getStaticProps !== "function") {
|
|
717
|
+
if (typeof pageModule.getServerSideProps !== "function" && typeof pageModule.getStaticProps !== "function" && hasAppGetInitialProps) {
|
|
718
|
+
if (await loadAppInitialProps()) return;
|
|
719
|
+
}
|
|
720
|
+
if (typeof pageModule.getServerSideProps !== "function" && typeof pageModule.getStaticProps !== "function" && !hasAppGetInitialProps) {
|
|
538
721
|
const initialProps = await loadPagesGetInitialProps(PageComponent, {
|
|
539
722
|
req,
|
|
540
723
|
res,
|
|
541
724
|
pathname: patternToNextFormat(route.pattern),
|
|
542
725
|
query,
|
|
543
|
-
asPath:
|
|
726
|
+
asPath: requestAsPath,
|
|
544
727
|
locale: locale ?? currentDefaultLocale,
|
|
545
728
|
locales: i18nConfig?.locales,
|
|
546
729
|
defaultLocale: currentDefaultLocale
|
|
547
730
|
});
|
|
548
731
|
if (res.headersSent || res.writableEnded) return;
|
|
549
|
-
if (initialProps)
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
732
|
+
if (initialProps) {
|
|
733
|
+
pageProps = {
|
|
734
|
+
...pageProps,
|
|
735
|
+
...initialProps
|
|
736
|
+
};
|
|
737
|
+
renderProps = {
|
|
738
|
+
...renderProps,
|
|
739
|
+
pageProps
|
|
740
|
+
};
|
|
741
|
+
}
|
|
553
742
|
}
|
|
554
743
|
if (isDataReq) {
|
|
744
|
+
if (shouldPersistFallbackData) {
|
|
745
|
+
const cacheKey = pagesIsrCacheKey(url.split("?")[0]);
|
|
746
|
+
const revalidateSeconds = isrRevalidateSeconds ?? 31536e3;
|
|
747
|
+
await isrSet(cacheKey, {
|
|
748
|
+
kind: "PAGES",
|
|
749
|
+
html: "",
|
|
750
|
+
pageData: renderProps,
|
|
751
|
+
generatedFromDataRequest: true,
|
|
752
|
+
headers: void 0,
|
|
753
|
+
status: void 0
|
|
754
|
+
}, revalidateSeconds);
|
|
755
|
+
setRevalidateDuration(cacheKey, revalidateSeconds);
|
|
756
|
+
}
|
|
555
757
|
const dataHeaders = { "Content-Type": "application/json" };
|
|
556
758
|
if (gsspExtraHeaders) for (const [k, v] of Object.entries(gsspExtraHeaders)) dataHeaders[k] = v;
|
|
759
|
+
const dataRoutePattern = patternToNextFormat(route.pattern);
|
|
760
|
+
if (dataRoutePattern !== "/_error" && dataRoutePattern !== "/500") {
|
|
761
|
+
const deploymentId = process.env.__VINEXT_DEPLOYMENT_ID || process.env.NEXT_DEPLOYMENT_ID;
|
|
762
|
+
if (deploymentId) dataHeaders[NEXTJS_DEPLOYMENT_ID_HEADER] = deploymentId;
|
|
763
|
+
}
|
|
557
764
|
res.writeHead(statusCode ?? 200, dataHeaders);
|
|
558
|
-
res.end(JSON.stringify(
|
|
765
|
+
res.end(JSON.stringify(renderProps));
|
|
559
766
|
_renderEnd = now();
|
|
560
767
|
return;
|
|
561
768
|
}
|
|
@@ -563,8 +770,10 @@ function createSSRHandler(server, runner, routes, pagesDir, i18nConfig, fileMatc
|
|
|
563
770
|
let element;
|
|
564
771
|
const wrapWithRouterContext = routerShim.wrapWithRouterContext;
|
|
565
772
|
if (AppComponent) element = createElement(AppComponent, {
|
|
773
|
+
...renderProps,
|
|
566
774
|
Component: PageComponent,
|
|
567
|
-
pageProps
|
|
775
|
+
pageProps: renderProps.pageProps,
|
|
776
|
+
router: routerShim.default
|
|
568
777
|
});
|
|
569
778
|
else element = createElement(PageComponent, pageProps);
|
|
570
779
|
if (wrapWithRouterContext) element = wrapWithRouterContext(element);
|
|
@@ -616,11 +825,14 @@ function createSSRHandler(server, runner, routes, pagesDir, i18nConfig, fileMatc
|
|
|
616
825
|
import "vinext/instrumentation-client";
|
|
617
826
|
import React from "react";
|
|
618
827
|
import { hydrateRoot } from "react-dom/client";
|
|
619
|
-
import {
|
|
620
|
-
import { wrapWithRouterContext } from "next/router";
|
|
828
|
+
import Router, { wrapWithRouterContext } from "next/router";
|
|
621
829
|
|
|
622
830
|
const nextData = window.__NEXT_DATA__;
|
|
623
|
-
const
|
|
831
|
+
const props = nextData.props && typeof nextData.props === "object" ? nextData.props : {};
|
|
832
|
+
const rawPageProps = props.pageProps;
|
|
833
|
+
const pageProps = rawPageProps && typeof rawPageProps === "object" ? rawPageProps : {};
|
|
834
|
+
window.__VINEXT_PAGE_LOADERS__ = { [nextData.page]: () => import("${pageModuleUrl}") };
|
|
835
|
+
window.__VINEXT_APP_LOADER__ = ${appModuleUrl ? `() => import("${appModuleUrl}")` : "undefined"};
|
|
624
836
|
|
|
625
837
|
async function hydrate() {
|
|
626
838
|
let hydrateRootOptions;
|
|
@@ -642,24 +854,34 @@ async function hydrate() {
|
|
|
642
854
|
const appModule = await import("${appModuleUrl}");
|
|
643
855
|
const AppComponent = appModule.default;
|
|
644
856
|
window.__VINEXT_APP__ = AppComponent;
|
|
645
|
-
element = React.createElement(AppComponent, {
|
|
857
|
+
element = React.createElement(AppComponent, {
|
|
858
|
+
...props,
|
|
859
|
+
Component: PageComponent,
|
|
860
|
+
pageProps: rawPageProps,
|
|
861
|
+
router: Router,
|
|
862
|
+
});
|
|
646
863
|
` : `
|
|
647
864
|
element = React.createElement(PageComponent, pageProps);
|
|
648
865
|
`}
|
|
649
|
-
|
|
866
|
+
let resolveHydrationCommit;
|
|
867
|
+
const hydrationCommitted = new Promise((resolve) => { resolveHydrationCommit = resolve; });
|
|
868
|
+
element = wrapWithRouterContext(element, resolveHydrationCommit);
|
|
650
869
|
const root = hydrateRoot(document.getElementById("__next"), element, hydrateRootOptions);
|
|
651
870
|
window.__VINEXT_ROOT__ = root;
|
|
652
|
-
|
|
871
|
+
await hydrationCommitted;
|
|
653
872
|
const hydratedAt = performance.now();
|
|
654
873
|
window.__VINEXT_HYDRATED_AT = hydratedAt;
|
|
655
874
|
window.__NEXT_HYDRATED = true;
|
|
656
875
|
window.__NEXT_HYDRATED_AT = hydratedAt;
|
|
657
876
|
window.__NEXT_HYDRATED_CB?.();
|
|
877
|
+
if (nextData.isFallback) {
|
|
878
|
+
await Router.replace(window.location.pathname + window.location.search + window.location.hash, undefined, { _h: 1, scroll: false });
|
|
879
|
+
}
|
|
658
880
|
}
|
|
659
881
|
hydrate();
|
|
660
882
|
<\/script>`;
|
|
661
883
|
const nextDataScript = createInlineScriptTag(`window.__NEXT_DATA__ = ${safeJsonStringify({
|
|
662
|
-
props:
|
|
884
|
+
props: renderProps,
|
|
663
885
|
page: patternToNextFormat(route.pattern),
|
|
664
886
|
query: params,
|
|
665
887
|
buildId: process.env.__VINEXT_BUILD_ID,
|
|
@@ -677,9 +899,9 @@ hydrate();
|
|
|
677
899
|
} catch {}
|
|
678
900
|
const allScripts = `${nextDataScript}\n ${createInlineScriptTag(`window.__VINEXT_PAGE_PATTERNS__=${safeJsonStringify(pagePatterns)}`, scriptNonce)}\n ${hydrationScript}`;
|
|
679
901
|
const extraHeaders = { ...gsspExtraHeaders };
|
|
680
|
-
if (isrRevalidateSeconds) if (scriptNonce) extraHeaders["Cache-Control"] =
|
|
902
|
+
if (isrRevalidateSeconds) if (scriptNonce) extraHeaders["Cache-Control"] = NO_STORE_CACHE_CONTROL;
|
|
681
903
|
else {
|
|
682
|
-
extraHeaders["Cache-Control"] =
|
|
904
|
+
extraHeaders["Cache-Control"] = buildMissIsrCacheControl(isrRevalidateSeconds);
|
|
683
905
|
Object.assign(extraHeaders, buildCacheStateHeaders("MISS"));
|
|
684
906
|
}
|
|
685
907
|
if (allFontPreloads.length > 0) extraHeaders["Link"] = allFontPreloads.map((p) => `<${p.href}>; rel=preload; as=font; type=${p.type}; crossorigin`).join(", ");
|
|
@@ -695,7 +917,7 @@ hydrate();
|
|
|
695
917
|
documentContext: {
|
|
696
918
|
pathname: patternToNextFormat(route.pattern),
|
|
697
919
|
query,
|
|
698
|
-
asPath:
|
|
920
|
+
asPath: requestAsPath
|
|
699
921
|
},
|
|
700
922
|
enhancePageElement: (renderPageOpts) => {
|
|
701
923
|
let FinalApp = AppComponent;
|
|
@@ -704,6 +926,7 @@ hydrate();
|
|
|
704
926
|
if (renderPageOpts && typeof renderPageOpts.enhanceComponent === "function") FinalComp = renderPageOpts.enhanceComponent(FinalComp);
|
|
705
927
|
let enhancedElement;
|
|
706
928
|
if (FinalApp) enhancedElement = createElement(FinalApp, {
|
|
929
|
+
...renderProps,
|
|
707
930
|
Component: FinalComp,
|
|
708
931
|
pageProps
|
|
709
932
|
});
|
|
@@ -722,6 +945,7 @@ hydrate();
|
|
|
722
945
|
if (typeof routerShim.setSSRContext === "function") routerShim.setSSRContext(null);
|
|
723
946
|
if (!scriptNonce && isrRevalidateSeconds !== null && isrRevalidateSeconds > 0) {
|
|
724
947
|
let isrElement = AppComponent ? createElement(AppComponent, {
|
|
948
|
+
...renderProps,
|
|
725
949
|
Component: pageModule.default,
|
|
726
950
|
pageProps
|
|
727
951
|
}) : createElement(pageModule.default, pageProps);
|
|
@@ -736,7 +960,7 @@ hydrate();
|
|
|
736
960
|
reportRequestError(e instanceof Error ? e : new Error(String(e)), {
|
|
737
961
|
path: url,
|
|
738
962
|
method: req.method ?? "GET",
|
|
739
|
-
headers: Object.fromEntries(Object.entries(req.headers).map(([k, v]) => [k, Array.isArray(v) ? v.join(", ") : String(v ?? "")]))
|
|
963
|
+
headers: Object.fromEntries(Object.entries(req.headers).filter(([k]) => !k.startsWith(":")).map(([k, v]) => [k, Array.isArray(v) ? v.join(", ") : String(v ?? "")]))
|
|
740
964
|
}, {
|
|
741
965
|
routerKind: "Pages Router",
|
|
742
966
|
routePath: route.pattern,
|
package/dist/server/headers.d.ts
CHANGED
|
@@ -60,6 +60,13 @@ declare const RSC_ACTION_HEADER = "x-rsc-action";
|
|
|
60
60
|
declare const NEXT_ACTION_HEADER = "next-action";
|
|
61
61
|
/** Next.js action-not-found indicator (value "1"). */
|
|
62
62
|
declare const NEXTJS_ACTION_NOT_FOUND_HEADER = "x-nextjs-action-not-found";
|
|
63
|
+
/**
|
|
64
|
+
* Deployment ID header used by the Pages Router for deployment-skew
|
|
65
|
+
* protection. Set on every `/_next/data/` response so the client can detect
|
|
66
|
+
* when a new deployment has been rolled out and trigger a hard navigation.
|
|
67
|
+
* Mirrors `NEXT_NAV_DEPLOYMENT_ID_HEADER` from Next.js `lib/constants.ts`.
|
|
68
|
+
*/
|
|
69
|
+
declare const NEXTJS_DEPLOYMENT_ID_HEADER = "x-nextjs-deployment-id";
|
|
63
70
|
/** Forwarded action marker — set when a request has already been forwarded between workers. */
|
|
64
71
|
declare const ACTION_FORWARDED_HEADER = "x-action-forwarded";
|
|
65
72
|
/** Indicates revalidation occurred — value is JSON kind (1 = path/tag, 2 = dynamic-only). */
|
|
@@ -100,4 +107,4 @@ declare const INTERNAL_HEADERS: string[];
|
|
|
100
107
|
/** Vinext-only internal headers stripped alongside Next.js protocol internals. */
|
|
101
108
|
declare const VINEXT_INTERNAL_HEADERS: string[];
|
|
102
109
|
//#endregion
|
|
103
|
-
export { ACTION_FORWARDED_HEADER, ACTION_REDIRECT_HEADER, ACTION_REDIRECT_STATUS_HEADER, ACTION_REDIRECT_TYPE_HEADER, ACTION_REVALIDATED_HEADER, FLIGHT_HEADERS, INTERNAL_HEADERS, MIDDLEWARE_HEADER_PREFIX, MIDDLEWARE_NEXT_HEADER, MIDDLEWARE_OVERRIDE_HEADERS, MIDDLEWARE_REQUEST_HEADER_PREFIX, MIDDLEWARE_REWRITE_HEADER, MIDDLEWARE_SET_COOKIE_HEADER, NEXTJS_ACTION_NOT_FOUND_HEADER, NEXTJS_CACHE_HEADER, NEXT_ACTION_HEADER, NEXT_ROUTER_PREFETCH_HEADER, NEXT_ROUTER_SEGMENT_PREFETCH_HEADER, NEXT_ROUTER_STATE_TREE_HEADER, NEXT_URL_HEADER, RSC_ACTION_HEADER, RSC_HEADER, VINEXT_CACHE_HEADER, VINEXT_CLIENT_REUSE_MANIFEST_HEADER, VINEXT_DYNAMIC_STALE_TIME_HEADER, VINEXT_INTERCEPTION_CONTEXT_HEADER, VINEXT_INTERNAL_HEADERS, VINEXT_MOUNTED_SLOTS_HEADER, VINEXT_MW_CTX_HEADER, VINEXT_PARAMS_HEADER, VINEXT_PRERENDER_ROUTE_PARAMS_HEADER, VINEXT_PRERENDER_SECRET_HEADER, VINEXT_REVALIDATE_HEADER, VINEXT_RSC_MARKER_HEADER, VINEXT_RSC_REDIRECT_HEADER, VINEXT_RSC_RENDER_MODE_HEADER, VINEXT_STATIC_FILE_HEADER, VINEXT_TIMING_HEADER };
|
|
110
|
+
export { ACTION_FORWARDED_HEADER, ACTION_REDIRECT_HEADER, ACTION_REDIRECT_STATUS_HEADER, ACTION_REDIRECT_TYPE_HEADER, ACTION_REVALIDATED_HEADER, FLIGHT_HEADERS, INTERNAL_HEADERS, MIDDLEWARE_HEADER_PREFIX, MIDDLEWARE_NEXT_HEADER, MIDDLEWARE_OVERRIDE_HEADERS, MIDDLEWARE_REQUEST_HEADER_PREFIX, MIDDLEWARE_REWRITE_HEADER, MIDDLEWARE_SET_COOKIE_HEADER, NEXTJS_ACTION_NOT_FOUND_HEADER, NEXTJS_CACHE_HEADER, NEXTJS_DEPLOYMENT_ID_HEADER, NEXT_ACTION_HEADER, NEXT_ROUTER_PREFETCH_HEADER, NEXT_ROUTER_SEGMENT_PREFETCH_HEADER, NEXT_ROUTER_STATE_TREE_HEADER, NEXT_URL_HEADER, RSC_ACTION_HEADER, RSC_HEADER, VINEXT_CACHE_HEADER, VINEXT_CLIENT_REUSE_MANIFEST_HEADER, VINEXT_DYNAMIC_STALE_TIME_HEADER, VINEXT_INTERCEPTION_CONTEXT_HEADER, VINEXT_INTERNAL_HEADERS, VINEXT_MOUNTED_SLOTS_HEADER, VINEXT_MW_CTX_HEADER, VINEXT_PARAMS_HEADER, VINEXT_PRERENDER_ROUTE_PARAMS_HEADER, VINEXT_PRERENDER_SECRET_HEADER, VINEXT_REVALIDATE_HEADER, VINEXT_RSC_MARKER_HEADER, VINEXT_RSC_REDIRECT_HEADER, VINEXT_RSC_RENDER_MODE_HEADER, VINEXT_STATIC_FILE_HEADER, VINEXT_TIMING_HEADER };
|