vinext 1.0.0-beta.2 → 1.0.0-beta.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/README.md +6 -9
- package/dist/build/client-build-config.js +7 -1
- package/dist/build/precompress.js +1 -1
- package/dist/build/prerender.d.ts +2 -1
- package/dist/build/prerender.js +12 -2
- package/dist/check.js +4 -0
- package/dist/cli-args.d.ts +2 -1
- package/dist/cli-args.js +10 -0
- package/dist/cli.js +14 -8
- package/dist/client/navigation-runtime.d.ts +6 -0
- package/dist/client/navigation-runtime.js +1 -1
- package/dist/config/config-matchers.js +4 -1
- package/dist/config/dotenv.d.ts +3 -4
- package/dist/config/dotenv.js +30 -22
- package/dist/config/next-config.d.ts +16 -5
- package/dist/config/next-config.js +7 -0
- package/dist/entries/app-browser-entry.d.ts +4 -10
- package/dist/entries/app-browser-entry.js +20 -4
- package/dist/entries/app-rsc-entry.js +21 -3
- package/dist/entries/app-rsc-manifest.js +19 -0
- package/dist/entries/pages-client-entry.js +0 -1
- package/dist/entries/pages-server-entry.js +13 -3
- package/dist/index.js +122 -49
- package/dist/init-cloudflare.d.ts +3 -1
- package/dist/init-cloudflare.js +59 -5
- package/dist/plugins/client-reference-dedup.js +7 -5
- package/dist/plugins/extensionless-dynamic-import.js +23 -18
- package/dist/plugins/ignore-dynamic-requests.js +3 -1
- package/dist/plugins/import-meta-url.js +17 -6
- package/dist/plugins/require-context.js +20 -15
- package/dist/plugins/sass.js +3 -4
- package/dist/plugins/transform-cache.d.ts +19 -0
- package/dist/plugins/transform-cache.js +36 -0
- package/dist/routing/app-route-graph.d.ts +14 -6
- package/dist/routing/app-route-graph.js +106 -16
- package/dist/server/api-handler.d.ts +2 -0
- package/dist/server/api-handler.js +7 -6
- package/dist/server/app-bfcache-identity.js +28 -2
- package/dist/server/app-browser-entry.js +175 -75
- package/dist/server/app-browser-navigation-controller.d.ts +23 -21
- package/dist/server/app-browser-navigation-controller.js +30 -5
- package/dist/server/app-browser-prefetch-response.d.ts +9 -0
- package/dist/server/app-browser-prefetch-response.js +32 -0
- package/dist/server/app-browser-state.d.ts +8 -3
- package/dist/server/app-browser-state.js +9 -3
- package/dist/server/app-page-cache-finalizer.js +1 -1
- package/dist/server/app-page-cache.d.ts +1 -1
- package/dist/server/app-page-cache.js +16 -2
- package/dist/server/app-page-dispatch.d.ts +9 -1
- package/dist/server/app-page-dispatch.js +37 -8
- package/dist/server/app-page-element-builder.d.ts +4 -1
- package/dist/server/app-page-element-builder.js +34 -7
- package/dist/server/app-page-head.d.ts +3 -3
- package/dist/server/app-page-head.js +58 -13
- package/dist/server/app-page-http-access-fallback-metadata.d.ts +2 -2
- package/dist/server/app-page-http-access-fallback-metadata.js +9 -1
- package/dist/server/app-page-probe.d.ts +4 -0
- package/dist/server/app-page-probe.js +6 -2
- package/dist/server/app-page-render.d.ts +1 -1
- package/dist/server/app-page-render.js +13 -3
- package/dist/server/app-page-request.d.ts +3 -1
- package/dist/server/app-page-request.js +4 -13
- package/dist/server/app-page-response.d.ts +2 -0
- package/dist/server/app-page-response.js +7 -2
- package/dist/server/app-page-route-wiring.d.ts +10 -2
- package/dist/server/app-page-route-wiring.js +269 -59
- package/dist/server/app-pages-bridge.d.ts +2 -1
- package/dist/server/app-pages-bridge.js +3 -1
- package/dist/server/app-route-handler-cache.js +4 -0
- package/dist/server/app-route-handler-dispatch.js +9 -3
- package/dist/server/app-route-handler-response.js +1 -1
- package/dist/server/app-route-module-loader.d.ts +6 -0
- package/dist/server/app-route-module-loader.js +3 -0
- package/dist/server/app-router-entry.js +6 -3
- package/dist/server/app-rsc-cache-busting.d.ts +7 -0
- package/dist/server/app-rsc-cache-busting.js +6 -0
- package/dist/server/app-rsc-errors.js +10 -0
- package/dist/server/app-rsc-handler.d.ts +2 -0
- package/dist/server/app-rsc-handler.js +30 -13
- package/dist/server/app-rsc-render-mode.d.ts +3 -2
- package/dist/server/app-rsc-render-mode.js +4 -1
- package/dist/server/app-rsc-request-normalization.js +65 -4
- package/dist/server/app-rsc-route-matching.d.ts +9 -0
- package/dist/server/app-rsc-route-matching.js +6 -0
- package/dist/server/app-server-action-execution.d.ts +1 -1
- package/dist/server/app-ssr-entry.js +4 -4
- package/dist/server/app-visited-response-cache.d.ts +6 -1
- package/dist/server/app-visited-response-cache.js +49 -1
- package/dist/server/cache-control.d.ts +2 -2
- package/dist/server/cache-control.js +2 -1
- package/dist/server/dev-server.d.ts +3 -1
- package/dist/server/dev-server.js +204 -348
- package/dist/server/edge-api-runtime.d.ts +10 -1
- package/dist/server/edge-api-runtime.js +29 -1
- package/dist/server/headers.d.ts +4 -2
- package/dist/server/headers.js +6 -3
- package/dist/server/isr-cache.d.ts +10 -33
- package/dist/server/isr-cache.js +33 -43
- package/dist/server/isr-decision.d.ts +2 -2
- package/dist/server/pages-api-route.d.ts +4 -0
- package/dist/server/pages-api-route.js +6 -3
- package/dist/server/pages-asset-tags.d.ts +1 -0
- package/dist/server/pages-asset-tags.js +6 -4
- package/dist/server/pages-dev-hydration.js +0 -1
- package/dist/server/pages-document-asset-props.d.ts +26 -0
- package/dist/server/pages-document-asset-props.js +69 -0
- package/dist/server/pages-get-initial-props.d.ts +1 -1
- package/dist/server/pages-get-initial-props.js +1 -4
- package/dist/server/pages-i18n.js +64 -16
- package/dist/server/pages-node-compat.d.ts +2 -0
- package/dist/server/pages-node-compat.js +10 -6
- package/dist/server/pages-page-data.d.ts +61 -9
- package/dist/server/pages-page-data.js +334 -74
- package/dist/server/pages-page-handler.d.ts +6 -1
- package/dist/server/pages-page-handler.js +119 -20
- package/dist/server/pages-page-response.d.ts +7 -3
- package/dist/server/pages-page-response.js +41 -33
- package/dist/server/pages-request-pipeline.d.ts +7 -0
- package/dist/server/pages-request-pipeline.js +5 -1
- package/dist/server/pages-revalidate.d.ts +1 -1
- package/dist/server/pages-revalidate.js +54 -8
- package/dist/server/pages-router-entry.d.ts +1 -0
- package/dist/server/pages-router-entry.js +10 -4
- package/dist/server/prerender-manifest.d.ts +1 -0
- package/dist/server/prod-server.d.ts +2 -1
- package/dist/server/prod-server.js +38 -13
- package/dist/server/revalidation-host.d.ts +11 -0
- package/dist/server/revalidation-host.js +19 -0
- package/dist/server/seed-cache.js +1 -1
- package/dist/server/worker-revalidation-context.d.ts +13 -0
- package/dist/server/worker-revalidation-context.js +30 -0
- package/dist/shims/app-router-scroll-state.d.ts +2 -1
- package/dist/shims/app-router-scroll-state.js +7 -2
- package/dist/shims/cache-handler.d.ts +1 -1
- package/dist/shims/cache-handler.js +10 -7
- package/dist/shims/cache-runtime.d.ts +6 -0
- package/dist/shims/cache-runtime.js +4 -1
- package/dist/shims/cache.js +1 -1
- package/dist/shims/document.js +15 -2
- package/dist/shims/error.js +1 -1
- package/dist/shims/fetch-cache.js +1 -1
- package/dist/shims/font-google-base.js +17 -8
- package/dist/shims/font-local.js +41 -10
- package/dist/shims/hash-scroll.d.ts +1 -1
- package/dist/shims/hash-scroll.js +2 -1
- package/dist/shims/headers.d.ts +10 -13
- package/dist/shims/headers.js +85 -36
- package/dist/shims/internal/cookie-serialize.d.ts +10 -9
- package/dist/shims/internal/cookie-serialize.js +9 -8
- package/dist/shims/internal/interpolate-as.d.ts +15 -1
- package/dist/shims/internal/interpolate-as.js +27 -2
- package/dist/shims/link.d.ts +2 -0
- package/dist/shims/link.js +77 -24
- package/dist/shims/metadata.d.ts +18 -34
- package/dist/shims/metadata.js +98 -56
- package/dist/shims/navigation.d.ts +18 -2
- package/dist/shims/navigation.js +70 -21
- package/dist/shims/request-context.d.ts +6 -2
- package/dist/shims/router.js +18 -7
- package/dist/shims/script.js +1 -1
- package/dist/shims/server.d.ts +7 -6
- package/dist/shims/server.js +156 -57
- package/dist/shims/slot.d.ts +2 -1
- package/dist/shims/slot.js +6 -2
- package/dist/shims/streamed-icons.d.ts +9 -0
- package/dist/shims/streamed-icons.js +33 -0
- package/dist/shims/unified-request-context.d.ts +21 -2
- package/dist/shims/unified-request-context.js +82 -1
- package/dist/utils/cache-control-metadata.d.ts +2 -1
- package/dist/utils/cache-control-metadata.js +5 -1
- package/dist/utils/html-limited-bots.js +1 -1
- package/dist/utils/protocol-headers.d.ts +7 -1
- package/dist/utils/protocol-headers.js +7 -1
- package/package.json +1 -1
|
@@ -195,6 +195,7 @@ import {
|
|
|
195
195
|
isrGet as __isrGet,
|
|
196
196
|
isrSet as __isrSet,
|
|
197
197
|
isrSetPrerenderedAppPage as __isrSetPrerenderedAppPage,
|
|
198
|
+
isOnDemandRevalidateRequest as __isOnDemandRevalidateRequest,
|
|
198
199
|
triggerBackgroundRegeneration as __triggerBackgroundRegeneration,
|
|
199
200
|
} from ${JSON.stringify(isrCachePath)};
|
|
200
201
|
// Import server-only state module to register ALS-backed accessors.
|
|
@@ -413,7 +414,7 @@ function findIntercept(pathname, sourcePathname = null) {
|
|
|
413
414
|
return __routeMatcher.findIntercept(pathname, sourcePathname);
|
|
414
415
|
}
|
|
415
416
|
|
|
416
|
-
async function buildPageElements(route, params, routePath, pageRequest, layoutParamAccess, displayPathname = routePath) {
|
|
417
|
+
async function buildPageElements(route, params, routePath, pageRequest, layoutParamAccess, displayPathname = routePath, scriptNonce) {
|
|
417
418
|
// Hydrate lazy page/route-handler modules before any synchronous read.
|
|
418
419
|
await __ensureRouteLoaded(route);
|
|
419
420
|
return __buildPageElements({
|
|
@@ -432,10 +433,13 @@ async function buildPageElements(route, params, routePath, pageRequest, layoutPa
|
|
|
432
433
|
basePath: __basePath,
|
|
433
434
|
trailingSlash: __trailingSlash,
|
|
434
435
|
htmlLimitedBots: __htmlLimitedBots,
|
|
436
|
+
scriptNonce,
|
|
435
437
|
});
|
|
436
438
|
}
|
|
437
439
|
|
|
438
440
|
const __i18nConfig = ${JSON.stringify(i18nConfig)};
|
|
441
|
+
export { __i18nConfig };
|
|
442
|
+
export const authorizeOnDemandRevalidate = __isOnDemandRevalidateRequest;
|
|
439
443
|
const __configRedirects = ${JSON.stringify(redirects)};
|
|
440
444
|
const __configRewrites = ${JSON.stringify(rewrites)};
|
|
441
445
|
const __configHeaders = ${JSON.stringify(headers)};
|
|
@@ -595,7 +599,7 @@ export default createAppRscHandler({
|
|
|
595
599
|
observePageSearchParamsAccess: buildOptions?.observePageSearchParamsAccess === true,
|
|
596
600
|
serveStreamingMetadata: buildOptions?.serveStreamingMetadata,
|
|
597
601
|
isProduction: process.env.NODE_ENV === "production",
|
|
598
|
-
}, layoutParamAccess, displayPathname);
|
|
602
|
+
}, layoutParamAccess, displayPathname, scriptNonce);
|
|
599
603
|
},
|
|
600
604
|
clientReuseManifest,
|
|
601
605
|
cleanPathname,
|
|
@@ -839,6 +843,7 @@ export default createAppRscHandler({
|
|
|
839
843
|
middlewareContext,
|
|
840
844
|
mountedSlotsHeader,
|
|
841
845
|
request,
|
|
846
|
+
scriptNonce,
|
|
842
847
|
routeMatch,
|
|
843
848
|
routePathname,
|
|
844
849
|
searchParams,
|
|
@@ -881,7 +886,7 @@ export default createAppRscHandler({
|
|
|
881
886
|
renderMode: actionRenderMode,
|
|
882
887
|
observeMetadataSearchParamsAccess: observeMetadataSearchParamsAccess === true,
|
|
883
888
|
observePageSearchParamsAccess: observePageSearchParamsAccess === true,
|
|
884
|
-
});
|
|
889
|
+
}, undefined, actionCleanPathname, scriptNonce);
|
|
885
890
|
},
|
|
886
891
|
cleanPathname,
|
|
887
892
|
clearRequestContext() {
|
|
@@ -981,6 +986,19 @@ export default createAppRscHandler({
|
|
|
981
986
|
},` : ""}
|
|
982
987
|
matchRoute,
|
|
983
988
|
matchRequestRoute,
|
|
989
|
+
matchInterceptRoute(pathname, sourcePathname) {
|
|
990
|
+
const intercept = findIntercept(pathname, sourcePathname);
|
|
991
|
+
if (!intercept) return null;
|
|
992
|
+
const route = routes[intercept.sourceRouteIndex];
|
|
993
|
+
if (!route) return null;
|
|
994
|
+
const params = Object.create(null);
|
|
995
|
+
for (const name of route.params) {
|
|
996
|
+
if (Object.prototype.hasOwnProperty.call(intercept.sourceMatchedParams, name)) {
|
|
997
|
+
params[name] = intercept.sourceMatchedParams[name];
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
return { route, params };
|
|
1001
|
+
},
|
|
984
1002
|
${middlewarePath ? `runMiddleware({ cleanPathname, context, hadBasePath, isDataRequest, request }) {
|
|
985
1003
|
return __applyAppMiddleware({
|
|
986
1004
|
basePath: __basePath,
|
|
@@ -53,6 +53,7 @@ function registerRouteModules(routes, imports) {
|
|
|
53
53
|
for (const layout of route.layouts) imports.getLazyLoaderVar(layout);
|
|
54
54
|
for (const tmpl of route.templates) imports.getLazyLoaderVar(tmpl);
|
|
55
55
|
if (route.loadingPath) imports.getLazyLoaderVar(route.loadingPath);
|
|
56
|
+
for (const loadingPath of route.loadingPaths ?? []) imports.getLazyLoaderVar(loadingPath);
|
|
56
57
|
if (route.errorPath) imports.getLazyLoaderVar(route.errorPath);
|
|
57
58
|
if (route.layoutErrorPaths) {
|
|
58
59
|
for (const ep of route.layoutErrorPaths) if (ep) imports.getLazyLoaderVar(ep);
|
|
@@ -76,18 +77,21 @@ function registerRouteModules(routes, imports) {
|
|
|
76
77
|
if (slot.layoutPath) imports.getLazyLoaderVar(slot.layoutPath);
|
|
77
78
|
for (const layoutPath of slot.configLayoutPaths ?? []) imports.getLazyLoaderVar(layoutPath);
|
|
78
79
|
if (slot.loadingPath) imports.getLazyLoaderVar(slot.loadingPath);
|
|
80
|
+
for (const loadingPath of slot.loadingPaths ?? []) imports.getLazyLoaderVar(loadingPath);
|
|
79
81
|
if (slot.errorPath) imports.getLazyLoaderVar(slot.errorPath);
|
|
80
82
|
if (slot.notFoundPath) imports.getLazyLoaderVar(slot.notFoundPath);
|
|
81
83
|
for (const ir of slot.interceptingRoutes) {
|
|
82
84
|
imports.getLazyLoaderVar(ir.pagePath);
|
|
83
85
|
if (ir.notFoundPath) imports.getLazyLoaderVar(ir.notFoundPath);
|
|
84
86
|
for (const layoutPath of ir.layoutPaths) imports.getLazyLoaderVar(layoutPath);
|
|
87
|
+
for (const loadingPath of ir.loadingPaths ?? []) imports.getLazyLoaderVar(loadingPath);
|
|
85
88
|
}
|
|
86
89
|
}
|
|
87
90
|
for (const ir of route.siblingIntercepts ?? []) {
|
|
88
91
|
imports.getLazyLoaderVar(ir.pagePath);
|
|
89
92
|
if (ir.notFoundPath) imports.getLazyLoaderVar(ir.notFoundPath);
|
|
90
93
|
for (const layoutPath of ir.layoutPaths) imports.getLazyLoaderVar(layoutPath);
|
|
94
|
+
for (const loadingPath of ir.loadingPaths ?? []) imports.getLazyLoaderVar(loadingPath);
|
|
91
95
|
}
|
|
92
96
|
}
|
|
93
97
|
}
|
|
@@ -102,10 +106,12 @@ function buildRouteEntries(routes, imports) {
|
|
|
102
106
|
const staticSiblings = route.isDynamic ? computeAppRouteStaticSiblings(routes, route) : [];
|
|
103
107
|
const layoutLoaders = lazyLoaderArray(route.layouts, imports);
|
|
104
108
|
const templateLoaders = lazyLoaderArray(route.templates, imports);
|
|
109
|
+
const loadingPaths = route.loadingPaths ?? [];
|
|
105
110
|
const notFoundPaths = route.notFoundPaths ?? [];
|
|
106
111
|
const forbiddenPaths = route.forbiddenPaths ?? [];
|
|
107
112
|
const unauthorizedPaths = route.unauthorizedPaths ?? [];
|
|
108
113
|
const notFoundLoaders = lazyLoaderArray(notFoundPaths, imports);
|
|
114
|
+
const loadingLoaders = lazyLoaderArray(loadingPaths, imports);
|
|
109
115
|
const forbiddenLoaders = lazyLoaderArray(forbiddenPaths, imports);
|
|
110
116
|
const unauthorizedLoaders = lazyLoaderArray(unauthorizedPaths, imports);
|
|
111
117
|
const siblingInterceptEntries = (route.siblingIntercepts ?? []).map((ir) => ` {
|
|
@@ -118,6 +124,9 @@ function buildRouteEntries(routes, imports) {
|
|
|
118
124
|
__loadInterceptLayouts: ${lazyLoaderArray(ir.layoutPaths, imports)},
|
|
119
125
|
interceptLayoutSegments: ${JSON.stringify(ir.layoutSegments ?? [])},
|
|
120
126
|
interceptBranchSegments: ${JSON.stringify(ir.branchSegments ?? [])},
|
|
127
|
+
interceptLoadings: ${moduleArray(ir.loadingPaths?.length ?? 0)},
|
|
128
|
+
__loadInterceptLoadings: ${lazyLoaderArray(ir.loadingPaths ?? [], imports)},
|
|
129
|
+
interceptLoadingTreePositions: ${JSON.stringify(ir.loadingTreePositions ?? [])},
|
|
121
130
|
interceptNotFoundBranchSegments: ${JSON.stringify(ir.notFoundBranchSegments ?? ir.branchSegments ?? [])},
|
|
122
131
|
page: null,
|
|
123
132
|
__pageLoader: ${imports.getLazyLoaderVar(ir.pagePath)},
|
|
@@ -136,6 +145,9 @@ function buildRouteEntries(routes, imports) {
|
|
|
136
145
|
__loadInterceptLayouts: ${lazyLoaderArray(ir.layoutPaths, imports)},
|
|
137
146
|
interceptLayoutSegments: ${JSON.stringify(ir.layoutSegments ?? [])},
|
|
138
147
|
interceptBranchSegments: ${JSON.stringify(ir.branchSegments ?? [])},
|
|
148
|
+
interceptLoadings: ${moduleArray(ir.loadingPaths?.length ?? 0)},
|
|
149
|
+
__loadInterceptLoadings: ${lazyLoaderArray(ir.loadingPaths ?? [], imports)},
|
|
150
|
+
interceptLoadingTreePositions: ${JSON.stringify(ir.loadingTreePositions ?? [])},
|
|
139
151
|
interceptNotFoundBranchSegments: ${JSON.stringify(ir.notFoundBranchSegments ?? ir.branchSegments ?? [])},
|
|
140
152
|
page: null,
|
|
141
153
|
__pageLoader: ${imports.getLazyLoaderVar(ir.pagePath)},
|
|
@@ -147,6 +159,7 @@ function buildRouteEntries(routes, imports) {
|
|
|
147
159
|
return ` ${JSON.stringify(slot.key)}: {
|
|
148
160
|
id: ${JSON.stringify(slot.id ?? null)},
|
|
149
161
|
name: ${JSON.stringify(slot.name)},
|
|
162
|
+
ownerTreePosition: ${slot.ownerTreePosition ?? "null"},
|
|
150
163
|
page: null,
|
|
151
164
|
__loadPage: ${slot.pagePath ? imports.getLazyLoaderVar(slot.pagePath) : "null"},
|
|
152
165
|
default: null,
|
|
@@ -158,6 +171,9 @@ function buildRouteEntries(routes, imports) {
|
|
|
158
171
|
configLayoutTreePositions: ${JSON.stringify(slot.configLayoutTreePositions ?? [])},
|
|
159
172
|
loading: null,
|
|
160
173
|
__loadLoading: ${slot.loadingPath ? imports.getLazyLoaderVar(slot.loadingPath) : "null"},
|
|
174
|
+
loadings: ${moduleArray(slot.loadingPaths?.length ?? 0)},
|
|
175
|
+
__loadLoadings: ${lazyLoaderArray(slot.loadingPaths ?? [], imports)},
|
|
176
|
+
loadingTreePositions: ${JSON.stringify(slot.loadingTreePositions ?? [])},
|
|
161
177
|
error: null,
|
|
162
178
|
__loadError: ${slot.errorPath ? imports.getLazyLoaderVar(slot.errorPath) : "null"},
|
|
163
179
|
notFound: null,
|
|
@@ -200,6 +216,9 @@ ${interceptEntries.join(",\n")}
|
|
|
200
216
|
layoutTreePositions: ${JSON.stringify(route.layoutTreePositions)},
|
|
201
217
|
templates: ${moduleArray(route.templates.length)},
|
|
202
218
|
__loadTemplates: ${templateLoaders},
|
|
219
|
+
loadings: ${moduleArray(loadingPaths.length)},
|
|
220
|
+
__loadLoadings: ${loadingLoaders},
|
|
221
|
+
loadingTreePositions: ${JSON.stringify(route.loadingTreePositions ?? null)},
|
|
203
222
|
errors: ${moduleArray(layoutErrorPaths.length)},
|
|
204
223
|
__loadErrors: ${layoutErrorLoaders},
|
|
205
224
|
errorPaths: ${moduleArray(errorPaths.length)},
|
|
@@ -24,6 +24,7 @@ const _pagesApiRoutePath = resolveEntryPath("../server/pages-api-route.js", impo
|
|
|
24
24
|
const _serverGlobalsPath = resolveEntryPath("../server/server-globals.js", import.meta.url);
|
|
25
25
|
const _queryUtilsPath = resolveEntryPath("../utils/query.js", import.meta.url);
|
|
26
26
|
const _pagesPageHandlerPath = resolveEntryPath("../server/pages-page-handler.js", import.meta.url);
|
|
27
|
+
const _isrCachePath = resolveEntryPath("../server/isr-cache.js", import.meta.url);
|
|
27
28
|
async function getPagesDataKind(filePath) {
|
|
28
29
|
const source = await readFile(filePath, "utf8");
|
|
29
30
|
if (hasExportedName(source, "getStaticProps")) return "static";
|
|
@@ -71,10 +72,12 @@ async function generateServerEntry(pagesDir, nextConfig, fileMatcher, middleware
|
|
|
71
72
|
},
|
|
72
73
|
headers: nextConfig?.headers ?? [],
|
|
73
74
|
expireTime: nextConfig?.expireTime,
|
|
75
|
+
allowedRevalidateHeaderKeys: nextConfig?.allowedRevalidateHeaderKeys ?? [],
|
|
74
76
|
cacheMaxMemorySize: nextConfig?.cacheMaxMemorySize,
|
|
75
77
|
htmlLimitedBots: nextConfig?.htmlLimitedBots,
|
|
76
78
|
i18n: nextConfig?.i18n ?? null,
|
|
77
79
|
disableOptimizedLoading: nextConfig?.disableOptimizedLoading === true,
|
|
80
|
+
crossOrigin: nextConfig?.crossOrigin,
|
|
78
81
|
clientTraceMetadata: nextConfig?.clientTraceMetadata,
|
|
79
82
|
images: {
|
|
80
83
|
deviceSizes: nextConfig?.images?.deviceSizes,
|
|
@@ -151,11 +154,17 @@ import { handlePagesApiRoute as __handlePagesApiRoute } from ${JSON.stringify(_p
|
|
|
151
154
|
import { normalizePagesDataRequest as __normalizePagesDataRequest, buildNextDataNotFoundResponse as __buildNextDataNotFoundResponse } from ${JSON.stringify(_pagesDataRoutePath)};
|
|
152
155
|
import { buildDefaultPagesNotFoundResponse as __buildDefaultPagesNotFoundResponse } from ${JSON.stringify(_pagesDefault404Path)};
|
|
153
156
|
import { createPagesPageHandler as __createPagesPageHandler } from ${JSON.stringify(_pagesPageHandlerPath)};
|
|
157
|
+
import { isOnDemandRevalidateRequest as __isOnDemandRevalidateRequest } from ${JSON.stringify(_isrCachePath)};
|
|
154
158
|
${instrumentationImportCode}
|
|
155
159
|
${middlewareImportCode}
|
|
156
160
|
|
|
157
161
|
${instrumentationInitCode}
|
|
158
162
|
|
|
163
|
+
// The outer Node production pipeline runs outside this generated bundle, so
|
|
164
|
+
// it cannot safely validate against its own development fallback secret. Give
|
|
165
|
+
// it a verifier closed over this entry's build-time-baked secret instead.
|
|
166
|
+
export const authorizeOnDemandRevalidate = __isOnDemandRevalidateRequest;
|
|
167
|
+
|
|
159
168
|
// i18n config (embedded at build time)
|
|
160
169
|
const i18nConfig = ${i18nConfigJson};
|
|
161
170
|
|
|
@@ -290,6 +299,7 @@ const _renderPage = __createPagesPageHandler({
|
|
|
290
299
|
htmlLimitedBots: vinextConfig.htmlLimitedBots,
|
|
291
300
|
clientTraceMetadata: vinextConfig.clientTraceMetadata,
|
|
292
301
|
disableOptimizedLoading: vinextConfig.disableOptimizedLoading,
|
|
302
|
+
crossOrigin: vinextConfig.crossOrigin,
|
|
293
303
|
},
|
|
294
304
|
buildId,
|
|
295
305
|
hasMiddleware,
|
|
@@ -344,7 +354,6 @@ const _renderPage = __createPagesPageHandler({
|
|
|
344
354
|
? React.createElement(AppComponent, {
|
|
345
355
|
...props,
|
|
346
356
|
Component: PageComponent,
|
|
347
|
-
pageProps: rawPageProps,
|
|
348
357
|
router: Router,
|
|
349
358
|
})
|
|
350
359
|
: React.createElement(PageComponent, pageProps);
|
|
@@ -362,7 +371,6 @@ const _renderPage = __createPagesPageHandler({
|
|
|
362
371
|
? React.createElement(FinalApp, {
|
|
363
372
|
...props,
|
|
364
373
|
Component: FinalComp,
|
|
365
|
-
pageProps: rawPageProps,
|
|
366
374
|
router: Router,
|
|
367
375
|
})
|
|
368
376
|
: React.createElement(FinalComp, pageProps);
|
|
@@ -379,14 +387,16 @@ export async function renderPage(request, url, manifest, ctx, middlewareHeaders,
|
|
|
379
387
|
|
|
380
388
|
|
|
381
389
|
|
|
382
|
-
export async function handleApiRoute(request, url, ctx) {
|
|
390
|
+
export async function handleApiRoute(request, url, ctx, trustedRevalidateOrigin, edgeRuntime = "worker") {
|
|
383
391
|
__registerConfiguredCacheAdapters();
|
|
384
392
|
const match = matchRoute(url, apiRoutes);
|
|
385
393
|
return __handlePagesApiRoute({
|
|
386
394
|
ctx,
|
|
395
|
+
edgeRuntime,
|
|
387
396
|
match,
|
|
388
397
|
nextConfig: vinextConfig,
|
|
389
398
|
request,
|
|
399
|
+
trustedRevalidateOrigin,
|
|
390
400
|
url,
|
|
391
401
|
reportRequestError(error, routePattern) {
|
|
392
402
|
console.error("[vinext] API error:", error);
|
package/dist/index.js
CHANGED
|
@@ -35,17 +35,19 @@ import { generateRscEntry } from "./entries/app-rsc-entry.js";
|
|
|
35
35
|
import { generateSsrEntry } from "./entries/app-ssr-entry.js";
|
|
36
36
|
import { VINEXT_CACHE_CONFIG_PLUGIN_PROPERTY, VIRTUAL_CACHE_ADAPTERS, generateCacheAdaptersModule } from "./cache/cache-adapters-virtual.js";
|
|
37
37
|
import { VIRTUAL_IMAGE_ADAPTERS, generateImageAdaptersModule } from "./image/image-adapters-virtual.js";
|
|
38
|
-
import { generateBrowserEntry,
|
|
38
|
+
import { generateBrowserEntry, toLinkPrefetchRoutes } from "./entries/app-browser-entry.js";
|
|
39
39
|
import { collectRouteClassificationManifest } from "./build/route-classification-manifest.js";
|
|
40
40
|
import { planRouteClassificationInjection } from "./build/route-classification-injector.js";
|
|
41
41
|
import { PHASE_DEVELOPMENT_SERVER, PHASE_PRODUCTION_BUILD } from "./shims/constants.js";
|
|
42
42
|
import { RESOLVED_VIRTUAL_GOOGLE_FONTS, VIRTUAL_GOOGLE_FONTS, createGoogleFontsPlugin, createLocalFontsPlugin, generateGoogleFontsVirtualModule, parseStaticObjectLiteral } from "./plugins/fonts.js";
|
|
43
43
|
import { VINEXT_NEXT_CONFIG_PLUGIN_PROPERTY, createRscCompatibilityId, findNextConfigPath, loadNextConfig, resolveNextConfig, resolveNextConfigInput } from "./config/next-config.js";
|
|
44
|
+
import { loadDotenv } from "./config/dotenv.js";
|
|
44
45
|
import { mergeServerExternalPackages } from "./config/server-external-packages.js";
|
|
45
46
|
import { precompressAssets } from "./build/precompress.js";
|
|
46
47
|
import { ensureAssetsIgnore } from "./build/assets-ignore.js";
|
|
47
48
|
import { emitNextClientRuntimeManifests } from "./build/next-client-runtime-manifests.js";
|
|
48
49
|
import { collectInlineCssManifest, injectInlineCssManifestGlobal } from "./build/inline-css.js";
|
|
50
|
+
import { readTrustedRevalidationHostname } from "./server/revalidation-host.js";
|
|
49
51
|
import { installDevStackSourcemapMiddleware } from "./server/dev-stack-sourcemap.js";
|
|
50
52
|
import { runPagesRequest } from "./server/pages-request-pipeline.js";
|
|
51
53
|
import { pagesRouteHasPriorityOverAppRoute, validateHybridRouteConflicts } from "./server/hybrid-route-priority.js";
|
|
@@ -83,6 +85,7 @@ import { createClientAssetFileNames, createClientCodeSplittingConfig, createClie
|
|
|
83
85
|
import { hasExportAllCandidate, stripServerExports, validatePageExports } from "./plugins/strip-server-exports.js";
|
|
84
86
|
import { removeConsoleCalls } from "./plugins/remove-console.js";
|
|
85
87
|
import { createImportMetaUrlPlugin } from "./plugins/import-meta-url.js";
|
|
88
|
+
import { createTransformCache } from "./plugins/transform-cache.js";
|
|
86
89
|
import { createRequireContextPlugin } from "./plugins/require-context.js";
|
|
87
90
|
import { createExtensionlessDynamicImportPlugin } from "./plugins/extensionless-dynamic-import.js";
|
|
88
91
|
import { createWasmModuleImportPlugin } from "./plugins/wasm-module-import.js";
|
|
@@ -95,7 +98,7 @@ import { VINEXT_PRERENDER_CONFIG_PLUGIN_PROPERTY, VINEXT_ROUTE_ROOT_CONFIG_PLUGI
|
|
|
95
98
|
import { staticExportApp, staticExportPages } from "./build/static-export.js";
|
|
96
99
|
import { createRequire } from "node:module";
|
|
97
100
|
import fs from "node:fs";
|
|
98
|
-
import { createLogger,
|
|
101
|
+
import { createLogger, parseAst, transformWithOxc } from "vite";
|
|
99
102
|
import { pathToFileURL } from "node:url";
|
|
100
103
|
import { createHash, randomBytes } from "node:crypto";
|
|
101
104
|
import commonjs from "vite-plugin-commonjs";
|
|
@@ -114,6 +117,63 @@ const OPTIONAL_OPTIMIZE_DEPS_WARNING_RE = /Failed to resolve dependency: .*use-s
|
|
|
114
117
|
const VINEXT_FILTERED_OPTIMIZE_DEPS_WARN = Symbol.for("vinext.filteredOptimizeDepsWarn");
|
|
115
118
|
const ANSI_ESCAPE_RE = new RegExp(`${String.fromCharCode(27)}\\[[0-9;]*m`, "g");
|
|
116
119
|
installSocketErrorBackstop();
|
|
120
|
+
function isUseCacheAstNode(value) {
|
|
121
|
+
return typeof value === "object" && value !== null && typeof Reflect.get(value, "type") === "string";
|
|
122
|
+
}
|
|
123
|
+
function hasInlineUseCacheDirective(node) {
|
|
124
|
+
const body = isUseCacheAstNode(node.body) && node.body.type === "BlockStatement" ? node.body : null;
|
|
125
|
+
if (!body || !Array.isArray(body.body)) return false;
|
|
126
|
+
return body.body.some((statement) => {
|
|
127
|
+
if (!isUseCacheAstNode(statement) || statement.type !== "ExpressionStatement") return false;
|
|
128
|
+
const expression = isUseCacheAstNode(statement.expression) ? statement.expression : null;
|
|
129
|
+
return expression?.type === "Literal" && typeof expression.value === "string" && /^use cache(:\s*\w+)?$/.test(expression.value);
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
function functionAcceptsSecondArgument(node) {
|
|
133
|
+
const params = Array.isArray(node.params) ? node.params : [];
|
|
134
|
+
if (params.length >= 2) return true;
|
|
135
|
+
return params.some((param) => isUseCacheAstNode(param) && param.type === "RestElement");
|
|
136
|
+
}
|
|
137
|
+
function collectInlineUseCacheSecondArgumentUsage(value) {
|
|
138
|
+
const usage = [];
|
|
139
|
+
function walk(node) {
|
|
140
|
+
if (Array.isArray(node)) {
|
|
141
|
+
for (const child of node) walk(child);
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
if (!isUseCacheAstNode(node)) return;
|
|
145
|
+
if ((node.type === "FunctionDeclaration" || node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression") && hasInlineUseCacheDirective(node)) usage.push(functionAcceptsSecondArgument(node));
|
|
146
|
+
for (const [key, child] of Object.entries(node)) {
|
|
147
|
+
if (key === "type" || key === "start" || key === "end" || key === "loc" || key === "parent") continue;
|
|
148
|
+
walk(child);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
walk(value);
|
|
152
|
+
return usage;
|
|
153
|
+
}
|
|
154
|
+
function collectFileUseCacheSecondArgumentUsage(body) {
|
|
155
|
+
const localFunctions = /* @__PURE__ */ new Map();
|
|
156
|
+
function collectDeclaration(value) {
|
|
157
|
+
if (!isUseCacheAstNode(value)) return;
|
|
158
|
+
if (value.type === "FunctionDeclaration") {
|
|
159
|
+
const id = isUseCacheAstNode(value.id) ? value.id : null;
|
|
160
|
+
if (id?.type === "Identifier" && typeof id.name === "string") localFunctions.set(id.name, functionAcceptsSecondArgument(value));
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
if (value.type !== "VariableDeclaration" || !Array.isArray(value.declarations)) return;
|
|
164
|
+
for (const declaration of value.declarations) {
|
|
165
|
+
if (!isUseCacheAstNode(declaration) || declaration.type !== "VariableDeclarator") continue;
|
|
166
|
+
const id = isUseCacheAstNode(declaration.id) ? declaration.id : null;
|
|
167
|
+
const init = isUseCacheAstNode(declaration.init) ? declaration.init : null;
|
|
168
|
+
if (id?.type === "Identifier" && typeof id.name === "string" && init && (init.type === "FunctionExpression" || init.type === "ArrowFunctionExpression")) localFunctions.set(id.name, functionAcceptsSecondArgument(init));
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
for (const statement of body) {
|
|
172
|
+
if (!isUseCacheAstNode(statement)) continue;
|
|
173
|
+
collectDeclaration(statement.type === "ExportNamedDeclaration" || statement.type === "ExportDefaultDeclaration" ? statement.declaration : statement);
|
|
174
|
+
}
|
|
175
|
+
return localFunctions;
|
|
176
|
+
}
|
|
117
177
|
function isInsideDirectory(dir, filePath) {
|
|
118
178
|
const relativePath = path.relative(dir, filePath);
|
|
119
179
|
return relativePath !== "" && !relativePath.startsWith("..") && !path.isAbsolute(relativePath);
|
|
@@ -475,16 +535,17 @@ const _tsconfigAliasCache = /* @__PURE__ */ new Map();
|
|
|
475
535
|
function sortTsconfigAliasesBySpecificity(aliases) {
|
|
476
536
|
return Object.fromEntries(Object.entries(aliases).sort((a, b) => b[0].length - a[0].length));
|
|
477
537
|
}
|
|
478
|
-
function resolveTsconfigAliases(projectRoot) {
|
|
479
|
-
|
|
538
|
+
function resolveTsconfigAliases(projectRoot, configuredPath) {
|
|
539
|
+
const configPath = configuredPath ? path.resolve(projectRoot, configuredPath) : void 0;
|
|
540
|
+
const cacheKey = configPath ?? projectRoot;
|
|
541
|
+
if (_tsconfigAliasCache.has(cacheKey)) return _tsconfigAliasCache.get(cacheKey);
|
|
480
542
|
let aliases = {};
|
|
481
|
-
for (const
|
|
482
|
-
const candidate = path.join(projectRoot, name);
|
|
543
|
+
for (const candidate of configPath ? [configPath] : TSCONFIG_FILES.map((name) => path.join(projectRoot, name))) {
|
|
483
544
|
if (!fs.existsSync(candidate)) continue;
|
|
484
545
|
aliases = sortTsconfigAliasesBySpecificity(loadTsconfigPathAliases(candidate, projectRoot));
|
|
485
546
|
break;
|
|
486
547
|
}
|
|
487
|
-
_tsconfigAliasCache.set(
|
|
548
|
+
_tsconfigAliasCache.set(cacheKey, aliases);
|
|
488
549
|
return aliases;
|
|
489
550
|
}
|
|
490
551
|
/**
|
|
@@ -755,7 +816,7 @@ function vinext(options = {}) {
|
|
|
755
816
|
* __NEXT_DATA__ to determine which page to hydrate.
|
|
756
817
|
*/
|
|
757
818
|
async function generateClientEntry$1() {
|
|
758
|
-
const appPrefetchRoutes = hasAppDir ? (await appRouter(appDir, nextConfig?.pageExtensions, fileMatcher))
|
|
819
|
+
const appPrefetchRoutes = hasAppDir ? toLinkPrefetchRoutes(await appRouter(appDir, nextConfig?.pageExtensions, fileMatcher)) : [];
|
|
759
820
|
return generateClientEntry(pagesDir, nextConfig, fileMatcher, {
|
|
760
821
|
appPrefetchRoutes,
|
|
761
822
|
instrumentationClientPath,
|
|
@@ -895,6 +956,7 @@ function vinext(options = {}) {
|
|
|
895
956
|
return (typeof hook === "function" ? hook : hook.handler).call(this, config, env);
|
|
896
957
|
}
|
|
897
958
|
};
|
|
959
|
+
const cachedTypeofWindowTransform = createTransformCache();
|
|
898
960
|
const plugins = [
|
|
899
961
|
createStyledJsxPlugin(earlyBaseDir),
|
|
900
962
|
mdxProxyPlugin,
|
|
@@ -923,7 +985,7 @@ function vinext(options = {}) {
|
|
|
923
985
|
transform: {
|
|
924
986
|
filter: { id: /\.m?js(?:\?.*)?$/ },
|
|
925
987
|
async handler(code, id) {
|
|
926
|
-
const cleanId = id
|
|
988
|
+
const cleanId = toSlash(stripViteModuleQuery(id));
|
|
927
989
|
if (isInsideDirectory(__dirname, cleanId)) return;
|
|
928
990
|
if (cleanId.includes("/node_modules/")) {
|
|
929
991
|
if (!code.includes("use client") && !code.includes("use server")) return;
|
|
@@ -967,16 +1029,17 @@ function vinext(options = {}) {
|
|
|
967
1029
|
async config(config, env) {
|
|
968
1030
|
isServeCommand = env.command === "serve";
|
|
969
1031
|
root = toSlash(config.root ?? process.cwd());
|
|
970
|
-
const
|
|
971
|
-
|
|
1032
|
+
const userResolve = config.resolve;
|
|
1033
|
+
let tsconfigPathAliases = {};
|
|
972
1034
|
const swcHelpersAlias = resolveSwcHelpersAlias(root);
|
|
973
|
-
if (Object.keys(tsconfigPathAliases).length > 0) config.customLogger = suppressAliasCustomResolverDeprecationWarning(config.customLogger ?? createLogger(config.logLevel, { allowClearScreen: config.clearScreen }));
|
|
974
1035
|
const mode = env?.mode ?? "development";
|
|
975
|
-
|
|
976
|
-
|
|
1036
|
+
if (config.envDir !== false) loadDotenv({
|
|
1037
|
+
root: config.envDir ?? root,
|
|
1038
|
+
mode
|
|
1039
|
+
});
|
|
977
1040
|
let resolvedNodeEnv;
|
|
978
|
-
if (
|
|
979
|
-
else if (
|
|
1041
|
+
if (env?.command === "build" || env?.isPreview === true) resolvedNodeEnv = "production";
|
|
1042
|
+
else if (mode === "test") resolvedNodeEnv = "test";
|
|
980
1043
|
else resolvedNodeEnv = "development";
|
|
981
1044
|
if (process.env.NODE_ENV !== resolvedNodeEnv) Reflect.set(process.env, "NODE_ENV", resolvedNodeEnv);
|
|
982
1045
|
if (env?.command === "build") previewBuildCredentials = getPreviewBuildCredentials() ?? createPreviewBuildCredentials();
|
|
@@ -1017,6 +1080,10 @@ function vinext(options = {}) {
|
|
|
1017
1080
|
buildId: sharedBuildId
|
|
1018
1081
|
};
|
|
1019
1082
|
}
|
|
1083
|
+
const configuredTsconfigPath = isUnknownRecord(nextConfig.typescript) ? typeof nextConfig.typescript.tsconfigPath === "string" ? nextConfig.typescript.tsconfigPath : void 0 : void 0;
|
|
1084
|
+
tsconfigPathAliases = resolveTsconfigAliases(root, configuredTsconfigPath);
|
|
1085
|
+
const shouldAutoEnableNativeTsconfigPaths = userResolve?.tsconfigPaths === void 0 && configuredTsconfigPath === void 0;
|
|
1086
|
+
if (Object.keys(tsconfigPathAliases).length > 0) config.customLogger = suppressAliasCustomResolverDeprecationWarning(config.customLogger ?? createLogger(config.logLevel, { allowClearScreen: config.clearScreen }));
|
|
1020
1087
|
if (rscCompatibilityId === void 0) {
|
|
1021
1088
|
const sharedRscCompatibilityId = process.env.__VINEXT_SHARED_RSC_COMPATIBILITY_ID;
|
|
1022
1089
|
rscCompatibilityId = sharedRscCompatibilityId && sharedRscCompatibilityId.length > 0 ? sharedRscCompatibilityId : createRscCompatibilityId(nextConfig);
|
|
@@ -1054,6 +1121,7 @@ function vinext(options = {}) {
|
|
|
1054
1121
|
defines["process.env.__VINEXT_PREFETCH_INLINING"] = JSON.stringify(nextConfig.prefetchInlining ? "true" : "false");
|
|
1055
1122
|
defines["process.env.__NEXT_GESTURE_TRANSITION"] = JSON.stringify(nextConfig.gestureTransition);
|
|
1056
1123
|
defines["process.env.__NEXT_APP_NAV_FAIL_HANDLING"] = JSON.stringify(nextConfig.appNavFailHandling);
|
|
1124
|
+
defines["process.env.__NEXT_TEST_MODE"] = JSON.stringify(process.env.__NEXT_TEST_MODE ?? false);
|
|
1057
1125
|
defines["process.env.__NEXT_SCROLL_RESTORATION"] = JSON.stringify(nextConfig.scrollRestoration ? "true" : "false");
|
|
1058
1126
|
defines["process.env.__VINEXT_TRAILING_SLASH"] = JSON.stringify(nextConfig.trailingSlash ? "true" : "false");
|
|
1059
1127
|
defines["process.env.__VINEXT_IMAGE_REMOTE_PATTERNS"] = JSON.stringify(JSON.stringify(nextConfig.images?.remotePatterns ?? []));
|
|
@@ -1222,7 +1290,7 @@ function vinext(options = {}) {
|
|
|
1222
1290
|
"react/jsx-runtime",
|
|
1223
1291
|
"react/jsx-dev-runtime"
|
|
1224
1292
|
],
|
|
1225
|
-
...
|
|
1293
|
+
...shouldAutoEnableNativeTsconfigPaths ? { tsconfigPaths: true } : {}
|
|
1226
1294
|
},
|
|
1227
1295
|
oxc: {
|
|
1228
1296
|
jsx: { runtime: "automatic" },
|
|
@@ -1840,6 +1908,14 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
1840
1908
|
});
|
|
1841
1909
|
const pageExtensions = fileMatcher.extensionRegex;
|
|
1842
1910
|
let pagesRunner = null;
|
|
1911
|
+
const getTrustedDevRevalidateOrigin = () => {
|
|
1912
|
+
const resolved = server.resolvedUrls?.local[0];
|
|
1913
|
+
if (resolved) try {
|
|
1914
|
+
return new URL(resolved).origin;
|
|
1915
|
+
} catch {}
|
|
1916
|
+
const address = server.httpServer?.address();
|
|
1917
|
+
return `http://localhost:${typeof address === "object" && address ? address.port : server.config.server.port ?? 3e3}`;
|
|
1918
|
+
};
|
|
1843
1919
|
let cachedSSRHandler = null;
|
|
1844
1920
|
function getPagesRunner() {
|
|
1845
1921
|
if (!pagesRunner) pagesRunner = createDirectRunner(server.environments["ssr"] ?? Object.values(server.environments).find((e) => e !== server.environments["rsc"]) ?? Object.values(server.environments)[0]);
|
|
@@ -2161,7 +2237,16 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
2161
2237
|
res.end("Forbidden");
|
|
2162
2238
|
return;
|
|
2163
2239
|
}
|
|
2164
|
-
|
|
2240
|
+
let revalidationHostname = null;
|
|
2241
|
+
if (req.headers["x-vinext-revalidate-host"] !== void 0) {
|
|
2242
|
+
const revalidationHeaders = new Headers();
|
|
2243
|
+
for (const [name, value] of Object.entries(req.headers)) {
|
|
2244
|
+
if (value === void 0 || name.startsWith(":")) continue;
|
|
2245
|
+
revalidationHeaders.set(name, Array.isArray(value) ? value.join(", ") : value);
|
|
2246
|
+
}
|
|
2247
|
+
revalidationHostname = readTrustedRevalidationHostname(revalidationHeaders, nextConfig?.i18n);
|
|
2248
|
+
}
|
|
2249
|
+
const requestHost = revalidationHostname ?? ((Array.isArray(req.headers.host) ? req.headers.host[0] : req.headers.host) || "localhost");
|
|
2165
2250
|
const requestOrigin = `http://${requestHost}`;
|
|
2166
2251
|
const getUrlHostname = (requestUrl) => new URL(requestUrl).hostname;
|
|
2167
2252
|
if (isImageOptimizationPath(url.split("?")[0])) {
|
|
@@ -2296,6 +2381,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
2296
2381
|
const rawHeaders = 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)])));
|
|
2297
2382
|
const isDataRequest = isDataReq;
|
|
2298
2383
|
const nodeRequestHeaders = filterInternalHeaders(rawHeaders);
|
|
2384
|
+
if (revalidationHostname) nodeRequestHeaders.set("host", revalidationHostname);
|
|
2299
2385
|
for (const header of INTERNAL_HEADERS) delete req.headers[header];
|
|
2300
2386
|
for (const header of VINEXT_INTERNAL_HEADERS) delete req.headers[header];
|
|
2301
2387
|
const method = req.method ?? "GET";
|
|
@@ -2416,6 +2502,8 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
2416
2502
|
if (await handleApiRoute(getPagesRunner(), req, res, pipelineResult.apiUrl, apiRoutes, {
|
|
2417
2503
|
basePath: nextConfig?.basePath,
|
|
2418
2504
|
i18n: nextConfig?.i18n,
|
|
2505
|
+
trustedRevalidateOrigin: getTrustedDevRevalidateOrigin(),
|
|
2506
|
+
allowedRevalidateHeaderKeys: nextConfig?.allowedRevalidateHeaderKeys,
|
|
2419
2507
|
trailingSlash: nextConfig?.trailingSlash
|
|
2420
2508
|
})) return;
|
|
2421
2509
|
if (hasAppDir) return next();
|
|
@@ -2434,7 +2522,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
2434
2522
|
}
|
|
2435
2523
|
if (!cachedSSRHandler || cachedSSRHandler.routes !== routes) cachedSSRHandler = {
|
|
2436
2524
|
routes,
|
|
2437
|
-
handler: createSSRHandler(server, getPagesRunner(), routes, pagesDir, nextConfig?.i18n, fileMatcher, nextConfig?.basePath ?? "", nextConfig?.trailingSlash ?? false, middlewarePath !== null, (nextConfig?.rewrites.beforeFiles.length ?? 0) > 0 || (nextConfig?.rewrites.afterFiles.length ?? 0) > 0 || (nextConfig?.rewrites.fallback.length ?? 0) > 0, nextConfig?.clientTraceMetadata, nextConfig?.htmlLimitedBots, nextConfig?.reactStrictMode === true)
|
|
2525
|
+
handler: createSSRHandler(server, getPagesRunner(), routes, pagesDir, nextConfig?.i18n, fileMatcher, nextConfig?.basePath ?? "", nextConfig?.trailingSlash ?? false, middlewarePath !== null, (nextConfig?.rewrites.beforeFiles.length ?? 0) > 0 || (nextConfig?.rewrites.afterFiles.length ?? 0) > 0 || (nextConfig?.rewrites.fallback.length ?? 0) > 0, nextConfig?.clientTraceMetadata, nextConfig?.htmlLimitedBots, nextConfig?.reactStrictMode === true, nextConfig?.expireTime, nextConfig?.crossOrigin)
|
|
2438
2526
|
};
|
|
2439
2527
|
flushStagedHeaders();
|
|
2440
2528
|
flushRequestHeaders();
|
|
@@ -2561,7 +2649,8 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
2561
2649
|
if (useNativeTypeofWindowFolding && this.environment.config.build.write !== false) return null;
|
|
2562
2650
|
const cacheDir = `${toSlash(this.environment.config.cacheDir).replace(/\/$/, "")}/`;
|
|
2563
2651
|
if (toSlash(id).startsWith(cacheDir)) return null;
|
|
2564
|
-
|
|
2652
|
+
const replacement = getTypeofWindowReplacement(this.environment);
|
|
2653
|
+
return cachedTypeofWindowTransform(id, code, replacement, () => replaceTypeofWindow(code, replacement, id));
|
|
2565
2654
|
}
|
|
2566
2655
|
}
|
|
2567
2656
|
},
|
|
@@ -2740,32 +2829,8 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
2740
2829
|
async handler(code, id) {
|
|
2741
2830
|
const ast = parseAst(code);
|
|
2742
2831
|
const cacheDirective = ast.body.find((node) => node.type === "ExpressionStatement" && node.expression?.type === "Literal" && typeof node.expression.value === "string" && node.expression.value.startsWith("use cache"));
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
const fn = node.type === "MethodDefinition" ? node.value : node;
|
|
2746
|
-
const stmts = fn?.body?.type === "BlockStatement" ? fn.body.body : null;
|
|
2747
|
-
if (Array.isArray(stmts)) {
|
|
2748
|
-
for (const stmt of stmts) if (stmt?.type === "ExpressionStatement" && stmt.expression?.type === "Literal" && typeof stmt.expression?.value === "string" && /^use cache(:\s*\w+)?$/.test(stmt.expression.value)) return true;
|
|
2749
|
-
}
|
|
2750
|
-
return false;
|
|
2751
|
-
}
|
|
2752
|
-
function astHasInlineCache(nodes) {
|
|
2753
|
-
for (const node of nodes) {
|
|
2754
|
-
if (!node || typeof node !== "object") continue;
|
|
2755
|
-
if ((node.type === "FunctionDeclaration" || node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression" || node.type === "MethodDefinition") && nodeHasInlineCacheDirective(node)) return true;
|
|
2756
|
-
for (const key of Object.keys(node)) {
|
|
2757
|
-
if (key === "type" || key === "start" || key === "end" || key === "loc") continue;
|
|
2758
|
-
const child = node[key];
|
|
2759
|
-
if (Array.isArray(child) && child.some((c) => c && typeof c === "object")) {
|
|
2760
|
-
if (astHasInlineCache(child)) return true;
|
|
2761
|
-
} else if (child && typeof child === "object" && child.type) {
|
|
2762
|
-
if (astHasInlineCache([child])) return true;
|
|
2763
|
-
}
|
|
2764
|
-
}
|
|
2765
|
-
}
|
|
2766
|
-
return false;
|
|
2767
|
-
}
|
|
2768
|
-
const hasInlineCache = !cacheDirective && astHasInlineCache(ast.body);
|
|
2832
|
+
const inlineCacheSecondArgumentUsage = cacheDirective ? [] : collectInlineUseCacheSecondArgumentUsage(ast.body);
|
|
2833
|
+
const hasInlineCache = inlineCacheSecondArgumentUsage.length > 0;
|
|
2769
2834
|
if (!cacheDirective && !hasInlineCache) return null;
|
|
2770
2835
|
if (!resolvedRscTransformsPath) throw new Error("vinext: 'use cache' requires @vitejs/plugin-rsc to be installed.\nRun: " + detectPackageManager(process.cwd()) + " @vitejs/plugin-rsc");
|
|
2771
2836
|
const { transformWrapExport, transformHoistInlineDirective } = await import(pathToFileURL(resolvedRscTransformsPath).href);
|
|
@@ -2777,10 +2842,15 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
2777
2842
|
const moduleFileName = path.basename(modulePath);
|
|
2778
2843
|
const isAppPageModule = hasAppDir && isInsideDirectory(appDir, modulePath) && path.parse(moduleFileName).name === "page" && fileMatcher.extensionRegex.test(moduleFileName);
|
|
2779
2844
|
const runtimeModuleUrl = pathToFileURL(resolveShimModulePath(shimsDir, "cache-runtime")).href;
|
|
2845
|
+
const secondArgumentUsage = collectFileUseCacheSecondArgumentUsage(ast.body);
|
|
2780
2846
|
const result = transformWrapExport(code, ast, {
|
|
2781
2847
|
runtime: (value, name) => {
|
|
2782
|
-
const
|
|
2783
|
-
|
|
2848
|
+
const runtimeOptions = [];
|
|
2849
|
+
const acceptsSecondArgument = secondArgumentUsage.get(value) ?? true;
|
|
2850
|
+
runtimeOptions.push(`acceptsSecondArgument: ${acceptsSecondArgument}`);
|
|
2851
|
+
if (name === "default" && isAppPageModule) runtimeOptions.push("appPageDefaultExport: true");
|
|
2852
|
+
const optionsArgument = runtimeOptions.length > 0 ? `, { ${runtimeOptions.join(", ")} }` : "";
|
|
2853
|
+
return `(await import(${JSON.stringify(runtimeModuleUrl)})).registerCachedFunction(${value}, ${JSON.stringify(id + ":" + name)}, ${JSON.stringify(variant)}${optionsArgument})`;
|
|
2784
2854
|
},
|
|
2785
2855
|
rejectNonAsyncFunction: false,
|
|
2786
2856
|
filter: (name, meta) => {
|
|
@@ -2807,12 +2877,15 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
2807
2877
|
if (hasInlineCache) {
|
|
2808
2878
|
const runtimeModuleUrl2 = pathToFileURL(resolveShimModulePath(shimsDir, "cache-runtime")).href;
|
|
2809
2879
|
try {
|
|
2880
|
+
let transformedFunctionIndex = 0;
|
|
2810
2881
|
const result = transformHoistInlineDirective(code, ast, {
|
|
2811
2882
|
directive: /^use cache(:\s*\w+)?$/,
|
|
2812
2883
|
runtime: (value, name, meta) => {
|
|
2813
2884
|
const directiveMatch = meta.directiveMatch[0];
|
|
2814
2885
|
const variant = directiveMatch === "use cache" ? "" : directiveMatch.replace("use cache:", "").trim();
|
|
2815
|
-
|
|
2886
|
+
const acceptsSecondArgument = inlineCacheSecondArgumentUsage[transformedFunctionIndex++];
|
|
2887
|
+
const optionsArgument = acceptsSecondArgument === void 0 ? "" : `, { acceptsSecondArgument: ${acceptsSecondArgument} }`;
|
|
2888
|
+
return `(await import(${JSON.stringify(runtimeModuleUrl2)})).registerCachedFunction(${value}, ${JSON.stringify(id + ":" + name)}, ${JSON.stringify(variant)}${optionsArgument})`;
|
|
2816
2889
|
},
|
|
2817
2890
|
rejectNonAsyncFunction: false
|
|
2818
2891
|
});
|
|
@@ -25,7 +25,9 @@ type CloudflarePlatformSetupResult = {
|
|
|
25
25
|
declare function validateCloudflarePlatformSetup(context: CloudflarePlatformSetupContext, cloudflare: CloudflareInitOptions): void;
|
|
26
26
|
declare function setupCloudflarePlatform(context: CloudflarePlatformSetupContext, cloudflare: CloudflareInitOptions): CloudflarePlatformSetupResult;
|
|
27
27
|
declare function generateWranglerConfig(info: CloudflareProjectInfo, options?: CloudflareInitOptions, today?: string): string;
|
|
28
|
-
declare function updateWranglerConfigForCloudflare(code: string, options: CloudflareInitOptions
|
|
28
|
+
declare function updateWranglerConfigForCloudflare(code: string, options: CloudflareInitOptions, context?: {
|
|
29
|
+
root?: string;
|
|
30
|
+
}): string;
|
|
29
31
|
declare function getWranglerImagesBinding(code: string): string;
|
|
30
32
|
/** Generate vite.config.ts for App Router */
|
|
31
33
|
declare function generateAppRouterViteConfig(info?: CloudflareProjectInfo, options?: CloudflareInitOptions, imagesBinding?: string, prerender?: boolean): string;
|