main repo

This commit is contained in:
Basilosaurusrex
2025-11-24 18:09:40 +01:00
parent b636ee5e70
commit f027651f9b
34146 changed files with 4436636 additions and 0 deletions

View File

@@ -0,0 +1,166 @@
import { getModuleBuildInfo } from "../get-module-build-info";
import { WEBPACK_RESOURCE_QUERIES } from "../../../../lib/constants";
import { stringifyRequest } from "../../stringify-request";
import { RouteKind } from "../../../../server/future/route-kind";
import { normalizePagePath } from "../../../../shared/lib/page-path/normalize-page-path";
/*
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.PAGES,
page: normalizePagePath(page),
pathname: page,
// The following aren't used in production.
bundlePath: "",
filename: ""
}
};
return options;
}
const edgeSSRLoader = function edgeSSRLoader() {
const { dev, page, buildId, absolutePagePath, absoluteAppPath, absoluteDocumentPath, absolute500Path, absoluteErrorPath, isServerComponent, stringifiedConfig: stringifiedConfigBase64, appDirLoader: appDirLoaderBase64, pagesType, sriEnabled, incrementalCacheHandlerPath, preferredRegion, middlewareConfig: middlewareConfigBase64, serverActionsBodySizeLimit } = this.getOptions();
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 = getModuleBuildInfo(this._module);
buildInfo.nextEdgeSSR = {
// @ts-expect-error === 'true' is correct because loader options are serialized as searchParams. Type needs to be fixed somehow.
isServerComponent: isServerComponent === "true",
page: page,
isAppDir
};
buildInfo.route = {
page,
absolutePagePath,
preferredRegion,
middlewareConfig
};
const stringifiedPagePath = stringifyRequest(this, absolutePagePath);
const stringifiedAppPath = stringifyRequest(this, swapDistFolderWithEsmDistFolder(absoluteAppPath));
const stringifiedErrorPath = stringifyRequest(this, swapDistFolderWithEsmDistFolder(absoluteErrorPath));
const stringifiedDocumentPath = stringifyRequest(this, swapDistFolderWithEsmDistFolder(absoluteDocumentPath));
const stringified500Path = absolute500Path ? stringifyRequest(this, absolute500Path) : null;
const pageModPath = `${appDirLoader}${stringifiedPagePath.substring(1, stringifiedPagePath.length - 1)}${isAppDir ? `?${WEBPACK_RESOURCE_QUERIES.edgeSSREntry}` : ""}`;
const transformed = `
import 'next/dist/esm/server/web/globals'
import { adapter } from 'next/dist/esm/server/web/adapter'
import { getRender } from 'next/dist/esm/build/webpack/loaders/next-edge-ssr-loader/render'
import { IncrementalCache } from 'next/dist/esm/server/lib/incremental-cache'
const pagesType = ${JSON.stringify(pagesType)}
${isAppDir ? `
import { renderToHTMLOrFlight as renderToHTML } from 'next/dist/esm/server/app-render/app-render'
import * as pageMod from ${JSON.stringify(pageModPath)}
const Document = null
const appMod = null
const errorMod = null
const error500Mod = null
` : `
import Document from ${stringifiedDocumentPath}
import * as appMod from ${stringifiedAppPath}
import * as userlandPage from ${stringifiedPagePath}
import * as userlandErrorPage from ${stringifiedErrorPath}
${stringified500Path ? `import * as userland500Page from ${stringified500Path}` : ""}
// TODO: re-enable this once we've refactored to use implicit matches
// const renderToHTML = undefined
import { renderToHTML } from 'next/dist/esm/server/render'
import RouteModule from "next/dist/esm/server/future/route-modules/pages/module"
const pageMod = {
...userlandPage,
routeModule: new RouteModule({
...${JSON.stringify(getRouteModuleOptions(page))},
components: {
App: appMod.default,
Document,
},
userland: userlandPage,
}),
}
const errorMod = {
...userlandErrorPage,
routeModule: new RouteModule({
...${JSON.stringify(getRouteModuleOptions("/_error"))},
components: {
App: appMod.default,
Document,
},
userland: userlandErrorPage,
}),
}
const error500Mod = ${stringified500Path ? `{
...userland500Page,
routeModule: new RouteModule({
...${JSON.stringify(getRouteModuleOptions("/500"))},
components: {
App: appMod.default,
Document,
},
userland: userland500Page,
}),
}` : "null"}`}
${incrementalCacheHandlerPath ? `import incrementalCacheHandler from ${JSON.stringify(incrementalCacheHandlerPath)}` : "const incrementalCacheHandler = null"}
const maybeJSONParse = (str) => str ? JSON.parse(str) : undefined
const buildManifest = self.__BUILD_MANIFEST
const prerenderManifest = maybeJSONParse(self.__PRERENDER_MANIFEST)
const reactLoadableManifest = maybeJSONParse(self.__REACT_LOADABLE_MANIFEST)
const rscManifest = self.__RSC_MANIFEST?.[${JSON.stringify(page)}]
const rscServerManifest = maybeJSONParse(self.__RSC_SERVER_MANIFEST)
const subresourceIntegrityManifest = ${sriEnabled ? "maybeJSONParse(self.__SUBRESOURCE_INTEGRITY_MANIFEST)" : "undefined"}
const nextFontManifest = maybeJSONParse(self.__NEXT_FONT_MANIFEST)
const render = getRender({
pagesType,
dev: ${dev},
page: ${JSON.stringify(page)},
appMod,
pageMod,
errorMod,
error500Mod,
Document,
buildManifest,
isAppPath: ${!!isAppDir},
prerenderManifest,
renderToHTML,
reactLoadableManifest,
clientReferenceManifest: ${isServerComponent} ? rscManifest : null,
serverActionsManifest: ${isServerComponent} ? rscServerManifest : null,
serverActionsBodySizeLimit: ${isServerComponent} ? ${typeof serverActionsBodySizeLimit === "undefined" ? "undefined" : JSON.stringify(serverActionsBodySizeLimit)} : undefined,
subresourceIntegrityManifest,
config: ${stringifiedConfig},
buildId: ${JSON.stringify(buildId)},
nextFontManifest,
incrementalCacheHandler,
})
export const ComponentMod = pageMod
export default function(opts) {
return adapter({
...opts,
IncrementalCache,
handler: render
})
}`;
return transformed;
};
export default edgeSSRLoader;
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../../src/build/webpack/loaders/next-edge-ssr-loader/index.ts"],"names":["getModuleBuildInfo","WEBPACK_RESOURCE_QUERIES","stringifyRequest","RouteKind","normalizePagePath","swapDistFolderWithEsmDistFolder","path","replace","getRouteModuleOptions","page","options","definition","kind","PAGES","pathname","bundlePath","filename","edgeSSRLoader","dev","buildId","absolutePagePath","absoluteAppPath","absoluteDocumentPath","absolute500Path","absoluteErrorPath","isServerComponent","stringifiedConfig","stringifiedConfigBase64","appDirLoader","appDirLoaderBase64","pagesType","sriEnabled","incrementalCacheHandlerPath","preferredRegion","middlewareConfig","middlewareConfigBase64","serverActionsBodySizeLimit","getOptions","JSON","parse","Buffer","from","toString","isAppDir","buildInfo","_module","nextEdgeSSR","route","stringifiedPagePath","stringifiedAppPath","stringifiedErrorPath","stringifiedDocumentPath","stringified500Path","pageModPath","substring","length","edgeSSREntry","transformed","stringify"],"mappings":"AAKA,SAASA,kBAAkB,QAAQ,2BAA0B;AAC7D,SAASC,wBAAwB,QAAQ,4BAA2B;AACpE,SAASC,gBAAgB,QAAQ,0BAAyB;AAC1D,SAASC,SAAS,QAAQ,uCAAsC;AAChE,SAASC,iBAAiB,QAAQ,uDAAsD;AAsBxF;;;;;;;AAOA,GACA,SAASC,gCAAgCC,IAAY;IACnD,OAAOA,KAAKC,OAAO,CAAC,mBAAmB;AACzC;AAEA,SAASC,sBAAsBC,IAAY;IACzC,MAAMC,UAAoE;QACxEC,YAAY;YACVC,MAAMT,UAAUU,KAAK;YACrBJ,MAAML,kBAAkBK;YACxBK,UAAUL;YACV,2CAA2C;YAC3CM,YAAY;YACZC,UAAU;QACZ;IACF;IAEA,OAAON;AACT;AAEA,MAAMO,gBACJ,SAASA;IACP,MAAM,EACJC,GAAG,EACHT,IAAI,EACJU,OAAO,EACPC,gBAAgB,EAChBC,eAAe,EACfC,oBAAoB,EACpBC,eAAe,EACfC,iBAAiB,EACjBC,iBAAiB,EACjBC,mBAAmBC,uBAAuB,EAC1CC,cAAcC,kBAAkB,EAChCC,SAAS,EACTC,UAAU,EACVC,2BAA2B,EAC3BC,eAAe,EACfC,kBAAkBC,sBAAsB,EACxCC,0BAA0B,EAC3B,GAA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AC,iCAAiC,EAAEA,mBAAmB,CAAC,GACxD,GACL;;;;;;;;;;;aAWM,EAAEd,KAAKoB,SAAS,CAAClD,sBAAsBC,OAAO;;;;;;;;;;;;aAY9C,EAAE6B,KAAKoB,SAAS,CAAClD,sBAAsB,YAAY;;;;;;;;;0BAStC,EAClB4C,qBACI,CAAC;;;aAGA,EAAEd,KAAKoB,SAAS,CAAClD,sBAAsB,SAAS;;;;;;;OAOtD,CAAC,GACI,OACL,CAAC,CACH;;IAED,EACEwB,8BACI,CAAC,oCAAoC,EAAEM,KAAKoB,SAAS,CACnD1B,6BACA,CAAC,GACH,uCACL;;;;;;;8CAOyC,EAAEM,KAAKoB,SAAS,CAACjD,MAAM;;yCAE5B,EACnCsB,aACI,0DACA,YACL;;;;;WAKM,EAAEb,IAAI;YACL,EAAEoB,KAAKoB,SAAS,CAACjD,MAAM;;;;;;;iBAOlB,EAAE,CAAC,CAACkC,SAAS;;;;+BAIC,EAAElB,kBAAkB;6BACtB,EAAEA,kBAAkB;kCACf,EAAEA,kBAAkB,GAAG,EACnD,OAAOW,+BAA+B,cAClC,cACAE,KAAKoB,SAAS,CAACtB,4BACpB;;cAES,EAAEV,kBAAkB;eACnB,EAAEY,KAAKoB,SAAS,CAACvC,SAAS;;;;;;;;;;;;;KAapC,CAAC;IAEF,OAAOsC;AACT;AACF,eAAexC,cAAa"}

View File

@@ -0,0 +1,91 @@
import WebServer from "../../../../server/web-server";
import { WebNextRequest, WebNextResponse } from "../../../../server/base-http/web";
import { SERVER_RUNTIME } from "../../../../lib/constants";
import { normalizeAppPath } from "../../../../shared/lib/router/utils/app-paths";
export function getRender({ dev, page, appMod, pageMod, errorMod, error500Mod, pagesType, Document, buildManifest, prerenderManifest, reactLoadableManifest, renderToHTML, clientReferenceManifest, subresourceIntegrityManifest, serverActionsManifest, serverActionsBodySizeLimit, config, buildId, nextFontManifest, incrementalCacheHandler }) {
const isAppPath = pagesType === "app";
const baseLoadComponentResult = {
dev,
buildManifest,
reactLoadableManifest,
subresourceIntegrityManifest,
Document,
App: appMod == null ? void 0 : appMod.default,
clientReferenceManifest
};
const server = new WebServer({
dev,
conf: config,
minimalMode: true,
webServerConfig: {
page,
pathname: isAppPath ? normalizeAppPath(page) : page,
pagesType,
prerenderManifest,
extendRenderOpts: {
buildId,
runtime: SERVER_RUNTIME.experimentalEdge,
supportsDynamicHTML: true,
disableOptimizedLoading: true,
serverActionsManifest,
serverActionsBodySizeLimit,
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) {
const extendedReq = new WebNextRequest(request);
const extendedRes = new WebNextResponse();
handler(extendedReq, extendedRes);
return await extendedRes.toResponse();
};
}
//# sourceMappingURL=render.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../../src/build/webpack/loaders/next-edge-ssr-loader/render.ts"],"names":["WebServer","WebNextRequest","WebNextResponse","SERVER_RUNTIME","normalizeAppPath","getRender","dev","page","appMod","pageMod","errorMod","error500Mod","pagesType","Document","buildManifest","prerenderManifest","reactLoadableManifest","renderToHTML","clientReferenceManifest","subresourceIntegrityManifest","serverActionsManifest","serverActionsBodySizeLimit","config","buildId","nextFontManifest","incrementalCacheHandler","isAppPath","baseLoadComponentResult","App","default","server","conf","minimalMode","webServerConfig","pathname","extendRenderOpts","runtime","experimentalEdge","supportsDynamicHTML","disableOptimizedLoading","loadComponent","inputPage","Component","pageConfig","getStaticProps","getServerSideProps","getStaticPaths","ComponentMod","__next_app__","routeModule","handler","getRequestHandler","render","request","extendedReq","extendedRes","toResponse"],"mappings":"AAQA,OAAOA,eAAe,gCAA+B;AACrD,SACEC,cAAc,EACdC,eAAe,QACV,mCAAkC;AACzC,SAASC,cAAc,QAAQ,4BAA2B;AAE1D,SAASC,gBAAgB,QAAQ,gDAA+C;AAGhF,OAAO,SAASC,UAAU,EACxBC,GAAG,EACHC,IAAI,EACJC,MAAM,EACNC,OAAO,EACPC,QAAQ,EACRC,WAAW,EACXC,SAAS,EACTC,QAAQ,EACRC,aAAa,EACbC,iBAAiB,EACjBC,qBAAqB,EACrBC,YAAY,EACZC,uBAAuB,EACvBC,4BAA4B,EAC5BC,qBAAqB,EACrBC,0BAA0B,EAC1BC,MAAM,EACNC,OAAO,EACPC,gBAAgB,EAChBC,uBAAuB,EAuBxB;IACC,MAAMC,YAAYd,cAAc;IAChC,MAAMe,0BAA0B;QAC9BrB;QACAQ;QACAE;QACAG;QACAN;QACAe,GAAG,EAAEpB,0BAAAA,OAAQqB,OAAO;QACpBX;IACF;IAEA,MAAMY,SAAS,IAAI9B,UAAU;QAC3BM;QACAyB,MAAMT;QACNU,aAAa;QACbC,iBAAiB;YACf1B;YACA2B,UAAUR,YAAYtB,iBAAiBG,QAAQA;YAC/CK;YACAG;YACAoB,kBAAkB;gBAChBZ;gBACAa,SAASjC,eAAekC,gBAAgB;gBACxCC,qBAAqB;gBACrBC,y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