inital commit

This commit is contained in:
2026-01-01 15:25:19 +05:30
commit f0ae49465a
36361 changed files with 4894111 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
import type webpack from 'webpack';
import type { SizeLimit } from '../../../../types';
import type { PAGE_TYPES } from '../../../../lib/page-types';
export type EdgeSSRLoaderQuery = {
absolute500Path: string;
absoluteAppPath: string;
absoluteDocumentPath: string;
absoluteErrorPath: string;
absolutePagePath: string;
dev: boolean;
isServerComponent: boolean;
page: string;
stringifiedConfig: string;
appDirLoader?: string;
pagesType: PAGE_TYPES;
sriEnabled: boolean;
cacheHandler?: string;
cacheHandlers?: string;
preferredRegion: string | string[] | undefined;
middlewareConfig: string;
serverActions?: {
bodySizeLimit?: SizeLimit;
allowedOrigins?: string[];
};
};
declare const edgeSSRLoader: webpack.LoaderDefinitionFunction<EdgeSSRLoaderQuery>;
export default edgeSSRLoader;

View File

@@ -0,0 +1,104 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "default", {
enumerable: true,
get: function() {
return _default;
}
});
const _getmodulebuildinfo = require("../get-module-build-info");
const _constants = require("../../../../lib/constants");
const _routekind = require("../../../../server/route-kind");
const _normalizepagepath = require("../../../../shared/lib/page-path/normalize-page-path");
const _loadentrypoint = require("../../../load-entrypoint");
/*
For pages SSR'd at the edge, we bundle them with the ESM version of Next in order to
benefit from the better tree-shaking and thus, smaller bundle sizes.
The absolute paths for _app, _error and _document, used in this loader, link to the regular CJS modules.
They are generated in `createPagesMapping` where we don't have access to `isEdgeRuntime`,
so we have to do it here. It's not that bad because it keeps all references to ESM modules magic in this place.
*/ function swapDistFolderWithEsmDistFolder(path) {
return path.replace('next/dist/pages', 'next/dist/esm/pages');
}
function getRouteModuleOptions(page) {
const options = {
definition: {
kind: _routekind.RouteKind.PAGES,
page: (0, _normalizepagepath.normalizePagePath)(page),
pathname: page,
// The following aren't used in production.
bundlePath: '',
filename: ''
}
};
return options;
}
const edgeSSRLoader = async function edgeSSRLoader() {
const { dev, page, absolutePagePath, absoluteAppPath, absoluteDocumentPath, absolute500Path, absoluteErrorPath, isServerComponent, stringifiedConfig: stringifiedConfigBase64, appDirLoader: appDirLoaderBase64, pagesType, sriEnabled, cacheHandler, cacheHandlers: cacheHandlersStringified, preferredRegion, middlewareConfig: middlewareConfigBase64, serverActions } = this.getOptions();
const cacheHandlers = JSON.parse(cacheHandlersStringified || '{}');
if (!cacheHandlers.default) {
cacheHandlers.default = require.resolve('../../../../server/lib/cache-handlers/default');
}
const middlewareConfig = JSON.parse(Buffer.from(middlewareConfigBase64, 'base64').toString());
const stringifiedConfig = Buffer.from(stringifiedConfigBase64 || '', 'base64').toString();
const appDirLoader = Buffer.from(appDirLoaderBase64 || '', 'base64').toString();
const isAppDir = pagesType === 'app';
const buildInfo = (0, _getmodulebuildinfo.getModuleBuildInfo)(this._module);
buildInfo.nextEdgeSSR = {
isServerComponent,
page: page,
isAppDir
};
buildInfo.route = {
page,
absolutePagePath,
preferredRegion,
middlewareConfig
};
const pagePath = this.utils.contextify(this.context || this.rootContext, absolutePagePath);
const appPath = this.utils.contextify(this.context || this.rootContext, swapDistFolderWithEsmDistFolder(absoluteAppPath));
const errorPath = this.utils.contextify(this.context || this.rootContext, swapDistFolderWithEsmDistFolder(absoluteErrorPath));
const documentPath = this.utils.contextify(this.context || this.rootContext, swapDistFolderWithEsmDistFolder(absoluteDocumentPath));
const userland500Path = absolute500Path ? this.utils.contextify(this.context || this.rootContext, swapDistFolderWithEsmDistFolder(absolute500Path)) : null;
const stringifiedPagePath = JSON.stringify(pagePath);
const pageModPath = `${appDirLoader}${stringifiedPagePath.substring(1, stringifiedPagePath.length - 1)}${isAppDir ? `?${_constants.WEBPACK_RESOURCE_QUERIES.edgeSSREntry}` : ''}`;
if (isAppDir) {
return await (0, _loadentrypoint.loadEntrypoint)('edge-ssr-app', {
VAR_USERLAND: pageModPath,
VAR_PAGE: page
}, {
sriEnabled: JSON.stringify(sriEnabled),
nextConfig: stringifiedConfig,
isServerComponent: JSON.stringify(isServerComponent),
dev: JSON.stringify(dev),
serverActions: typeof serverActions === 'undefined' ? 'undefined' : JSON.stringify(serverActions)
}, {
incrementalCacheHandler: cacheHandler ?? null
});
} else {
return await (0, _loadentrypoint.loadEntrypoint)('edge-ssr', {
VAR_USERLAND: pageModPath,
VAR_PAGE: page,
VAR_MODULE_DOCUMENT: documentPath,
VAR_MODULE_APP: appPath,
VAR_MODULE_GLOBAL_ERROR: errorPath
}, {
pagesType: JSON.stringify(pagesType),
sriEnabled: JSON.stringify(sriEnabled),
nextConfig: stringifiedConfig,
dev: JSON.stringify(dev),
pageRouteModuleOptions: JSON.stringify(getRouteModuleOptions(page)),
errorRouteModuleOptions: JSON.stringify(getRouteModuleOptions('/_error')),
user500RouteModuleOptions: JSON.stringify(getRouteModuleOptions('/500'))
}, {
userland500Page: userland500Path,
incrementalCacheHandler: cacheHandler ?? null
});
}
};
const _default = edgeSSRLoader;
//# sourceMappingURL=index.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,37 @@
import type { NextConfigComplete } from '../../../../server/config-shared';
import type { DocumentType } from '../../../../shared/lib/utils';
import type { BuildManifest } from '../../../../server/get-page-files';
import type { DynamicCssManifest, ReactLoadableManifest } from '../../../../server/load-components';
import type { ClientReferenceManifest } from '../../plugins/flight-manifest-plugin';
import type { NextFontManifest } from '../../plugins/next-font-manifest-plugin';
import type { NextFetchEvent } from '../../../../server/web/spec-extension/fetch-event';
import type { ManifestRewriteRoute } from '../../..';
import type { SizeLimit } from '../../../../types';
import type { PAGE_TYPES } from '../../../../lib/page-types';
import type { NextRequestHint } from '../../../../server/web/adapter';
export declare function getRender({ dev, page, appMod, pageMod, errorMod, error500Mod, pagesType, Document, buildManifest, reactLoadableManifest, dynamicCssManifest, interceptionRouteRewrites, renderToHTML, clientReferenceManifest, subresourceIntegrityManifest, serverActionsManifest, serverActions, config, buildId, nextFontManifest, incrementalCacheHandler, }: {
pagesType: PAGE_TYPES;
dev: boolean;
page: string;
appMod: any;
pageMod: any;
errorMod: any;
error500Mod: any;
renderToHTML?: any;
Document: DocumentType;
buildManifest: BuildManifest;
reactLoadableManifest: ReactLoadableManifest;
dynamicCssManifest?: DynamicCssManifest;
subresourceIntegrityManifest?: Record<string, string>;
interceptionRouteRewrites?: ManifestRewriteRoute[];
clientReferenceManifest?: ClientReferenceManifest;
serverActionsManifest?: any;
serverActions?: {
bodySizeLimit?: SizeLimit;
allowedOrigins?: string[];
};
config: NextConfigComplete;
buildId: string;
nextFontManifest: NextFontManifest;
incrementalCacheHandler?: any;
}): (request: NextRequestHint, event?: NextFetchEvent) => Promise<Response>;

View File

@@ -0,0 +1,119 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "getRender", {
enumerable: true,
get: function() {
return getRender;
}
});
const _webserver = /*#__PURE__*/ _interop_require_default(require("../../../../server/web-server"));
const _web = require("../../../../server/base-http/web");
const _constants = require("../../../../lib/constants");
const _apppaths = require("../../../../shared/lib/router/utils/app-paths");
const _internaledgewaituntil = require("../../../../server/web/internal-edge-wait-until");
function _interop_require_default(obj) {
return obj && obj.__esModule ? obj : {
default: obj
};
}
function getRender({ dev, page, appMod, pageMod, errorMod, error500Mod, pagesType, Document, buildManifest, reactLoadableManifest, dynamicCssManifest, interceptionRouteRewrites, renderToHTML, clientReferenceManifest, subresourceIntegrityManifest, serverActionsManifest, serverActions, config, buildId, nextFontManifest, incrementalCacheHandler }) {
const isAppPath = pagesType === 'app';
const baseLoadComponentResult = {
dev,
buildManifest,
reactLoadableManifest,
dynamicCssManifest,
subresourceIntegrityManifest,
Document,
App: appMod == null ? void 0 : appMod.default,
clientReferenceManifest
};
const server = new _webserver.default({
dev,
buildId,
conf: config,
minimalMode: true,
webServerConfig: {
page,
pathname: isAppPath ? (0, _apppaths.normalizeAppPath)(page) : page,
pagesType,
interceptionRouteRewrites,
extendRenderOpts: {
runtime: _constants.SERVER_RUNTIME.experimentalEdge,
supportsDynamicResponse: true,
disableOptimizedLoading: true,
serverActionsManifest,
serverActions,
nextFontManifest
},
renderToHTML,
incrementalCacheHandler,
loadComponent: async (inputPage)=>{
if (inputPage === page) {
return {
...baseLoadComponentResult,
Component: pageMod.default,
pageConfig: pageMod.config || {},
getStaticProps: pageMod.getStaticProps,
getServerSideProps: pageMod.getServerSideProps,
getStaticPaths: pageMod.getStaticPaths,
ComponentMod: pageMod,
isAppPath: !!pageMod.__next_app__,
page: inputPage,
routeModule: pageMod.routeModule
};
}
// If there is a custom 500 page, we need to handle it separately.
if (inputPage === '/500' && error500Mod) {
return {
...baseLoadComponentResult,
Component: error500Mod.default,
pageConfig: error500Mod.config || {},
getStaticProps: error500Mod.getStaticProps,
getServerSideProps: error500Mod.getServerSideProps,
getStaticPaths: error500Mod.getStaticPaths,
ComponentMod: error500Mod,
page: inputPage,
routeModule: error500Mod.routeModule
};
}
if (inputPage === '/_error') {
return {
...baseLoadComponentResult,
Component: errorMod.default,
pageConfig: errorMod.config || {},
getStaticProps: errorMod.getStaticProps,
getServerSideProps: errorMod.getServerSideProps,
getStaticPaths: errorMod.getStaticPaths,
ComponentMod: errorMod,
page: inputPage,
routeModule: errorMod.routeModule
};
}
return null;
}
}
});
const handler = server.getRequestHandler();
return async function render(request, event) {
const extendedReq = new _web.WebNextRequest(request);
const extendedRes = new _web.WebNextResponse(undefined);
handler(extendedReq, extendedRes);
const result = await extendedRes.toResponse();
request.fetchMetrics = extendedReq.fetchMetrics;
if (event == null ? void 0 : event.waitUntil) {
// TODO(after):
// remove `internal_runWithWaitUntil` and the `internal-edge-wait-until` module
// when consumers switch to `after`.
const waitUntilPromise = (0, _internaledgewaituntil.internal_getCurrentFunctionWaitUntil)();
if (waitUntilPromise) {
event.waitUntil(waitUntilPromise);
}
}
return result;
};
}
//# sourceMappingURL=render.js.map

File diff suppressed because one or more lines are too long