added fonts

This commit is contained in:
guus committed 2025-07-02 11:28:41 +02:00
1 parent 4134e3a234
commit 142d2986b6
9079 files changed
+1498421 -2

No files matched your search

@@ -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;
@@ -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
@@ -0,0 +1 @@
{"version":3,"sources":["../../../../../src/build/webpack/loaders/next-edge-ssr-loader/index.ts"],"sourcesContent":["import type webpack from 'webpack'\nimport type { SizeLimit } from '../../../../types'\nimport type { PagesRouteModuleOptions } from '../../../../server/route-modules/pages/module'\nimport type { MiddlewareConfig } from '../../../analysis/get-page-static-info'\n\nimport { getModuleBuildInfo } from '../get-module-build-info'\nimport { WEBPACK_RESOURCE_QUERIES } from '../../../../lib/constants'\nimport { RouteKind } from '../../../../server/route-kind'\nimport { normalizePagePath } from '../../../../shared/lib/page-path/normalize-page-path'\nimport { loadEntrypoint } from '../../../load-entrypoint'\nimport type { PAGE_TYPES } from '../../../../lib/page-types'\n\nexport type EdgeSSRLoaderQuery = {\n absolute500Path: string\n absoluteAppPath: string\n absoluteDocumentPath: string\n absoluteErrorPath: string\n absolutePagePath: string\n dev: boolean\n isServerComponent: boolean\n page: string\n stringifiedConfig: string\n appDirLoader?: string\n pagesType: PAGE_TYPES\n sriEnabled: boolean\n cacheHandler?: string\n cacheHandlers?: string\n preferredRegion: string | string[] | undefined\n middlewareConfig: string\n serverActions?: {\n bodySizeLimit?: SizeLimit\n allowedOrigins?: string[]\n }\n}\n\n/*\nFor pages SSR'd at the edge, we bundle them with the ESM version of Next in order to\nbenefit from the better tree-shaking and thus, smaller bundle sizes.\n\nThe absolute paths for _app, _error and _document, used in this loader, link to the regular CJS modules.\nThey are generated in `createPagesMapping` where we don't have access to `isEdgeRuntime`,\nso we have to do it here. It's not that bad because it keeps all references to ESM modules magic in this place.\n*/\nfunction swapDistFolderWithEsmDistFolder(path: string) {\n return path.replace('next/dist/pages', 'next/dist/esm/pages')\n}\n\nfunction getRouteModuleOptions(page: string) {\n const options: Omit<PagesRouteModuleOptions, 'userland' | 'components'> = {\n definition: {\n kind: RouteKind.PAGES,\n page: normalizePagePath(page),\n pathname: page,\n // The following aren't used in production.\n bundlePath: '',\n filename: '',\n },\n }\n\n return options\n}\n\nconst edgeSSRLoader: webpack.LoaderDefinitionFunction<EdgeSSRLoaderQuery> =\n async function edgeSSRLoader(this) {\n const {\n dev,\n page,\n absolutePagePath,\n absoluteAppPath,\n absoluteDocumentPath,\n absolute500Path,\n absoluteErrorPath,\n isServerComponent,\n stringifiedConfig: stringifiedConfigBase64,\n appDirLoader: appDirLoaderBase64,\n pagesType,\n sriEnabled,\n cacheHandler,\n cacheHandlers: cacheHandlersStringified,\n preferredRegion,\n middlewareConfig: middlewareConfigBase64,\n serverActions,\n } = this.getOptions()\n\n const cacheHandlers = JSON.parse(cacheHandlersStringified || '{}')\n\n if (!cacheHandlers.default) {\n cacheHandlers.default = require.resolve(\n '../../../../server/lib/cache-handlers/default'\n )\n }\n\n const middlewareConfig: MiddlewareConfig = JSON.parse(\n Buffer.from(middlewareConfigBase64, 'base64').toString()\n )\n\n const stringifiedConfig = Buffer.from(\n stringifiedConfigBase64 || '',\n 'base64'\n ).toString()\n const appDirLoader = Buffer.from(\n appDirLoaderBase64 || '',\n 'base64'\n ).toString()\n const isAppDir = pagesType === 'app'\n\n const buildInfo = getModuleBuildInfo(this._module as any)\n buildInfo.nextEdgeSSR = {\n isServerComponent,\n page: page,\n isAppDir,\n }\n buildInfo.route = {\n page,\n absolutePagePath,\n preferredRegion,\n middlewareConfig,\n }\n\n const pagePath = this.utils.contextify(\n this.context || this.rootContext,\n absolutePagePath\n )\n const appPath = this.utils.contextify(\n this.context || this.rootContext,\n swapDistFolderWithEsmDistFolder(absoluteAppPath)\n )\n const errorPath = this.utils.contextify(\n this.context || this.rootContext,\n swapDistFolderWithEsmDistFolder(absoluteErrorPath)\n )\n const documentPath = this.utils.contextify(\n this.context || this.rootContext,\n swapDistFolderWithEsmDistFolder(absoluteDocumentPath)\n )\n const userland500Path = absolute500Path\n ? this.utils.contextify(\n this.context || this.rootContext,\n swapDistFolderWithEsmDistFolder(absolute500Path)\n )\n : null\n\n const stringifiedPagePath = JSON.stringify(pagePath)\n\n const pageModPath = `${appDirLoader}${stringifiedPagePath.substring(\n 1,\n stringifiedPagePath.length - 1\n )}${isAppDir ? `?${WEBPACK_RESOURCE_QUERIES.edgeSSREntry}` : ''}`\n\n if (isAppDir) {\n return await loadEntrypoint(\n 'edge-ssr-app',\n Line truncated
@@ -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>;
@@ -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
@@ -0,0 +1 @@
{"version":3,"sources":["../../../../../src/build/webpack/loaders/next-edge-ssr-loader/render.ts"],"sourcesContent":["import type { NextConfigComplete } from '../../../../server/config-shared'\n\nimport type { DocumentType, AppType } from '../../../../shared/lib/utils'\nimport type { BuildManifest } from '../../../../server/get-page-files'\nimport type {\n DynamicCssManifest,\n ReactLoadableManifest,\n} from '../../../../server/load-components'\nimport type { ClientReferenceManifest } from '../../plugins/flight-manifest-plugin'\nimport type { NextFontManifest } from '../../plugins/next-font-manifest-plugin'\nimport type { NextFetchEvent } from '../../../../server/web/spec-extension/fetch-event'\n\nimport WebServer from '../../../../server/web-server'\nimport {\n WebNextRequest,\n WebNextResponse,\n} from '../../../../server/base-http/web'\nimport { SERVER_RUNTIME } from '../../../../lib/constants'\nimport type { ManifestRewriteRoute } from '../../..'\nimport { normalizeAppPath } from '../../../../shared/lib/router/utils/app-paths'\nimport type { SizeLimit } from '../../../../types'\nimport { internal_getCurrentFunctionWaitUntil } from '../../../../server/web/internal-edge-wait-until'\nimport type { PAGE_TYPES } from '../../../../lib/page-types'\nimport type { NextRequestHint } from '../../../../server/web/adapter'\n\nexport function getRender({\n dev,\n page,\n appMod,\n pageMod,\n errorMod,\n error500Mod,\n pagesType,\n Document,\n buildManifest,\n reactLoadableManifest,\n dynamicCssManifest,\n interceptionRouteRewrites,\n renderToHTML,\n clientReferenceManifest,\n subresourceIntegrityManifest,\n serverActionsManifest,\n serverActions,\n config,\n buildId,\n nextFontManifest,\n incrementalCacheHandler,\n}: {\n pagesType: PAGE_TYPES\n dev: boolean\n page: string\n appMod: any\n pageMod: any\n errorMod: any\n error500Mod: any\n renderToHTML?: any\n Document: DocumentType\n buildManifest: BuildManifest\n reactLoadableManifest: ReactLoadableManifest\n dynamicCssManifest?: DynamicCssManifest\n subresourceIntegrityManifest?: Record<string, string>\n interceptionRouteRewrites?: ManifestRewriteRoute[]\n clientReferenceManifest?: ClientReferenceManifest\n serverActionsManifest?: any\n serverActions?: {\n bodySizeLimit?: SizeLimit\n allowedOrigins?: string[]\n }\n config: NextConfigComplete\n buildId: string\n nextFontManifest: NextFontManifest\n incrementalCacheHandler?: any\n}) {\n const isAppPath = pagesType === 'app'\n const baseLoadComponentResult = {\n dev,\n buildManifest,\n reactLoadableManifest,\n dynamicCssManifest,\n subresourceIntegrityManifest,\n Document,\n App: appMod?.default as AppType,\n clientReferenceManifest,\n }\n\n const server = new WebServer({\n dev,\n buildId,\n conf: config,\n minimalMode: true,\n webServerConfig: {\n page,\n pathname: isAppPath ? normalizeAppPath(page) : page,\n pagesType,\n interceptionRouteRewrites,\n extendRenderOpts: {\n runtime: SERVER_RUNTIME.experimentalEdge,\n supportsDynamicResponse: true,\n disableOptimizedLoading: true,\n serverActionsManifest,\n serverActions,\n nextFontManifest,\n },\n renderToHTML,\n incrementalCacheHandler,\n loadComponent: async (inputPage) => {\n if (inputPage === page) {\n return {\n ...baseLoadComponentResult,\n Component: pageMod.default,\n pageConfig: pageMod.config || {},\n getStaticProps: pageMod.getStaticProps,\n getServerSideProps: pageMod.getServerSideProps,\n getStaticPaths: pageMod.getStaticPaths,\n ComponentMod: pageMod,\n isAppPath: !!pageMod.__next_app__,\n page: inputPage,\n routeModule: pageMod.routeModule,\n }\n }\n\n // If there is a custom 500 page, we need to handle it separately.\n if (inputPage === '/500' && error500Mod) {\n return {\n ...baseLoadComponentResult,\n Component: error500Mod.default,\n pageConfig: error500Mod.config || {},\n getStaticProps: error500Mod.getStaticProps,\n getServerSideProps: error500Mod.getServerSideProps,\n getStaticPaths: error500Mod.getStaticPaths,\n ComponentMod: error500Mod,\n page: inputPage,\n routeModule: error500Mod.routeModule,\n }\n }\n\n if (inputPage === '/_error') {\n return {\n ...baseLoadComponentResult,\n Component: errorMod.default,\n pageConfig: errorMod.config || {},\n getStaticProps: errorMod.getStaticProps,\n getServerSideProps: errorMod.getServerSideProps,\n getStaticPaths: errorMod.getStaticPaths,\n ComponentMod: errorMod,\n page: inputPage,\n routeModule: errorMod.routeModule,\n }\n Line truncated