vinext 0.1.8 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +51 -30
- package/dist/build/inject-pregenerated-paths.d.ts +4 -0
- package/dist/build/inject-pregenerated-paths.js +18 -0
- package/dist/build/layout-classification.js +1 -1
- package/dist/build/nitro-route-rules.js +1 -1
- package/dist/build/pages-client-assets-module.d.ts +11 -0
- package/dist/build/pages-client-assets-module.js +27 -0
- package/dist/build/prerender.d.ts +2 -1
- package/dist/build/prerender.js +13 -6
- package/dist/build/report.d.ts +13 -2
- package/dist/build/report.js +99 -2
- package/dist/build/run-prerender.d.ts +7 -0
- package/dist/build/run-prerender.js +10 -1
- package/dist/build/standalone.js +2 -0
- package/dist/cache/cache-adapters-virtual.js +3 -3
- package/dist/check.js +40 -2
- package/dist/cli-args.d.ts +1 -2
- package/dist/cli-args.js +1 -1
- package/dist/cli-dev-config.d.ts +12 -0
- package/dist/cli-dev-config.js +23 -0
- package/dist/cli.js +111 -95
- package/dist/{server → client}/dev-error-overlay-store.d.ts +1 -1
- package/dist/{server → client}/dev-error-overlay-store.js +1 -1
- package/dist/{server → client}/dev-error-overlay.d.ts +1 -1
- package/dist/{server → client}/dev-error-overlay.js +2 -2
- package/dist/client/navigation-runtime.d.ts +2 -0
- package/dist/client/navigation-runtime.js +3 -1
- package/dist/client/window-next.d.ts +2 -1
- package/dist/cloudflare/index.d.ts +2 -2
- package/dist/cloudflare/index.js +2 -2
- package/dist/config/config-matchers.js +14 -10
- package/dist/config/next-config.d.ts +5 -3
- package/dist/config/next-config.js +44 -1
- package/dist/config/prerender.d.ts +34 -0
- package/dist/config/prerender.js +55 -0
- package/dist/entries/app-rsc-entry.d.ts +2 -1
- package/dist/entries/app-rsc-entry.js +40 -10
- package/dist/entries/app-rsc-manifest.js +2 -0
- package/dist/entries/pages-client-entry.d.ts +3 -0
- package/dist/entries/pages-client-entry.js +15 -1
- package/dist/entries/pages-server-entry.js +5 -2
- package/dist/image/image-adapters-virtual.d.ts +59 -0
- package/dist/image/image-adapters-virtual.js +59 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +167 -100
- package/dist/init-cloudflare.d.ts +43 -0
- package/dist/init-cloudflare.js +839 -0
- package/dist/init-platform.d.ts +40 -0
- package/dist/init-platform.js +195 -0
- package/dist/init.d.ts +16 -38
- package/dist/init.js +209 -99
- package/dist/node_modules/.pnpm/am-i-vibing@0.5.0/node_modules/am-i-vibing/dist/detector-1yx2Hoe0.js +294 -0
- package/dist/node_modules/.pnpm/process-ancestry@0.1.0/node_modules/process-ancestry/dist/index.js +94 -0
- package/dist/{cloudflare → packages/cloudflare}/src/cache/cdn-adapter.runtime.js +1 -1
- package/dist/{cloudflare → packages/cloudflare}/src/cache/kv-data-adapter.runtime.d.ts +2 -2
- package/dist/{cloudflare → packages/cloudflare}/src/cache/kv-data-adapter.runtime.js +1 -1
- package/dist/packages/cloudflare/src/deploy-config.js +150 -0
- package/dist/packages/cloudflare/src/deploy-help.js +55 -0
- package/dist/packages/cloudflare/src/deploy.js +276 -0
- package/dist/{cloudflare → packages/cloudflare/src}/tpr.d.ts +4 -41
- package/dist/{cloudflare → packages/cloudflare/src}/tpr.js +18 -15
- package/dist/plugins/ast-scope.d.ts +16 -0
- package/dist/plugins/ast-scope.js +62 -0
- package/dist/plugins/ast-utils.d.ts +27 -1
- package/dist/plugins/ast-utils.js +32 -1
- package/dist/plugins/css-module-imports.d.ts +14 -0
- package/dist/plugins/css-module-imports.js +59 -0
- package/dist/plugins/extensionless-dynamic-import.js +2 -2
- package/dist/plugins/ignore-dynamic-requests.d.ts +11 -0
- package/dist/plugins/ignore-dynamic-requests.js +530 -0
- package/dist/plugins/typeof-window.d.ts +1 -1
- package/dist/plugins/typeof-window.js +28 -56
- package/dist/routing/app-route-graph.d.ts +23 -2
- package/dist/routing/app-route-graph.js +126 -32
- package/dist/routing/file-matcher.d.ts +3 -0
- package/dist/routing/file-matcher.js +3 -0
- package/dist/routing/pages-router.js +2 -2
- package/dist/server/api-handler.js +9 -14
- package/dist/server/app-browser-action-result.d.ts +4 -1
- package/dist/server/app-browser-action-result.js +8 -1
- package/dist/server/app-browser-entry.js +161 -52
- package/dist/server/app-browser-interception-context.d.ts +1 -0
- package/dist/server/app-browser-interception-context.js +4 -2
- package/dist/server/app-browser-navigation-controller.d.ts +2 -0
- package/dist/server/app-browser-navigation-controller.js +60 -31
- package/dist/server/app-browser-server-action-client.d.ts +1 -1
- package/dist/server/app-browser-server-action-client.js +3 -4
- package/dist/server/app-browser-state.d.ts +11 -1
- package/dist/server/app-browser-state.js +25 -8
- package/dist/server/app-browser-visible-commit.d.ts +6 -1
- package/dist/server/app-browser-visible-commit.js +43 -25
- package/dist/server/app-elements-wire.d.ts +9 -2
- package/dist/server/app-elements-wire.js +8 -1
- package/dist/server/app-elements.d.ts +2 -2
- package/dist/server/app-elements.js +4 -3
- package/dist/server/app-fallback-renderer.d.ts +2 -1
- package/dist/server/app-fallback-renderer.js +10 -6
- package/dist/server/app-hydration-cache-publication.d.ts +11 -0
- package/dist/server/app-hydration-cache-publication.js +43 -0
- package/dist/server/app-middleware.d.ts +4 -3
- package/dist/server/app-middleware.js +8 -3
- package/dist/server/app-optimistic-routing.js +11 -4
- package/dist/server/app-page-cache-finalizer.js +2 -1
- package/dist/server/app-page-cache-render.d.ts +1 -0
- package/dist/server/app-page-cache-render.js +8 -4
- package/dist/server/app-page-cache.d.ts +1 -0
- package/dist/server/app-page-cache.js +5 -2
- package/dist/server/app-page-dispatch.js +1 -0
- package/dist/server/app-page-element-builder.d.ts +2 -1
- package/dist/server/app-page-element-builder.js +58 -4
- package/dist/server/app-page-probe.js +5 -0
- package/dist/server/app-page-render-identity.d.ts +1 -0
- package/dist/server/app-page-render-identity.js +1 -1
- package/dist/server/app-page-render.js +18 -0
- package/dist/server/app-page-request.d.ts +14 -0
- package/dist/server/app-page-request.js +69 -4
- package/dist/server/app-page-route-wiring.d.ts +8 -1
- package/dist/server/app-page-route-wiring.js +32 -18
- package/dist/server/app-page-segment-state.d.ts +2 -1
- package/dist/server/app-page-segment-state.js +3 -1
- package/dist/server/app-page-stream.d.ts +5 -0
- package/dist/server/app-page-stream.js +3 -1
- package/dist/server/app-route-handler-execution.js +5 -1
- package/dist/server/app-route-handler-response.js +1 -0
- package/dist/server/app-route-handler-runtime.js +1 -1
- package/dist/server/app-router-entry.js +9 -2
- package/dist/server/app-rsc-handler.d.ts +1 -0
- package/dist/server/app-rsc-handler.js +62 -31
- package/dist/server/app-rsc-request-normalization.d.ts +3 -2
- package/dist/server/app-rsc-request-normalization.js +6 -3
- package/dist/server/app-segment-config.d.ts +11 -0
- package/dist/server/app-segment-config.js +62 -6
- package/dist/server/app-server-action-execution.d.ts +1 -0
- package/dist/server/app-server-action-execution.js +58 -28
- package/dist/server/app-ssr-entry.d.ts +3 -0
- package/dist/server/app-ssr-entry.js +15 -7
- package/dist/server/app-ssr-stream.d.ts +7 -3
- package/dist/server/app-ssr-stream.js +10 -6
- package/dist/server/app-visited-response-cache.d.ts +6 -0
- package/dist/server/app-visited-response-cache.js +3 -1
- package/dist/server/client-trace-metadata.js +26 -0
- package/dist/server/default-global-not-found-module.d.ts +14 -0
- package/dist/server/default-global-not-found-module.js +14 -0
- package/dist/server/dev-route-files.js +4 -0
- package/dist/server/dev-server.js +19 -18
- package/dist/server/dev-stack-sourcemap.d.ts +1 -1
- package/dist/server/dev-stack-sourcemap.js +1 -1
- package/dist/server/fetch-handler.d.ts +2 -0
- package/dist/server/fetch-handler.js +18 -0
- package/dist/server/headers.d.ts +3 -15
- package/dist/server/headers.js +2 -15
- package/dist/server/image-optimization.d.ts +51 -1
- package/dist/server/image-optimization.js +52 -2
- package/dist/server/implicit-tags.js +1 -1
- package/dist/server/isr-cache.d.ts +1 -1
- package/dist/server/isr-cache.js +2 -2
- package/dist/server/metadata-routes.d.ts +3 -1
- package/dist/server/metadata-routes.js +12 -2
- package/dist/server/middleware-runtime.js +6 -1
- package/dist/server/navigation-planner.d.ts +1 -0
- package/dist/server/navigation-planner.js +14 -3
- package/dist/server/pages-api-route.js +2 -2
- package/dist/server/pages-asset-tags.d.ts +4 -6
- package/dist/server/pages-asset-tags.js +12 -12
- package/dist/server/pages-client-assets.d.ts +12 -0
- package/dist/server/pages-client-assets.js +10 -0
- package/dist/server/pages-node-compat.d.ts +8 -1
- package/dist/server/pages-node-compat.js +32 -4
- package/dist/server/pages-page-data.d.ts +24 -1
- package/dist/server/pages-page-data.js +45 -24
- package/dist/server/pages-page-handler.d.ts +2 -1
- package/dist/server/pages-page-handler.js +19 -12
- package/dist/server/pages-page-response.d.ts +7 -0
- package/dist/server/pages-page-response.js +4 -1
- package/dist/server/pages-request-pipeline.d.ts +2 -0
- package/dist/server/pages-request-pipeline.js +25 -1
- package/dist/server/pages-router-entry.d.ts +30 -0
- package/dist/server/pages-router-entry.js +108 -0
- package/dist/server/prerender-manifest.d.ts +3 -1
- package/dist/server/prerender-route-params.js +1 -1
- package/dist/server/prod-server.d.ts +1 -1
- package/dist/server/prod-server.js +33 -20
- package/dist/server/request-pipeline.js +1 -0
- package/dist/server/seed-cache.js +4 -4
- package/dist/shims/app-router-scroll-state.d.ts +1 -0
- package/dist/shims/app-router-scroll-state.js +1 -0
- package/dist/shims/app-router-scroll.js +2 -1
- package/dist/shims/cache.js +19 -15
- package/dist/shims/cdn-cache.js +1 -1
- package/dist/shims/dynamic-preload-chunks.js +2 -1
- package/dist/shims/form.d.ts +3 -1
- package/dist/shims/form.js +37 -43
- package/dist/shims/headers.d.ts +7 -1
- package/dist/shims/headers.js +17 -3
- package/dist/shims/image.js +75 -14
- package/dist/shims/internal/app-route-detection.d.ts +2 -17
- package/dist/shims/internal/app-route-detection.js +4 -17
- package/dist/shims/internal/hybrid-client-route-owner-direct.d.ts +23 -0
- package/dist/shims/internal/hybrid-client-route-owner-direct.js +51 -0
- package/dist/shims/internal/hybrid-client-route-owner.d.ts +2 -15
- package/dist/shims/internal/hybrid-client-route-owner.js +9 -60
- package/dist/shims/internal/pages-data-fetch-dedup.d.ts +9 -5
- package/dist/shims/internal/pages-data-fetch-dedup.js +73 -14
- package/dist/shims/internal/pages-data-target.d.ts +10 -9
- package/dist/shims/internal/pages-data-target.js +91 -12
- package/dist/shims/internal/pages-router-components.d.ts +7 -0
- package/dist/shims/internal/pages-router-components.js +13 -0
- package/dist/shims/layout-segment-context.d.ts +4 -1
- package/dist/shims/layout-segment-context.js +18 -4
- package/dist/shims/link.js +55 -26
- package/dist/shims/navigation.d.ts +5 -1
- package/dist/shims/navigation.js +45 -10
- package/dist/shims/navigation.react-server.js +1 -1
- package/dist/shims/root-params.d.ts +15 -1
- package/dist/shims/root-params.js +21 -1
- package/dist/shims/router.d.ts +5 -7
- package/dist/shims/router.js +362 -93
- package/dist/shims/server.js +3 -2
- package/dist/shims/slot.js +3 -6
- package/dist/utils/client-runtime-metadata.d.ts +2 -18
- package/dist/utils/client-runtime-metadata.js +31 -22
- package/dist/utils/dev-stack-sourcemap-endpoint.d.ts +4 -0
- package/dist/{server → utils}/dev-stack-sourcemap-endpoint.js +1 -1
- package/dist/utils/domain-locale.d.ts +6 -3
- package/dist/{server → utils}/middleware-request-headers.d.ts +1 -1
- package/dist/{server → utils}/middleware-request-headers.js +2 -2
- package/dist/utils/project.d.ts +48 -2
- package/dist/utils/project.js +225 -4
- package/dist/utils/protocol-headers.d.ts +17 -0
- package/dist/utils/protocol-headers.js +17 -0
- package/dist/utils/react-version.d.ts +4 -0
- package/dist/utils/react-version.js +44 -0
- package/package.json +47 -2
- package/dist/deploy.d.ts +0 -197
- package/dist/deploy.js +0 -1040
- package/dist/server/dev-stack-sourcemap-endpoint.d.ts +0 -4
- /package/dist/{cloudflare → packages/cloudflare}/src/utils/cache-control-metadata.js +0 -0
|
@@ -19,12 +19,16 @@ import "./app-page-stream.js";
|
|
|
19
19
|
import { buildAppPageTags } from "./implicit-tags.js";
|
|
20
20
|
import { resolveAppPageNavigationParams } from "./app-page-element-builder.js";
|
|
21
21
|
import { resolveAppPageActionRerenderTarget } from "./app-page-request.js";
|
|
22
|
+
import { createRootParamsUsageController, pickRootParams, runWithRootParamsScope, runWithRootParamsUsage } from "../shims/root-params.js";
|
|
22
23
|
import { getSetCookieName } from "./cookie-utils.js";
|
|
23
24
|
import { createStaticGenerationHeadersContext } from "./app-static-generation.js";
|
|
24
25
|
//#region src/server/app-server-action-execution.ts
|
|
25
26
|
function prepareActionPageRerenderContext(options) {
|
|
26
27
|
if (options.dynamicConfig === "force-static" || options.dynamicConfig === "error") setHeadersContext(createStaticGenerationHeadersContext({
|
|
27
|
-
draftModeEnabled: isDraftModeRequest(
|
|
28
|
+
draftModeEnabled: isDraftModeRequest(createActionRerenderRequest({
|
|
29
|
+
draftModeCookie: options.draftModeCookie,
|
|
30
|
+
request: options.request
|
|
31
|
+
}), options.draftModeSecret),
|
|
28
32
|
draftModeSecret: options.draftModeSecret,
|
|
29
33
|
dynamicConfig: options.dynamicConfig,
|
|
30
34
|
routeKind: "page",
|
|
@@ -32,6 +36,14 @@ function prepareActionPageRerenderContext(options) {
|
|
|
32
36
|
}));
|
|
33
37
|
return options.dynamicConfig === "force-static" ? new URLSearchParams() : options.searchParams;
|
|
34
38
|
}
|
|
39
|
+
function createActionRerenderRequest(options) {
|
|
40
|
+
if (!options.draftModeCookie) return options.request;
|
|
41
|
+
const headers = new Headers(options.request.headers);
|
|
42
|
+
const cookieHeader = applySetCookieMutationsToRequestCookieHeader(headers.get("cookie"), [options.draftModeCookie]);
|
|
43
|
+
if (cookieHeader === null) headers.delete("cookie");
|
|
44
|
+
else headers.set("cookie", cookieHeader);
|
|
45
|
+
return new Request(options.request.url, { headers });
|
|
46
|
+
}
|
|
35
47
|
/**
|
|
36
48
|
* Matches Next.js' server action argument cap to prevent stack overflow in
|
|
37
49
|
* Function.prototype.apply when decoding hostile action payloads.
|
|
@@ -362,11 +374,14 @@ async function handleProgressiveServerActionRequest(options) {
|
|
|
362
374
|
let actionRedirect = null;
|
|
363
375
|
let actionError = void 0;
|
|
364
376
|
let actionFailed = false;
|
|
377
|
+
let actionThrew = false;
|
|
365
378
|
let actionResult;
|
|
379
|
+
const rootParamsUsage = createRootParamsUsageController();
|
|
366
380
|
const previousHeadersPhase = options.setHeadersAccessPhase("action");
|
|
367
381
|
try {
|
|
368
|
-
actionResult = await action
|
|
382
|
+
actionResult = await runWithRootParamsUsage({ kind: "server-action" }, action, rootParamsUsage);
|
|
369
383
|
} catch (error) {
|
|
384
|
+
actionThrew = true;
|
|
370
385
|
actionRedirect = getActionRedirect(error);
|
|
371
386
|
if (!actionRedirect) {
|
|
372
387
|
actionError = error;
|
|
@@ -386,8 +401,10 @@ async function handleProgressiveServerActionRequest(options) {
|
|
|
386
401
|
}
|
|
387
402
|
} finally {
|
|
388
403
|
options.setHeadersAccessPhase(previousHeadersPhase);
|
|
404
|
+
if (actionThrew) rootParamsUsage.transitionToRender();
|
|
389
405
|
}
|
|
390
406
|
if (!actionRedirect) {
|
|
407
|
+
if (!actionThrew) rootParamsUsage.transitionToRender();
|
|
391
408
|
const actionPendingCookies = dedupePendingCookies(options.getAndClearPendingCookies());
|
|
392
409
|
const actionDraftCookie = options.getDraftModeCookieHeader();
|
|
393
410
|
const revalidationKind = resolveActionRevalidationKind(actionPendingCookies.length > 0 || Boolean(actionDraftCookie));
|
|
@@ -555,16 +572,19 @@ async function handleServerActionRscRequest(options) {
|
|
|
555
572
|
let returnValue;
|
|
556
573
|
let actionRedirect = null;
|
|
557
574
|
let actionStatus = 200;
|
|
575
|
+
let actionThrew = false;
|
|
558
576
|
const actionWasForwarded = Boolean(options.request.headers.get(ACTION_FORWARDED_HEADER));
|
|
577
|
+
const rootParamsUsage = createRootParamsUsageController();
|
|
559
578
|
const previousHeadersPhase = options.setHeadersAccessPhase("action");
|
|
560
579
|
try {
|
|
561
580
|
try {
|
|
562
581
|
validateServerActionArgs(args);
|
|
563
582
|
returnValue = {
|
|
564
583
|
ok: true,
|
|
565
|
-
data: await action.apply(null, args)
|
|
584
|
+
data: await runWithRootParamsUsage({ kind: "server-action" }, () => action.apply(null, args), rootParamsUsage)
|
|
566
585
|
};
|
|
567
586
|
} catch (error) {
|
|
587
|
+
actionThrew = true;
|
|
568
588
|
actionRedirect = getActionRedirect(error);
|
|
569
589
|
if (actionRedirect) returnValue = {
|
|
570
590
|
ok: true,
|
|
@@ -579,6 +599,7 @@ async function handleServerActionRscRequest(options) {
|
|
|
579
599
|
data: error
|
|
580
600
|
};
|
|
581
601
|
} else {
|
|
602
|
+
actionStatus = 500;
|
|
582
603
|
console.error("[vinext] Server action error:", error);
|
|
583
604
|
returnValue = {
|
|
584
605
|
ok: false,
|
|
@@ -589,6 +610,7 @@ async function handleServerActionRscRequest(options) {
|
|
|
589
610
|
}
|
|
590
611
|
} finally {
|
|
591
612
|
options.setHeadersAccessPhase(previousHeadersPhase);
|
|
613
|
+
if (actionThrew && !actionWasForwarded) rootParamsUsage.transitionToRender();
|
|
592
614
|
}
|
|
593
615
|
if (actionRedirect) {
|
|
594
616
|
const actionPendingCookies = dedupePendingCookies(options.getAndClearPendingCookies());
|
|
@@ -633,9 +655,10 @@ async function handleServerActionRscRequest(options) {
|
|
|
633
655
|
request: options.request,
|
|
634
656
|
url: redirectTarget
|
|
635
657
|
});
|
|
636
|
-
setHeadersContext(headersContextFromRequest(redirectRenderRequest));
|
|
658
|
+
setHeadersContext(headersContextFromRequest(redirectRenderRequest, { draftModeSecret: options.draftModeSecret }));
|
|
637
659
|
const redirectDynamicConfig = options.resolveRouteDynamicConfig?.(targetMatch.route);
|
|
638
660
|
const redirectSearchParams = prepareActionPageRerenderContext({
|
|
661
|
+
draftModeCookie: actionDraftCookie,
|
|
639
662
|
draftModeSecret: options.draftModeSecret,
|
|
640
663
|
dynamicConfig: redirectDynamicConfig,
|
|
641
664
|
request: redirectRenderRequest,
|
|
@@ -651,27 +674,29 @@ async function handleServerActionRscRequest(options) {
|
|
|
651
674
|
setCurrentFetchCacheMode(options.resolveRouteFetchCacheMode?.(targetMatch.route) ?? null);
|
|
652
675
|
setCurrentForceDynamicFetchDefault(redirectDynamicConfig === "force-dynamic");
|
|
653
676
|
setCurrentFetchSoftTags(buildServerActionPageTags(targetMatch.route, targetPathname));
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
677
|
+
return createServerActionRscResponse(await runWithRootParamsScope(pickRootParams(targetMatch.params, targetMatch.route.rootParamNames), () => runWithRootParamsUsage({ kind: "route" }, async () => {
|
|
678
|
+
const element = options.buildPageElement({
|
|
679
|
+
cleanPathname: targetPathname,
|
|
680
|
+
interceptOpts: void 0,
|
|
681
|
+
isRscRequest: true,
|
|
682
|
+
mountedSlotsHeader: null,
|
|
683
|
+
params: targetMatch.params,
|
|
684
|
+
request: redirectRenderRequest,
|
|
685
|
+
route: targetMatch.route,
|
|
686
|
+
searchParams: redirectSearchParams,
|
|
687
|
+
renderMode: APP_RSC_RENDER_MODE_ACTION_RERENDER_PRESERVE_UI,
|
|
688
|
+
observeMetadataSearchParamsAccess: redirectDynamicConfig !== "force-static",
|
|
689
|
+
observePageSearchParamsAccess: redirectDynamicConfig !== "force-static"
|
|
690
|
+
});
|
|
691
|
+
const onRenderError = options.createRscOnErrorHandler(redirectRenderRequest, targetPathname, targetMatch.route.pattern);
|
|
692
|
+
return options.renderToReadableStream({
|
|
693
|
+
root: element,
|
|
694
|
+
returnValue
|
|
695
|
+
}, {
|
|
696
|
+
temporaryReferences,
|
|
697
|
+
onError: onRenderError
|
|
698
|
+
});
|
|
699
|
+
})), {
|
|
675
700
|
status: shouldUseForwardedActionRedirectStatus({
|
|
676
701
|
actionWasForwarded,
|
|
677
702
|
currentPathname: options.cleanPathname,
|
|
@@ -686,7 +711,8 @@ async function handleServerActionRscRequest(options) {
|
|
|
686
711
|
const actionPendingCookies = dedupePendingCookies(options.getAndClearPendingCookies());
|
|
687
712
|
const actionDraftCookie = options.getDraftModeCookieHeader();
|
|
688
713
|
const actionRevalidationKind = resolveActionRevalidationKind(actionPendingCookies.length > 0 || Boolean(actionDraftCookie));
|
|
689
|
-
|
|
714
|
+
const isHttpFallback = actionStatus === 401 || actionStatus === 403 || actionStatus === 404;
|
|
715
|
+
if (!isHttpFallback && (actionWasForwarded || actionRevalidationKind === ACTION_DID_NOT_REVALIDATE)) {
|
|
690
716
|
const onRenderError = options.createRscOnErrorHandler(options.request, options.cleanPathname, options.cleanPathname);
|
|
691
717
|
const rscStream = await options.renderToReadableStream({ returnValue }, {
|
|
692
718
|
temporaryReferences,
|
|
@@ -707,6 +733,7 @@ async function handleServerActionRscRequest(options) {
|
|
|
707
733
|
headers: actionHeaders
|
|
708
734
|
}, options.clearRequestContext);
|
|
709
735
|
}
|
|
736
|
+
if (!actionThrew) rootParamsUsage.transitionToRender();
|
|
710
737
|
const match = options.matchRoute(options.cleanPathname);
|
|
711
738
|
let element;
|
|
712
739
|
let errorPattern = match ? match.route.pattern : options.cleanPathname;
|
|
@@ -726,6 +753,7 @@ async function handleServerActionRscRequest(options) {
|
|
|
726
753
|
await options.ensureRouteLoaded?.(actionRerenderTarget.route);
|
|
727
754
|
const actionRerenderDynamicConfig = options.resolveRouteDynamicConfig?.(actionRerenderTarget.route);
|
|
728
755
|
const actionRerenderSearchParams = prepareActionPageRerenderContext({
|
|
756
|
+
draftModeCookie: actionDraftCookie,
|
|
729
757
|
draftModeSecret: options.draftModeSecret,
|
|
730
758
|
dynamicConfig: actionRerenderDynamicConfig,
|
|
731
759
|
request: options.request,
|
|
@@ -740,7 +768,7 @@ async function handleServerActionRscRequest(options) {
|
|
|
740
768
|
setCurrentFetchCacheMode(options.resolveRouteFetchCacheMode?.(actionRerenderTarget.route) ?? null);
|
|
741
769
|
setCurrentForceDynamicFetchDefault(actionRerenderDynamicConfig === "force-dynamic");
|
|
742
770
|
setCurrentFetchSoftTags(buildServerActionPageTags(actionRerenderTarget.route, options.cleanPathname));
|
|
743
|
-
|
|
771
|
+
const buildActionRerenderElement = () => options.buildPageElement({
|
|
744
772
|
cleanPathname: options.cleanPathname,
|
|
745
773
|
interceptOpts: actionRerenderTarget.interceptOpts,
|
|
746
774
|
isRscRequest: options.isRscRequest,
|
|
@@ -753,19 +781,21 @@ async function handleServerActionRscRequest(options) {
|
|
|
753
781
|
observeMetadataSearchParamsAccess: actionRerenderDynamicConfig !== "force-static",
|
|
754
782
|
observePageSearchParamsAccess: actionRerenderDynamicConfig !== "force-static"
|
|
755
783
|
});
|
|
784
|
+
element = actionWasForwarded && isHttpFallback ? await runWithRootParamsUsage({ kind: "route" }, async () => buildActionRerenderElement()) : buildActionRerenderElement();
|
|
756
785
|
errorPattern = actionRerenderTarget.route.pattern;
|
|
757
786
|
} else {
|
|
758
787
|
const actionRouteId = options.createPayloadRouteId(options.cleanPathname, null);
|
|
759
788
|
element = options.createNotFoundElement(actionRouteId);
|
|
760
789
|
}
|
|
761
790
|
const onRenderError = options.createRscOnErrorHandler(options.request, options.cleanPathname, errorPattern);
|
|
762
|
-
const
|
|
791
|
+
const renderActionRerender = () => options.renderToReadableStream({
|
|
763
792
|
root: element,
|
|
764
793
|
returnValue
|
|
765
794
|
}, {
|
|
766
795
|
temporaryReferences,
|
|
767
796
|
onError: onRenderError
|
|
768
797
|
});
|
|
798
|
+
const rscStream = await (actionWasForwarded && isHttpFallback ? runWithRootParamsUsage({ kind: "route" }, renderActionRerender) : renderActionRerender());
|
|
769
799
|
const actionHeaders = new Headers({
|
|
770
800
|
"Content-Type": VINEXT_RSC_CONTENT_TYPE,
|
|
771
801
|
Vary: VINEXT_RSC_VARY_HEADER
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { NavigationContext } from "../shims/navigation-context-state.js";
|
|
2
2
|
import { RootParams } from "../shims/root-params.js";
|
|
3
|
+
import { InitialNavigationCacheMetadata } from "./app-ssr-stream.js";
|
|
3
4
|
import { AppSsrRenderResult } from "./app-page-stream.js";
|
|
4
5
|
import { ReactFormState } from "react-dom/client";
|
|
5
6
|
|
|
@@ -44,6 +45,8 @@ declare function handleSsr(rscStream: ReadableStream<Uint8Array>, navContext: Na
|
|
|
44
45
|
* and ISR cache writes to avoid caching fallback content. */
|
|
45
46
|
waitForAllReady?: boolean;
|
|
46
47
|
fallbackToErrorDocumentOnShellError?: boolean;
|
|
48
|
+
dynamicStaleTimeSeconds?: number;
|
|
49
|
+
getInitialNavigationCacheMetadata?: () => InitialNavigationCacheMetadata;
|
|
47
50
|
}): Promise<AppSsrRenderResult>;
|
|
48
51
|
declare const _default: {
|
|
49
52
|
fetch(request: Request): Promise<Response>;
|
|
@@ -16,20 +16,24 @@ import DefaultGlobalError from "../shims/default-global-error.js";
|
|
|
16
16
|
import { BfcacheStateKeyMapContext, ElementsContext, Slot } from "../shims/slot.js";
|
|
17
17
|
import { createSsrErrorMetaRenderer } from "./app-ssr-error-meta.js";
|
|
18
18
|
import { createNavigationRuntimeRscMetadataScript, createRscEmbedTransform, createTickBufferedTransform } from "./app-ssr-stream.js";
|
|
19
|
-
import {
|
|
20
|
-
import { runWithRootParamsScope } from "../shims/root-params.js";
|
|
19
|
+
import { setPagesClientAssets } from "./pages-client-assets.js";
|
|
21
20
|
import { createInitialBfcacheMaps } from "./app-bfcache-identity.js";
|
|
22
21
|
import { RSC_FORM_STATE_GLOBAL } from "./app-browser-hydration.js";
|
|
23
22
|
import { createClientReferencePreloader } from "./app-client-reference-preloader.js";
|
|
24
23
|
import { deferUntilStreamConsumed } from "./defer-until-stream-consumed.js";
|
|
24
|
+
import { runWithRootParamsScope } from "../shims/root-params.js";
|
|
25
|
+
import { BeforeInteractiveContext } from "../shims/before-interactive-context.js";
|
|
25
26
|
import { renderBeforeInteractiveInlineScripts } from "./before-interactive-head.js";
|
|
26
27
|
import { createInitialDevServerErrorScript } from "./dev-initial-server-error.js";
|
|
27
28
|
import { ssrAppRouterInstance } from "./app-ssr-router-instance.js";
|
|
28
29
|
import { Fragment, createElement, use } from "react";
|
|
29
30
|
import { renderToReadableStream, renderToStaticMarkup } from "react-dom/server.edge";
|
|
31
|
+
import { preinitModule } from "react-dom";
|
|
30
32
|
import { createFromReadableStream } from "@vitejs/plugin-rsc/ssr";
|
|
31
33
|
import clientReferences from "virtual:vite-rsc/client-references";
|
|
34
|
+
import pagesClientAssets from "virtual:vinext-pages-client-assets";
|
|
32
35
|
//#region src/server/app-ssr-entry.ts
|
|
36
|
+
setPagesClientAssets(pagesClientAssets);
|
|
33
37
|
/**
|
|
34
38
|
* Default cap for the preload `Link` header, matching Next.js's
|
|
35
39
|
* `defaultConfig.reactMaxHeadersLength`. Used when no config value threads
|
|
@@ -149,12 +153,12 @@ function buildModulePreloadHtml(bootstrapModuleUrl, nonce) {
|
|
|
149
153
|
if (!bootstrapModuleUrl) return "";
|
|
150
154
|
return `<link rel="modulepreload"${createNonceAttribute(nonce)} href="${escapeHtmlAttr(bootstrapModuleUrl)}" />\n`;
|
|
151
155
|
}
|
|
152
|
-
function buildHeadInjectionHtml(navContext, bootstrapModuleUrl, formState, insertedHTML, fontHTML, scriptNonce) {
|
|
156
|
+
function buildHeadInjectionHtml(navContext, bootstrapModuleUrl, formState, insertedHTML, fontHTML, dynamicStaleTimeSeconds, scriptNonce) {
|
|
153
157
|
const navPayload = {
|
|
154
158
|
pathname: navContext.pathname,
|
|
155
159
|
searchParams: [...navContext.searchParams.entries()]
|
|
156
160
|
};
|
|
157
|
-
return createInlineScriptTag(createNavigationRuntimeRscMetadataScript(navContext.params, navPayload), scriptNonce) + (formState === null ? "" : createInlineScriptTag("self[" + safeJsonStringify(RSC_FORM_STATE_GLOBAL) + "]=" + safeJsonStringify(formState), scriptNonce)) + buildModulePreloadHtml(bootstrapModuleUrl, scriptNonce) + insertedHTML + fontHTML;
|
|
161
|
+
return createInlineScriptTag(createNavigationRuntimeRscMetadataScript(navContext.params, navPayload, dynamicStaleTimeSeconds), scriptNonce) + (formState === null ? "" : createInlineScriptTag("self[" + safeJsonStringify(RSC_FORM_STATE_GLOBAL) + "]=" + safeJsonStringify(formState), scriptNonce)) + buildModulePreloadHtml(bootstrapModuleUrl, scriptNonce) + insertedHTML + fontHTML;
|
|
158
162
|
}
|
|
159
163
|
function requireNavigationContext(navContext) {
|
|
160
164
|
if (!navContext) throw new Error("App SSR requires navigation context for BFCache state keys");
|
|
@@ -176,15 +180,19 @@ async function handleSsr(rscStream, navContext, fontData, options) {
|
|
|
176
180
|
let rscEmbed;
|
|
177
181
|
if (options?.sideStream) {
|
|
178
182
|
ssrStream = rscStream;
|
|
179
|
-
rscEmbed = createRscEmbedTransform(options.sideStream, options?.scriptNonce);
|
|
183
|
+
rscEmbed = createRscEmbedTransform(options.sideStream, options?.scriptNonce, options?.getInitialNavigationCacheMetadata);
|
|
180
184
|
if (options.capturedRscDataRef) options.capturedRscDataRef.value = rscEmbed.getRawBuffer();
|
|
181
185
|
} else {
|
|
182
186
|
const [s1, s2] = rscStream.tee();
|
|
183
187
|
ssrStream = s1;
|
|
184
|
-
rscEmbed = createRscEmbedTransform(s2, options?.scriptNonce);
|
|
188
|
+
rscEmbed = createRscEmbedTransform(s2, options?.scriptNonce, options?.getInitialNavigationCacheMetadata);
|
|
185
189
|
}
|
|
186
190
|
let flightRoot = null;
|
|
187
191
|
function VinextFlightRoot() {
|
|
192
|
+
for (const moduleUrl of pagesClientAssets.appBootstrapPreinitModules ?? []) preinitModule(moduleUrl, {
|
|
193
|
+
as: "script",
|
|
194
|
+
nonce: options?.scriptNonce
|
|
195
|
+
});
|
|
188
196
|
if (!flightRoot) flightRoot = createFromReadableStream(ssrStream);
|
|
189
197
|
const wireElements = use(flightRoot);
|
|
190
198
|
const elements = AppElementsWire.decode(wireElements);
|
|
@@ -270,7 +278,7 @@ async function handleSsr(rscStream, navContext, fontData, options) {
|
|
|
270
278
|
const initialDevServerErrorHTML = createInitialDevServerErrorScript(options?.initialDevServerError, options?.scriptNonce);
|
|
271
279
|
if (didInjectHeadHTML) return insertedHTML + errorMetaHTML;
|
|
272
280
|
didInjectHeadHTML = true;
|
|
273
|
-
return buildHeadInjectionHtml(ssrNavigationContext, bootstrapModuleUrl, options?.formState ?? null, insertedHTML + errorMetaHTML + getTraceMetaHTML() + initialDevServerErrorHTML, fontHTML, options?.scriptNonce);
|
|
281
|
+
return buildHeadInjectionHtml(ssrNavigationContext, bootstrapModuleUrl, options?.formState ?? null, insertedHTML + errorMetaHTML + getTraceMetaHTML() + initialDevServerErrorHTML, fontHTML, options?.dynamicStaleTimeSeconds, options?.scriptNonce);
|
|
274
282
|
};
|
|
275
283
|
const getBeforeInteractiveHeadHTML = () => renderBeforeInteractiveInlineScripts(beforeInteractiveInlineScripts);
|
|
276
284
|
return {
|
|
@@ -6,11 +6,15 @@ type RscEmbedTransform = {
|
|
|
6
6
|
};
|
|
7
7
|
type HtmlInsertion = string | (() => string);
|
|
8
8
|
type InlineCssManifest = Record<string, string>;
|
|
9
|
+
type InitialNavigationCacheMetadata = {
|
|
10
|
+
kind: "dynamic" | "static";
|
|
11
|
+
dynamicStaleTimeSeconds?: number;
|
|
12
|
+
};
|
|
9
13
|
declare function navigationRuntimeRscBootstrapExpression(): string;
|
|
10
14
|
declare function createNavigationRuntimeRscMetadataScript(params: Record<string, string | string[]>, nav: {
|
|
11
15
|
pathname: string;
|
|
12
16
|
searchParams: [string, string][];
|
|
13
|
-
}): string;
|
|
17
|
+
}, dynamicStaleTimeSeconds?: number): string;
|
|
14
18
|
/**
|
|
15
19
|
* Fix invalid preload "as" values in RSC Flight hint lines before they reach
|
|
16
20
|
* the client. React Flight emits HL hints with as="stylesheet" for CSS, but
|
|
@@ -21,7 +25,7 @@ declare function fixFlightHints(text: string): string;
|
|
|
21
25
|
* Create a helper that progressively embeds RSC chunks as inline <script> tags.
|
|
22
26
|
* The browser entry turns the embedded chunks back into Uint8Array data.
|
|
23
27
|
*/
|
|
24
|
-
declare function createRscEmbedTransform(embedStream: ReadableStream<Uint8Array>, scriptNonce?: string): RscEmbedTransform;
|
|
28
|
+
declare function createRscEmbedTransform(embedStream: ReadableStream<Uint8Array>, scriptNonce?: string, getInitialNavigationCacheMetadata?: () => InitialNavigationCacheMetadata): RscEmbedTransform;
|
|
25
29
|
/**
|
|
26
30
|
* Fix invalid preload "as" values in server-rendered HTML.
|
|
27
31
|
* React Fizz emits <link rel="preload" as="stylesheet"> for CSS, but the
|
|
@@ -57,4 +61,4 @@ declare function fixPreloadAs(html: string): string;
|
|
|
57
61
|
*/
|
|
58
62
|
declare function createTickBufferedTransform(rscEmbed: RscEmbedTransform, injectHTML?: HtmlInsertion, injectAfterHeadOpenHTML?: HtmlInsertion, inlineCssManifest?: InlineCssManifest, inlineCssPrependCss?: string, inlineCssPrependFallbackHTML?: string, inlineCssScriptNonce?: string): TransformStream<Uint8Array, Uint8Array>;
|
|
59
63
|
//#endregion
|
|
60
|
-
export { createNavigationRuntimeRscMetadataScript, createRscEmbedTransform, createTickBufferedTransform, fixFlightHints, fixPreloadAs, navigationRuntimeRscBootstrapExpression };
|
|
64
|
+
export { InitialNavigationCacheMetadata, createNavigationRuntimeRscMetadataScript, createRscEmbedTransform, createTickBufferedTransform, fixFlightHints, fixPreloadAs, navigationRuntimeRscBootstrapExpression };
|
|
@@ -6,14 +6,18 @@ const NAVIGATION_RUNTIME_REFERENCE = `self[Symbol.for(${safeJsonStringify(NAVIGA
|
|
|
6
6
|
function navigationRuntimeRscBootstrapExpression() {
|
|
7
7
|
return `((${NAVIGATION_RUNTIME_REFERENCE}??={bootstrap:{routeManifest:null},functions:{}}).bootstrap.rsc??={rsc:[]})`;
|
|
8
8
|
}
|
|
9
|
-
function createNavigationRuntimeRscMetadataScript(params, nav) {
|
|
10
|
-
return "Object.assign(" + navigationRuntimeRscBootstrapExpression() + ",{params:" + safeJsonStringify(params) + ",nav:" + safeJsonStringify(nav) + "})";
|
|
9
|
+
function createNavigationRuntimeRscMetadataScript(params, nav, dynamicStaleTimeSeconds) {
|
|
10
|
+
return "Object.assign(" + navigationRuntimeRscBootstrapExpression() + ",{params:" + safeJsonStringify(params) + ",nav:" + safeJsonStringify(nav) + (dynamicStaleTimeSeconds === void 0 ? "" : ",dynamicStaleTimeSeconds:" + safeJsonStringify(dynamicStaleTimeSeconds)) + "})";
|
|
11
11
|
}
|
|
12
12
|
function createNavigationRuntimeRscChunkScript(chunk) {
|
|
13
13
|
return navigationRuntimeRscBootstrapExpression() + ".rsc.push(" + safeJsonStringify(chunk) + ")";
|
|
14
14
|
}
|
|
15
|
-
function createNavigationRuntimeRscDoneScript() {
|
|
16
|
-
|
|
15
|
+
function createNavigationRuntimeRscDoneScript(metadata) {
|
|
16
|
+
const bootstrap = navigationRuntimeRscBootstrapExpression();
|
|
17
|
+
return (metadata === void 0 ? "" : "Object.assign(" + bootstrap + "," + safeJsonStringify({
|
|
18
|
+
initialCacheKind: metadata.kind,
|
|
19
|
+
...metadata.dynamicStaleTimeSeconds === void 0 ? {} : { dynamicStaleTimeSeconds: metadata.dynamicStaleTimeSeconds }
|
|
20
|
+
}) + ");") + bootstrap + ".done=true";
|
|
17
21
|
}
|
|
18
22
|
/**
|
|
19
23
|
* Fix invalid preload "as" values in RSC Flight hint lines before they reach
|
|
@@ -27,7 +31,7 @@ function fixFlightHints(text) {
|
|
|
27
31
|
* Create a helper that progressively embeds RSC chunks as inline <script> tags.
|
|
28
32
|
* The browser entry turns the embedded chunks back into Uint8Array data.
|
|
29
33
|
*/
|
|
30
|
-
function createRscEmbedTransform(embedStream, scriptNonce) {
|
|
34
|
+
function createRscEmbedTransform(embedStream, scriptNonce, getInitialNavigationCacheMetadata) {
|
|
31
35
|
const reader = embedStream.getReader();
|
|
32
36
|
let pendingChunks = [];
|
|
33
37
|
const rawChunks = [];
|
|
@@ -67,7 +71,7 @@ function createRscEmbedTransform(embedStream, scriptNonce) {
|
|
|
67
71
|
async finalize() {
|
|
68
72
|
await pumpPromise;
|
|
69
73
|
let scripts = this.flush();
|
|
70
|
-
scripts += createInlineScriptTag(createNavigationRuntimeRscDoneScript(), scriptNonce);
|
|
74
|
+
scripts += createInlineScriptTag(createNavigationRuntimeRscDoneScript(getInitialNavigationCacheMetadata?.()), scriptNonce);
|
|
71
75
|
return scripts;
|
|
72
76
|
},
|
|
73
77
|
async getRawBuffer() {
|
|
@@ -1,17 +1,23 @@
|
|
|
1
|
+
import { AppElements } from "./app-elements-wire.js";
|
|
1
2
|
import { CachedRscResponse } from "../shims/navigation.js";
|
|
2
3
|
|
|
3
4
|
//#region src/server/app-visited-response-cache.d.ts
|
|
4
5
|
type VisitedResponseCacheNavigationKind = "navigate" | "refresh" | "traverse";
|
|
5
6
|
type VisitedResponseCacheEntry = {
|
|
6
7
|
createdAt: number;
|
|
8
|
+
elements?: AppElements;
|
|
7
9
|
expiresAt: number;
|
|
10
|
+
mountedSlotsHeader: string | null;
|
|
8
11
|
params: Record<string, string | string[]>;
|
|
9
12
|
response: CachedRscResponse;
|
|
10
13
|
};
|
|
11
14
|
declare const VISITED_RESPONSE_CACHE_TTL: number;
|
|
12
15
|
declare const MAX_TRAVERSAL_CACHE_TTL: number;
|
|
13
16
|
declare function createVisitedResponseCacheEntry(options: {
|
|
17
|
+
elements?: AppElements;
|
|
18
|
+
fallbackTtlMs?: number;
|
|
14
19
|
now: number;
|
|
20
|
+
mountedSlotsHeader?: string | null;
|
|
15
21
|
params: Record<string, string | string[]>;
|
|
16
22
|
response: CachedRscResponse;
|
|
17
23
|
}): VisitedResponseCacheEntry;
|
|
@@ -5,7 +5,9 @@ const MAX_TRAVERSAL_CACHE_TTL = 30 * 6e4;
|
|
|
5
5
|
function createVisitedResponseCacheEntry(options) {
|
|
6
6
|
return {
|
|
7
7
|
createdAt: options.now,
|
|
8
|
-
|
|
8
|
+
...options.elements ? { elements: options.elements } : {},
|
|
9
|
+
expiresAt: resolveCachedRscResponseExpiresAt(options.now, options.response, options.fallbackTtlMs ?? 3e5),
|
|
10
|
+
mountedSlotsHeader: options.mountedSlotsHeader ?? null,
|
|
9
11
|
params: options.params,
|
|
10
12
|
response: options.response
|
|
11
13
|
};
|
|
@@ -24,7 +24,32 @@ const carrierSetter = { set(carrier, key, value) {
|
|
|
24
24
|
value
|
|
25
25
|
});
|
|
26
26
|
} };
|
|
27
|
+
const OPEN_TELEMETRY_API_SYMBOL = Symbol.for("opentelemetry.js.api.1");
|
|
28
|
+
const OPEN_TELEMETRY_SPAN_SYMBOL = Symbol.for("OpenTelemetry Context Key SPAN");
|
|
29
|
+
function getRegisteredOpenTelemetryTraceData() {
|
|
30
|
+
let metadataSpan = null;
|
|
31
|
+
try {
|
|
32
|
+
const registry = globalThis[OPEN_TELEMETRY_API_SYMBOL];
|
|
33
|
+
if (!registry?.context || !registry.propagation) return null;
|
|
34
|
+
const contextApi = registry.context;
|
|
35
|
+
const propagation = registry.propagation;
|
|
36
|
+
const activeContext = contextApi.active();
|
|
37
|
+
metadataSpan = activeContext.getValue(OPEN_TELEMETRY_SPAN_SYMBOL) !== void 0 ? null : registry.trace?.getTracer("vinext").startSpan("vinext.clientTraceMetadata", void 0, activeContext) ?? null;
|
|
38
|
+
const context = metadataSpan ? activeContext.setValue(OPEN_TELEMETRY_SPAN_SYMBOL, metadataSpan) : activeContext;
|
|
39
|
+
const entries = [];
|
|
40
|
+
contextApi.with(context, () => {
|
|
41
|
+
propagation.inject(context, entries, carrierSetter);
|
|
42
|
+
});
|
|
43
|
+
return entries;
|
|
44
|
+
} catch {
|
|
45
|
+
return [];
|
|
46
|
+
} finally {
|
|
47
|
+
metadataSpan?.end();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
27
50
|
function getOpenTelemetryTraceData() {
|
|
51
|
+
const registeredEntries = getRegisteredOpenTelemetryTraceData();
|
|
52
|
+
if (registeredEntries) return registeredEntries;
|
|
28
53
|
let api;
|
|
29
54
|
try {
|
|
30
55
|
const req = globalThis.require;
|
|
@@ -75,6 +100,7 @@ function renderClientTraceMetadataTags(entries) {
|
|
|
75
100
|
*/
|
|
76
101
|
function getClientTraceMetadataHTML(allowList) {
|
|
77
102
|
if (!allowList || allowList.length === 0) return "";
|
|
103
|
+
if (typeof process !== "undefined" && process.env.VINEXT_PRERENDER === "1") return "";
|
|
78
104
|
return renderClientTraceMetadataTags(filterClientTraceMetadata(getOpenTelemetryTraceData(), allowList));
|
|
79
105
|
}
|
|
80
106
|
//#endregion
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
|
|
3
|
+
//#region src/server/default-global-not-found-module.d.ts
|
|
4
|
+
declare function DefaultGlobalNotFound(): React.ReactElement;
|
|
5
|
+
/**
|
|
6
|
+
* Module-shaped wrapper around Next.js's built-in global not-found document.
|
|
7
|
+
* Unlike the regular default not-found boundary, this component owns the
|
|
8
|
+
* document shell because global not-found responses skip the root layout.
|
|
9
|
+
*/
|
|
10
|
+
declare const DEFAULT_GLOBAL_NOT_FOUND_MODULE: {
|
|
11
|
+
readonly default: typeof DefaultGlobalNotFound;
|
|
12
|
+
};
|
|
13
|
+
//#endregion
|
|
14
|
+
export { DEFAULT_GLOBAL_NOT_FOUND_MODULE };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import DefaultNotFound from "../shims/default-not-found.js";
|
|
2
|
+
import React from "react";
|
|
3
|
+
//#region src/server/default-global-not-found-module.ts
|
|
4
|
+
function DefaultGlobalNotFound() {
|
|
5
|
+
return React.createElement("html", null, React.createElement("body", null, React.createElement(DefaultNotFound)));
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Module-shaped wrapper around Next.js's built-in global not-found document.
|
|
9
|
+
* Unlike the regular default not-found boundary, this component owns the
|
|
10
|
+
* document shell because global not-found responses skip the root layout.
|
|
11
|
+
*/
|
|
12
|
+
const DEFAULT_GLOBAL_NOT_FOUND_MODULE = { default: DefaultGlobalNotFound };
|
|
13
|
+
//#endregion
|
|
14
|
+
export { DEFAULT_GLOBAL_NOT_FOUND_MODULE };
|
|
@@ -48,6 +48,10 @@ function isRootGlobalError(parts, matcher) {
|
|
|
48
48
|
function isMetadataRouteFile(parts) {
|
|
49
49
|
const fileName = parts[parts.length - 1];
|
|
50
50
|
if (!fileName) return false;
|
|
51
|
+
if (fileName.endsWith(".alt.txt")) {
|
|
52
|
+
const imageBaseName = fileName.slice(0, -8);
|
|
53
|
+
return matchMetadataFileBaseName("opengraph-image", imageBaseName) !== null || matchMetadataFileBaseName("twitter-image", imageBaseName) !== null;
|
|
54
|
+
}
|
|
51
55
|
const { baseName, extension } = stripLastExtension(fileName);
|
|
52
56
|
if (!extension) return false;
|
|
53
57
|
const routePrefix = visibleRoutePrefix(parts);
|
|
@@ -3,7 +3,6 @@ import { createValidFileMatcher, findFileWithExtensions } from "../routing/file-
|
|
|
3
3
|
import { patternToNextFormat } from "../routing/route-validation.js";
|
|
4
4
|
import { matchRoute } from "../routing/pages-router.js";
|
|
5
5
|
import { NEXTJS_DEPLOYMENT_ID_HEADER } from "./headers.js";
|
|
6
|
-
import { normalizeStaticPathname } from "../routing/route-pattern.js";
|
|
7
6
|
import { importModule, reportRequestError } from "./instrumentation.js";
|
|
8
7
|
import { buildCacheStateHeaders } from "./cache-headers.js";
|
|
9
8
|
import { isUnknownRecord } from "../utils/record.js";
|
|
@@ -26,12 +25,14 @@ import { detectLocaleFromAcceptLanguage, extractLocaleFromUrl as extractLocaleFr
|
|
|
26
25
|
import { buildDefaultPagesNotFoundResponse } from "./pages-default-404.js";
|
|
27
26
|
import { buildPagesReadinessNextData } from "./pages-readiness.js";
|
|
28
27
|
import { resolvePagesPageMethodResponse } from "./pages-page-method.js";
|
|
29
|
-
import { createPagesDevModuleUrl } from "./pages-dev-module-url.js";
|
|
30
|
-
import { isSerializableProps } from "./pages-serializable-props.js";
|
|
31
28
|
import { loadUserDocumentInitialProps, runDocumentRenderPage } from "./pages-document-initial-props.js";
|
|
32
29
|
import { callDocumentGetInitialProps } from "./document-initial-head.js";
|
|
33
30
|
import { hasPagesGetInitialProps, loadDevAppInitialProps, loadPagesGetInitialProps } from "./pages-get-initial-props.js";
|
|
31
|
+
import { isSerializableProps } from "./pages-serializable-props.js";
|
|
34
32
|
import { isBotUserAgent } from "../utils/html-limited-bots.js";
|
|
33
|
+
import { getPagesRouteParams, matchesPagesStaticPath } from "./pages-page-data.js";
|
|
34
|
+
import { createPagesDevModuleUrl } from "./pages-dev-module-url.js";
|
|
35
|
+
import { attachPagesRequestCookies } from "./pages-node-compat.js";
|
|
35
36
|
import path from "node:path";
|
|
36
37
|
import React from "react";
|
|
37
38
|
import { renderToReadableStream } from "react-dom/server.edge";
|
|
@@ -101,7 +102,7 @@ const STREAM_BODY_MARKER = "<!--VINEXT_STREAM_BODY-->";
|
|
|
101
102
|
* shell sooner).
|
|
102
103
|
*/
|
|
103
104
|
async function streamPageToResponse(res, element, options) {
|
|
104
|
-
const { url, server, fontHeadHTML, scripts, DocumentComponent, statusCode
|
|
105
|
+
const { url, server, fontHeadHTML, scripts, DocumentComponent, statusCode, extraHeaders, getHeadHTML, enhancePageElement, scriptNonce, documentContext, setDocumentInitialHead, bufferBodyBeforeHeaders = false } = options;
|
|
105
106
|
const documentRenderPage = await runDocumentRenderPage({
|
|
106
107
|
DocumentComponent,
|
|
107
108
|
enhancePageElement,
|
|
@@ -110,6 +111,7 @@ async function streamPageToResponse(res, element, options) {
|
|
|
110
111
|
scriptNonce,
|
|
111
112
|
context: documentContext
|
|
112
113
|
});
|
|
114
|
+
if (res.headersSent || res.writableEnded) return;
|
|
113
115
|
let bodyStream;
|
|
114
116
|
if (documentRenderPage.status === "rendered") {
|
|
115
117
|
const synthesised = documentRenderPage.bodyHtml;
|
|
@@ -152,7 +154,7 @@ async function streamPageToResponse(res, element, options) {
|
|
|
152
154
|
};
|
|
153
155
|
if (extraHeaders) for (const [key, val] of Object.entries(extraHeaders)) if (Array.isArray(val)) res.setHeader(key, val);
|
|
154
156
|
else headers[key] = val;
|
|
155
|
-
res.writeHead(statusCode, headers);
|
|
157
|
+
res.writeHead(statusCode ?? res.statusCode, headers);
|
|
156
158
|
res.write(prefix);
|
|
157
159
|
if (bufferedBody !== null) {
|
|
158
160
|
res.end(bufferedBody + suffix);
|
|
@@ -211,6 +213,7 @@ function createSSRHandler(server, runner, routes, pagesDir, i18nConfig, fileMatc
|
|
|
211
213
|
const _reqStart = now();
|
|
212
214
|
let _compileEnd;
|
|
213
215
|
let _renderEnd;
|
|
216
|
+
attachPagesRequestCookies(req);
|
|
214
217
|
res.on("finish", () => {
|
|
215
218
|
const totalMs = now() - _reqStart;
|
|
216
219
|
const compileMs = _compileEnd !== void 0 ? Math.round(_compileEnd - _reqStart) : void 0;
|
|
@@ -248,8 +251,9 @@ function createSSRHandler(server, runner, routes, pagesDir, i18nConfig, fileMatc
|
|
|
248
251
|
if (isDataReq) {
|
|
249
252
|
const deploymentId = process.env.__VINEXT_DEPLOYMENT_ID || process.env.NEXT_DEPLOYMENT_ID;
|
|
250
253
|
const notFoundHeaders = { "Content-Type": "application/json" };
|
|
254
|
+
if (hasMiddleware) notFoundHeaders["x-nextjs-matched-path"] = `${locale ? `/${locale}` : ""}${localeStrippedUrl}`;
|
|
251
255
|
if (deploymentId) notFoundHeaders[NEXTJS_DEPLOYMENT_ID_HEADER] = deploymentId;
|
|
252
|
-
res.writeHead(404, notFoundHeaders);
|
|
256
|
+
res.writeHead(hasMiddleware ? 200 : 404, notFoundHeaders);
|
|
253
257
|
res.end("{}");
|
|
254
258
|
return;
|
|
255
259
|
}
|
|
@@ -340,17 +344,8 @@ function createSSRHandler(server, runner, routes, pagesDir, i18nConfig, fileMatc
|
|
|
340
344
|
});
|
|
341
345
|
const fallback = pathsResult?.fallback ?? false;
|
|
342
346
|
const paths = pathsResult?.paths ?? [];
|
|
343
|
-
const
|
|
344
|
-
const isValidPath = paths.some((
|
|
345
|
-
if (typeof p === "string") return normalizeStaticPathname(p) === currentPathname;
|
|
346
|
-
const entryParams = p.params;
|
|
347
|
-
if (entryParams === void 0 || entryParams === null) return false;
|
|
348
|
-
return Object.entries(entryParams).every(([key, val]) => {
|
|
349
|
-
const actual = params[key];
|
|
350
|
-
if (Array.isArray(val)) return Array.isArray(actual) && val.join("/") === actual.join("/");
|
|
351
|
-
return String(val) === String(actual);
|
|
352
|
-
});
|
|
353
|
-
});
|
|
347
|
+
const routeParams = getPagesRouteParams(patternToNextFormat(route.pattern));
|
|
348
|
+
const isValidPath = paths.some((pathEntry) => matchesPagesStaticPath(pathEntry, params, routeParams, url));
|
|
354
349
|
if (fallback === false && !isValidPath) {
|
|
355
350
|
if (isDataReq) {
|
|
356
351
|
const deploymentId = process.env.__VINEXT_DEPLOYMENT_ID || process.env.NEXT_DEPLOYMENT_ID;
|
|
@@ -762,6 +757,7 @@ function createSSRHandler(server, runner, routes, pagesDir, i18nConfig, fileMatc
|
|
|
762
757
|
setRevalidateDuration(cacheKey, revalidateSeconds);
|
|
763
758
|
}
|
|
764
759
|
const dataHeaders = { "Content-Type": "application/json" };
|
|
760
|
+
if ((statusCode ?? 200) === 200) dataHeaders["x-nextjs-matched-path"] = `${locale ? `/${locale}` : ""}${patternToNextFormat(route.pattern)}`;
|
|
765
761
|
if (gsspExtraHeaders) for (const [k, v] of Object.entries(gsspExtraHeaders)) dataHeaders[k] = v;
|
|
766
762
|
const dataRoutePattern = patternToNextFormat(route.pattern);
|
|
767
763
|
if (dataRoutePattern !== "/_error" && dataRoutePattern !== "/500") {
|
|
@@ -935,7 +931,11 @@ hydrate();
|
|
|
935
931
|
documentContext: {
|
|
936
932
|
pathname: patternToNextFormat(route.pattern),
|
|
937
933
|
query,
|
|
938
|
-
asPath: requestAsPath
|
|
934
|
+
asPath: requestAsPath,
|
|
935
|
+
...pagesNextData.autoExport === true ? {} : {
|
|
936
|
+
req,
|
|
937
|
+
res
|
|
938
|
+
}
|
|
939
939
|
},
|
|
940
940
|
enhancePageElement: (renderPageOpts) => {
|
|
941
941
|
let FinalApp = AppComponent;
|
|
@@ -1004,6 +1004,7 @@ hydrate();
|
|
|
1004
1004
|
* - other: pages/_error.tsx -> default
|
|
1005
1005
|
*/
|
|
1006
1006
|
async function renderErrorPage(server, runner, req, res, url, pagesDir, statusCode, wrapWithRouterContext, fileMatcher, err) {
|
|
1007
|
+
attachPagesRequestCookies(req);
|
|
1007
1008
|
const matcher = fileMatcher ?? createValidFileMatcher();
|
|
1008
1009
|
const candidates = statusCode === 404 ? ["404", "_error"] : statusCode === 500 ? ["500", "_error"] : ["_error"];
|
|
1009
1010
|
for (const candidate of candidates) try {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { VINEXT_ORIGINAL_STACK_TRACE_ENDPOINT } from "
|
|
1
|
+
import { VINEXT_ORIGINAL_STACK_TRACE_ENDPOINT } from "../utils/dev-stack-sourcemap-endpoint.js";
|
|
2
2
|
import { ViteDevServer } from "vite";
|
|
3
3
|
|
|
4
4
|
//#region src/server/dev-stack-sourcemap.d.ts
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { VINEXT_ORIGINAL_STACK_TRACE_ENDPOINT } from "
|
|
1
|
+
import { VINEXT_ORIGINAL_STACK_TRACE_ENDPOINT } from "../utils/dev-stack-sourcemap-endpoint.js";
|
|
2
2
|
import { readFile } from "node:fs/promises";
|
|
3
3
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
4
4
|
//#region src/server/dev-stack-sourcemap.ts
|