vinext 1.4.3 → 1.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/build/prerender-paths.js +5 -1
- package/dist/index.js +26 -14
- package/dist/server/api-handler.js +1 -2
- package/dist/server/app-browser-entry.js +10 -10
- package/dist/server/app-browser-navigation-controller.js +2 -2
- package/dist/server/app-browser-server-action-client.js +2 -2
- package/dist/server/app-browser-state.js +2 -2
- package/dist/server/app-browser-visible-commit.js +1 -1
- package/dist/server/app-history-state.js +1 -1
- package/dist/server/app-page-boundary-render.js +2 -2
- package/dist/server/app-page-element-builder.js +4 -4
- package/dist/server/app-page-render.js +1 -1
- package/dist/server/app-page-route-wiring.js +8 -8
- package/dist/server/app-request-context.js +1 -1
- package/dist/server/app-route-handler-dispatch.js +1 -1
- package/dist/server/app-route-handler-execution.js +1 -1
- package/dist/server/app-route-handler-response.d.ts +1 -0
- package/dist/server/app-route-handler-response.js +27 -2
- package/dist/server/app-rsc-handler.js +2 -2
- package/dist/server/app-rsc-response-stage.js +1 -1
- package/dist/server/app-server-action-execution.js +1 -1
- package/dist/server/app-ssr-entry.js +10 -10
- package/dist/server/edge-api-runtime.d.ts +6 -2
- package/dist/server/edge-api-runtime.js +21 -4
- package/dist/server/metadata-route-response.js +2 -2
- package/dist/server/navigation-planner.js +14 -6
- package/dist/server/remove-request-headers.d.ts +16 -0
- package/dist/server/remove-request-headers.js +23 -0
- package/dist/shims/cache-runtime.js +1 -1
- package/dist/shims/cache.js +6 -3
- package/dist/shims/client-page-root.js +2 -2
- package/dist/shims/error-boundary.js +2 -2
- package/dist/shims/internal/navigation-untracked.js +1 -1
- package/dist/shims/metadata.js +1 -1
- package/dist/shims/navigation-server.js +1 -1
- package/dist/shims/navigation.js +4 -4
- package/dist/shims/navigation.react-server.js +3 -3
- package/dist/shims/root-params.js +16 -2
- package/dist/shims/slot.js +3 -3
- package/package.json +1 -1
|
@@ -18,6 +18,7 @@ import { normalizePathTrailingSlash } from "../shims/url-utils.js";
|
|
|
18
18
|
import { resolveAppPageDynamicConfig } from "../server/app-segment-config.js";
|
|
19
19
|
import { classifyAppPageRouteStaticEligibility } from "./app-page-static-eligibility.js";
|
|
20
20
|
import { pagesRouteHasPriorityOverAppRoute } from "../server/hybrid-route-priority.js";
|
|
21
|
+
import { tryRealpathSync } from "./ssr-manifest.js";
|
|
21
22
|
import { readPrerenderSecret } from "./server-manifest.js";
|
|
22
23
|
import { loadMdxEsmReader } from "../utils/mdx-scan.js";
|
|
23
24
|
import { startProdServer } from "../server/prod-server.js";
|
|
@@ -674,10 +675,13 @@ function configuredRulesAffectWarmPath(pathname, rules, config) {
|
|
|
674
675
|
function configuredRewritesCanReplaceWarmPath(pathname, rewrites, hasNonDynamicRoute, config, include) {
|
|
675
676
|
return configuredRulesAffectWarmPath(pathname, [...rewrites.beforeFiles.filter(include), ...hasNonDynamicRoute ? [] : rewrites.afterFiles.filter(include)], config);
|
|
676
677
|
}
|
|
678
|
+
function canonicalDir(dir) {
|
|
679
|
+
return toSlash(tryRealpathSync(dir) ?? dir);
|
|
680
|
+
}
|
|
677
681
|
function findMiddlewareConventionFile(root, appDir, pagesDir, pageExtensions) {
|
|
678
682
|
const routeDir = appDir ?? pagesDir;
|
|
679
683
|
const routeRoot = routeDir ? path.dirname(routeDir) : root;
|
|
680
|
-
const conventionDir = routeRoot === path.join(root, "src") ? routeRoot : root;
|
|
684
|
+
const conventionDir = canonicalDir(routeRoot) === canonicalDir(path.join(root, "src")) ? routeRoot : root;
|
|
681
685
|
for (const name of ["proxy", "middleware"]) for (const extension of pageExtensions) {
|
|
682
686
|
const filePath = path.join(conventionDir, `${name}.${extension}`);
|
|
683
687
|
if (fs.existsSync(filePath)) return filePath;
|
package/dist/index.js
CHANGED
|
@@ -18,7 +18,7 @@ import { hasBasePath, restoreBasePath, stripBasePath } from "./utils/base-path.j
|
|
|
18
18
|
import { INTERNAL_HEADERS, NEXTJS_DEPLOYMENT_ID_HEADER, VINEXT_INTERNAL_HEADERS, VINEXT_TIMING_HEADER } from "./server/headers.js";
|
|
19
19
|
import { methodNotAllowedResponse, notFoundStaticAssetResponse } from "./server/http-error-responses.js";
|
|
20
20
|
import { isOpenRedirectShaped, sendRepeatedSlashRedirect } from "./server/open-redirect.js";
|
|
21
|
-
import { canonicalizeRequestUrlPathname,
|
|
21
|
+
import { canonicalizeRequestUrlPathname, normalizeTrailingSlash } from "./server/request-pipeline.js";
|
|
22
22
|
import { proxyExternalRequest } from "./config/config-matchers.js";
|
|
23
23
|
import { omitUnusedBuildSourcemap } from "./plugins/transform-result.js";
|
|
24
24
|
import { assetPrefixPathname, isNextStaticPath, resolveAssetsDir } from "./utils/asset-prefix.js";
|
|
@@ -64,6 +64,7 @@ import { generateBrowserEntry, generateBrowserRouteManifestModule, toHashedRoute
|
|
|
64
64
|
import { createRscScanGlobImportsPlugin, isRscScanGlobImportsAffected } from "./plugins/rsc-scan-glob-imports.js";
|
|
65
65
|
import { loadOrGenerateServerActionsEncryptionKey } from "./build/server-actions-encryption-key.js";
|
|
66
66
|
import { findOpenTelemetryPackages, mergeServerExternalPackages } from "./config/server-external-packages.js";
|
|
67
|
+
import { removeRequestHeaders } from "./server/remove-request-headers.js";
|
|
67
68
|
import { precompressAssets } from "./build/precompress.js";
|
|
68
69
|
import { VINEXT_PRERENDER_CONFIG_PLUGIN_PROPERTY, VINEXT_ROUTE_ROOT_CONFIG_PLUGIN_PROPERTY, normalizeVinextPrerenderConfig } from "./config/prerender.js";
|
|
69
70
|
import { VINEXT_CLIENT_ENTRY_MANIFEST, VINEXT_CLIENT_REFERENCE_SOURCES } from "./utils/client-entry-manifest.js";
|
|
@@ -182,10 +183,10 @@ const RSC_ENVIRONMENTS = /* @__PURE__ */ new Set([
|
|
|
182
183
|
"client"
|
|
183
184
|
]);
|
|
184
185
|
const VINEXT_GENERATED_DIR_RE = /(?:^|[/\\])\.vinext(?:[/\\]|$)/;
|
|
186
|
+
const FORWARDED_MIDDLEWARE_CONTEXT_HEADERS = /* @__PURE__ */ new Set([VINEXT_MW_CTX_HEADER]);
|
|
187
|
+
const STRIPPED_INTERNAL_REQUEST_HEADERS = /* @__PURE__ */ new Set([...INTERNAL_HEADERS, ...VINEXT_INTERNAL_HEADERS]);
|
|
185
188
|
function removeForwardedMiddlewareContext(req) {
|
|
186
|
-
|
|
187
|
-
const rawHeaders = req.rawHeaders;
|
|
188
|
-
for (let i = rawHeaders.length - 2; i >= 0; i -= 2) if (rawHeaders[i].toLowerCase() === "x-vinext-mw-ctx") rawHeaders.splice(i, 2);
|
|
189
|
+
removeRequestHeaders(req, FORWARDED_MIDDLEWARE_CONTEXT_HEADERS);
|
|
189
190
|
}
|
|
190
191
|
function setForwardedMiddlewareContext(req, key, context) {
|
|
191
192
|
removeForwardedMiddlewareContext(req);
|
|
@@ -940,6 +941,20 @@ function getLeadingReactDirective(code) {
|
|
|
940
941
|
function hasReactDirective(code) {
|
|
941
942
|
return getLeadingReactDirective(code) !== null;
|
|
942
943
|
}
|
|
944
|
+
/**
|
|
945
|
+
* Resolve a project directory through symlinks the way Vite resolves
|
|
946
|
+
* `config.root` (and Next.js its project dir), so route files, `server.config.root`
|
|
947
|
+
* and module ids all share one path. Windows uses the JS realpath, as Vite
|
|
948
|
+
* does, to keep mapped network drives.
|
|
949
|
+
*/
|
|
950
|
+
function resolveProjectDir(dir, preserveSymlinks) {
|
|
951
|
+
if (preserveSymlinks) return toSlash(dir);
|
|
952
|
+
try {
|
|
953
|
+
return toSlash(process.platform === "win32" ? fs.realpathSync(dir) : fs.realpathSync.native(dir));
|
|
954
|
+
} catch {
|
|
955
|
+
return toSlash(dir);
|
|
956
|
+
}
|
|
957
|
+
}
|
|
943
958
|
function generateRootParamsModule(rootParamNames) {
|
|
944
959
|
const names = Array.from(new Set(rootParamNames)).filter(isValidExportIdentifier).sort();
|
|
945
960
|
if (names.length === 0) return "export {};\n";
|
|
@@ -1489,7 +1504,7 @@ function vinext(options = {}) {
|
|
|
1489
1504
|
buildEmptyOutDir = typeof config.build?.emptyOutDir === "boolean" ? config.build.emptyOutDir : void 0;
|
|
1490
1505
|
isServeCommand = env.command === "serve";
|
|
1491
1506
|
const ipaddrSsrExternal = env.command === "serve" ? ["ipaddr.js"] : [];
|
|
1492
|
-
root = path.resolve(toSlash(process.cwd()), config.root ?? ".");
|
|
1507
|
+
root = resolveProjectDir(path.resolve(toSlash(process.cwd()), config.root ?? "."), config.resolve?.preserveSymlinks);
|
|
1493
1508
|
if (env.command === "build") assertClientOutDirIsSeparate(root, options);
|
|
1494
1509
|
const devCliLifecycleEnabled = env.command === "serve" && env.isPreview !== true && claimViteCliDevInvocation(root, config["__vinextDevRestart"] === true, reservedDevCliInvocation && config.configFile === false);
|
|
1495
1510
|
buildLifecycleInvocation = config[VINEXT_BUILD_LIFECYCLE_CONFIG];
|
|
@@ -1501,7 +1516,7 @@ function vinext(options = {}) {
|
|
|
1501
1516
|
const swcHelpersAlias = resolveSwcHelpersAlias(root);
|
|
1502
1517
|
const mode = env?.mode ?? "development";
|
|
1503
1518
|
const envDir = config.envDir === false ? void 0 : config.envDir ? path.resolve(root, config.envDir) : root;
|
|
1504
|
-
if (earlyDotenv && envDir !== earlyDotenv.dir) {
|
|
1519
|
+
if (earlyDotenv && (envDir === void 0 || resolveProjectDir(envDir, config.resolve?.preserveSymlinks) !== resolveProjectDir(earlyDotenv.dir, config.resolve?.preserveSymlinks))) {
|
|
1505
1520
|
for (const [key, value] of Object.entries(earlyDotenv.env)) if (process.env[key] === value) Reflect.deleteProperty(process.env, key);
|
|
1506
1521
|
earlyDotenv = void 0;
|
|
1507
1522
|
}
|
|
@@ -1520,10 +1535,8 @@ function vinext(options = {}) {
|
|
|
1520
1535
|
}
|
|
1521
1536
|
draftModeSecret = previewBuildCredentials?.id ?? getPagesPreviewModeId();
|
|
1522
1537
|
let baseDir;
|
|
1523
|
-
if (options.appDir)
|
|
1524
|
-
|
|
1525
|
-
baseDir = toSlash(dir);
|
|
1526
|
-
} else {
|
|
1538
|
+
if (options.appDir) baseDir = resolveProjectDir(path.isAbsolute(options.appDir) ? options.appDir : path.resolve(root, options.appDir), config.resolve?.preserveSymlinks);
|
|
1539
|
+
else {
|
|
1527
1540
|
const hasRootApp = fs.existsSync(path.join(root, "app"));
|
|
1528
1541
|
const hasRootPages = fs.existsSync(path.join(root, "pages"));
|
|
1529
1542
|
const hasSrcApp = fs.existsSync(path.join(root, "src", "app"));
|
|
@@ -1758,6 +1771,7 @@ function vinext(options = {}) {
|
|
|
1758
1771
|
delete config.resolve.alias;
|
|
1759
1772
|
}
|
|
1760
1773
|
const viteConfig = {
|
|
1774
|
+
root,
|
|
1761
1775
|
appType: "custom",
|
|
1762
1776
|
...devCliLifecycleEnabled ? { [VINEXT_DEV_CLI_LIFECYCLE]: true } : {},
|
|
1763
1777
|
...hasAppDir && hasNitroPlugin ? { rsc: { serverHandler: false } } : {},
|
|
@@ -3342,6 +3356,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
3342
3356
|
}
|
|
3343
3357
|
revalidationHostname = readTrustedRevalidationHostname(revalidationHeaders, nextConfig?.i18n);
|
|
3344
3358
|
}
|
|
3359
|
+
removeRequestHeaders(req, STRIPPED_INTERNAL_REQUEST_HEADERS);
|
|
3345
3360
|
const requestHost = revalidationHostname ?? ((Array.isArray(req.headers.host) ? req.headers.host[0] : req.headers.host) || "localhost");
|
|
3346
3361
|
const requestOrigin = `http://${requestHost}`;
|
|
3347
3362
|
const getUrlHostname = (requestUrl) => new URL(requestUrl).hostname;
|
|
@@ -3451,12 +3466,9 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
3451
3466
|
});
|
|
3452
3467
|
}
|
|
3453
3468
|
}
|
|
3454
|
-
const
|
|
3469
|
+
const nodeRequestHeaders = new Headers(Object.fromEntries(Object.entries(req.headers).filter(([k, v]) => v !== void 0 && !k.startsWith(":")).map(([k, v]) => [k, Array.isArray(v) ? v.join(", ") : String(v)])));
|
|
3455
3470
|
const isDataRequest = isDataReq;
|
|
3456
|
-
const nodeRequestHeaders = filterInternalHeaders(rawHeaders);
|
|
3457
3471
|
if (revalidationHostname) nodeRequestHeaders.set("host", revalidationHostname);
|
|
3458
|
-
for (const header of INTERNAL_HEADERS) delete req.headers[header];
|
|
3459
|
-
for (const header of VINEXT_INTERNAL_HEADERS) delete req.headers[header];
|
|
3460
3472
|
const method = req.method ?? "GET";
|
|
3461
3473
|
const webRequest = new Request(new URL(routeUrl, requestOrigin), {
|
|
3462
3474
|
method,
|
|
@@ -263,11 +263,10 @@ async function handleApiRoute(runner, req, res, url, apiRoutes, nextConfig) {
|
|
|
263
263
|
const response = finalizeEdgeApiResponse(handlerResponse, "node");
|
|
264
264
|
res.statusCode = response.status;
|
|
265
265
|
res.statusMessage = response.statusText;
|
|
266
|
-
const setCookieHeaders = response.headers.getSetCookie();
|
|
267
266
|
response.headers.forEach((value, name) => {
|
|
268
267
|
if (name !== "set-cookie") res.setHeader(name, value);
|
|
269
268
|
});
|
|
270
|
-
|
|
269
|
+
for (const cookie of response.headers.getSetCookie()) res.appendHeader("set-cookie", cookie);
|
|
271
270
|
await writeEdgeApiResponseBody(res, response.body, nextRequest.signal);
|
|
272
271
|
return true;
|
|
273
272
|
}
|
|
@@ -7,24 +7,26 @@ import { clearAppNavigationFailureTarget, installAppNavigationFailureListeners }
|
|
|
7
7
|
import { notifyAppRouterTransitionStart } from "../client/instrumentation-client-state.js";
|
|
8
8
|
import "../client/instrumentation-client.js";
|
|
9
9
|
import { createNavigationRuntimeRouteManifestLoader, getNavigationRuntime, loadNavigationRuntimeRouteManifest, registerNavigationRuntimeBootstrap, registerNavigationRuntimeFunctions } from "../client/navigation-runtime.js";
|
|
10
|
+
import { beginAppRouterScrollIntent, consumeAppRouterScrollIntent } from "../shims/app-router-scroll-state.js";
|
|
11
|
+
import { AppRouterScrollCommitProvider } from "../shims/app-router-scroll.js";
|
|
12
|
+
import { getBfcacheIdMapContext, getNavigationContext, setNavigationContext } from "../shims/navigation-context-state.js";
|
|
13
|
+
import { decodeRedirectError, isRedirectError } from "../shims/navigation-errors.js";
|
|
10
14
|
import { AppElementsWire } from "./app-elements-wire.js";
|
|
11
15
|
import { getMountedSlotIdsHeader, resolveVisitedResponseInterceptionContext } from "./app-elements.js";
|
|
12
|
-
import { createBfcacheSegmentIdentityMap, createInitialBfcacheIdMap } from "./app-bfcache-identity.js";
|
|
13
|
-
import { createDiscardedServerActionRefreshScheduler, createServerActionInitiationSnapshot, resolveServerActionOperationLane } from "./app-browser-action-result.js";
|
|
14
16
|
import { resolveManifestNavigationInterceptionContext, resolveMiddlewareRewriteNavigationInterceptionContext } from "./app-browser-interception-context.js";
|
|
15
17
|
import { isExternalHistoryState, readHistoryStateActiveRoutePaths, readHistoryStatePreviousNextUrl, resolveActiveRoutePaths } from "./app-history-state.js";
|
|
16
18
|
import { AppBrowserMpaNavigationScheduler } from "./app-browser-mpa-navigation.js";
|
|
17
19
|
import { stripRscCompletionMetadataResponse } from "./rsc-completion-metadata.js";
|
|
18
20
|
import { blockDangerousStreamedRscRedirect } from "./app-browser-rsc-redirect.js";
|
|
19
21
|
import { navigationPlanner } from "./navigation-planner.js";
|
|
20
|
-
import { decodeRedirectError, isRedirectError } from "../shims/navigation-errors.js";
|
|
21
|
-
import { beginAppRouterScrollIntent, consumeAppRouterScrollIntent } from "../shims/app-router-scroll-state.js";
|
|
22
|
-
import { getBfcacheIdMapContext, getNavigationContext, setNavigationContext } from "../shims/navigation-context-state.js";
|
|
23
22
|
import { DYNAMIC_NAVIGATION_CACHE_TTL, PREFETCH_CACHE_TTL, __basePath, activateNavigationSnapshot, appRouterInstance, commitClientNavigationState, consumePrefetchResponse, consumePrefetchResponseForNavigation, createCachedRscResponseSnapshot, createClientNavigationRenderSnapshot, createSnapshotPathAndSearch, deletePrefetchResponseSnapshot, disableNavigationResponsePrefetchCacheReuse, getClientNavigationRenderContext, getMountedSlotsHeader, getPrefetchCache, hasPrefetchCacheEntryForNavigation, invalidateDynamicPrefetchCache, invalidatePrefetchCache, invalidateVisitedResponsePrefetches, parseRenderedPathAndSearchHeader, preloadHybridClientRouteOwner, pushHistoryStateWithoutNotify, replaceClientParamsWithoutNotify, replaceHistoryStateWithoutNotify, resolveLoadedHybridClientRewriteHref, resolvePrefetchCacheEntryMountedSlotsHeader, restoreRscResponse, saveScrollPosition, seedPrefetchResponseSnapshot, setClientParams, setMountedSlotsHeader, setPendingPathname, trackAppRouterNavigationInFlight, useRouter } from "../shims/navigation.js";
|
|
24
|
-
import {
|
|
23
|
+
import { BfcacheIdentityMapContext, bindAppElementsRenderedSearch, isBfcacheIdentityRetained, setAppElementsRenderedSearch } from "../shims/slot.js";
|
|
24
|
+
import DefaultGlobalError from "../shims/default-global-error.js";
|
|
25
|
+
import { DevRecoveryBoundary, GlobalErrorBoundary, RedirectBoundary } from "../shims/error-boundary.js";
|
|
26
|
+
import { createBfcacheSegmentIdentityMap, createInitialBfcacheIdMap } from "./app-bfcache-identity.js";
|
|
27
|
+
import { createDiscardedServerActionRefreshScheduler, createServerActionInitiationSnapshot, resolveServerActionOperationLane } from "./app-browser-action-result.js";
|
|
25
28
|
import { chunksToReadableStream, createProgressiveRscStream, getVinextBrowserGlobal } from "./app-browser-stream.js";
|
|
26
29
|
import { createMountedLayoutsHeader, holdsSkippedLayouts } from "./app-mounted-layouts.js";
|
|
27
|
-
import { BfcacheIdentityMapContext, bindAppElementsRenderedSearch, isBfcacheIdentityRetained, setAppElementsRenderedSearch } from "../shims/slot.js";
|
|
28
30
|
import { COMMITTED_CACHE_APP_NAVIGATION_PAYLOAD_ORIGIN, FRESH_APP_NAVIGATION_PAYLOAD_ORIGIN, VISITED_CACHE_APP_NAVIGATION_PAYLOAD_ORIGIN, isCacheRestorableAppPayloadMetadata, isCompleteAppPayloadMetadata, resolveInterceptionContextFromPreviousNextUrl } from "./app-browser-state.js";
|
|
29
31
|
import { clearHardNavigationLoopGuard, createAppBrowserNavigationController, createBasePathStrippedPathAndSearch, navigateDocumentDirectly } from "./app-browser-navigation-controller.js";
|
|
30
32
|
import { createAppRouteTree } from "./app-route-tree.js";
|
|
@@ -35,8 +37,6 @@ import { consumeInitialFormState, createVinextHydrateRootOptions, hydrateRootInT
|
|
|
35
37
|
import { AppBrowserHistoryController } from "./app-browser-history-controller.js";
|
|
36
38
|
import { createVisitedResponseCacheEntry, deleteAllVisitedResponseCacheEntries, deleteVisitedResponseCacheEntry, findVisitedResponseCacheEntry, findVisitedResponseForFullPrefetch, hasNavigationResponseHistoryLifetime, isVisitedResponseCacheEntryFresh, revokeHistoryRestoreNavigationReuse } from "./app-visited-response-cache.js";
|
|
37
39
|
import { createPopstateRestoreHandler, restoreSynchronousPopstateScrollPosition, shouldCommitPopstateUrlWithoutNavigation } from "./app-browser-popstate.js";
|
|
38
|
-
import DefaultGlobalError from "../shims/default-global-error.js";
|
|
39
|
-
import { DevRecoveryBoundary, GlobalErrorBoundary, RedirectBoundary } from "../shims/error-boundary.js";
|
|
40
40
|
import { createDevOnCaughtError, createOnUncaughtError, createProdOnCaughtError, createProdOnRecoverableError } from "./app-browser-error.js";
|
|
41
41
|
import { createHydrationCachePublication } from "./app-hydration-cache-publication.js";
|
|
42
42
|
import { peekSettledPrefetchResponseForNavigation, prepareConsumedPrefetchResponseForPublication, preserveCommittedPrefetchExpiry, resolvePrefetchNavigationResponseUrl } from "./app-browser-prefetch-response.js";
|
|
@@ -44,8 +44,8 @@ import { canCommitOptimisticRouteTemplate, createOptimisticRouteTemplate, create
|
|
|
44
44
|
import { removeStylesheetLinksCoveredByInlineCss } from "./app-inline-css-client.js";
|
|
45
45
|
import { Fragment, createElement, startTransition, use, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
46
46
|
import { createRoot, hydrateRoot } from "react-dom/client";
|
|
47
|
-
import { createFromFetch, createFromReadableStream, setServerCallback } from "@vitejs/plugin-rsc/browser";
|
|
48
47
|
import { flushSync } from "react-dom";
|
|
48
|
+
import { createFromFetch, createFromReadableStream, setServerCallback } from "@vitejs/plugin-rsc/browser";
|
|
49
49
|
import { hasServerActions, loadServerActionClient } from "virtual:vinext-app-capabilities";
|
|
50
50
|
//#region src/server/app-browser-entry.ts
|
|
51
51
|
const HAS_CLIENT_REWRITES = process.env.__VINEXT_HAS_CLIENT_REWRITES !== "false";
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { stripBasePath } from "../utils/base-path.js";
|
|
2
2
|
import { withBasePath } from "../shims/url-utils.js";
|
|
3
3
|
import { clearAppNavigationFailureTarget, getAppNavigationFailureTarget } from "../client/app-nav-failure-handler.js";
|
|
4
|
-
import { resolveServerActionOperationLane, shouldScheduleRefreshForDiscardedServerAction } from "./app-browser-action-result.js";
|
|
5
|
-
import { resolveActiveRoutePaths } from "./app-history-state.js";
|
|
6
4
|
import { claimAppRouterScrollIntentForCommit, clearAppRouterScrollIntent, consumeAppRouterScrollIntent } from "../shims/app-router-scroll-state.js";
|
|
5
|
+
import { resolveActiveRoutePaths } from "./app-history-state.js";
|
|
7
6
|
import { activateNavigationSnapshot, clearPendingPathname, commitClientNavigationState, createSnapshotPathAndSearch } from "../shims/navigation.js";
|
|
7
|
+
import { resolveServerActionOperationLane, shouldScheduleRefreshForDiscardedServerAction } from "./app-browser-action-result.js";
|
|
8
8
|
import { FRESH_APP_NAVIGATION_PAYLOAD_ORIGIN, createPendingNavigationCommit, createPendingNavigationCommitFromElements } from "./app-browser-state.js";
|
|
9
9
|
import { applyApprovedVisibleCommit, approveHmrVisibleCommit, approvePendingNavigationCommit, resolveAndClassifyNavigationCommit } from "./app-browser-visible-commit.js";
|
|
10
10
|
import { startTransition, useInsertionEffect, useLayoutEffect } from "react";
|
|
@@ -2,11 +2,11 @@ import { hasBasePath } from "../utils/base-path.js";
|
|
|
2
2
|
import { ACTION_REDIRECT_HEADER, ACTION_REDIRECT_STATUS_HEADER, VINEXT_RENDERED_PATH_AND_SEARCH_HEADER } from "./headers.js";
|
|
3
3
|
import { DANGEROUS_URL_BLOCK_MESSAGE, isDangerousScheme } from "../shims/url-safety.js";
|
|
4
4
|
import { VINEXT_RSC_COMPATIBILITY_ID_HEADER, createServerActionRequestUrl, toPathAbsolutePathname } from "./app-rsc-cache-busting.js";
|
|
5
|
-
import { throwOnServerActionNotFound } from "./server-action-not-found.js";
|
|
6
5
|
import { AppElementsWire } from "./app-elements-wire.js";
|
|
7
6
|
import "./app-elements.js";
|
|
8
|
-
import { createServerActionResultFacts, isServerActionResult, normalizeServerActionThrownValue, parseServerActionRevalidationHeader, readInvalidServerActionResponseError, shouldClearClientNavigationCachesForServerActionResult, shouldSyncServerActionHttpFallbackHead } from "./app-browser-action-result.js";
|
|
9
7
|
import { parseRenderedPathAndSearchHeader } from "../shims/navigation.js";
|
|
8
|
+
import { throwOnServerActionNotFound } from "./server-action-not-found.js";
|
|
9
|
+
import { createServerActionResultFacts, isServerActionResult, normalizeServerActionThrownValue, parseServerActionRevalidationHeader, readInvalidServerActionResponseError, shouldClearClientNavigationCachesForServerActionResult, shouldSyncServerActionHttpFallbackHead } from "./app-browser-action-result.js";
|
|
10
10
|
import { resolveServerActionRequestState } from "./app-browser-state.js";
|
|
11
11
|
import { applyServerActionResultDecision } from "./app-browser-server-action-navigation.js";
|
|
12
12
|
import { createFromFetch, createTemporaryReferenceSet, encodeReply } from "@vitejs/plugin-rsc/browser";
|
|
@@ -6,15 +6,15 @@ import { normalizePath } from "./normalize-path.js";
|
|
|
6
6
|
import { createRscRequestHeaders } from "./app-rsc-cache-busting.js";
|
|
7
7
|
import { AppElementsWire } from "./app-elements-wire.js";
|
|
8
8
|
import { getMountedSlotIds, getMountedSlotIdsHeader } from "./app-elements.js";
|
|
9
|
-
import { createBfcacheSegmentIdentityMap, createInitialBfcacheIdMap, createNextBfcacheIdMap, preserveBfcacheIdsForMergedElements } from "./app-bfcache-identity.js";
|
|
10
9
|
import { createAppOwnedHistoryState, createExternalHistoryStatePreservingMetadata, createHistoryStateWithNavigationMetadata, createHistoryStateWithPreviousNextUrl, createHistoryStateWithTreeSnapshotId, isExternalHistoryState, isHistoryStateBfcacheVersionCurrent, readHistoryStateActiveRoutePaths, readHistoryStateBfcacheIds, readHistoryStateBfcacheVersion, readHistoryStatePreviousNextUrl, readHistoryStateTraversalIndex, resolveActiveRoutePaths, resolveHistoryTraversalIntent } from "./app-history-state.js";
|
|
11
10
|
import { NavigationTraceReasonCodes, createNavigationLifecycleTraceFields, createNavigationTrace } from "./navigation-trace.js";
|
|
12
11
|
import { verifyOperationTokenForCommit } from "./operation-token.js";
|
|
13
12
|
import { navigationPlanner, resolveDefaultOrUnmatchedSlotPersistenceForLayouts } from "./navigation-planner.js";
|
|
14
13
|
import { createSnapshotPathAndSearch } from "../shims/navigation.js";
|
|
14
|
+
import { bindAppElementsRenderedSearch } from "../shims/slot.js";
|
|
15
|
+
import { createBfcacheSegmentIdentityMap, createInitialBfcacheIdMap, createNextBfcacheIdMap, preserveBfcacheIdsForMergedElements } from "./app-bfcache-identity.js";
|
|
15
16
|
import { holdsSkippedLayouts } from "./app-mounted-layouts.js";
|
|
16
17
|
import { createCacheEntryReuseProof } from "./cache-proof.js";
|
|
17
|
-
import { bindAppElementsRenderedSearch } from "../shims/slot.js";
|
|
18
18
|
//#region src/server/app-browser-state.ts
|
|
19
19
|
const COMMITTED_CACHE_APP_NAVIGATION_PAYLOAD_ORIGIN = { origin: "committed-cache" };
|
|
20
20
|
const FRESH_APP_NAVIGATION_PAYLOAD_ORIGIN = { origin: "fresh" };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { AppElementsWire, normalizeAppElementsSlotBindings } from "./app-elements-wire.js";
|
|
2
2
|
import "./app-elements.js";
|
|
3
|
-
import { createBfcacheSegmentIdentityMap, preserveBfcacheIdsForMergedElements } from "./app-bfcache-identity.js";
|
|
4
3
|
import { NavigationTraceReasonCodes, NavigationTraceTransactionCodes, createNavigationTrace, prependNavigationTraceEntry } from "./navigation-trace.js";
|
|
5
4
|
import { mergeElements } from "../shims/slot.js";
|
|
5
|
+
import { createBfcacheSegmentIdentityMap, preserveBfcacheIdsForMergedElements } from "./app-bfcache-identity.js";
|
|
6
6
|
import { createPendingNavigationCommit, resolvePendingNavigationCommitDispositionDecision } from "./app-browser-state.js";
|
|
7
7
|
import { resolveAppPageRouteStateKey } from "./app-page-segment-state.js";
|
|
8
8
|
//#region src/server/app-browser-visible-commit.ts
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { isNonNegativeSafeInteger } from "../utils/number.js";
|
|
1
2
|
import { AppElementsWire } from "./app-elements-wire.js";
|
|
2
3
|
import "./app-elements.js";
|
|
3
4
|
import { isBfcacheSegmentId } from "./app-bfcache-id.js";
|
|
4
|
-
import { isNonNegativeSafeInteger } from "../utils/number.js";
|
|
5
5
|
//#region src/server/app-history-state.ts
|
|
6
6
|
const VINEXT_PREVIOUS_NEXT_URL_HISTORY_STATE_KEY = "__vinext_previousNextUrl";
|
|
7
7
|
const VINEXT_HISTORY_INDEX_HISTORY_STATE_KEY = "__vinext_historyIndex";
|
|
@@ -3,14 +3,14 @@ import { isNavigationSignalError } from "../utils/navigation-signal.js";
|
|
|
3
3
|
import { NEVER_CACHE_CONTROL, applyCdnResponseHeaders } from "./cache-control.js";
|
|
4
4
|
import { isRenderDynamicLatched, isStaticGenerationAccessError } from "../shims/internal/headers-state.js";
|
|
5
5
|
import { copyLinkHeaderProvenance } from "./app-response-header-provenance.js";
|
|
6
|
+
import { withUseCacheLayoutMarker } from "../shims/internal/app-page-props-cache-key.js";
|
|
7
|
+
import { rewriteClientHookError } from "../shims/client-hook-error.js";
|
|
6
8
|
import { createArtifactCompatibilityEnvelope } from "./artifact-compatibility.js";
|
|
7
9
|
import { AppElementsWire } from "./app-elements-wire.js";
|
|
8
10
|
import "./app-elements.js";
|
|
9
11
|
import DefaultGlobalError from "../shims/default-global-error.js";
|
|
10
12
|
import { ErrorBoundary, GlobalErrorBoundary, SerializedErrorBoundary } from "../shims/error-boundary.js";
|
|
11
|
-
import { rewriteClientHookError } from "../shims/client-hook-error.js";
|
|
12
13
|
import { LayoutSegmentProvider } from "../shims/layout-segment-context.js";
|
|
13
|
-
import { withUseCacheLayoutMarker } from "../shims/internal/app-page-props-cache-key.js";
|
|
14
14
|
import { MetadataHead, ViewportHead } from "../shims/metadata.js";
|
|
15
15
|
import { buildRscRedirectFlightStream } from "./app-rsc-redirect-flight.js";
|
|
16
16
|
import { bufferAppPageBinaryStream, buildAppPageSpecialErrorResponse, resolveAppPageSpecialError } from "./app-page-execution.js";
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { isPromiseLike } from "../utils/promise.js";
|
|
2
2
|
import { APP_RSC_RENDER_MODE_NAVIGATION } from "./app-rsc-render-mode.js";
|
|
3
|
+
import { makeThenableParams } from "../shims/thenable-params.js";
|
|
4
|
+
import { withUseCacheLayoutMarker, withUseCachePageMarker } from "../shims/internal/app-page-props-cache-key.js";
|
|
3
5
|
import { AppElementsWire } from "./app-elements-wire.js";
|
|
4
6
|
import "./app-elements.js";
|
|
5
|
-
import {
|
|
7
|
+
import { ClientPageRoot } from "../shims/client-page-root.js";
|
|
6
8
|
import { ErrorBoundary, ForbiddenBoundary, NotFoundBoundary, UnauthorizedBoundary } from "../shims/error-boundary.js";
|
|
7
|
-
import {
|
|
8
|
-
import { makeThenableParams } from "../shims/thenable-params.js";
|
|
9
|
+
import { APP_PAGE_SEGMENT_KEY, isAppPageRouteGroupSegment, resolveAppPagePatternStateKey, resolveAppPageRouteStateKey, resolveAppPageSemanticSegmentStateKey } from "./app-page-segment-state.js";
|
|
9
10
|
import { tagAppPagePageError, tagAppPageSlotError } from "./app-page-execution.js";
|
|
10
11
|
import { createAppPageMetadataSearchParamsObserver, makeObservedAppPageSearchParamsThenable } from "./app-page-search-params-observation.js";
|
|
11
12
|
import { resolveAppPageBranchParams } from "./app-page-params.js";
|
|
@@ -19,7 +20,6 @@ import { resolveAppPageModuleTraceSegment, traceCreateComponentTree, traceGetLay
|
|
|
19
20
|
import { buildAppPageElements, createAppPageSourcePage, createAppPageTreePath, resolveAppPageLoadingModuleAtOrAbove } from "./app-page-route-wiring.js";
|
|
20
21
|
import { DEFAULT_GLOBAL_ERROR_MODULE } from "./default-global-error-module.js";
|
|
21
22
|
import { shouldServeStreamingMetadata } from "./streaming-metadata.js";
|
|
22
|
-
import { ClientPageRoot } from "../shims/client-page-root.js";
|
|
23
23
|
import { createAppPageRenderIdentity } from "./app-page-render-identity.js";
|
|
24
24
|
import { Fragment, Suspense, cache, createElement } from "react";
|
|
25
25
|
//#region src/server/app-page-element-builder.ts
|
|
@@ -17,11 +17,11 @@ import { applyPrerenderCacheLifeHeader, applyPrerenderCacheTagsHeader } from "./
|
|
|
17
17
|
import { copyLinkHeaderProvenance, getFrameworkLinkHeader } from "./app-response-header-provenance.js";
|
|
18
18
|
import { traceResponseStartWithCompletion } from "./response-start-tracing.js";
|
|
19
19
|
import { mergeMiddlewareResponseHeaders } from "./middleware-response-headers.js";
|
|
20
|
+
import { isBailoutToCSRError } from "../shims/navigation-errors.js";
|
|
20
21
|
import { createArtifactCompatibilityEnvelope, createArtifactCompatibilityGraphVersion } from "./artifact-compatibility.js";
|
|
21
22
|
import { AppElementsWire, isAppElementsRecord } from "./app-elements-wire.js";
|
|
22
23
|
import "./app-elements.js";
|
|
23
24
|
import { appendRscCompletionMetadata } from "./rsc-completion-metadata.js";
|
|
24
|
-
import { isBailoutToCSRError } from "../shims/navigation-errors.js";
|
|
25
25
|
import { applyClientStaleTimeHeader, applyEdgeRuntimeHeader, buildAppPageHtmlResponse, buildAppPageRscResponse, resolveAppPageHtmlResponsePolicy, resolveAppPageRscResponsePolicy, resolveUncacheableCacheControl } from "./app-page-response.js";
|
|
26
26
|
import { buildAppPageFontLinkHeader, readAppPageBinaryStream, resolveAppPageCaughtNotFoundBoundaries, resolveAppPageShellSpecialError, resolveAppPageSpecialError, resolveAppPageSpecialErrorStoredHeaders, teeAppPageRscStreamForCapture } from "./app-page-execution.js";
|
|
27
27
|
import { buildAppPageHtmlDocumentResponse, buildAppPageLinkHeader, createAppPageFontData, createAppPageRscErrorTracker, createAppPageSsrErrorHandler, renderAppPageHtmlStream, renderAppPageHtmlStreamWithRecovery } from "./app-page-stream.js";
|
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
import { APP_RSC_RENDER_MODE_PREFETCH_EMPTY, APP_RSC_RENDER_MODE_PREFETCH_LOADING_SHELL } from "./app-rsc-render-mode.js";
|
|
2
2
|
import { fnv1a64 } from "../utils/hash.js";
|
|
3
3
|
import { createInlineScriptTag, escapeHtmlAttr } from "./html.js";
|
|
4
|
+
import { AppRouterScrollTarget } from "../shims/app-router-scroll.js";
|
|
5
|
+
import { withUseCacheLayoutMarker } from "../shims/internal/app-page-props-cache-key.js";
|
|
4
6
|
import { APP_LAYOUT_IDS_KEY, APP_ROOT_LAYOUT_KEY, APP_SKIPPED_LAYOUT_IDS_KEY, APP_STATIC_SIBLINGS_KEY, AppElementsWire, normalizeAppElementsSlotBindings } from "./app-elements-wire.js";
|
|
5
7
|
import { APP_PREFETCH_LOADING_SHELL_MARKER_KEY, APP_STREAMING_METADATA_BODY_ID_PREFIX } from "./app-elements.js";
|
|
6
8
|
import { createBfcacheChildSegmentStateKey } from "./bfcache-identity.js";
|
|
7
|
-
import { AppRouterScrollTarget } from "../shims/app-router-scroll.js";
|
|
8
|
-
import { hashMountedLayoutIdentity } from "./app-mounted-layouts.js";
|
|
9
9
|
import { BfcacheChildrenBoundary, BfcacheSegmentBoundary, Children as Children$1, ParallelSlot, Slot } from "../shims/slot.js";
|
|
10
|
-
import
|
|
10
|
+
import DefaultForbidden from "../shims/default-forbidden.js";
|
|
11
11
|
import DefaultGlobalError from "../shims/default-global-error.js";
|
|
12
|
+
import DefaultNotFound from "../shims/default-not-found.js";
|
|
13
|
+
import DefaultUnauthorized from "../shims/default-unauthorized.js";
|
|
12
14
|
import { ErrorBoundary, ForbiddenBoundary, GlobalErrorBoundary, HttpAccessFallbackPassthrough, NotFoundBoundary, RedirectBoundary, UnauthorizedBoundary } from "../shims/error-boundary.js";
|
|
13
15
|
import { LayoutSegmentProvider } from "../shims/layout-segment-context.js";
|
|
14
|
-
import { withUseCacheLayoutMarker } from "../shims/internal/app-page-props-cache-key.js";
|
|
15
16
|
import { MetadataHead, ViewportHead, renderMetadataToHtml } from "../shims/metadata.js";
|
|
17
|
+
import { StreamedIconsInsertion } from "../shims/streamed-icons.js";
|
|
18
|
+
import { hashMountedLayoutIdentity } from "./app-mounted-layouts.js";
|
|
19
|
+
import { APP_PAGE_SEGMENT_KEY, isAppPageRouteGroupSegment, resolveAppPageChildSegments, resolveAppPageSegmentStateKey, resolveAppPageTemplateStateKey } from "./app-page-segment-state.js";
|
|
16
20
|
import { APP_PAGE_NOT_FOUND_BOUNDARY_ID, tagAppPageLayoutError, tagAppPageSlotError } from "./app-page-execution.js";
|
|
17
21
|
import { resolveAppPageBranchParams, resolveAppPageSegmentParams } from "./app-page-params.js";
|
|
18
|
-
import DefaultForbidden from "../shims/default-forbidden.js";
|
|
19
|
-
import DefaultNotFound from "../shims/default-not-found.js";
|
|
20
|
-
import DefaultUnauthorized from "../shims/default-unauthorized.js";
|
|
21
|
-
import { StreamedIconsInsertion } from "../shims/streamed-icons.js";
|
|
22
22
|
import { createAppRenderDependency, invokeAppComponentMappingErrors, isReactOwnedAppComponent, renderAfterAppDependencies, renderAppComponentWithDependencyBarrier } from "./app-render-dependency.js";
|
|
23
23
|
import { createAppPageLayoutGate, registerAppPageLayoutGate } from "./app-page-layout-gate.js";
|
|
24
24
|
import { probeReactServerSubtree } from "./app-page-probe.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { setHeadersContext } from "../shims/headers.js";
|
|
2
|
+
import { setRootParams } from "../shims/root-params.js";
|
|
2
3
|
import { setNavigationContext } from "../shims/navigation-context-state.js";
|
|
3
4
|
import "../shims/navigation-server.js";
|
|
4
|
-
import { setRootParams } from "../shims/root-params.js";
|
|
5
5
|
//#region src/server/app-request-context.ts
|
|
6
6
|
/**
|
|
7
7
|
* Set navigation context in the ALS-backed store. "use client" components
|
|
@@ -14,9 +14,9 @@ import { ensureFetchPatch, getCollectedFetchTags, setCurrentFetchCacheMode, setC
|
|
|
14
14
|
import { resolveAppRouteHandlerFetchCacheMode } from "./app-segment-config.js";
|
|
15
15
|
import { traceResponseStart } from "./response-start-tracing.js";
|
|
16
16
|
import { applyRouteHandlerMiddlewareContext, finalizeRouteHandlerResponse } from "./app-route-handler-response.js";
|
|
17
|
+
import { makeThenableParams } from "../shims/thenable-params.js";
|
|
17
18
|
import { setNavigationContext } from "../shims/navigation-context-state.js";
|
|
18
19
|
import "../shims/navigation.js";
|
|
19
|
-
import { makeThenableParams } from "../shims/thenable-params.js";
|
|
20
20
|
import { buildPageCacheTags } from "./implicit-tags.js";
|
|
21
21
|
import { isKnownDynamicAppRoute, isValidHTTPMethod } from "./app-route-handler-runtime.js";
|
|
22
22
|
import { getAppRouteHandlerRevalidateSeconds, hasAppRouteHandlerDefaultExport, hasNonStaticAppRouteHandlerMethods, resolveAppRouteHandlerMethod, shouldReadAppRouteHandlerCache } from "./app-route-handler-policy.js";
|
|
@@ -10,8 +10,8 @@ import { isDraftModeRequest, setHeadersContext } from "../shims/headers.js";
|
|
|
10
10
|
import { _drainPendingRevalidations } from "../shims/cache-request-state.js";
|
|
11
11
|
import { copyLinkHeaderProvenance } from "./app-response-header-provenance.js";
|
|
12
12
|
import { applyRouteHandlerMiddlewareContext, applyRouteHandlerRevalidateHeader, assertSupportedAppRouteHandlerResponse, buildAppRouteCacheValue, finalizeRouteHandlerResponse, markRouteHandlerCacheMiss } from "./app-route-handler-response.js";
|
|
13
|
-
import { isPossibleAppRouteActionRequest } from "./app-action-request.js";
|
|
14
13
|
import { runWithRootParamsUsage } from "../shims/root-params.js";
|
|
14
|
+
import { isPossibleAppRouteActionRequest } from "./app-action-request.js";
|
|
15
15
|
import { createTrackedAppRouteRequest, markKnownDynamicAppRoute } from "./app-route-handler-runtime.js";
|
|
16
16
|
import { resolveAppRouteHandlerSpecialError, shouldApplyAppRouteHandlerRevalidateHeader, shouldCompleteAppRouteHandlerResponse, shouldWriteAppRouteHandlerCache } from "./app-route-handler-policy.js";
|
|
17
17
|
import { createStaticGenerationHeadersContext, getAppRouteStaticGenerationErrorMessage } from "./app-static-generation.js";
|
|
@@ -17,6 +17,7 @@ type FinalizeRouteHandlerResponseOptions = {
|
|
|
17
17
|
draftCookie?: string | null;
|
|
18
18
|
isHead: boolean;
|
|
19
19
|
};
|
|
20
|
+
export declare function stripRouteHandlerFramingHeaders(response: Response): Response;
|
|
20
21
|
export declare function applyRouteHandlerMiddlewareContext(response: Response, middlewareContext: RouteHandlerMiddlewareContext, options?: MiddlewareResponseMergeOptions & {
|
|
21
22
|
appendResponseLink?: boolean;
|
|
22
23
|
}): Response;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { preserveFullyBufferedBodyMetadata } from "./fully-buffered-response.js";
|
|
1
2
|
import "../utils/protocol-headers.js";
|
|
2
3
|
import { NEXT_CACHE_TAGS_HEADER, VINEXT_METADATA_ROUTE_CACHE_HEADER } from "./headers.js";
|
|
3
4
|
import { processMiddlewareHeaders } from "./request-pipeline.js";
|
|
@@ -11,6 +12,28 @@ import { getSetCookieName } from "./cookie-utils.js";
|
|
|
11
12
|
//#region src/server/app-route-handler-response.ts
|
|
12
13
|
const APP_ROUTE_REWRITE_ERROR = "NextResponse.rewrite() was used in a app route handler, this is not currently supported. Please remove the invocation to continue.";
|
|
13
14
|
const APP_ROUTE_NEXT_ERROR = "NextResponse.next() was used in a app route handler, this is not supported. See here for more info: https://nextjs.org/docs/messages/next-response-next-in-app-route-handler";
|
|
15
|
+
const ROUTE_HANDLER_FRAMING_HEADERS = [
|
|
16
|
+
"content-length",
|
|
17
|
+
"content-encoding",
|
|
18
|
+
"transfer-encoding"
|
|
19
|
+
];
|
|
20
|
+
function shouldDropRouteHandlerFramingHeaders(headers) {
|
|
21
|
+
if ("WebSocketPair" in globalThis) return false;
|
|
22
|
+
return ROUTE_HANDLER_FRAMING_HEADERS.some((name) => headers.has(name));
|
|
23
|
+
}
|
|
24
|
+
function deleteRouteHandlerFramingHeaders(headers) {
|
|
25
|
+
for (const name of ROUTE_HANDLER_FRAMING_HEADERS) headers.delete(name);
|
|
26
|
+
}
|
|
27
|
+
function stripRouteHandlerFramingHeaders(response) {
|
|
28
|
+
if (!shouldDropRouteHandlerFramingHeaders(response.headers)) return response;
|
|
29
|
+
const headers = new Headers(response.headers);
|
|
30
|
+
deleteRouteHandlerFramingHeaders(headers);
|
|
31
|
+
return preserveFullyBufferedBodyMetadata(response, new Response(response.body, {
|
|
32
|
+
status: response.status,
|
|
33
|
+
statusText: response.statusText,
|
|
34
|
+
headers
|
|
35
|
+
}));
|
|
36
|
+
}
|
|
14
37
|
function hasMiddlewareHeader(headers) {
|
|
15
38
|
for (const key of headers.keys()) if (key.startsWith("x-middleware-")) return true;
|
|
16
39
|
return false;
|
|
@@ -42,6 +65,7 @@ function buildRouteHandlerCachedResponse(cachedValue, options) {
|
|
|
42
65
|
else headers.set(key, value);
|
|
43
66
|
headers.delete(NEXT_CACHE_TAGS_HEADER);
|
|
44
67
|
headers.delete(VINEXT_METADATA_ROUTE_CACHE_HEADER);
|
|
68
|
+
if (shouldDropRouteHandlerFramingHeaders(headers)) deleteRouteHandlerFramingHeaders(headers);
|
|
45
69
|
setCacheStateHeaders(headers, options.cacheState);
|
|
46
70
|
const { cacheControl } = decideIsr({
|
|
47
71
|
cacheState: options.cacheState,
|
|
@@ -152,8 +176,9 @@ async function buildAppRouteCacheValue(response, browserCacheControl) {
|
|
|
152
176
|
}
|
|
153
177
|
function finalizeRouteHandlerResponse(response, options) {
|
|
154
178
|
const { pendingCookies, draftCookie, isHead } = options;
|
|
155
|
-
if (pendingCookies.length === 0 && !draftCookie && !isHead && !hasMiddlewareHeader(response.headers)) return response;
|
|
179
|
+
if (pendingCookies.length === 0 && !draftCookie && !isHead && !hasMiddlewareHeader(response.headers) && !shouldDropRouteHandlerFramingHeaders(response.headers)) return response;
|
|
156
180
|
const headers = new Headers(response.headers);
|
|
181
|
+
if (shouldDropRouteHandlerFramingHeaders(headers)) deleteRouteHandlerFramingHeaders(headers);
|
|
157
182
|
processMiddlewareHeaders(headers);
|
|
158
183
|
applyMutableCookieFallbacks(headers, pendingCookies);
|
|
159
184
|
if (draftCookie) headers.append("Set-Cookie", draftCookie);
|
|
@@ -164,4 +189,4 @@ function finalizeRouteHandlerResponse(response, options) {
|
|
|
164
189
|
});
|
|
165
190
|
}
|
|
166
191
|
//#endregion
|
|
167
|
-
export { applyRouteHandlerMiddlewareContext, applyRouteHandlerRevalidateHeader, assertSupportedAppRouteHandlerResponse, buildAppRouteCacheValue, buildRouteHandlerCachedResponse, finalizeRouteHandlerResponse, markRouteHandlerCacheMiss };
|
|
192
|
+
export { applyRouteHandlerMiddlewareContext, applyRouteHandlerRevalidateHeader, assertSupportedAppRouteHandlerResponse, buildAppRouteCacheValue, buildRouteHandlerCachedResponse, finalizeRouteHandlerResponse, markRouteHandlerCacheMiss, stripRouteHandlerFramingHeaders };
|
|
@@ -34,6 +34,8 @@ import { setFrameworkRequestRoute, traceFrameworkRequest } from "./request-traci
|
|
|
34
34
|
import { mergeMiddlewareResponseHeaders, mergeMiddlewareResponseHeadersOntoResponse, withExternalRewriteResponseHeaders } from "./middleware-response-headers.js";
|
|
35
35
|
import { VINEXT_RSC_CACHE_BUSTING_SEARCH_PARAM, canonicalizeDynamicShellRscRequestHeaders, canonicalizeLoadingShellRscRequestHeaders, canonicalizePrewarmableRscRequestHeaders, createCanonicalRscRequestUrl, createRscRedirectLocation, createRscRequestUrl, hasRscCacheBustingSearchParam, resolveInvalidRscCacheBustingRequest, stripRscCacheBustingSearchParam } from "./app-rsc-cache-busting.js";
|
|
36
36
|
import { matchPrerenderRouteParamsPayload, readTrustedPrerenderRouteParams, serializePrerenderRouteParamsHeader } from "./prerender-route-params.js";
|
|
37
|
+
import { flattenErrorCauses } from "../utils/error-cause.js";
|
|
38
|
+
import { pickRootParams, setRootParams } from "../shims/root-params.js";
|
|
37
39
|
import { applyAppRscConfigHeaders, finalizeAppRscResponse, isStreamedActionRedirectResponse, markAppRscApplicationResponse, markAppRscResponseConfigHeadersApplied, markAppRscRouteHandlerResponse, markStreamedActionRedirectResponse } from "./app-rsc-response-finalizer.js";
|
|
38
40
|
import { createServerActionNotFoundResponse, getServerActionNotFoundMessage } from "./server-action-not-found.js";
|
|
39
41
|
import { isPossibleAppRouteActionRequest } from "./app-action-request.js";
|
|
@@ -45,10 +47,8 @@ import { traceAppPageRender } from "./app-page-tracing.js";
|
|
|
45
47
|
import { normalizeInterceptionContextHeader } from "./app-interception-context-header.js";
|
|
46
48
|
import { buildPageCacheTags } from "./implicit-tags.js";
|
|
47
49
|
import { buildPostMwRequestContext } from "./app-post-middleware-context.js";
|
|
48
|
-
import { pickRootParams, setRootParams } from "../shims/root-params.js";
|
|
49
50
|
import { createRouteTreePrefetchResponse, isRouteTreePrefetchRequest } from "./app-route-tree-prefetch.js";
|
|
50
51
|
import { createSharedAppCacheIdentity, createSharedAppPageCacheIdentity, createSharedAppRouteCacheIdentity, createSharedHybridPagesCacheIdentity, isStaticCandidateAppPageDispatch, prepareSharedAppPageDispatch, withoutAppPageDispatchQuery } from "./app-worker-stages.js";
|
|
51
|
-
import { flattenErrorCauses } from "../utils/error-cause.js";
|
|
52
52
|
import { normalizeRscRequest } from "./app-rsc-request-normalization.js";
|
|
53
53
|
import { hasPagesPreviewCookie } from "./pages-response-stage.js";
|
|
54
54
|
import { runWithPrerenderWorkUnit } from "./prerender-work-unit-setup.js";
|
|
@@ -11,9 +11,9 @@ import { ensureFetchPatch, setCurrentFetchSoftTags } from "../shims/fetch-cache.
|
|
|
11
11
|
import { traceFindPageComponents } from "./pages-execution-tracing.js";
|
|
12
12
|
import { getRenderedConcreteUrlPathsForRoute } from "./pregenerated-concrete-paths.js";
|
|
13
13
|
import { VINEXT_RSC_CACHE_BUSTING_SEARCH_PARAM, hasRscCacheBustingSearchParam, stripRscCacheBustingSearchParam } from "./app-rsc-cache-busting.js";
|
|
14
|
+
import { pickRootParams, setRootParams } from "../shims/root-params.js";
|
|
14
15
|
import { traceAppPageRender } from "./app-page-tracing.js";
|
|
15
16
|
import { buildPageCacheTags } from "./implicit-tags.js";
|
|
16
|
-
import { pickRootParams, setRootParams } from "../shims/root-params.js";
|
|
17
17
|
import "./app-worker-stages.js";
|
|
18
18
|
import { normalizeRscRequest } from "./app-rsc-request-normalization.js";
|
|
19
19
|
import { runWithPrerenderWorkUnit } from "./prerender-work-unit-setup.js";
|
|
@@ -22,6 +22,7 @@ import { readStreamAsTextWithLimit } from "../utils/text-stream.js";
|
|
|
22
22
|
import { mergeMiddlewareResponseHeaders } from "./middleware-response-headers.js";
|
|
23
23
|
import { VINEXT_RSC_CONTENT_TYPE, applyRscCompatibilityIdHeader, createRscRequestUrl, stripRscCacheBustingSearchParam } from "./app-rsc-cache-busting.js";
|
|
24
24
|
import { getSetCookieName } from "./cookie-utils.js";
|
|
25
|
+
import { createRootParamsUsageController, runWithRootParamsUsage } from "../shims/root-params.js";
|
|
25
26
|
import { markAppRscResponseConfigHeadersApplied, markStreamedActionRedirectResponse } from "./app-rsc-response-finalizer.js";
|
|
26
27
|
import { createServerActionNotFoundResponse, getServerActionNotFoundMessage, isServerActionNotFoundError } from "./server-action-not-found.js";
|
|
27
28
|
import { applyEdgeRuntimeHeader } from "./app-page-response.js";
|
|
@@ -32,7 +33,6 @@ import { hasDigest } from "./app-rsc-errors.js";
|
|
|
32
33
|
import { buildAppPageTags } from "./implicit-tags.js";
|
|
33
34
|
import { resolveAppPageInterceptSegmentConfig } from "./app-page-intercept-segment-config.js";
|
|
34
35
|
import { resolveAppPageActionRerenderTarget } from "./app-page-request.js";
|
|
35
|
-
import { createRootParamsUsageController, runWithRootParamsUsage } from "../shims/root-params.js";
|
|
36
36
|
import { createStaticGenerationHeadersContext } from "./app-static-generation.js";
|
|
37
37
|
//#region src/server/app-server-action-execution.ts
|
|
38
38
|
/**
|
|
@@ -13,28 +13,28 @@ import { getClientTraceMetadataHTML, markClientTraceMetadataBlock } from "./clie
|
|
|
13
13
|
import { setPagesClientAssets } from "./pages-client-assets.js";
|
|
14
14
|
import { RSC_FORM_STATE_GLOBAL } from "../client/browser-globals.js";
|
|
15
15
|
import { createNavigationRuntimeRenderedSearchScript, createNavigationRuntimeRscCompatibilityScript, createNavigationRuntimeRscMetadataScript, createRscEmbedTransform, createTickBufferedTransform, rewriteInlineCssStylesheetLinks, waitAtLeastOneReactRenderTask } from "./app-ssr-stream.js";
|
|
16
|
-
import {
|
|
17
|
-
import "
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
16
|
+
import { withAppRouterTree } from "../shims/app-router-tree-context.js";
|
|
17
|
+
import { BeforeInteractiveContext } from "../shims/before-interactive-context.js";
|
|
18
|
+
import { runWithRootParamsScope } from "../shims/root-params.js";
|
|
19
|
+
import { CAUGHT_NOT_FOUND_BOUNDARIES_GLOBAL, withCaughtNotFoundBoundaries } from "../shims/caught-not-found-boundaries.js";
|
|
20
20
|
import { ServerInsertedHTMLContext, clearServerInsertedHTML, getBfcacheIdMapContext, registerServerInsertedHTMLCallback, renderServerInsertedHTML, setNavigationContext } from "../shims/navigation-context-state.js";
|
|
21
|
+
import { isBailoutToCSRError, isDynamicServerError } from "../shims/navigation-errors.js";
|
|
21
22
|
import "../shims/navigation-server.js";
|
|
23
|
+
import { AppElementsWire } from "./app-elements-wire.js";
|
|
24
|
+
import "./app-elements.js";
|
|
22
25
|
import { BfcacheIdentityMapContext } from "../shims/slot.js";
|
|
23
|
-
import { createAppRouteTree } from "./app-route-tree.js";
|
|
24
26
|
import DefaultGlobalError from "../shims/default-global-error.js";
|
|
25
|
-
import {
|
|
27
|
+
import { runWithNavigationContext } from "../shims/navigation-state.js";
|
|
28
|
+
import { createInitialBfcacheMaps } from "./app-bfcache-identity.js";
|
|
29
|
+
import { createAppRouteTree } from "./app-route-tree.js";
|
|
26
30
|
import { ssrServerConsumerManifest } from "./app-client-reference-manifest.js";
|
|
27
31
|
import { createClientReferencePreloader, resolveRouteClientReferences } from "./app-client-reference-preloader.js";
|
|
28
32
|
import { getNextErrorDigest } from "./next-error-digest.js";
|
|
29
33
|
import { createSsrErrorMetaRenderer } from "./app-ssr-error-meta.js";
|
|
30
34
|
import { createClientPageSsrSearchParamsSource } from "./app-page-search-params-observation.js";
|
|
31
35
|
import { createRenderStreamCancellation, isAppRenderAbortError } from "./app-render-abort-error.js";
|
|
32
|
-
import { runWithRootParamsScope } from "../shims/root-params.js";
|
|
33
|
-
import { runWithNavigationContext } from "../shims/navigation-state.js";
|
|
34
36
|
import { startCandidateSearchParamsGate } from "./app-ssr-search-params-gate.js";
|
|
35
37
|
import { isSrvxAbsoluteFormTarget } from "./srvx-request-target.js";
|
|
36
|
-
import { withAppRouterTree } from "../shims/app-router-tree-context.js";
|
|
37
|
-
import { BeforeInteractiveContext } from "../shims/before-interactive-context.js";
|
|
38
38
|
import { renderBeforeInteractiveInlineScripts } from "./before-interactive-head.js";
|
|
39
39
|
import { createInitialDevServerErrorScript } from "./dev-initial-server-error.js";
|
|
40
40
|
import { createStreamedClientReferences, renderStreamedStylesheets, resetStreamedClientReferences, runWithStreamedClientReferences, wrapClientReferenceRequire } from "./app-streamed-client-references.js";
|
|
@@ -5,8 +5,12 @@ export type EdgeApiExecutionRuntime = "node" | "worker";
|
|
|
5
5
|
* Remove wire-level body headers after Node's fetch implementation has decoded
|
|
6
6
|
* an Edge API response. Next.js applies the same boundary in its edge sandbox.
|
|
7
7
|
*
|
|
8
|
-
* Workers keep the original response untouched: workerd preserves
|
|
9
|
-
* body/header pair and can stream it directly to the client.
|
|
8
|
+
* Workers otherwise keep the original response untouched: workerd preserves
|
|
9
|
+
* the encoded body/header pair and can stream it directly to the client.
|
|
10
|
+
*
|
|
11
|
+
* Both runtimes drop `x-middleware-set-cookie`, the internal copy of the
|
|
12
|
+
* cookies that `NextResponse.cookies` keeps for middleware. Next.js's
|
|
13
|
+
* send-response never writes it to the client.
|
|
10
14
|
*/
|
|
11
15
|
export declare function finalizeEdgeApiResponse(response: Response, runtime: EdgeApiExecutionRuntime): Response;
|
|
12
16
|
//#endregion
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { MIDDLEWARE_SET_COOKIE_HEADER } from "../utils/protocol-headers.js";
|
|
2
|
+
import "./headers.js";
|
|
1
3
|
//#region src/server/edge-api-runtime.ts
|
|
2
4
|
function isEdgeApiRuntime(runtime) {
|
|
3
5
|
return runtime === "edge" || runtime === "experimental-edge";
|
|
@@ -11,13 +13,28 @@ const NODE_EDGE_RESPONSE_FORBIDDEN_HEADERS = [
|
|
|
11
13
|
* Remove wire-level body headers after Node's fetch implementation has decoded
|
|
12
14
|
* an Edge API response. Next.js applies the same boundary in its edge sandbox.
|
|
13
15
|
*
|
|
14
|
-
* Workers keep the original response untouched: workerd preserves
|
|
15
|
-
* body/header pair and can stream it directly to the client.
|
|
16
|
+
* Workers otherwise keep the original response untouched: workerd preserves
|
|
17
|
+
* the encoded body/header pair and can stream it directly to the client.
|
|
18
|
+
*
|
|
19
|
+
* Both runtimes drop `x-middleware-set-cookie`, the internal copy of the
|
|
20
|
+
* cookies that `NextResponse.cookies` keeps for middleware. Next.js's
|
|
21
|
+
* send-response never writes it to the client.
|
|
16
22
|
*/
|
|
17
23
|
function finalizeEdgeApiResponse(response, runtime) {
|
|
18
|
-
if (runtime === "worker")
|
|
24
|
+
if (runtime === "worker") {
|
|
25
|
+
if (!response.headers.has("x-middleware-set-cookie")) return response;
|
|
26
|
+
try {
|
|
27
|
+
response.headers.delete(MIDDLEWARE_SET_COOKIE_HEADER);
|
|
28
|
+
return response;
|
|
29
|
+
} catch {
|
|
30
|
+
const copy = new Response(response.body, response);
|
|
31
|
+
copy.headers.delete(MIDDLEWARE_SET_COOKIE_HEADER);
|
|
32
|
+
return copy;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
19
35
|
const headers = new Headers(response.headers);
|
|
20
|
-
let changed =
|
|
36
|
+
let changed = headers.has(MIDDLEWARE_SET_COOKIE_HEADER);
|
|
37
|
+
headers.delete(MIDDLEWARE_SET_COOKIE_HEADER);
|
|
21
38
|
for (const name of NODE_EDGE_RESPONSE_FORBIDDEN_HEADERS) {
|
|
22
39
|
if (!headers.has(name)) continue;
|
|
23
40
|
headers.delete(name);
|
|
@@ -16,7 +16,7 @@ import { _consumeRequestScopedCacheLife, _isOnDemandRevalidate } from "../shims/
|
|
|
16
16
|
import { ensureFetchPatch, getCollectedFetchTags, setCurrentFetchSoftTags } from "../shims/fetch-cache.js";
|
|
17
17
|
import { applyPrerenderCacheLifeHeader, applyPrerenderCacheTagsHeader } from "./prerender-cache-life-header.js";
|
|
18
18
|
import { isValidMetadataImageId, manifestToJson, matchMetadataRoutePattern, robotsToText, sitemapToXml } from "./metadata-routes.js";
|
|
19
|
-
import { buildAppRouteCacheValue, buildRouteHandlerCachedResponse } from "./app-route-handler-response.js";
|
|
19
|
+
import { buildAppRouteCacheValue, buildRouteHandlerCachedResponse, stripRouteHandlerFramingHeaders } from "./app-route-handler-response.js";
|
|
20
20
|
import { canonicalizeAppPageParams } from "./app-page-segment-state.js";
|
|
21
21
|
import { buildPageCacheTags } from "./implicit-tags.js";
|
|
22
22
|
import { createStaticGenerationHeadersContext } from "./app-static-generation.js";
|
|
@@ -261,7 +261,7 @@ async function renderMetadataRouteMiss(options, route, render, cachedEntry) {
|
|
|
261
261
|
const rendered = await render();
|
|
262
262
|
if (!rendered) return null;
|
|
263
263
|
await writeMetadataRouteMiss(options, route, rendered, cachedEntry);
|
|
264
|
-
return rendered.response;
|
|
264
|
+
return stripRouteHandlerFramingHeaders(rendered.response);
|
|
265
265
|
};
|
|
266
266
|
const routeKey = _isOnDemandRevalidate() ? getOuterMetadataCacheKey(options, route) : null;
|
|
267
267
|
if (routeKey === null || !options.isrSet) return renderAndStore();
|
|
@@ -262,11 +262,12 @@ function createFreshFetchDecision(facts, reason) {
|
|
|
262
262
|
}
|
|
263
263
|
function classifyNavigationReuse(facts) {
|
|
264
264
|
if (facts.navigationKind === "refresh") return createFreshFetchDecision(facts, "refresh");
|
|
265
|
-
if (
|
|
265
|
+
if (facts.bypassNavigationCache) return createFreshFetchDecision(facts, "cacheBypassed");
|
|
266
|
+
if (facts.visitedResponse.status === "available") return {
|
|
266
267
|
kind: "reuseVisitedResponse",
|
|
267
268
|
trace: createNavigationReuseTrace(NavigationTraceReasonCodes.visitedResponseReuse, facts)
|
|
268
269
|
};
|
|
269
|
-
if (
|
|
270
|
+
if (facts.prefetch.status === "available") return {
|
|
270
271
|
kind: "consumePrefetch",
|
|
271
272
|
trace: createNavigationReuseTrace(NavigationTraceReasonCodes.prefetchResponseReuse, facts)
|
|
272
273
|
};
|
|
@@ -275,9 +276,8 @@ function classifyNavigationReuse(facts) {
|
|
|
275
276
|
kind: "attemptOptimisticRouteShell",
|
|
276
277
|
trace: createNavigationReuseTrace(NavigationTraceReasonCodes.optimisticRouteShell, facts)
|
|
277
278
|
};
|
|
278
|
-
return createFreshFetchDecision(facts, facts.
|
|
279
|
+
return createFreshFetchDecision(facts, facts.optimisticRouteShell.reason);
|
|
279
280
|
}
|
|
280
|
-
if (facts.bypassNavigationCache) return createFreshFetchDecision(facts, "cacheBypassed");
|
|
281
281
|
return createFreshFetchDecision(facts, "cacheMiss");
|
|
282
282
|
}
|
|
283
283
|
function classifyNavigationPrefetchProbe(facts) {
|
|
@@ -676,10 +676,11 @@ function planFlightResponseArrived(options) {
|
|
|
676
676
|
slotBindingSource: "manifestTarget",
|
|
677
677
|
snapshot: targetSnapshot
|
|
678
678
|
});
|
|
679
|
+
const renderedRootLayoutChanged = classifyRootBoundaryTransition(options.state.visibleSnapshot.rootBoundaryId, targetSnapshot.rootBoundaryId) === "rootBoundaryChanged";
|
|
679
680
|
const traceFields = createRootBoundaryTraceFields({
|
|
680
|
-
currentRootLayoutTreePath: currentTopology.kind === "known" ? currentTopology.topology.rootLayoutTreePath : null,
|
|
681
|
+
currentRootLayoutTreePath: renderedRootLayoutChanged ? options.state.visibleSnapshot.rootBoundaryId : currentTopology.kind === "known" ? currentTopology.topology.rootLayoutTreePath : null,
|
|
681
682
|
event: options.event,
|
|
682
|
-
nextRootLayoutTreePath: targetTopology.kind === "known" ? targetTopology.topology.rootLayoutTreePath : null,
|
|
683
|
+
nextRootLayoutTreePath: renderedRootLayoutChanged ? targetSnapshot.rootBoundaryId : targetTopology.kind === "known" ? targetTopology.topology.rootLayoutTreePath : null,
|
|
683
684
|
state: options.state
|
|
684
685
|
});
|
|
685
686
|
if (options.event.token.lane === "prefetch") return {
|
|
@@ -708,6 +709,13 @@ function planFlightResponseArrived(options) {
|
|
|
708
709
|
}
|
|
709
710
|
const commitTraceFields = createAcceptedCacheProofTraceFields(traceFields, acceptedCacheEntryDecision);
|
|
710
711
|
const cacheEntryProposalFields = createCacheEntryProposalFields(acceptedCacheEntryDecision);
|
|
712
|
+
if (renderedRootLayoutChanged) return {
|
|
713
|
+
kind: "hardNavigate",
|
|
714
|
+
reason: "rootBoundaryChanged",
|
|
715
|
+
token: options.event.token,
|
|
716
|
+
trace: createNavigationTrace(NavigationTraceReasonCodes.rootBoundaryChanged, commitTraceFields),
|
|
717
|
+
url: options.event.result.href
|
|
718
|
+
};
|
|
711
719
|
if (targetSnapshot.interception !== null) {
|
|
712
720
|
if (currentTopology.kind === "unknown" || targetTopology.kind === "unknown") return createInterceptionProofRejectedDecision({
|
|
713
721
|
event: options.event,
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { IncomingMessage } from "node:http";
|
|
2
|
+
import { Http2ServerRequest } from "node:http2";
|
|
3
|
+
//#region src/server/remove-request-headers.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Remove headers from every view of a Node request.
|
|
6
|
+
*
|
|
7
|
+
* Node keeps each client header in req.rawHeaders as well as req.headers, and
|
|
8
|
+
* srvx (plugin-rsc's dev request adapter) answers Headers reads from rawHeaders
|
|
9
|
+
* once anything iterates them, so later handlers must not find a removed
|
|
10
|
+
* header in either. On HTTP/1, Node builds req.headers and req.headersDistinct
|
|
11
|
+
* lazily from rawHeaders and the header count it parsed, so both must exist
|
|
12
|
+
* before rawHeaders gets shorter. HTTP/2 compatibility requests (Vite with
|
|
13
|
+
* `server.https`) have no headersDistinct.
|
|
14
|
+
*/
|
|
15
|
+
export declare function removeRequestHeaders(req: IncomingMessage | Http2ServerRequest, names: ReadonlySet<string>): void;
|
|
16
|
+
//#endregion
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//#region src/server/remove-request-headers.ts
|
|
2
|
+
/**
|
|
3
|
+
* Remove headers from every view of a Node request.
|
|
4
|
+
*
|
|
5
|
+
* Node keeps each client header in req.rawHeaders as well as req.headers, and
|
|
6
|
+
* srvx (plugin-rsc's dev request adapter) answers Headers reads from rawHeaders
|
|
7
|
+
* once anything iterates them, so later handlers must not find a removed
|
|
8
|
+
* header in either. On HTTP/1, Node builds req.headers and req.headersDistinct
|
|
9
|
+
* lazily from rawHeaders and the header count it parsed, so both must exist
|
|
10
|
+
* before rawHeaders gets shorter. HTTP/2 compatibility requests (Vite with
|
|
11
|
+
* `server.https`) have no headersDistinct.
|
|
12
|
+
*/
|
|
13
|
+
function removeRequestHeaders(req, names) {
|
|
14
|
+
const headersDistinct = "headersDistinct" in req ? req.headersDistinct : void 0;
|
|
15
|
+
for (const name of names) {
|
|
16
|
+
delete req.headers[name];
|
|
17
|
+
if (headersDistinct) delete headersDistinct[name];
|
|
18
|
+
}
|
|
19
|
+
const rawHeaders = req.rawHeaders;
|
|
20
|
+
for (let i = rawHeaders.length - 2; i >= 0; i -= 2) if (names.has(rawHeaders[i].toLowerCase())) rawHeaders.splice(i, 2);
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
export { removeRequestHeaders };
|
|
@@ -14,9 +14,9 @@ import { isDraftModeEnabled } from "./headers.js";
|
|
|
14
14
|
import { _registerCacheContextAccessor } from "./internal/cache-context-accessor.js";
|
|
15
15
|
import { _hasPendingRevalidatedTag, _isOnDemandRevalidate, _setRequestScopedCacheLife, cacheLifeProfiles, runWithDetachedCacheObservations, shouldServeStaleUnstableCacheEntry } from "./cache-request-state.js";
|
|
16
16
|
import "./fetch-cache.js";
|
|
17
|
-
import { hasUseCacheLayoutMarker, hasUseCachePageMarker, isUseCacheFunctionReference, withoutUseCacheSegmentMarker } from "./internal/app-page-props-cache-key.js";
|
|
18
17
|
import { isWellKnownProperty } from "./internal/thenable-well-known-properties.js";
|
|
19
18
|
import { getFallbackParamsSnapshot, restoreThenableParams } from "./thenable-params.js";
|
|
19
|
+
import { hasUseCacheLayoutMarker, hasUseCachePageMarker, isUseCacheFunctionReference, withoutUseCacheSegmentMarker } from "./internal/app-page-props-cache-key.js";
|
|
20
20
|
import { getCurrentRootParams } from "./root-params.js";
|
|
21
21
|
import { flightArgumentsKey, restoreFlightReply, snapshotFlightReply } from "./cache-flight-arguments.js";
|
|
22
22
|
import { cache } from "react";
|
package/dist/shims/cache.js
CHANGED
|
@@ -334,7 +334,7 @@ function unstable_cacheTag(...tags) {
|
|
|
334
334
|
}
|
|
335
335
|
return cacheTag(...tags);
|
|
336
336
|
}
|
|
337
|
-
const UNSTABLE_CACHE_KEY_PREFIX = "unstable_cache:
|
|
337
|
+
const UNSTABLE_CACHE_KEY_PREFIX = "unstable_cache:v4";
|
|
338
338
|
/**
|
|
339
339
|
* AsyncLocalStorage to track whether we're inside an unstable_cache() callback.
|
|
340
340
|
* Stored on globalThis via Symbol so headers.ts can detect the scope without
|
|
@@ -403,9 +403,12 @@ function scheduleUnstableCacheBackgroundRevalidation(cacheKey, refresh) {
|
|
|
403
403
|
pending.set(cacheKey, trackedRevalidation);
|
|
404
404
|
waitUntilUnstableCacheRevalidation(trackedRevalidation);
|
|
405
405
|
}
|
|
406
|
+
function runUnstableCacheCallback(fn, args) {
|
|
407
|
+
return _unstableCacheAls.run(true, () => _unstableCacheCallbackAls.run({ useCacheContext: _useCacheContextAls.getStore() }, () => fn(...args)));
|
|
408
|
+
}
|
|
406
409
|
async function refreshUnstableCacheResult(fn, args, keyedArgs, cacheKey, tags, revalidateSeconds, staleEntry, deferWrite) {
|
|
407
410
|
const argsUnchanged = serializeArgsOrNull(args) === keyedArgs;
|
|
408
|
-
const result = await
|
|
411
|
+
const result = await runUnstableCacheCallback(fn, args);
|
|
409
412
|
if (!argsUnchanged) return result;
|
|
410
413
|
const cacheValue = {
|
|
411
414
|
kind: "FETCH",
|
|
@@ -478,7 +481,7 @@ function unstable_cache(fn, keyParts, options) {
|
|
|
478
481
|
}
|
|
479
482
|
}
|
|
480
483
|
}
|
|
481
|
-
if (isDraftMode) return await
|
|
484
|
+
if (isDraftMode) return await runUnstableCacheCallback(fn, args);
|
|
482
485
|
return await refreshUnstableCacheResult(fn, args, keyedArgs, cacheKey, tags, revalidateSeconds, staleEntry, !staleEntry && isInsideWorkStoreScope());
|
|
483
486
|
};
|
|
484
487
|
return cachedFn;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { searchParamsToRecord } from "../utils/query.js";
|
|
3
|
+
import { isOwnPropertyCheck, isWellKnownProperty } from "./internal/thenable-well-known-properties.js";
|
|
3
4
|
import { getNavigationContext } from "./navigation-context-state.js";
|
|
4
|
-
import { getClientNavigationRenderContext, useSearchParams } from "./navigation.js";
|
|
5
5
|
import "./navigation-server.js";
|
|
6
|
+
import { getClientNavigationRenderContext, useSearchParams } from "./navigation.js";
|
|
6
7
|
import { RenderedSearchContext } from "./slot.js";
|
|
7
|
-
import { isOwnPropertyCheck, isWellKnownProperty } from "./internal/thenable-well-known-properties.js";
|
|
8
8
|
import { createElement, use, useMemo } from "react";
|
|
9
9
|
//#region src/shims/client-page-root.tsx
|
|
10
10
|
/**
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
import { isNavigationSignalError } from "../utils/navigation-signal.js";
|
|
3
3
|
import { handleAppNavigationFailure } from "../client/app-nav-failure-handler.js";
|
|
4
4
|
import { VINEXT_DEV_ERROR_RECOVERY_EVENT } from "../utils/dev-error-recovery-event.js";
|
|
5
|
+
import { consumeCaughtNotFoundBoundary, useCaughtNotFoundBoundary } from "./caught-not-found-boundaries.js";
|
|
5
6
|
import { decodeRedirectError, forbidden, isRedirectError, notFound, unauthorized } from "./navigation-errors.js";
|
|
6
7
|
import "./navigation-server.js";
|
|
7
|
-
import { isRedirectToCurrentUrl, useErrorBoundaryPathname, useErrorBoundaryRouter } from "./error-boundary-navigation.js";
|
|
8
8
|
import DefaultGlobalError from "./default-global-error.js";
|
|
9
|
-
import {
|
|
9
|
+
import { isRedirectToCurrentUrl, useErrorBoundaryPathname, useErrorBoundaryRouter } from "./error-boundary-navigation.js";
|
|
10
10
|
import React from "react";
|
|
11
11
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
12
12
|
//#region src/shims/error-boundary.tsx
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { getPagesNavigationContext } from "./pages-router-accessor.js";
|
|
2
1
|
import { getNavigationContext } from "../navigation-context-state.js";
|
|
2
|
+
import { getPagesNavigationContext } from "./pages-router-accessor.js";
|
|
3
3
|
import { getClientNavigationState, useClientNavigationRenderSnapshot } from "../navigation.js";
|
|
4
4
|
//#region src/shims/internal/navigation-untracked.ts
|
|
5
5
|
/**
|
package/dist/shims/metadata.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isAbsoluteOrProtocolRelativeUrl } from "./url-utils.js";
|
|
2
|
-
import { withUseCacheLayoutMarker, withUseCachePageMarker } from "./internal/app-page-props-cache-key.js";
|
|
3
2
|
import { makeThenableParams } from "./thenable-params.js";
|
|
3
|
+
import { withUseCacheLayoutMarker, withUseCachePageMarker } from "./internal/app-page-props-cache-key.js";
|
|
4
4
|
import React from "react";
|
|
5
5
|
import { Fragment as Fragment$1, jsx } from "react/jsx-runtime";
|
|
6
6
|
//#region src/shims/metadata.tsx
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { BailoutToCSRError, DynamicServerError, HTTP_ERROR_FALLBACK_ERROR_CODE, RedirectType, decodeRedirectError, forbidden, getAccessFallbackHTTPStatus, isBailoutToCSRError, isDynamicServerError, isHTTPAccessFallbackError, isNextRouterError, isRedirectError, notFound, permanentRedirect, redirect, unauthorized, unstable_rethrow } from "./navigation-errors.js";
|
|
2
1
|
import { GLOBAL_ACCESSORS_KEY, ServerInsertedHTMLContext, _registerStateAccessors, clearClientHydrationContext, clearServerInsertedHTML, flushServerInsertedHTML, getBfcacheIdMapContext, getBfcacheSegmentIdContext, getLayoutSegmentContext, getNavigationContext, registerServerInsertedHTMLCallback, renderServerInsertedHTML, setNavigationContext } from "./navigation-context-state.js";
|
|
2
|
+
import { BailoutToCSRError, DynamicServerError, HTTP_ERROR_FALLBACK_ERROR_CODE, RedirectType, decodeRedirectError, forbidden, getAccessFallbackHTTPStatus, isBailoutToCSRError, isDynamicServerError, isHTTPAccessFallbackError, isNextRouterError, isRedirectError, notFound, permanentRedirect, redirect, unauthorized, unstable_rethrow } from "./navigation-errors.js";
|
|
3
3
|
export { BailoutToCSRError, DynamicServerError, GLOBAL_ACCESSORS_KEY, HTTP_ERROR_FALLBACK_ERROR_CODE, RedirectType, ServerInsertedHTMLContext, _registerStateAccessors, clearClientHydrationContext, clearServerInsertedHTML, decodeRedirectError, flushServerInsertedHTML, forbidden, getAccessFallbackHTTPStatus, getBfcacheIdMapContext, getBfcacheSegmentIdContext, getLayoutSegmentContext, getNavigationContext, isBailoutToCSRError, isDynamicServerError, isHTTPAccessFallbackError, isNextRouterError, isRedirectError, notFound, permanentRedirect, redirect, registerServerInsertedHTMLCallback, renderServerInsertedHTML, setNavigationContext, unauthorized, unstable_rethrow };
|
package/dist/shims/navigation.js
CHANGED
|
@@ -15,7 +15,9 @@ import { VINEXT_RSC_COMPATIBILITY_ID_HEADER, VINEXT_RSC_CONTENT_TYPE, createRscR
|
|
|
15
15
|
import { clearAppNavigationFailureTarget, stageAppNavigationFailureTarget } from "../client/app-nav-failure-handler.js";
|
|
16
16
|
import { notifyAppRouterTransitionStart } from "../client/instrumentation-client-state.js";
|
|
17
17
|
import { getNavigationRuntime, hasAppNavigationRuntime, loadNavigationRuntimeRouteManifest } from "../client/navigation-runtime.js";
|
|
18
|
-
import {
|
|
18
|
+
import { beginAppRouterScrollIntent, clearAppRouterScrollIntent, consumeAppRouterScrollIntent, getPendingAppRouterScrollIntent, isLatestAppRouterScrollIntent } from "./app-router-scroll-state.js";
|
|
19
|
+
import { GLOBAL_ACCESSORS_KEY, ServerInsertedHTMLContext, _registerStateAccessors, clearClientHydrationContext, clearServerInsertedHTML, flushServerInsertedHTML, getBfcacheIdMapContext, getBfcacheSegmentIdContext, getLayoutSegmentContext, getNavigationContext, registerServerInsertedHTMLCallback, renderServerInsertedHTML, setNavigationContext } from "./navigation-context-state.js";
|
|
20
|
+
import { BailoutToCSRError, DynamicServerError, HTTP_ERROR_FALLBACK_ERROR_CODE, RedirectType, decodeRedirectError, forbidden, getAccessFallbackHTTPStatus, isBailoutToCSRError, isDynamicServerError, isHTTPAccessFallbackError, isNextRouterError, isRedirectError, notFound, permanentRedirect, redirect, unauthorized, unstable_rethrow } from "./navigation-errors.js";
|
|
19
21
|
import { AppElementsWire } from "../server/app-elements-wire.js";
|
|
20
22
|
import "../server/app-elements.js";
|
|
21
23
|
import { PUBLIC_INITIAL_BFCACHE_ID } from "../server/app-bfcache-id.js";
|
|
@@ -25,11 +27,9 @@ import { hasPendingAppRouterPageRedirect } from "../server/app-browser-mpa-navig
|
|
|
25
27
|
import { extractRscCompletionMetadata } from "../server/rsc-completion-metadata.js";
|
|
26
28
|
import { navigationPlanner } from "../server/navigation-planner.js";
|
|
27
29
|
import { ReadonlyURLSearchParams } from "./readonly-url-search-params.js";
|
|
28
|
-
import { BailoutToCSRError, DynamicServerError, HTTP_ERROR_FALLBACK_ERROR_CODE, RedirectType, decodeRedirectError, forbidden, getAccessFallbackHTTPStatus, isBailoutToCSRError, isDynamicServerError, isHTTPAccessFallbackError, isNextRouterError, isRedirectError, notFound, permanentRedirect, redirect, unauthorized, unstable_rethrow } from "./navigation-errors.js";
|
|
29
30
|
import { getPagesNavigationContext } from "./internal/pages-router-accessor.js";
|
|
30
|
-
import { beginAppRouterScrollIntent, clearAppRouterScrollIntent, consumeAppRouterScrollIntent, getPendingAppRouterScrollIntent, isLatestAppRouterScrollIntent } from "./app-router-scroll-state.js";
|
|
31
|
-
import { GLOBAL_ACCESSORS_KEY, ServerInsertedHTMLContext, _registerStateAccessors, clearClientHydrationContext, clearServerInsertedHTML, flushServerInsertedHTML, getBfcacheIdMapContext, getBfcacheSegmentIdContext, getLayoutSegmentContext, getNavigationContext, registerServerInsertedHTMLCallback, renderServerInsertedHTML, setNavigationContext } from "./navigation-context-state.js";
|
|
32
31
|
import { cancelAppPrefetchFetch, promoteAppPrefetchFetch, releaseAppPrefetchFetchSlot, scheduleAppPrefetchFetch } from "./internal/app-prefetch-fetch-queue.js";
|
|
32
|
+
import { UnrecognizedActionError, unstable_isUnrecognizedActionError } from "./unrecognized-action-error.js";
|
|
33
33
|
import * as React$1 from "react";
|
|
34
34
|
//#region src/shims/navigation.ts
|
|
35
35
|
/**
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { BailoutToCSRError, DynamicServerError, HTTP_ERROR_FALLBACK_ERROR_CODE, RedirectType, forbidden, getAccessFallbackHTTPStatus, isBailoutToCSRError, isDynamicServerError, isHTTPAccessFallbackError, isNextRouterError, isRedirectError, notFound, permanentRedirect, redirect, unauthorized, unstable_rethrow } from "./navigation-errors.js";
|
|
1
|
+
import { throwClientHookError } from "./client-hook-error.js";
|
|
3
2
|
import { GLOBAL_ACCESSORS_KEY, ServerInsertedHTMLContext, _registerStateAccessors, clearServerInsertedHTML, flushServerInsertedHTML, getLayoutSegmentContext, getNavigationContext, renderServerInsertedHTML, setNavigationContext } from "./navigation-context-state.js";
|
|
3
|
+
import { BailoutToCSRError, DynamicServerError, HTTP_ERROR_FALLBACK_ERROR_CODE, RedirectType, forbidden, getAccessFallbackHTTPStatus, isBailoutToCSRError, isDynamicServerError, isHTTPAccessFallbackError, isNextRouterError, isRedirectError, notFound, permanentRedirect, redirect, unauthorized, unstable_rethrow } from "./navigation-errors.js";
|
|
4
4
|
import "./navigation-server.js";
|
|
5
|
-
import {
|
|
5
|
+
import { ReadonlyURLSearchParams } from "./readonly-url-search-params.js";
|
|
6
6
|
//#region src/shims/navigation.react-server.ts
|
|
7
7
|
function usePathname() {
|
|
8
8
|
throwClientHookError("usePathname()");
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getOrCreateAls } from "./internal/als-registry.js";
|
|
2
2
|
import { getRequestContext, isInsideUnifiedScope, runWithUnifiedStateMutation } from "./unified-request-context.js";
|
|
3
|
-
import { _recordUseCacheRootParamRead } from "./internal/cache-context-accessor.js";
|
|
3
|
+
import { _recordUseCacheRootParamRead, getRegisteredCacheContext } from "./internal/cache-context-accessor.js";
|
|
4
4
|
//#region src/shims/root-params.ts
|
|
5
5
|
function createRootParamsUsageError(message) {
|
|
6
6
|
return new Error(message);
|
|
@@ -9,6 +9,7 @@ const _FALLBACK_KEY = Symbol.for("vinext.rootParams.fallback");
|
|
|
9
9
|
const _g = globalThis;
|
|
10
10
|
const _als = getOrCreateAls("vinext.rootParams.als");
|
|
11
11
|
const _usageAls = getOrCreateAls("vinext.rootParams.usage.als");
|
|
12
|
+
const _unstableCacheCallbackAls = getOrCreateAls("vinext.unstableCache.callbackAls");
|
|
12
13
|
const _fallbackState = _g[_FALLBACK_KEY] ??= { rootParams: null };
|
|
13
14
|
function getState() {
|
|
14
15
|
if (isInsideUnifiedScope()) return getRequestContext();
|
|
@@ -19,6 +20,16 @@ function pickRootParams(params, rootParamNames) {
|
|
|
19
20
|
for (const name of rootParamNames ?? []) picked[name] = params[name];
|
|
20
21
|
return picked;
|
|
21
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Like Next.js's `unstable-cache` work unit, an unstable_cache() callback has
|
|
25
|
+
* no root params, and neither does a "use cache" scope entered from it: the
|
|
26
|
+
* callback's entry is keyed by its source and arguments alone.
|
|
27
|
+
*/
|
|
28
|
+
function getUnstableCacheScope() {
|
|
29
|
+
const callback = _unstableCacheCallbackAls.getStore();
|
|
30
|
+
if (!callback) return null;
|
|
31
|
+
return (callback.useCacheContext ?? null) === getRegisteredCacheContext() ? "callback" : "use-cache";
|
|
32
|
+
}
|
|
22
33
|
function setRootParams(params) {
|
|
23
34
|
getState().rootParams = params;
|
|
24
35
|
}
|
|
@@ -26,12 +37,15 @@ function getRootParam(name) {
|
|
|
26
37
|
const usage = _usageAls.getStore();
|
|
27
38
|
if (usage?.kind === "server-action" && usage.phase === "active") throw createRootParamsUsageError(`\`import('next/root-params').${name}()\` was used inside a Server Action. This is not supported. Functions from 'next/root-params' can only be called in the context of a route.`);
|
|
28
39
|
if (usage?.kind === "route-handler" && usage.phase === "active") throw createRootParamsUsageError(`Route ${usage.routePattern} used \`import('next/root-params').${name}()\` inside a Route Handler. Support for this API in Route Handlers is planned for a future version of Next.js.`);
|
|
40
|
+
const unstableCacheScope = getUnstableCacheScope();
|
|
41
|
+
if (unstableCacheScope === "callback") throw createRootParamsUsageError(`\`import('next/root-params').${name}()\` was used inside \`unstable_cache\`. This is not supported. Use \`"use cache"\` instead.`);
|
|
42
|
+
if (unstableCacheScope === "use-cache") throw createRootParamsUsageError(`\`import('next/root-params').${name}()\` was used inside \`"use cache"\` nested within \`unstable_cache\`. Root params are not available in this context.`);
|
|
29
43
|
_recordUseCacheRootParamRead(name);
|
|
30
44
|
return Promise.resolve(getState().rootParams?.[name]);
|
|
31
45
|
}
|
|
32
46
|
/** @internal Current route root params for `"use cache"` key derivation. */
|
|
33
47
|
function getCurrentRootParams() {
|
|
34
|
-
return getState().rootParams;
|
|
48
|
+
return getUnstableCacheScope() ? null : getState().rootParams;
|
|
35
49
|
}
|
|
36
50
|
function runWithRootParamsUsage(usage, fn, controller) {
|
|
37
51
|
const state = {
|
package/dist/shims/slot.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { getBfcacheIdMapContext, getBfcacheSegmentIdContext } from "./navigation-context-state.js";
|
|
3
|
+
import { notFound } from "./navigation-errors.js";
|
|
4
|
+
import "./navigation-server.js";
|
|
2
5
|
import { APP_BFCACHE_SEGMENT_IDENTITIES_KEY, AppElementsWire, UNMATCHED_SLOT } from "../server/app-elements-wire.js";
|
|
3
6
|
import { readOptimisticStateKeyRebinder } from "../server/app-elements.js";
|
|
4
7
|
import { isNestedBfcacheSlotSegmentId, isNestedBfcacheSlotSegmentIdFor } from "../server/bfcache-identity.js";
|
|
5
|
-
import { notFound } from "./navigation-errors.js";
|
|
6
|
-
import { getBfcacheIdMapContext, getBfcacheSegmentIdContext } from "./navigation-context-state.js";
|
|
7
|
-
import "./navigation-server.js";
|
|
8
8
|
import * as React$1 from "react";
|
|
9
9
|
import { Fragment as Fragment$1, jsx } from "react/jsx-runtime";
|
|
10
10
|
//#region src/shims/slot.tsx
|