vinext 0.0.24 → 0.0.26
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 +30 -1
- package/dist/check.d.ts.map +1 -1
- package/dist/check.js +6 -5
- package/dist/check.js.map +1 -1
- package/dist/cli.js +32 -1
- package/dist/cli.js.map +1 -1
- package/dist/client/entry.js +1 -1
- package/dist/client/entry.js.map +1 -1
- package/dist/client/vinext-next-data.d.ts +22 -0
- package/dist/client/vinext-next-data.d.ts.map +1 -0
- package/dist/client/vinext-next-data.js +2 -0
- package/dist/client/vinext-next-data.js.map +1 -0
- package/dist/config/config-matchers.d.ts +21 -0
- package/dist/config/config-matchers.d.ts.map +1 -1
- package/dist/config/config-matchers.js +52 -8
- package/dist/config/config-matchers.js.map +1 -1
- package/dist/config/next-config.d.ts +39 -6
- package/dist/config/next-config.d.ts.map +1 -1
- package/dist/config/next-config.js +241 -48
- package/dist/config/next-config.js.map +1 -1
- package/dist/deploy.d.ts +21 -0
- package/dist/deploy.d.ts.map +1 -1
- package/dist/deploy.js +94 -41
- package/dist/deploy.js.map +1 -1
- package/dist/entries/app-browser-entry.d.ts +9 -0
- package/dist/entries/app-browser-entry.d.ts.map +1 -0
- package/dist/entries/app-browser-entry.js +340 -0
- package/dist/entries/app-browser-entry.js.map +1 -0
- package/dist/{server/app-dev-server.d.ts → entries/app-rsc-entry.d.ts} +6 -19
- package/dist/entries/app-rsc-entry.d.ts.map +1 -0
- package/dist/{server/app-dev-server.js → entries/app-rsc-entry.js} +572 -1293
- package/dist/entries/app-rsc-entry.js.map +1 -0
- package/dist/entries/app-ssr-entry.d.ts +8 -0
- package/dist/entries/app-ssr-entry.d.ts.map +1 -0
- package/dist/entries/app-ssr-entry.js +449 -0
- package/dist/entries/app-ssr-entry.js.map +1 -0
- package/dist/entries/pages-client-entry.d.ts +4 -0
- package/dist/entries/pages-client-entry.d.ts.map +1 -0
- package/dist/entries/pages-client-entry.js +94 -0
- package/dist/entries/pages-client-entry.js.map +1 -0
- package/dist/entries/pages-entry-helpers.d.ts +7 -0
- package/dist/entries/pages-entry-helpers.d.ts.map +1 -0
- package/dist/entries/pages-entry-helpers.js +18 -0
- package/dist/entries/pages-entry-helpers.js.map +1 -0
- package/dist/entries/pages-server-entry.d.ts +8 -0
- package/dist/entries/pages-server-entry.d.ts.map +1 -0
- package/dist/entries/pages-server-entry.js +993 -0
- package/dist/entries/pages-server-entry.js.map +1 -0
- package/dist/index.d.ts +4 -25
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +345 -1227
- package/dist/index.js.map +1 -1
- package/dist/plugins/async-hooks-stub.d.ts +16 -0
- package/dist/plugins/async-hooks-stub.d.ts.map +1 -0
- package/dist/plugins/async-hooks-stub.js +45 -0
- package/dist/plugins/async-hooks-stub.js.map +1 -0
- package/dist/routing/app-router.d.ts +12 -6
- package/dist/routing/app-router.d.ts.map +1 -1
- package/dist/routing/app-router.js +19 -40
- package/dist/routing/app-router.js.map +1 -1
- package/dist/routing/pages-router.d.ts.map +1 -1
- package/dist/routing/pages-router.js +3 -9
- package/dist/routing/pages-router.js.map +1 -1
- package/dist/routing/utils.d.ts +9 -0
- package/dist/routing/utils.d.ts.map +1 -1
- package/dist/routing/utils.js +10 -0
- package/dist/routing/utils.js.map +1 -1
- package/dist/server/api-handler.d.ts.map +1 -1
- package/dist/server/api-handler.js +6 -0
- package/dist/server/api-handler.js.map +1 -1
- package/dist/server/dev-module-runner.d.ts +84 -0
- package/dist/server/dev-module-runner.d.ts.map +1 -0
- package/dist/server/dev-module-runner.js +105 -0
- package/dist/server/dev-module-runner.js.map +1 -0
- package/dist/server/dev-server.js.map +1 -1
- package/dist/server/instrumentation.d.ts +52 -9
- package/dist/server/instrumentation.d.ts.map +1 -1
- package/dist/server/instrumentation.js +52 -15
- package/dist/server/instrumentation.js.map +1 -1
- package/dist/server/middleware-codegen.d.ts +1 -1
- package/dist/server/middleware-codegen.js +1 -1
- package/dist/server/middleware-codegen.js.map +1 -1
- package/dist/server/middleware.d.ts +7 -3
- package/dist/server/middleware.d.ts.map +1 -1
- package/dist/server/middleware.js +16 -6
- package/dist/server/middleware.js.map +1 -1
- package/dist/server/prod-server.d.ts.map +1 -1
- package/dist/server/prod-server.js +33 -28
- package/dist/server/prod-server.js.map +1 -1
- package/dist/server/request-pipeline.d.ts +92 -0
- package/dist/server/request-pipeline.d.ts.map +1 -0
- package/dist/server/request-pipeline.js +202 -0
- package/dist/server/request-pipeline.js.map +1 -0
- package/dist/shims/cache.d.ts.map +1 -1
- package/dist/shims/cache.js +14 -2
- package/dist/shims/cache.js.map +1 -1
- package/dist/shims/constants.d.ts +120 -3
- package/dist/shims/constants.d.ts.map +1 -1
- package/dist/shims/constants.js +170 -3
- package/dist/shims/constants.js.map +1 -1
- package/dist/shims/fetch-cache.d.ts.map +1 -1
- package/dist/shims/fetch-cache.js +139 -29
- package/dist/shims/fetch-cache.js.map +1 -1
- package/dist/shims/form.d.ts.map +1 -1
- package/dist/shims/form.js +2 -3
- package/dist/shims/form.js.map +1 -1
- package/dist/shims/headers.d.ts.map +1 -1
- package/dist/shims/headers.js +1 -0
- package/dist/shims/headers.js.map +1 -1
- package/dist/shims/layout-segment-context.d.ts +5 -4
- package/dist/shims/layout-segment-context.d.ts.map +1 -1
- package/dist/shims/layout-segment-context.js +6 -5
- package/dist/shims/layout-segment-context.js.map +1 -1
- package/dist/shims/link.d.ts.map +1 -1
- package/dist/shims/link.js +33 -18
- package/dist/shims/link.js.map +1 -1
- package/dist/shims/metadata.d.ts +7 -1
- package/dist/shims/metadata.d.ts.map +1 -1
- package/dist/shims/metadata.js +9 -3
- package/dist/shims/metadata.js.map +1 -1
- package/dist/shims/navigation.d.ts +14 -11
- package/dist/shims/navigation.d.ts.map +1 -1
- package/dist/shims/navigation.js +122 -102
- package/dist/shims/navigation.js.map +1 -1
- package/dist/shims/og.d.ts +6 -6
- package/dist/shims/og.js +6 -6
- package/dist/shims/og.js.map +1 -1
- package/dist/shims/router.d.ts.map +1 -1
- package/dist/shims/router.js +37 -21
- package/dist/shims/router.js.map +1 -1
- package/dist/shims/server.d.ts +2 -0
- package/dist/shims/server.d.ts.map +1 -1
- package/dist/shims/server.js +4 -0
- package/dist/shims/server.js.map +1 -1
- package/dist/shims/url-utils.d.ts +13 -0
- package/dist/shims/url-utils.d.ts.map +1 -0
- package/dist/shims/url-utils.js +28 -0
- package/dist/shims/url-utils.js.map +1 -0
- package/dist/utils/project.d.ts +15 -0
- package/dist/utils/project.d.ts.map +1 -1
- package/dist/utils/project.js +48 -0
- package/dist/utils/project.js.map +1 -1
- package/package.json +1 -1
- package/dist/server/app-dev-server.d.ts.map +0 -1
- package/dist/server/app-dev-server.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dev-server.js","sourceRoot":"","sources":["../../src/server/dev-server.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAE7E,OAAO,EACL,MAAM,EACN,MAAM,EACN,WAAW,EACX,oBAAoB,EACpB,6BAA6B,EAC7B,qBAAqB,EACrB,qBAAqB,GACtB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAChE,qEAAqE;AACrE,8DAA8D;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,gBAAgB,IAAI,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,IAAI,MA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AO,CAAC,2BAA2B,EAAE,EAAE,CAAC,CAAC;gBAC3D,IAAI,GAAG,OAAO,CAAC;YACjB,CAAC;iBAAM,CAAC;gBACN,IAAI,GAAG;;;;;;;qBAOM,QAAQ;;QAErB,CAAC;YACH,CAAC;YAED,MAAM,eAAe,GAAG,MAAM,MAAM,CAAC,kBAAkB,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;YACnE,GAAG,CAAC,SAAS,CAAC,UAAU,EAAE,EAAE,cAAc,EAAE,WAAW,EAAE,CAAC,CAAC;YAC3D,GAAG,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;YACzB,OAAO;QACT,CAAC;QAAC,MAAM,CAAC;YACP,yCAAyC;YACzC,SAAS;QACX,CAAC;IACH,CAAC;IAED,uDAAuD;IACvD,GAAG,CAAC,SAAS,CAAC,UAAU,EAAE,EAAE,cAAc,EAAE,YAAY,EAAE,CAAC,CAAC;IAC5D,GAAG,CAAC,GAAG,CAAC,GAAG,UAAU,MAAM,UAAU,KAAK,GAAG,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,uBAAuB,EAAE,CAAC,CAAC;AAChG,CAAC","sourcesContent":["import type { ViteDevServer } from \"vite\";\nimport type { IncomingMessage, ServerResponse } from \"node:http\";\nimport type { Route } from \"../routing/pages-router.js\";\nimport { matchRoute, patternToNextFormat } from \"../routing/pages-router.js\";\nimport type { NextI18nConfig } from \"../config/next-config.js\";\nimport {\n isrGet,\n isrSet,\n isrCacheKey,\n buildPagesCacheValue,\n triggerBackgroundRegeneration,\n setRevalidateDuration,\n getRevalidateDuration,\n} from \"./isr-cache.js\";\nimport type { CachedPagesValue } from \"../shims/cache.js\";\nimport { runWithFetchCache } from \"../shims/fetch-cache.js\";\nimport { _runWithCacheState } from \"../shims/cache.js\";\nimport { runWithPrivateCache } from \"../shims/cache-runtime.js\";\n// Import server-only state modules to register ALS-backed accessors.\n// These modules must be imported before any rendering occurs.\nimport { runWithRouterState } from \"../shims/router-state.js\";\nimport { runWithHeadState } from \"../shims/head-state.js\";\nimport { reportRequestError } from \"./instrumentation.js\";\nimport { safeJsonStringify } from \"./html.js\";\nimport { parseQueryString as parseQuery } from \"../utils/query.js\";\nimport path from \"node:path\";\nimport fs from \"node:fs\";\nimport React from \"react\";\nimport { renderToReadableStream } from \"react-dom/server.edge\";\nimport { logRequest, now } from \"./request-log.js\";\nimport { createValidFileMatcher, type ValidFileMatcher } from \"../routing/file-matcher.js\";\n\n/**\n * Render a React element to a string using renderToReadableStream.\n *\n * Uses the edge-compatible Web Streams API. Waits for all Suspense\n * boundaries to resolve via stream.allReady before collecting output.\n * Used for _document rendering and error pages (small, non-streaming).\n */\nasync function renderToStringAsync(element: React.ReactElement): Promise<string> {\n const stream = await renderToReadableStream(element);\n await stream.allReady;\n return new Response(stream).text();\n}\n\n/** Body placeholder used to split the document shell for streaming. */\nconst STREAM_BODY_MARKER = \"<!--VINEXT_STREAM_BODY-->\";\n\n/**\n * Stream a Pages Router page response using progressive SSR.\n *\n * Sends the HTML shell (head, layout, Suspense fallbacks) immediately\n * when the React shell is ready, then streams Suspense content as it\n * resolves. This gives the browser content to render while slow data\n * loads are still in flight.\n *\n * `__NEXT_DATA__` and the hydration script are appended after the body\n * stream completes (the data is known before rendering starts, but\n * deferring them reduces TTFB and lets the browser start parsing the\n * shell sooner).\n */\nasync function streamPageToResponse(\n res: ServerResponse,\n element: React.ReactElement,\n options: {\n url: string;\n server: ViteDevServer;\n fontHeadHTML: string;\n scripts: string;\n DocumentComponent: React.ComponentType | null;\n statusCode?: number;\n extraHeaders?: Record<string, string | string[]>;\n /** Called after renderToReadableStream resolves (shell ready) to collect head HTML */\n getHeadHTML: () => string;\n },\n): Promise<void> {\n const {\n url,\n server,\n fontHeadHTML,\n scripts,\n DocumentComponent,\n statusCode = 200,\n extraHeaders,\n getHeadHTML,\n } = options;\n\n // Start the React body stream FIRST — the promise resolves when the\n // shell is ready (synchronous content outside Suspense boundaries).\n // This triggers the render which populates <Head> tags.\n const bodyStream = await renderToReadableStream(element);\n\n // Now that the shell has rendered, collect head HTML\n const headHTML = getHeadHTML();\n\n // Build the document shell with a placeholder for the body\n let shellTemplate: string;\n\n if (DocumentComponent) {\n const docElement = React.createElement(DocumentComponent);\n let docHtml = await renderToStringAsync(docElement);\n // Replace __NEXT_MAIN__ with our stream marker\n docHtml = docHtml.replace(\"__NEXT_MAIN__\", STREAM_BODY_MARKER);\n // Inject head tags\n if (headHTML || fontHeadHTML) {\n docHtml = docHtml.replace(\"</head>\", ` ${fontHeadHTML}${headHTML}\\n</head>`);\n }\n // Inject scripts: replace placeholder or append before </body>\n docHtml = docHtml.replace(\"<!-- __NEXT_SCRIPTS__ -->\", scripts);\n if (!docHtml.includes(\"__NEXT_DATA__\")) {\n docHtml = docHtml.replace(\"</body>\", ` ${scripts}\\n</body>`);\n }\n shellTemplate = docHtml;\n } else {\n shellTemplate = `<!DOCTYPE html>\n<html>\n<head>\n <meta charset=\"utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n ${fontHeadHTML}${headHTML}\n</head>\n<body>\n <div id=\"__next\">${STREAM_BODY_MARKER}</div>\n ${scripts}\n</body>\n</html>`;\n }\n\n // Apply Vite's HTML transforms (injects HMR client, etc.) on the full\n // shell template, then split at the body marker.\n const transformedShell = await server.transformIndexHtml(url, shellTemplate);\n const markerIdx = transformedShell.indexOf(STREAM_BODY_MARKER);\n const prefix = transformedShell.slice(0, markerIdx);\n const suffix = transformedShell.slice(markerIdx + STREAM_BODY_MARKER.length);\n\n // Send headers and start streaming.\n // Set array-valued headers (e.g. Set-Cookie from gSSP) via setHeader()\n // before writeHead(), since writeHead()'s headers object doesn't handle\n // arrays portably. Then writeHead() merges with any setHeader() calls.\n const headers: Record<string, string> = {\n \"Content-Type\": \"text/html\",\n \"Transfer-Encoding\": \"chunked\",\n };\n if (extraHeaders) {\n for (const [key, val] of Object.entries(extraHeaders)) {\n if (Array.isArray(val)) {\n res.setHeader(key, val);\n } else {\n headers[key] = val;\n }\n }\n }\n res.writeHead(statusCode, headers);\n\n // Write the document prefix (head, opening body)\n res.write(prefix);\n\n // Pipe the React body stream through (Suspense content streams progressively)\n const reader = bodyStream.getReader();\n try {\n for (;;) {\n const { done, value } = await reader.read();\n if (done) break;\n res.write(value);\n }\n } finally {\n reader.releaseLock();\n }\n\n // Write the document suffix (closing tags, scripts)\n res.end(suffix);\n}\n\n/** Check if a file exists with any configured page extension. */\nfunction findFileWithExtensions(basePath: string, matcher: ValidFileMatcher): boolean {\n return matcher.dottedExtensions.some((ext) => fs.existsSync(basePath + ext));\n}\n\n/**\n * Extract locale prefix from a URL path.\n * e.g. /fr/about -> { locale: \"fr\", url: \"/about\", hadPrefix: true }\n * /about -> { locale: \"en\", url: \"/about\", hadPrefix: false } (defaultLocale)\n */\nexport function extractLocaleFromUrl(\n url: string,\n i18nConfig: NextI18nConfig,\n): { locale: string; url: string; hadPrefix: boolean } {\n const pathname = url.split(\"?\")[0];\n const parts = pathname.split(\"/\").filter(Boolean);\n const query = url.includes(\"?\") ? url.slice(url.indexOf(\"?\")) : \"\";\n\n if (parts.length > 0 && i18nConfig.locales.includes(parts[0])) {\n const locale = parts[0];\n const rest = \"/\" + parts.slice(1).join(\"/\");\n return { locale, url: (rest || \"/\") + query, hadPrefix: true };\n }\n\n return { locale: i18nConfig.defaultLocale, url, hadPrefix: false };\n}\n\n/**\n * Detect the preferred locale from the Accept-Language header.\n * Returns the best matching locale or null.\n */\nexport function detectLocaleFromHeaders(\n req: IncomingMessage,\n i18nConfig: NextI18nConfig,\n): string | null {\n const acceptLang = req.headers[\"accept-language\"];\n if (!acceptLang) return null;\n\n // Parse Accept-Language: en-US,en;q=0.9,fr;q=0.8\n const langs = acceptLang\n .split(\",\")\n .map((part) => {\n const [lang, qPart] = part.trim().split(\";\");\n const q = qPart ? parseFloat(qPart.replace(\"q=\", \"\")) : 1;\n return { lang: lang.trim().toLowerCase(), q };\n })\n .sort((a, b) => b.q - a.q);\n\n for (const { lang } of langs) {\n // Exact match\n const exactMatch = i18nConfig.locales.find((l) => l.toLowerCase() === lang);\n if (exactMatch) return exactMatch;\n\n // Prefix match (e.g. \"en-US\" matches \"en\")\n const prefix = lang.split(\"-\")[0];\n const prefixMatch = i18nConfig.locales.find(\n (l) => l.toLowerCase() === prefix || l.toLowerCase().startsWith(prefix + \"-\"),\n );\n if (prefixMatch) return prefixMatch;\n }\n\n return null;\n}\n\n/**\n * Parse the NEXT_LOCALE cookie from a request.\n * Returns the cookie value if it matches a configured locale, otherwise null.\n */\nexport function parseCookieLocale(\n req: IncomingMessage,\n i18nConfig: NextI18nConfig,\n): string | null {\n const cookieHeader = req.headers.cookie;\n if (!cookieHeader) return null;\n\n // Simple cookie parsing — find NEXT_LOCALE=value\n const match = cookieHeader.match(/(?:^|;\\s*)NEXT_LOCALE=([^;]*)/);\n if (!match) return null;\n\n let value: string;\n try {\n value = decodeURIComponent(match[1].trim());\n } catch {\n return null;\n }\n // Only return if it's a valid configured locale\n if (i18nConfig.locales.includes(value)) return value;\n return null;\n}\n\n/**\n * Create an SSR request handler for the Pages Router.\n *\n * For each request:\n * 1. Match the URL against discovered routes\n * 2. Load the page module via Vite's SSR module loader\n * 3. Call getServerSideProps/getStaticProps if present\n * 4. Render the component to HTML\n * 5. Wrap in _document shell and send response\n */\nexport function createSSRHandler(\n server: ViteDevServer,\n routes: Route[],\n pagesDir: string,\n i18nConfig?: NextI18nConfig | null,\n fileMatcher?: ValidFileMatcher,\n) {\n const matcher = fileMatcher ?? createValidFileMatcher();\n return async (\n req: IncomingMessage,\n res: ServerResponse,\n url: string,\n /** Status code override — propagated from middleware rewrite status. */\n statusCode?: number,\n ): Promise<void> => {\n const _reqStart = now();\n let _compileEnd: number | undefined;\n let _renderEnd: number | undefined;\n\n res.on(\"finish\", () => {\n const totalMs = now() - _reqStart;\n const compileMs = _compileEnd !== undefined ? Math.round(_compileEnd - _reqStart) : undefined;\n // renderMs = time from end of compile to end of stream.\n // _renderEnd is set just after streamPageToResponse resolves.\n const renderMs = _renderEnd !== undefined && _compileEnd !== undefined\n ? Math.round(_renderEnd - _compileEnd)\n : undefined;\n logRequest({\n method: req.method ?? \"GET\",\n url,\n status: res.statusCode,\n totalMs,\n compileMs,\n renderMs,\n });\n });\n\n // --- i18n: extract locale from URL prefix ---\n let locale: string | undefined;\n let localeStrippedUrl = url;\n\n if (i18nConfig) {\n const parsed = extractLocaleFromUrl(url, i18nConfig);\n locale = parsed.locale;\n localeStrippedUrl = parsed.url;\n\n // If no locale prefix, check NEXT_LOCALE cookie first, then Accept-Language\n if (!parsed.hadPrefix) {\n const cookieLocale = parseCookieLocale(req, i18nConfig);\n if (cookieLocale && cookieLocale !== i18nConfig.defaultLocale) {\n // NEXT_LOCALE cookie overrides Accept-Language — redirect to cookie locale\n const redirectUrl = `/${cookieLocale}${url === \"/\" ? \"\" : url}`;\n res.writeHead(307, { Location: redirectUrl });\n res.end();\n return;\n }\n // If no cookie or cookie matches default, fall through to Accept-Language detection\n if (!cookieLocale && i18nConfig.localeDetection !== false) {\n const detectedLocale = detectLocaleFromHeaders(req, i18nConfig);\n if (detectedLocale && detectedLocale !== i18nConfig.defaultLocale) {\n const redirectUrl = `/${detectedLocale}${url === \"/\" ? \"\" : url}`;\n res.writeHead(307, { Location: redirectUrl });\n res.end();\n return;\n }\n }\n }\n }\n\n const match = matchRoute(localeStrippedUrl, routes);\n\n if (!match) {\n // No route matched — try to render custom 404 page\n await renderErrorPage(server, req, res, url, pagesDir, 404, undefined, matcher);\n return;\n }\n\n const { route, params } = match;\n\n // Wrap the entire request in nested AsyncLocalStorage.run() scopes to\n // ensure per-request isolation for all state modules.\n return runWithRouterState(() =>\n runWithHeadState(() =>\n _runWithCacheState(() =>\n runWithPrivateCache(() =>\n runWithFetchCache(async () => {\n try {\n // Set SSR context for the router shim so useRouter() returns\n // the correct URL and params during server-side rendering.\n const routerShim = await server.ssrLoadModule(\"next/router\");\n if (typeof routerShim.setSSRContext === \"function\") {\n routerShim.setSSRContext({\n pathname: localeStrippedUrl.split(\"?\")[0],\n query: { ...params, ...parseQuery(url) },\n asPath: url,\n locale: locale ?? i18nConfig?.defaultLocale,\n locales: i18nConfig?.locales,\n defaultLocale: i18nConfig?.defaultLocale,\n });\n }\n\n // Set globalThis locale info for Link component locale prop support during SSR\n if (i18nConfig) {\n (globalThis as any).__VINEXT_LOCALE__ = locale ?? i18nConfig.defaultLocale;\n (globalThis as any).__VINEXT_LOCALES__ = i18nConfig.locales;\n (globalThis as any).__VINEXT_DEFAULT_LOCALE__ = i18nConfig.defaultLocale;\n }\n\n // Load the page module through Vite's SSR pipeline\n // This gives us HMR and transform support for free\n const pageModule = await server.ssrLoadModule(route.filePath);\n // Mark end of compile phase: everything from here is rendering.\n _compileEnd = now();\n\n // Get the page component (default export)\n const PageComponent = pageModule.default;\n if (!PageComponent) {\n console.error(`[vinext] Page ${route.filePath} has no default export`);\n res.statusCode = 500;\n res.end(\"Page has no default export\");\n return;\n }\n\n // Collect page props via data fetching methods\n let pageProps: Record<string, unknown> = {};\n let isrRevalidateSeconds: number | null = null;\n\n // Handle getStaticPaths for dynamic routes: validate the path\n // and respect fallback: false (return 404 for unlisted paths).\n if (typeof pageModule.getStaticPaths === \"function\" && route.isDynamic) {\n const pathsResult = await pageModule.getStaticPaths({\n locales: i18nConfig?.locales ?? [],\n defaultLocale: i18nConfig?.defaultLocale ?? \"\",\n });\n const fallback = pathsResult?.fallback ?? false;\n\n if (fallback === false) {\n // Only allow paths explicitly listed in getStaticPaths\n const paths: Array<{ params: Record<string, string | string[]> }> =\n pathsResult?.paths ?? [];\n const isValidPath = paths.some((p: { params: Record<string, string | string[]> }) => {\n return Object.entries(p.params).every(([key, val]) => {\n const actual = params[key];\n if (Array.isArray(val)) {\n return Array.isArray(actual) && val.join(\"/\") === actual.join(\"/\");\n }\n return String(val) === String(actual);\n });\n });\n\n if (!isValidPath) {\n await renderErrorPage(server, req, res, url, pagesDir, 404, routerShim.wrapWithRouterContext, matcher);\n return;\n }\n }\n // fallback: true or \"blocking\" — always SSR on-demand.\n // In dev mode, Next.js does the same (no fallback shell).\n // In production, both modes SSR on-demand with caching.\n // The difference is that fallback:true could serve a shell first,\n // but since we always have data available via SSR, we render fully.\n }\n\n // Headers set by getServerSideProps for explicit forwarding to\n // streamPageToResponse. Without this, they survive only through\n // Node.js writeHead() implicitly merging setHeader() calls, which\n // would silently break if streamPageToResponse is refactored.\n const gsspExtraHeaders: Record<string, string | string[]> = {};\n\n if (typeof pageModule.getServerSideProps === \"function\") {\n // Snapshot existing headers so we can detect what gSSP adds.\n const headersBeforeGSSP = new Set(Object.keys(res.getHeaders()));\n\n const context = {\n params,\n req,\n res,\n query: parseQuery(url),\n resolvedUrl: localeStrippedUrl,\n locale: locale ?? i18nConfig?.defaultLocale,\n locales: i18nConfig?.locales,\n defaultLocale: i18nConfig?.defaultLocale,\n };\n const result = await pageModule.getServerSideProps(context);\n // If gSSP called res.end() directly (short-circuit pattern),\n // the response is already sent. Do not continue rendering.\n // Note: middleware headers are already on `res` (middleware runs\n // before this handler in the connect chain), so they are included\n // in the short-circuited response. The prod path achieves the same\n // result via the worker entry merging middleware headers after\n // renderPage() returns.\n if (res.writableEnded) {\n return;\n }\n if (result && \"props\" in result) {\n pageProps = result.props;\n }\n if (result && \"redirect\" in result) {\n const { redirect } = result;\n const status = redirect.statusCode ?? (redirect.permanent ? 308 : 307);\n // Sanitize destination to prevent open redirect via protocol-relative URLs.\n // Also normalize backslashes — browsers treat \\ as / in URL contexts.\n let dest = redirect.destination;\n if (!dest.startsWith(\"http://\") && !dest.startsWith(\"https://\")) {\n dest = dest.replace(/^[\\\\/]+/, \"/\");\n }\n res.writeHead(status, {\n Location: dest,\n });\n res.end();\n return;\n }\n if (result && \"notFound\" in result && result.notFound) {\n await renderErrorPage(server, req, res, url, pagesDir, 404, routerShim.wrapWithRouterContext);\n return;\n }\n // Preserve any status code set by gSSP (e.g. res.statusCode = 201).\n // This takes precedence over the default 200 but not over middleware status.\n if (!statusCode && res.statusCode !== 200) {\n statusCode = res.statusCode;\n }\n\n // Capture headers newly set by gSSP and forward them explicitly.\n // Remove from `res` to prevent duplication when writeHead() merges.\n const headersAfterGSSP = res.getHeaders();\n for (const [key, val] of Object.entries(headersAfterGSSP)) {\n if (headersBeforeGSSP.has(key) || val == null) continue;\n res.removeHeader(key);\n if (Array.isArray(val)) {\n gsspExtraHeaders[key] = val.map(String);\n } else {\n gsspExtraHeaders[key] = String(val);\n }\n }\n }\n // Collect font preloads early so ISR cached responses can include\n // the Link header (font preloads are module-level state that persists\n // across requests after the font modules are first loaded).\n let earlyFontLinkHeader = \"\";\n try {\n const earlyPreloads: Array<{ href: string; type: string }> = [];\n const fontGoogleEarly = await server.ssrLoadModule(\"next/font/google\");\n if (typeof fontGoogleEarly.getSSRFontPreloads === \"function\") {\n earlyPreloads.push(...fontGoogleEarly.getSSRFontPreloads());\n }\n const fontLocalEarly = await server.ssrLoadModule(\"next/font/local\");\n if (typeof fontLocalEarly.getSSRFontPreloads === \"function\") {\n earlyPreloads.push(...fontLocalEarly.getSSRFontPreloads());\n }\n if (earlyPreloads.length > 0) {\n earlyFontLinkHeader = earlyPreloads\n .map((p) => `<${p.href}>; rel=preload; as=font; type=${p.type}; crossorigin`)\n .join(\", \");\n }\n } catch {\n // Font modules not loaded yet — skip\n }\n\n if (typeof pageModule.getStaticProps === \"function\") {\n // Check ISR cache before calling getStaticProps\n const cacheKey = isrCacheKey(\"pages\", url.split(\"?\")[0]);\n const cached = await isrGet(cacheKey);\n\n if (cached && !cached.isStale && cached.value.value?.kind === \"PAGES\") {\n // Fresh cache hit — serve directly\n const cachedPage = cached.value.value as CachedPagesValue;\n const cachedHtml = cachedPage.html;\n const transformedHtml = await server.transformIndexHtml(url, cachedHtml);\n const revalidateSecs = getRevalidateDuration(cacheKey) ?? 60;\n const hitHeaders: Record<string, string> = {\n \"Content-Type\": \"text/html\",\n \"X-Vinext-Cache\": \"HIT\",\n \"Cache-Control\": `s-maxage=${revalidateSecs}, stale-while-revalidate`,\n };\n if (earlyFontLinkHeader) hitHeaders[\"Link\"] = earlyFontLinkHeader;\n res.writeHead(200, hitHeaders);\n res.end(transformedHtml);\n return;\n }\n\n if (cached && cached.isStale && cached.value.value?.kind === \"PAGES\") {\n // Stale hit — serve stale immediately, trigger background regen\n const cachedPage = cached.value.value as CachedPagesValue;\n const cachedHtml = cachedPage.html;\n const transformedHtml = await server.transformIndexHtml(url, cachedHtml);\n\n // Trigger background regeneration: re-run getStaticProps and\n // update the cache so the next request is a HIT with fresh data.\n triggerBackgroundRegeneration(cacheKey, async () => {\n const freshResult = await pageModule.getStaticProps({ params });\n if (freshResult && \"props\" in freshResult) {\n const revalidate = typeof freshResult.revalidate === \"number\" ? freshResult.revalidate : 0;\n if (revalidate > 0) {\n await isrSet(cacheKey, buildPagesCacheValue(cachedHtml, freshResult.props), revalidate);\n }\n }\n });\n\n const revalidateSecs = getRevalidateDuration(cacheKey) ?? 60;\n const staleHeaders: Record<string, string> = {\n \"Content-Type\": \"text/html\",\n \"X-Vinext-Cache\": \"STALE\",\n \"Cache-Control\": `s-maxage=${revalidateSecs}, stale-while-revalidate`,\n };\n if (earlyFontLinkHeader) staleHeaders[\"Link\"] = earlyFontLinkHeader;\n res.writeHead(200, staleHeaders);\n res.end(transformedHtml);\n return;\n }\n\n // Cache miss — call getStaticProps normally\n const context = {\n params,\n locale: locale ?? i18nConfig?.defaultLocale,\n locales: i18nConfig?.locales,\n defaultLocale: i18nConfig?.defaultLocale,\n };\n const result = await pageModule.getStaticProps(context);\n if (result && \"props\" in result) {\n pageProps = result.props;\n }\n if (result && \"redirect\" in result) {\n const { redirect } = result;\n const status = redirect.statusCode ?? (redirect.permanent ? 308 : 307);\n // Sanitize destination to prevent open redirect via protocol-relative URLs.\n // Also normalize backslashes — browsers treat \\ as / in URL contexts.\n let dest = redirect.destination;\n if (!dest.startsWith(\"http://\") && !dest.startsWith(\"https://\")) {\n dest = dest.replace(/^[\\\\/]+/, \"/\");\n }\n res.writeHead(status, {\n Location: dest,\n });\n res.end();\n return;\n }\n if (result && \"notFound\" in result && result.notFound) {\n await renderErrorPage(server, req, res, url, pagesDir, 404, routerShim.wrapWithRouterContext);\n return;\n }\n\n // Extract revalidate period for ISR caching after render\n if (typeof result?.revalidate === \"number\" && result.revalidate > 0) {\n isrRevalidateSeconds = result.revalidate;\n }\n }\n\n // Try to load _app.tsx if it exists\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let AppComponent: any = null;\n const appPath = path.join(pagesDir, \"_app\");\n if (findFileWithExtensions(appPath, matcher)) {\n try {\n const appModule = await server.ssrLoadModule(appPath);\n AppComponent = appModule.default ?? null;\n } catch {\n // _app exists but failed to load\n }\n }\n\n // React and ReactDOMServer are imported at the top level as native Node\n // modules. They must NOT go through Vite's SSR module runner because\n // React is CJS and the ESModulesEvaluator doesn't define `module`.\n const createElement = React.createElement;\n let element: React.ReactElement;\n\n // wrapWithRouterContext wraps the element in RouterContext.Provider so that\n // next/compat/router's useRouter() returns the real router.\n const wrapWithRouterContext = routerShim.wrapWithRouterContext;\n\n if (AppComponent) {\n element = createElement(AppComponent, {\n Component: PageComponent,\n pageProps,\n });\n } else {\n element = createElement(PageComponent, pageProps);\n }\n\n if (wrapWithRouterContext) {\n element = wrapWithRouterContext(element);\n }\n\n // Reset SSR head collector before rendering so <Head> tags are captured\n const headShim = await server.ssrLoadModule(\"next/head\");\n if (typeof headShim.resetSSRHead === \"function\") {\n headShim.resetSSRHead();\n }\n\n // Flush any pending dynamic() preloads so components are ready\n const dynamicShim = await server.ssrLoadModule(\"next/dynamic\");\n if (typeof dynamicShim.flushPreloads === \"function\") {\n await dynamicShim.flushPreloads();\n }\n\n // Collect any <Head> tags that were rendered during data fetching\n // (shell head tags — Suspense children's head tags arrive late,\n // matching Next.js behavior)\n\n // Collect SSR font links (Google Fonts <link> tags) and font class styles\n let fontHeadHTML = \"\";\n const allFontStyles: string[] = [];\n const allFontPreloads: Array<{ href: string; type: string }> = [];\n try {\n const fontGoogle = await server.ssrLoadModule(\"next/font/google\");\n if (typeof fontGoogle.getSSRFontLinks === \"function\") {\n const fontUrls = fontGoogle.getSSRFontLinks();\n for (const fontUrl of fontUrls) {\n const safeFontUrl = fontUrl.replace(/&/g, \"&\").replace(/\"/g, \""\");\n fontHeadHTML += `<link rel=\"stylesheet\" href=\"${safeFontUrl}\" />\\n `;\n }\n }\n if (typeof fontGoogle.getSSRFontStyles === \"function\") {\n allFontStyles.push(...fontGoogle.getSSRFontStyles());\n }\n // Collect preloads from self-hosted Google fonts\n if (typeof fontGoogle.getSSRFontPreloads === \"function\") {\n allFontPreloads.push(...fontGoogle.getSSRFontPreloads());\n }\n } catch {\n // next/font/google not used — skip\n }\n try {\n const fontLocal = await server.ssrLoadModule(\"next/font/local\");\n if (typeof fontLocal.getSSRFontStyles === \"function\") {\n allFontStyles.push(...fontLocal.getSSRFontStyles());\n }\n // Collect preloads from local font files\n if (typeof fontLocal.getSSRFontPreloads === \"function\") {\n allFontPreloads.push(...fontLocal.getSSRFontPreloads());\n }\n } catch {\n // next/font/local not used — skip\n }\n // Emit <link rel=\"preload\"> for all collected font files (Google + local)\n for (const { href, type } of allFontPreloads) {\n // Escape href/type to prevent HTML attribute injection (defense-in-depth;\n // Vite-resolved asset paths should never contain special chars).\n const safeHref = href.replace(/&/g, \"&\").replace(/\"/g, \""\");\n const safeType = type.replace(/&/g, \"&\").replace(/\"/g, \""\");\n fontHeadHTML += `<link rel=\"preload\" href=\"${safeHref}\" as=\"font\" type=\"${safeType}\" crossorigin />\\n `;\n }\n if (allFontStyles.length > 0) {\n fontHeadHTML += `<style data-vinext-fonts>${allFontStyles.join(\"\\n\")}</style>\\n `;\n }\n\n // Convert absolute file paths to Vite-servable URLs (relative to root)\n const viteRoot = server.config.root;\n const pageModuleUrl = \"/\" + path.relative(viteRoot, route.filePath);\n const appModuleUrl = AppComponent\n ? \"/\" + path.relative(viteRoot, path.join(pagesDir, \"_app\"))\n : null;\n\n // Hydration entry: inline script that imports the page and hydrates.\n // Stores the React root and page loader for client-side navigation.\n const hydrationScript = `\n<script type=\"module\">\nimport React from \"react\";\nimport { hydrateRoot } from \"react-dom/client\";\nimport { wrapWithRouterContext } from \"next/router\";\n\nconst nextData = window.__NEXT_DATA__;\nconst { pageProps } = nextData.props;\n\nasync function hydrate() {\n const pageModule = await import(\"${pageModuleUrl}\");\n const PageComponent = pageModule.default;\n let element;\n ${\n appModuleUrl\n ? `\n const appModule = await import(\"${appModuleUrl}\");\n const AppComponent = appModule.default;\n window.__VINEXT_APP__ = AppComponent;\n element = React.createElement(AppComponent, { Component: PageComponent, pageProps });\n `\n : `\n element = React.createElement(PageComponent, pageProps);\n `\n }\n element = wrapWithRouterContext(element);\n const root = hydrateRoot(document.getElementById(\"__next\"), element);\n window.__VINEXT_ROOT__ = root;\n}\nhydrate();\n</script>`;\n\n const nextDataScript = `<script>window.__NEXT_DATA__ = ${safeJsonStringify({\n props: { pageProps },\n page: patternToNextFormat(route.pattern),\n query: params,\n isFallback: false,\n locale: locale ?? i18nConfig?.defaultLocale,\n locales: i18nConfig?.locales,\n defaultLocale: i18nConfig?.defaultLocale,\n // Include module URLs so client navigation can import pages directly\n __vinext: {\n pageModuleUrl,\n appModuleUrl,\n },\n })}${i18nConfig ? `;window.__VINEXT_LOCALE__=${safeJsonStringify(locale ?? i18nConfig.defaultLocale)};window.__VINEXT_LOCALES__=${safeJsonStringify(i18nConfig.locales)};window.__VINEXT_DEFAULT_LOCALE__=${safeJsonStringify(i18nConfig.defaultLocale)}` : \"\"}</script>`;\n\n // Try to load custom _document.tsx\n const docPath = path.join(pagesDir, \"_document\");\n let DocumentComponent: any = null;\n if (findFileWithExtensions(docPath, matcher)) {\n try {\n const docModule = await server.ssrLoadModule(docPath);\n DocumentComponent = docModule.default ?? null;\n } catch {\n // _document exists but failed to load\n }\n }\n\n const allScripts = `${nextDataScript}\\n ${hydrationScript}`;\n\n // Build response headers: start with gSSP headers, then layer on\n // ISR and font preload headers (which take precedence).\n const extraHeaders: Record<string, string | string[]> = { ...gsspExtraHeaders };\n if (isrRevalidateSeconds) {\n extraHeaders[\"Cache-Control\"] = `s-maxage=${isrRevalidateSeconds}, stale-while-revalidate`;\n extraHeaders[\"X-Vinext-Cache\"] = \"MISS\";\n }\n\n // Set HTTP Link header for font preloading.\n // This lets the browser (and CDN) start fetching font files before parsing HTML.\n if (allFontPreloads.length > 0) {\n extraHeaders[\"Link\"] = allFontPreloads\n .map((p) => `<${p.href}>; rel=preload; as=font; type=${p.type}; crossorigin`)\n .join(\", \");\n }\n\n // Stream the page using progressive SSR.\n // The shell (layouts, non-suspended content) arrives immediately.\n // Suspense content streams in as it resolves.\n await streamPageToResponse(res, element, {\n url,\n server,\n fontHeadHTML,\n scripts: allScripts,\n DocumentComponent,\n statusCode,\n extraHeaders,\n // Collect head HTML AFTER the shell renders (inside streamPageToResponse,\n // after renderToReadableStream resolves). Head tags from Suspense\n // children arrive late — this matches Next.js behavior.\n getHeadHTML: () => typeof headShim.getSSRHeadHTML === \"function\"\n ? headShim.getSSRHeadHTML()\n : \"\",\n });\n _renderEnd = now();\n\n // Clear SSR context after rendering\n if (typeof routerShim.setSSRContext === \"function\") {\n routerShim.setSSRContext(null);\n }\n\n // If ISR is enabled, we need the full HTML for caching.\n // For ISR, re-render synchronously to get the complete HTML string.\n // This runs after the stream is already sent, so it doesn't affect TTFB.\n if (isrRevalidateSeconds !== null && isrRevalidateSeconds > 0) {\n let isrElement = AppComponent\n ? createElement(AppComponent, { Component: pageModule.default, pageProps })\n : createElement(pageModule.default, pageProps);\n if (wrapWithRouterContext) {\n isrElement = wrapWithRouterContext(isrElement);\n }\n const isrBodyHtml = await renderToStringAsync(isrElement);\n const isrHtml = `<!DOCTYPE html><html><head></head><body><div id=\"__next\">${isrBodyHtml}</div>${allScripts}</body></html>`;\n const cacheKey = isrCacheKey(\"pages\", url.split(\"?\")[0]);\n await isrSet(\n cacheKey,\n buildPagesCacheValue(isrHtml, pageProps),\n isrRevalidateSeconds,\n );\n setRevalidateDuration(cacheKey, isrRevalidateSeconds);\n }\n } catch (e) {\n // Let Vite fix the stack trace for better dev experience\n server.ssrFixStacktrace(e as Error);\n console.error(e);\n // Report error via instrumentation hook if registered\n reportRequestError(\n e instanceof Error ? e : new Error(String(e)),\n {\n path: url,\n method: req.method ?? \"GET\",\n headers: Object.fromEntries(\n Object.entries(req.headers).map(([k, v]) => [k, Array.isArray(v) ? v.join(\", \") : String(v ?? \"\")]),\n ),\n },\n { routerKind: \"Pages Router\", routePath: route.pattern, routeType: \"render\" },\n ).catch(() => { /* ignore reporting errors */ });\n // Try to render custom 500 error page\n try {\n await renderErrorPage(server, req, res, url, pagesDir, 500, undefined, matcher);\n } catch (fallbackErr) {\n // If error page itself fails, fall back to plain text.\n // This is a dev-only code path (prod uses prod-server.ts), so\n // include the error message for debugging.\n res.statusCode = 500;\n res.end(`Internal Server Error: ${(fallbackErr as Error).message}`);\n }\n } finally {\n // Cleanup is handled by ALS scope unwinding —\n // each runWith*() scope is automatically cleaned up when it exits.\n }\n }) // end runWithFetchCache\n ) // end runWithPrivateCache\n ) // end _runWithCacheState\n ) // end runWithHeadState\n ); // end runWithRouterState\n };\n}\n\n/**\n * Render a custom error page (404.tsx, 500.tsx, or _error.tsx).\n *\n * Next.js resolution order:\n * - 404: pages/404.tsx -> pages/_error.tsx -> default\n * - 500: pages/500.tsx -> pages/_error.tsx -> default\n * - other: pages/_error.tsx -> default\n */\nasync function renderErrorPage(\n server: ViteDevServer,\n _req: IncomingMessage,\n res: ServerResponse,\n url: string,\n pagesDir: string,\n statusCode: number,\n wrapWithRouterContext?: ((el: React.ReactElement) => React.ReactElement) | null,\n fileMatcher?: ValidFileMatcher,\n): Promise<void> {\n const matcher = fileMatcher ?? createValidFileMatcher();\n // Try specific status page first, then _error, then fallback\n const candidates =\n statusCode === 404\n ? [\"404\", \"_error\"]\n : statusCode === 500\n ? [\"500\", \"_error\"]\n : [\"_error\"];\n\n for (const candidate of candidates) {\n try {\n const candidatePath = path.join(pagesDir, candidate);\n if (!findFileWithExtensions(candidatePath, matcher)) continue;\n\n const errorModule = await server.ssrLoadModule(candidatePath);\n const ErrorComponent = errorModule.default;\n if (!ErrorComponent) continue;\n\n // Try to load _app.tsx to wrap the error page\n let AppComponent: any = null;\n const appPathErr = path.join(pagesDir, \"_app\");\n if (findFileWithExtensions(appPathErr, matcher)) {\n try {\n const appModule = await server.ssrLoadModule(appPathErr);\n AppComponent = appModule.default ?? null;\n } catch {\n // _app exists but failed to load\n }\n }\n\n const createElement = React.createElement;\n const errorProps = { statusCode };\n\n // If the caller didn't supply wrapWithRouterContext, load it now.\n // ssrLoadModule caches internally so the cost is negligible.\n let wrapFn = wrapWithRouterContext;\n if (!wrapFn) {\n try {\n const errRouterShim = await server.ssrLoadModule(\"next/router\");\n wrapFn = errRouterShim.wrapWithRouterContext;\n } catch {\n // router shim not available — continue without it\n }\n }\n\n let element: React.ReactElement;\n if (AppComponent) {\n element = createElement(AppComponent, {\n Component: ErrorComponent,\n pageProps: errorProps,\n });\n } else {\n element = createElement(ErrorComponent, errorProps);\n }\n\n if (wrapFn) {\n element = wrapFn(element);\n }\n\n const bodyHtml = await renderToStringAsync(element);\n\n // Try custom _document\n let html: string;\n let DocumentComponent: any = null;\n const docPathErr = path.join(pagesDir, \"_document\");\n if (findFileWithExtensions(docPathErr, matcher)) {\n try {\n const docModule = await server.ssrLoadModule(docPathErr);\n DocumentComponent = docModule.default ?? null;\n } catch {\n // _document exists but failed to load\n }\n }\n\n if (DocumentComponent) {\n const docElement = createElement(DocumentComponent);\n let docHtml = await renderToStringAsync(docElement);\n docHtml = docHtml.replace(\"__NEXT_MAIN__\", bodyHtml);\n docHtml = docHtml.replace(\"<!-- __NEXT_SCRIPTS__ -->\", \"\");\n html = docHtml;\n } else {\n html = `<!DOCTYPE html>\n<html>\n<head>\n <meta charset=\"utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n</head>\n<body>\n <div id=\"__next\">${bodyHtml}</div>\n</body>\n</html>`;\n }\n\n const transformedHtml = await server.transformIndexHtml(url, html);\n res.writeHead(statusCode, { \"Content-Type\": \"text/html\" });\n res.end(transformedHtml);\n return;\n } catch {\n // This candidate doesn't exist, try next\n continue;\n }\n }\n\n // No custom error page found — use plain text fallback\n res.writeHead(statusCode, { \"Content-Type\": \"text/plain\" });\n res.end(`${statusCode} - ${statusCode === 404 ? \"Page not found\" : \"Internal Server Error\"}`);\n}\n\n\n"]}
|
|
1
|
+
{"version":3,"file":"dev-server.js","sourceRoot":"","sources":["../../src/server/dev-server.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAE7E,OAAO,EACL,MAAM,EACN,MAAM,EACN,WAAW,EACX,oBAAoB,EACpB,6BAA6B,EAC7B,qBAAqB,EACrB,qBAAqB,GACtB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAChE,qEAAqE;AACrE,8DAA8D;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,gBAAgB,IAAI,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,E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AED,MAAM,eAAe,GAAG,MAAM,MAAM,CAAC,kBAAkB,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;YACnE,GAAG,CAAC,SAAS,CAAC,UAAU,EAAE,EAAE,cAAc,EAAE,WAAW,EAAE,CAAC,CAAC;YAC3D,GAAG,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;YACzB,OAAO;QACT,CAAC;QAAC,MAAM,CAAC;YACP,yCAAyC;YACzC,SAAS;QACX,CAAC;IACH,CAAC;IAED,uDAAuD;IACvD,GAAG,CAAC,SAAS,CAAC,UAAU,EAAE,EAAE,cAAc,EAAE,YAAY,EAAE,CAAC,CAAC;IAC5D,GAAG,CAAC,GAAG,CAAC,GAAG,UAAU,MAAM,UAAU,KAAK,GAAG,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,uBAAuB,EAAE,CAAC,CAAC;AAChG,CAAC","sourcesContent":["import type { ViteDevServer } from \"vite\";\nimport type { IncomingMessage, ServerResponse } from \"node:http\";\nimport type { Route } from \"../routing/pages-router.js\";\nimport { matchRoute, patternToNextFormat } from \"../routing/pages-router.js\";\nimport type { NextI18nConfig } from \"../config/next-config.js\";\nimport {\n isrGet,\n isrSet,\n isrCacheKey,\n buildPagesCacheValue,\n triggerBackgroundRegeneration,\n setRevalidateDuration,\n getRevalidateDuration,\n} from \"./isr-cache.js\";\nimport type { CachedPagesValue } from \"../shims/cache.js\";\nimport { runWithFetchCache } from \"../shims/fetch-cache.js\";\nimport { _runWithCacheState } from \"../shims/cache.js\";\nimport { runWithPrivateCache } from \"../shims/cache-runtime.js\";\n// Import server-only state modules to register ALS-backed accessors.\n// These modules must be imported before any rendering occurs.\nimport { runWithRouterState } from \"../shims/router-state.js\";\nimport { runWithHeadState } from \"../shims/head-state.js\";\nimport { reportRequestError } from \"./instrumentation.js\";\nimport { safeJsonStringify } from \"./html.js\";\nimport { parseQueryString as parseQuery } from \"../utils/query.js\";\nimport path from \"node:path\";\nimport fs from \"node:fs\";\nimport React from \"react\";\nimport { renderToReadableStream } from \"react-dom/server.edge\";\nimport { logRequest, now } from \"./request-log.js\";\nimport { createValidFileMatcher, type ValidFileMatcher } from \"../routing/file-matcher.js\";\n\n/**\n * Render a React element to a string using renderToReadableStream.\n *\n * Uses the edge-compatible Web Streams API. Waits for all Suspense\n * boundaries to resolve via stream.allReady before collecting output.\n * Used for _document rendering and error pages (small, non-streaming).\n */\nasync function renderToStringAsync(element: React.ReactElement): Promise<string> {\n const stream = await renderToReadableStream(element);\n await stream.allReady;\n return new Response(stream).text();\n}\n\n/** Body placeholder used to split the document shell for streaming. */\nconst STREAM_BODY_MARKER = \"<!--VINEXT_STREAM_BODY-->\";\n\n/**\n * Stream a Pages Router page response using progressive SSR.\n *\n * Sends the HTML shell (head, layout, Suspense fallbacks) immediately\n * when the React shell is ready, then streams Suspense content as it\n * resolves. This gives the browser content to render while slow data\n * loads are still in flight.\n *\n * `__NEXT_DATA__` and the hydration script are appended after the body\n * stream completes (the data is known before rendering starts, but\n * deferring them reduces TTFB and lets the browser start parsing the\n * shell sooner).\n */\nasync function streamPageToResponse(\n res: ServerResponse,\n element: React.ReactElement,\n options: {\n url: string;\n server: ViteDevServer;\n fontHeadHTML: string;\n scripts: string;\n DocumentComponent: React.ComponentType | null;\n statusCode?: number;\n extraHeaders?: Record<string, string | string[]>;\n /** Called after renderToReadableStream resolves (shell ready) to collect head HTML */\n getHeadHTML: () => string;\n },\n): Promise<void> {\n const {\n url,\n server,\n fontHeadHTML,\n scripts,\n DocumentComponent,\n statusCode = 200,\n extraHeaders,\n getHeadHTML,\n } = options;\n\n // Start the React body stream FIRST — the promise resolves when the\n // shell is ready (synchronous content outside Suspense boundaries).\n // This triggers the render which populates <Head> tags.\n const bodyStream = await renderToReadableStream(element);\n\n // Now that the shell has rendered, collect head HTML\n const headHTML = getHeadHTML();\n\n // Build the document shell with a placeholder for the body\n let shellTemplate: string;\n\n if (DocumentComponent) {\n const docElement = React.createElement(DocumentComponent);\n let docHtml = await renderToStringAsync(docElement);\n // Replace __NEXT_MAIN__ with our stream marker\n docHtml = docHtml.replace(\"__NEXT_MAIN__\", STREAM_BODY_MARKER);\n // Inject head tags\n if (headHTML || fontHeadHTML) {\n docHtml = docHtml.replace(\"</head>\", ` ${fontHeadHTML}${headHTML}\\n</head>`);\n }\n // Inject scripts: replace placeholder or append before </body>\n docHtml = docHtml.replace(\"<!-- __NEXT_SCRIPTS__ -->\", scripts);\n if (!docHtml.includes(\"__NEXT_DATA__\")) {\n docHtml = docHtml.replace(\"</body>\", ` ${scripts}\\n</body>`);\n }\n shellTemplate = docHtml;\n } else {\n shellTemplate = `<!DOCTYPE html>\n<html>\n<head>\n <meta charset=\"utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n ${fontHeadHTML}${headHTML}\n</head>\n<body>\n <div id=\"__next\">${STREAM_BODY_MARKER}</div>\n ${scripts}\n</body>\n</html>`;\n }\n\n // Apply Vite's HTML transforms (injects HMR client, etc.) on the full\n // shell template, then split at the body marker.\n const transformedShell = await server.transformIndexHtml(url, shellTemplate);\n const markerIdx = transformedShell.indexOf(STREAM_BODY_MARKER);\n const prefix = transformedShell.slice(0, markerIdx);\n const suffix = transformedShell.slice(markerIdx + STREAM_BODY_MARKER.length);\n\n // Send headers and start streaming.\n // Set array-valued headers (e.g. Set-Cookie from gSSP) via setHeader()\n // before writeHead(), since writeHead()'s headers object doesn't handle\n // arrays portably. Then writeHead() merges with any setHeader() calls.\n const headers: Record<string, string> = {\n \"Content-Type\": \"text/html\",\n \"Transfer-Encoding\": \"chunked\",\n };\n if (extraHeaders) {\n for (const [key, val] of Object.entries(extraHeaders)) {\n if (Array.isArray(val)) {\n res.setHeader(key, val);\n } else {\n headers[key] = val;\n }\n }\n }\n res.writeHead(statusCode, headers);\n\n // Write the document prefix (head, opening body)\n res.write(prefix);\n\n // Pipe the React body stream through (Suspense content streams progressively)\n const reader = bodyStream.getReader();\n try {\n for (;;) {\n const { done, value } = await reader.read();\n if (done) break;\n res.write(value);\n }\n } finally {\n reader.releaseLock();\n }\n\n // Write the document suffix (closing tags, scripts)\n res.end(suffix);\n}\n\n/** Check if a file exists with any configured page extension. */\nfunction findFileWithExtensions(basePath: string, matcher: ValidFileMatcher): boolean {\n return matcher.dottedExtensions.some((ext) => fs.existsSync(basePath + ext));\n}\n\n/**\n * Extract locale prefix from a URL path.\n * e.g. /fr/about -> { locale: \"fr\", url: \"/about\", hadPrefix: true }\n * /about -> { locale: \"en\", url: \"/about\", hadPrefix: false } (defaultLocale)\n */\nexport function extractLocaleFromUrl(\n url: string,\n i18nConfig: NextI18nConfig,\n): { locale: string; url: string; hadPrefix: boolean } {\n const pathname = url.split(\"?\")[0];\n const parts = pathname.split(\"/\").filter(Boolean);\n const query = url.includes(\"?\") ? url.slice(url.indexOf(\"?\")) : \"\";\n\n if (parts.length > 0 && i18nConfig.locales.includes(parts[0])) {\n const locale = parts[0];\n const rest = \"/\" + parts.slice(1).join(\"/\");\n return { locale, url: (rest || \"/\") + query, hadPrefix: true };\n }\n\n return { locale: i18nConfig.defaultLocale, url, hadPrefix: false };\n}\n\n/**\n * Detect the preferred locale from the Accept-Language header.\n * Returns the best matching locale or null.\n */\nexport function detectLocaleFromHeaders(\n req: IncomingMessage,\n i18nConfig: NextI18nConfig,\n): string | null {\n const acceptLang = req.headers[\"accept-language\"];\n if (!acceptLang) return null;\n\n // Parse Accept-Language: en-US,en;q=0.9,fr;q=0.8\n const langs = acceptLang\n .split(\",\")\n .map((part) => {\n const [lang, qPart] = part.trim().split(\";\");\n const q = qPart ? parseFloat(qPart.replace(\"q=\", \"\")) : 1;\n return { lang: lang.trim().toLowerCase(), q };\n })\n .sort((a, b) => b.q - a.q);\n\n for (const { lang } of langs) {\n // Exact match\n const exactMatch = i18nConfig.locales.find((l) => l.toLowerCase() === lang);\n if (exactMatch) return exactMatch;\n\n // Prefix match (e.g. \"en-US\" matches \"en\")\n const prefix = lang.split(\"-\")[0];\n const prefixMatch = i18nConfig.locales.find(\n (l) => l.toLowerCase() === prefix || l.toLowerCase().startsWith(prefix + \"-\"),\n );\n if (prefixMatch) return prefixMatch;\n }\n\n return null;\n}\n\n/**\n * Parse the NEXT_LOCALE cookie from a request.\n * Returns the cookie value if it matches a configured locale, otherwise null.\n */\nexport function parseCookieLocale(\n req: IncomingMessage,\n i18nConfig: NextI18nConfig,\n): string | null {\n const cookieHeader = req.headers.cookie;\n if (!cookieHeader) return null;\n\n // Simple cookie parsing — find NEXT_LOCALE=value\n const match = cookieHeader.match(/(?:^|;\\s*)NEXT_LOCALE=([^;]*)/);\n if (!match) return null;\n\n let value: string;\n try {\n value = decodeURIComponent(match[1].trim());\n } catch {\n return null;\n }\n // Only return if it's a valid configured locale\n if (i18nConfig.locales.includes(value)) return value;\n return null;\n}\n\n/**\n * Create an SSR request handler for the Pages Router.\n *\n * For each request:\n * 1. Match the URL against discovered routes\n * 2. Load the page module via Vite's SSR module loader\n * 3. Call getServerSideProps/getStaticProps if present\n * 4. Render the component to HTML\n * 5. Wrap in _document shell and send response\n */\nexport function createSSRHandler(\n server: ViteDevServer,\n routes: Route[],\n pagesDir: string,\n i18nConfig?: NextI18nConfig | null,\n fileMatcher?: ValidFileMatcher,\n) {\n const matcher = fileMatcher ?? createValidFileMatcher();\n return async (\n req: IncomingMessage,\n res: ServerResponse,\n url: string,\n /** Status code override — propagated from middleware rewrite status. */\n statusCode?: number,\n ): Promise<void> => {\n const _reqStart = now();\n let _compileEnd: number | undefined;\n let _renderEnd: number | undefined;\n\n res.on(\"finish\", () => {\n const totalMs = now() - _reqStart;\n const compileMs = _compileEnd !== undefined ? Math.round(_compileEnd - _reqStart) : undefined;\n // renderMs = time from end of compile to end of stream.\n // _renderEnd is set just after streamPageToResponse resolves.\n const renderMs = _renderEnd !== undefined && _compileEnd !== undefined\n ? Math.round(_renderEnd - _compileEnd)\n : undefined;\n logRequest({\n method: req.method ?? \"GET\",\n url,\n status: res.statusCode,\n totalMs,\n compileMs,\n renderMs,\n });\n });\n\n // --- i18n: extract locale from URL prefix ---\n let locale: string | undefined;\n let localeStrippedUrl = url;\n\n if (i18nConfig) {\n const parsed = extractLocaleFromUrl(url, i18nConfig);\n locale = parsed.locale;\n localeStrippedUrl = parsed.url;\n\n // If no locale prefix, check NEXT_LOCALE cookie first, then Accept-Language\n if (!parsed.hadPrefix) {\n const cookieLocale = parseCookieLocale(req, i18nConfig);\n if (cookieLocale && cookieLocale !== i18nConfig.defaultLocale) {\n // NEXT_LOCALE cookie overrides Accept-Language — redirect to cookie locale\n const redirectUrl = `/${cookieLocale}${url === \"/\" ? \"\" : url}`;\n res.writeHead(307, { Location: redirectUrl });\n res.end();\n return;\n }\n // If no cookie or cookie matches default, fall through to Accept-Language detection\n if (!cookieLocale && i18nConfig.localeDetection !== false) {\n const detectedLocale = detectLocaleFromHeaders(req, i18nConfig);\n if (detectedLocale && detectedLocale !== i18nConfig.defaultLocale) {\n const redirectUrl = `/${detectedLocale}${url === \"/\" ? \"\" : url}`;\n res.writeHead(307, { Location: redirectUrl });\n res.end();\n return;\n }\n }\n }\n }\n\n const match = matchRoute(localeStrippedUrl, routes);\n\n if (!match) {\n // No route matched — try to render custom 404 page\n await renderErrorPage(server, req, res, url, pagesDir, 404, undefined, matcher);\n return;\n }\n\n const { route, params } = match;\n\n // Wrap the entire request in nested AsyncLocalStorage.run() scopes to\n // ensure per-request isolation for all state modules.\n return runWithRouterState(() =>\n runWithHeadState(() =>\n _runWithCacheState(() =>\n runWithPrivateCache(() =>\n runWithFetchCache(async () => {\n try {\n // Set SSR context for the router shim so useRouter() returns\n // the correct URL and params during server-side rendering.\n const routerShim = await server.ssrLoadModule(\"next/router\");\n if (typeof routerShim.setSSRContext === \"function\") {\n routerShim.setSSRContext({\n pathname: localeStrippedUrl.split(\"?\")[0],\n query: { ...params, ...parseQuery(url) },\n asPath: url,\n locale: locale ?? i18nConfig?.defaultLocale,\n locales: i18nConfig?.locales,\n defaultLocale: i18nConfig?.defaultLocale,\n });\n }\n\n // Set globalThis locale info for Link component locale prop support during SSR\n if (i18nConfig) {\n globalThis.__VINEXT_LOCALE__ = locale ?? i18nConfig.defaultLocale;\n globalThis.__VINEXT_LOCALES__ = i18nConfig.locales;\n globalThis.__VINEXT_DEFAULT_LOCALE__ = i18nConfig.defaultLocale;\n }\n\n // Load the page module through Vite's SSR pipeline\n // This gives us HMR and transform support for free\n const pageModule = await server.ssrLoadModule(route.filePath);\n // Mark end of compile phase: everything from here is rendering.\n _compileEnd = now();\n\n // Get the page component (default export)\n const PageComponent = pageModule.default;\n if (!PageComponent) {\n console.error(`[vinext] Page ${route.filePath} has no default export`);\n res.statusCode = 500;\n res.end(\"Page has no default export\");\n return;\n }\n\n // Collect page props via data fetching methods\n let pageProps: Record<string, unknown> = {};\n let isrRevalidateSeconds: number | null = null;\n\n // Handle getStaticPaths for dynamic routes: validate the path\n // and respect fallback: false (return 404 for unlisted paths).\n if (typeof pageModule.getStaticPaths === \"function\" && route.isDynamic) {\n const pathsResult = await pageModule.getStaticPaths({\n locales: i18nConfig?.locales ?? [],\n defaultLocale: i18nConfig?.defaultLocale ?? \"\",\n });\n const fallback = pathsResult?.fallback ?? false;\n\n if (fallback === false) {\n // Only allow paths explicitly listed in getStaticPaths\n const paths: Array<{ params: Record<string, string | string[]> }> =\n pathsResult?.paths ?? [];\n const isValidPath = paths.some((p: { params: Record<string, string | string[]> }) => {\n return Object.entries(p.params).every(([key, val]) => {\n const actual = params[key];\n if (Array.isArray(val)) {\n return Array.isArray(actual) && val.join(\"/\") === actual.join(\"/\");\n }\n return String(val) === String(actual);\n });\n });\n\n if (!isValidPath) {\n await renderErrorPage(server, req, res, url, pagesDir, 404, routerShim.wrapWithRouterContext, matcher);\n return;\n }\n }\n // fallback: true or \"blocking\" — always SSR on-demand.\n // In dev mode, Next.js does the same (no fallback shell).\n // In production, both modes SSR on-demand with caching.\n // The difference is that fallback:true could serve a shell first,\n // but since we always have data available via SSR, we render fully.\n }\n\n // Headers set by getServerSideProps for explicit forwarding to\n // streamPageToResponse. Without this, they survive only through\n // Node.js writeHead() implicitly merging setHeader() calls, which\n // would silently break if streamPageToResponse is refactored.\n const gsspExtraHeaders: Record<string, string | string[]> = {};\n\n if (typeof pageModule.getServerSideProps === \"function\") {\n // Snapshot existing headers so we can detect what gSSP adds.\n const headersBeforeGSSP = new Set(Object.keys(res.getHeaders()));\n\n const context = {\n params,\n req,\n res,\n query: parseQuery(url),\n resolvedUrl: localeStrippedUrl,\n locale: locale ?? i18nConfig?.defaultLocale,\n locales: i18nConfig?.locales,\n defaultLocale: i18nConfig?.defaultLocale,\n };\n const result = await pageModule.getServerSideProps(context);\n // If gSSP called res.end() directly (short-circuit pattern),\n // the response is already sent. Do not continue rendering.\n // Note: middleware headers are already on `res` (middleware runs\n // before this handler in the connect chain), so they are included\n // in the short-circuited response. The prod path achieves the same\n // result via the worker entry merging middleware headers after\n // renderPage() returns.\n if (res.writableEnded) {\n return;\n }\n if (result && \"props\" in result) {\n pageProps = result.props;\n }\n if (result && \"redirect\" in result) {\n const { redirect } = result;\n const status = redirect.statusCode ?? (redirect.permanent ? 308 : 307);\n // Sanitize destination to prevent open redirect via protocol-relative URLs.\n // Also normalize backslashes — browsers treat \\ as / in URL contexts.\n let dest = redirect.destination;\n if (!dest.startsWith(\"http://\") && !dest.startsWith(\"https://\")) {\n dest = dest.replace(/^[\\\\/]+/, \"/\");\n }\n res.writeHead(status, {\n Location: dest,\n });\n res.end();\n return;\n }\n if (result && \"notFound\" in result && result.notFound) {\n await renderErrorPage(server, req, res, url, pagesDir, 404, routerShim.wrapWithRouterContext);\n return;\n }\n // Preserve any status code set by gSSP (e.g. res.statusCode = 201).\n // This takes precedence over the default 200 but not over middleware status.\n if (!statusCode && res.statusCode !== 200) {\n statusCode = res.statusCode;\n }\n\n // Capture headers newly set by gSSP and forward them explicitly.\n // Remove from `res` to prevent duplication when writeHead() merges.\n const headersAfterGSSP = res.getHeaders();\n for (const [key, val] of Object.entries(headersAfterGSSP)) {\n if (headersBeforeGSSP.has(key) || val == null) continue;\n res.removeHeader(key);\n if (Array.isArray(val)) {\n gsspExtraHeaders[key] = val.map(String);\n } else {\n gsspExtraHeaders[key] = String(val);\n }\n }\n }\n // Collect font preloads early so ISR cached responses can include\n // the Link header (font preloads are module-level state that persists\n // across requests after the font modules are first loaded).\n let earlyFontLinkHeader = \"\";\n try {\n const earlyPreloads: Array<{ href: string; type: string }> = [];\n const fontGoogleEarly = await server.ssrLoadModule(\"next/font/google\");\n if (typeof fontGoogleEarly.getSSRFontPreloads === \"function\") {\n earlyPreloads.push(...fontGoogleEarly.getSSRFontPreloads());\n }\n const fontLocalEarly = await server.ssrLoadModule(\"next/font/local\");\n if (typeof fontLocalEarly.getSSRFontPreloads === \"function\") {\n earlyPreloads.push(...fontLocalEarly.getSSRFontPreloads());\n }\n if (earlyPreloads.length > 0) {\n earlyFontLinkHeader = earlyPreloads\n .map((p) => `<${p.href}>; rel=preload; as=font; type=${p.type}; crossorigin`)\n .join(\", \");\n }\n } catch {\n // Font modules not loaded yet — skip\n }\n\n if (typeof pageModule.getStaticProps === \"function\") {\n // Check ISR cache before calling getStaticProps\n const cacheKey = isrCacheKey(\"pages\", url.split(\"?\")[0]);\n const cached = await isrGet(cacheKey);\n\n if (cached && !cached.isStale && cached.value.value?.kind === \"PAGES\") {\n // Fresh cache hit — serve directly\n const cachedPage = cached.value.value as CachedPagesValue;\n const cachedHtml = cachedPage.html;\n const transformedHtml = await server.transformIndexHtml(url, cachedHtml);\n const revalidateSecs = getRevalidateDuration(cacheKey) ?? 60;\n const hitHeaders: Record<string, string> = {\n \"Content-Type\": \"text/html\",\n \"X-Vinext-Cache\": \"HIT\",\n \"Cache-Control\": `s-maxage=${revalidateSecs}, stale-while-revalidate`,\n };\n if (earlyFontLinkHeader) hitHeaders[\"Link\"] = earlyFontLinkHeader;\n res.writeHead(200, hitHeaders);\n res.end(transformedHtml);\n return;\n }\n\n if (cached && cached.isStale && cached.value.value?.kind === \"PAGES\") {\n // Stale hit — serve stale immediately, trigger background regen\n const cachedPage = cached.value.value as CachedPagesValue;\n const cachedHtml = cachedPage.html;\n const transformedHtml = await server.transformIndexHtml(url, cachedHtml);\n\n // Trigger background regeneration: re-run getStaticProps and\n // update the cache so the next request is a HIT with fresh data.\n triggerBackgroundRegeneration(cacheKey, async () => {\n const freshResult = await pageModule.getStaticProps({ params });\n if (freshResult && \"props\" in freshResult) {\n const revalidate = typeof freshResult.revalidate === \"number\" ? freshResult.revalidate : 0;\n if (revalidate > 0) {\n await isrSet(cacheKey, buildPagesCacheValue(cachedHtml, freshResult.props), revalidate);\n }\n }\n });\n\n const revalidateSecs = getRevalidateDuration(cacheKey) ?? 60;\n const staleHeaders: Record<string, string> = {\n \"Content-Type\": \"text/html\",\n \"X-Vinext-Cache\": \"STALE\",\n \"Cache-Control\": `s-maxage=${revalidateSecs}, stale-while-revalidate`,\n };\n if (earlyFontLinkHeader) staleHeaders[\"Link\"] = earlyFontLinkHeader;\n res.writeHead(200, staleHeaders);\n res.end(transformedHtml);\n return;\n }\n\n // Cache miss — call getStaticProps normally\n const context = {\n params,\n locale: locale ?? i18nConfig?.defaultLocale,\n locales: i18nConfig?.locales,\n defaultLocale: i18nConfig?.defaultLocale,\n };\n const result = await pageModule.getStaticProps(context);\n if (result && \"props\" in result) {\n pageProps = result.props;\n }\n if (result && \"redirect\" in result) {\n const { redirect } = result;\n const status = redirect.statusCode ?? (redirect.permanent ? 308 : 307);\n // Sanitize destination to prevent open redirect via protocol-relative URLs.\n // Also normalize backslashes — browsers treat \\ as / in URL contexts.\n let dest = redirect.destination;\n if (!dest.startsWith(\"http://\") && !dest.startsWith(\"https://\")) {\n dest = dest.replace(/^[\\\\/]+/, \"/\");\n }\n res.writeHead(status, {\n Location: dest,\n });\n res.end();\n return;\n }\n if (result && \"notFound\" in result && result.notFound) {\n await renderErrorPage(server, req, res, url, pagesDir, 404, routerShim.wrapWithRouterContext);\n return;\n }\n\n // Extract revalidate period for ISR caching after render\n if (typeof result?.revalidate === \"number\" && result.revalidate > 0) {\n isrRevalidateSeconds = result.revalidate;\n }\n }\n\n // Try to load _app.tsx if it exists\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let AppComponent: any = null;\n const appPath = path.join(pagesDir, \"_app\");\n if (findFileWithExtensions(appPath, matcher)) {\n try {\n const appModule = await server.ssrLoadModule(appPath);\n AppComponent = appModule.default ?? null;\n } catch {\n // _app exists but failed to load\n }\n }\n\n // React and ReactDOMServer are imported at the top level as native Node\n // modules. They must NOT go through Vite's SSR module runner because\n // React is CJS and the ESModulesEvaluator doesn't define `module`.\n const createElement = React.createElement;\n let element: React.ReactElement;\n\n // wrapWithRouterContext wraps the element in RouterContext.Provider so that\n // next/compat/router's useRouter() returns the real router.\n const wrapWithRouterContext = routerShim.wrapWithRouterContext;\n\n if (AppComponent) {\n element = createElement(AppComponent, {\n Component: PageComponent,\n pageProps,\n });\n } else {\n element = createElement(PageComponent, pageProps);\n }\n\n if (wrapWithRouterContext) {\n element = wrapWithRouterContext(element);\n }\n\n // Reset SSR head collector before rendering so <Head> tags are captured\n const headShim = await server.ssrLoadModule(\"next/head\");\n if (typeof headShim.resetSSRHead === \"function\") {\n headShim.resetSSRHead();\n }\n\n // Flush any pending dynamic() preloads so components are ready\n const dynamicShim = await server.ssrLoadModule(\"next/dynamic\");\n if (typeof dynamicShim.flushPreloads === \"function\") {\n await dynamicShim.flushPreloads();\n }\n\n // Collect any <Head> tags that were rendered during data fetching\n // (shell head tags — Suspense children's head tags arrive late,\n // matching Next.js behavior)\n\n // Collect SSR font links (Google Fonts <link> tags) and font class styles\n let fontHeadHTML = \"\";\n const allFontStyles: string[] = [];\n const allFontPreloads: Array<{ href: string; type: string }> = [];\n try {\n const fontGoogle = await server.ssrLoadModule(\"next/font/google\");\n if (typeof fontGoogle.getSSRFontLinks === \"function\") {\n const fontUrls = fontGoogle.getSSRFontLinks();\n for (const fontUrl of fontUrls) {\n const safeFontUrl = fontUrl.replace(/&/g, \"&\").replace(/\"/g, \""\");\n fontHeadHTML += `<link rel=\"stylesheet\" href=\"${safeFontUrl}\" />\\n `;\n }\n }\n if (typeof fontGoogle.getSSRFontStyles === \"function\") {\n allFontStyles.push(...fontGoogle.getSSRFontStyles());\n }\n // Collect preloads from self-hosted Google fonts\n if (typeof fontGoogle.getSSRFontPreloads === \"function\") {\n allFontPreloads.push(...fontGoogle.getSSRFontPreloads());\n }\n } catch {\n // next/font/google not used — skip\n }\n try {\n const fontLocal = await server.ssrLoadModule(\"next/font/local\");\n if (typeof fontLocal.getSSRFontStyles === \"function\") {\n allFontStyles.push(...fontLocal.getSSRFontStyles());\n }\n // Collect preloads from local font files\n if (typeof fontLocal.getSSRFontPreloads === \"function\") {\n allFontPreloads.push(...fontLocal.getSSRFontPreloads());\n }\n } catch {\n // next/font/local not used — skip\n }\n // Emit <link rel=\"preload\"> for all collected font files (Google + local)\n for (const { href, type } of allFontPreloads) {\n // Escape href/type to prevent HTML attribute injection (defense-in-depth;\n // Vite-resolved asset paths should never contain special chars).\n const safeHref = href.replace(/&/g, \"&\").replace(/\"/g, \""\");\n const safeType = type.replace(/&/g, \"&\").replace(/\"/g, \""\");\n fontHeadHTML += `<link rel=\"preload\" href=\"${safeHref}\" as=\"font\" type=\"${safeType}\" crossorigin />\\n `;\n }\n if (allFontStyles.length > 0) {\n fontHeadHTML += `<style data-vinext-fonts>${allFontStyles.join(\"\\n\")}</style>\\n `;\n }\n\n // Convert absolute file paths to Vite-servable URLs (relative to root)\n const viteRoot = server.config.root;\n const pageModuleUrl = \"/\" + path.relative(viteRoot, route.filePath);\n const appModuleUrl = AppComponent\n ? \"/\" + path.relative(viteRoot, path.join(pagesDir, \"_app\"))\n : null;\n\n // Hydration entry: inline script that imports the page and hydrates.\n // Stores the React root and page loader for client-side navigation.\n const hydrationScript = `\n<script type=\"module\">\nimport React from \"react\";\nimport { hydrateRoot } from \"react-dom/client\";\nimport { wrapWithRouterContext } from \"next/router\";\n\nconst nextData = window.__NEXT_DATA__;\nconst { pageProps } = nextData.props;\n\nasync function hydrate() {\n const pageModule = await import(\"${pageModuleUrl}\");\n const PageComponent = pageModule.default;\n let element;\n ${\n appModuleUrl\n ? `\n const appModule = await import(\"${appModuleUrl}\");\n const AppComponent = appModule.default;\n window.__VINEXT_APP__ = AppComponent;\n element = React.createElement(AppComponent, { Component: PageComponent, pageProps });\n `\n : `\n element = React.createElement(PageComponent, pageProps);\n `\n }\n element = wrapWithRouterContext(element);\n const root = hydrateRoot(document.getElementById(\"__next\"), element);\n window.__VINEXT_ROOT__ = root;\n}\nhydrate();\n</script>`;\n\n const nextDataScript = `<script>window.__NEXT_DATA__ = ${safeJsonStringify({\n props: { pageProps },\n page: patternToNextFormat(route.pattern),\n query: params,\n isFallback: false,\n locale: locale ?? i18nConfig?.defaultLocale,\n locales: i18nConfig?.locales,\n defaultLocale: i18nConfig?.defaultLocale,\n // Include module URLs so client navigation can import pages directly\n __vinext: {\n pageModuleUrl,\n appModuleUrl,\n },\n })}${i18nConfig ? `;window.__VINEXT_LOCALE__=${safeJsonStringify(locale ?? i18nConfig.defaultLocale)};window.__VINEXT_LOCALES__=${safeJsonStringify(i18nConfig.locales)};window.__VINEXT_DEFAULT_LOCALE__=${safeJsonStringify(i18nConfig.defaultLocale)}` : \"\"}</script>`;\n\n // Try to load custom _document.tsx\n const docPath = path.join(pagesDir, \"_document\");\n let DocumentComponent: any = null;\n if (findFileWithExtensions(docPath, matcher)) {\n try {\n const docModule = await server.ssrLoadModule(docPath);\n DocumentComponent = docModule.default ?? null;\n } catch {\n // _document exists but failed to load\n }\n }\n\n const allScripts = `${nextDataScript}\\n ${hydrationScript}`;\n\n // Build response headers: start with gSSP headers, then layer on\n // ISR and font preload headers (which take precedence).\n const extraHeaders: Record<string, string | string[]> = { ...gsspExtraHeaders };\n if (isrRevalidateSeconds) {\n extraHeaders[\"Cache-Control\"] = `s-maxage=${isrRevalidateSeconds}, stale-while-revalidate`;\n extraHeaders[\"X-Vinext-Cache\"] = \"MISS\";\n }\n\n // Set HTTP Link header for font preloading.\n // This lets the browser (and CDN) start fetching font files before parsing HTML.\n if (allFontPreloads.length > 0) {\n extraHeaders[\"Link\"] = allFontPreloads\n .map((p) => `<${p.href}>; rel=preload; as=font; type=${p.type}; crossorigin`)\n .join(\", \");\n }\n\n // Stream the page using progressive SSR.\n // The shell (layouts, non-suspended content) arrives immediately.\n // Suspense content streams in as it resolves.\n await streamPageToResponse(res, element, {\n url,\n server,\n fontHeadHTML,\n scripts: allScripts,\n DocumentComponent,\n statusCode,\n extraHeaders,\n // Collect head HTML AFTER the shell renders (inside streamPageToResponse,\n // after renderToReadableStream resolves). Head tags from Suspense\n // children arrive late — this matches Next.js behavior.\n getHeadHTML: () => typeof headShim.getSSRHeadHTML === \"function\"\n ? headShim.getSSRHeadHTML()\n : \"\",\n });\n _renderEnd = now();\n\n // Clear SSR context after rendering\n if (typeof routerShim.setSSRContext === \"function\") {\n routerShim.setSSRContext(null);\n }\n\n // If ISR is enabled, we need the full HTML for caching.\n // For ISR, re-render synchronously to get the complete HTML string.\n // This runs after the stream is already sent, so it doesn't affect TTFB.\n if (isrRevalidateSeconds !== null && isrRevalidateSeconds > 0) {\n let isrElement = AppComponent\n ? createElement(AppComponent, { Component: pageModule.default, pageProps })\n : createElement(pageModule.default, pageProps);\n if (wrapWithRouterContext) {\n isrElement = wrapWithRouterContext(isrElement);\n }\n const isrBodyHtml = await renderToStringAsync(isrElement);\n const isrHtml = `<!DOCTYPE html><html><head></head><body><div id=\"__next\">${isrBodyHtml}</div>${allScripts}</body></html>`;\n const cacheKey = isrCacheKey(\"pages\", url.split(\"?\")[0]);\n await isrSet(\n cacheKey,\n buildPagesCacheValue(isrHtml, pageProps),\n isrRevalidateSeconds,\n );\n setRevalidateDuration(cacheKey, isrRevalidateSeconds);\n }\n } catch (e) {\n // Let Vite fix the stack trace for better dev experience\n server.ssrFixStacktrace(e as Error);\n console.error(e);\n // Report error via instrumentation hook if registered\n reportRequestError(\n e instanceof Error ? e : new Error(String(e)),\n {\n path: url,\n method: req.method ?? \"GET\",\n headers: Object.fromEntries(\n Object.entries(req.headers).map(([k, v]) => [k, Array.isArray(v) ? v.join(\", \") : String(v ?? \"\")]),\n ),\n },\n { routerKind: \"Pages Router\", routePath: route.pattern, routeType: \"render\" },\n ).catch(() => { /* ignore reporting errors */ });\n // Try to render custom 500 error page\n try {\n await renderErrorPage(server, req, res, url, pagesDir, 500, undefined, matcher);\n } catch (fallbackErr) {\n // If error page itself fails, fall back to plain text.\n // This is a dev-only code path (prod uses prod-server.ts), so\n // include the error message for debugging.\n res.statusCode = 500;\n res.end(`Internal Server Error: ${(fallbackErr as Error).message}`);\n }\n } finally {\n // Cleanup is handled by ALS scope unwinding —\n // each runWith*() scope is automatically cleaned up when it exits.\n }\n }) // end runWithFetchCache\n ) // end runWithPrivateCache\n ) // end _runWithCacheState\n ) // end runWithHeadState\n ); // end runWithRouterState\n };\n}\n\n/**\n * Render a custom error page (404.tsx, 500.tsx, or _error.tsx).\n *\n * Next.js resolution order:\n * - 404: pages/404.tsx -> pages/_error.tsx -> default\n * - 500: pages/500.tsx -> pages/_error.tsx -> default\n * - other: pages/_error.tsx -> default\n */\nasync function renderErrorPage(\n server: ViteDevServer,\n _req: IncomingMessage,\n res: ServerResponse,\n url: string,\n pagesDir: string,\n statusCode: number,\n wrapWithRouterContext?: ((el: React.ReactElement) => React.ReactElement) | null,\n fileMatcher?: ValidFileMatcher,\n): Promise<void> {\n const matcher = fileMatcher ?? createValidFileMatcher();\n // Try specific status page first, then _error, then fallback\n const candidates =\n statusCode === 404\n ? [\"404\", \"_error\"]\n : statusCode === 500\n ? [\"500\", \"_error\"]\n : [\"_error\"];\n\n for (const candidate of candidates) {\n try {\n const candidatePath = path.join(pagesDir, candidate);\n if (!findFileWithExtensions(candidatePath, matcher)) continue;\n\n const errorModule = await server.ssrLoadModule(candidatePath);\n const ErrorComponent = errorModule.default;\n if (!ErrorComponent) continue;\n\n // Try to load _app.tsx to wrap the error page\n let AppComponent: any = null;\n const appPathErr = path.join(pagesDir, \"_app\");\n if (findFileWithExtensions(appPathErr, matcher)) {\n try {\n const appModule = await server.ssrLoadModule(appPathErr);\n AppComponent = appModule.default ?? null;\n } catch {\n // _app exists but failed to load\n }\n }\n\n const createElement = React.createElement;\n const errorProps = { statusCode };\n\n // If the caller didn't supply wrapWithRouterContext, load it now.\n // ssrLoadModule caches internally so the cost is negligible.\n let wrapFn = wrapWithRouterContext;\n if (!wrapFn) {\n try {\n const errRouterShim = await server.ssrLoadModule(\"next/router\");\n wrapFn = errRouterShim.wrapWithRouterContext;\n } catch {\n // router shim not available — continue without it\n }\n }\n\n let element: React.ReactElement;\n if (AppComponent) {\n element = createElement(AppComponent, {\n Component: ErrorComponent,\n pageProps: errorProps,\n });\n } else {\n element = createElement(ErrorComponent, errorProps);\n }\n\n if (wrapFn) {\n element = wrapFn(element);\n }\n\n const bodyHtml = await renderToStringAsync(element);\n\n // Try custom _document\n let html: string;\n let DocumentComponent: any = null;\n const docPathErr = path.join(pagesDir, \"_document\");\n if (findFileWithExtensions(docPathErr, matcher)) {\n try {\n const docModule = await server.ssrLoadModule(docPathErr);\n DocumentComponent = docModule.default ?? null;\n } catch {\n // _document exists but failed to load\n }\n }\n\n if (DocumentComponent) {\n const docElement = createElement(DocumentComponent);\n let docHtml = await renderToStringAsync(docElement);\n docHtml = docHtml.replace(\"__NEXT_MAIN__\", bodyHtml);\n docHtml = docHtml.replace(\"<!-- __NEXT_SCRIPTS__ -->\", \"\");\n html = docHtml;\n } else {\n html = `<!DOCTYPE html>\n<html>\n<head>\n <meta charset=\"utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n</head>\n<body>\n <div id=\"__next\">${bodyHtml}</div>\n</body>\n</html>`;\n }\n\n const transformedHtml = await server.transformIndexHtml(url, html);\n res.writeHead(statusCode, { \"Content-Type\": \"text/html\" });\n res.end(transformedHtml);\n return;\n } catch {\n // This candidate doesn't exist, try next\n continue;\n }\n }\n\n // No custom error page found — use plain text fallback\n res.writeHead(statusCode, { \"Content-Type\": \"text/plain\" });\n res.end(`${statusCode} - ${statusCode === 404 ? \"Page not found\" : \"Internal Server Error\"}`);\n}\n\n\n"]}
|
|
@@ -11,7 +11,38 @@
|
|
|
11
11
|
*
|
|
12
12
|
* References:
|
|
13
13
|
* - https://nextjs.org/docs/app/building-your-application/optimizing/instrumentation
|
|
14
|
+
*
|
|
15
|
+
* ## App Router
|
|
16
|
+
*
|
|
17
|
+
* For App Router, `register()` is baked directly into the generated RSC entry
|
|
18
|
+
* as a top-level `await` at module evaluation time (see `entries/app-rsc-entry.ts`
|
|
19
|
+
* `generateRscEntry`). This means it runs inside the Worker process (or RSC
|
|
20
|
+
* Vite environment) — the same process that handles requests — before any
|
|
21
|
+
* request is served. `runInstrumentation()` is NOT called from `configureServer`
|
|
22
|
+
* for App Router.
|
|
23
|
+
*
|
|
24
|
+
* The `onRequestError` handler is stored on `globalThis` so it is visible across
|
|
25
|
+
* the RSC and SSR Vite environments (separate module graphs, same Node.js process).
|
|
26
|
+
* With `@cloudflare/vite-plugin` it runs entirely inside the Worker, so
|
|
27
|
+
* `globalThis` is the Worker's global — also correct.
|
|
28
|
+
*
|
|
29
|
+
* ## Pages Router
|
|
30
|
+
*
|
|
31
|
+
* Pages Router has no RSC entry, so `configureServer()` is the right place to
|
|
32
|
+
* call `register()`. `runInstrumentation()` accepts a `ModuleRunner` (created
|
|
33
|
+
* via `createDirectRunner()`) rather than `server.ssrLoadModule()` so it is
|
|
34
|
+
* safe when `@cloudflare/vite-plugin` is present — that plugin replaces the
|
|
35
|
+
* SSR environment's hot channel, causing `ssrLoadModule()` to crash with
|
|
36
|
+
* `TypeError: Cannot read properties of undefined (reading 'outsideEmitter')`.
|
|
14
37
|
*/
|
|
38
|
+
/**
|
|
39
|
+
* Minimal duck-typed interface for the module runner passed to
|
|
40
|
+
* `runInstrumentation`. Only `.import()` is used — this avoids requiring
|
|
41
|
+
* callers (including tests) to provide a full `ModuleRunner` instance.
|
|
42
|
+
*/
|
|
43
|
+
export interface ModuleImporter {
|
|
44
|
+
import(id: string): Promise<unknown>;
|
|
45
|
+
}
|
|
15
46
|
/**
|
|
16
47
|
* Find the instrumentation file in the project root.
|
|
17
48
|
*/
|
|
@@ -39,26 +70,38 @@ export type OnRequestErrorHandler = (error: Error, request: {
|
|
|
39
70
|
}, context: OnRequestErrorContext) => void | Promise<void>;
|
|
40
71
|
/**
|
|
41
72
|
* Get the registered onRequestError handler (if any).
|
|
73
|
+
*
|
|
74
|
+
* Reads from globalThis so it works across Vite environment boundaries.
|
|
42
75
|
*/
|
|
43
76
|
export declare function getOnRequestErrorHandler(): OnRequestErrorHandler | null;
|
|
44
77
|
/**
|
|
45
|
-
* Load and execute the instrumentation file.
|
|
78
|
+
* Load and execute the instrumentation file via a ModuleRunner.
|
|
46
79
|
*
|
|
47
|
-
*
|
|
48
|
-
* 1. Loads the instrumentation module via
|
|
49
|
-
* 2. Calls the `register()` function if exported
|
|
50
|
-
* 3. Stores the `onRequestError()` handler
|
|
80
|
+
* Called once during Pages Router server startup (`configureServer`). It:
|
|
81
|
+
* 1. Loads the instrumentation module via `runner.import()`.
|
|
82
|
+
* 2. Calls the `register()` function if exported.
|
|
83
|
+
* 3. Stores the `onRequestError()` handler on `globalThis` so it is visible
|
|
84
|
+
* to all Vite environment module graphs (SSR and the host process share
|
|
85
|
+
* the same Node.js `globalThis`).
|
|
51
86
|
*
|
|
52
|
-
*
|
|
87
|
+
* **App Router** does not use this function. For App Router, `register()` is
|
|
88
|
+
* emitted as a top-level `await` inside the generated RSC entry module so it
|
|
89
|
+
* runs in the same Worker/environment as request handling.
|
|
90
|
+
*
|
|
91
|
+
* @param runner - A ModuleRunner created via `createDirectRunner()`. Must be
|
|
92
|
+
* the same long-lived runner used for middleware and SSR so the module graph
|
|
93
|
+
* is shared. Safe with all Vite plugin combinations, including
|
|
94
|
+
* `@cloudflare/vite-plugin`, because it never touches the hot channel.
|
|
53
95
|
* @param instrumentationPath - Absolute path to the instrumentation file
|
|
54
96
|
*/
|
|
55
|
-
export declare function runInstrumentation(
|
|
56
|
-
ssrLoadModule: (id: string) => Promise<Record<string, unknown>>;
|
|
57
|
-
}, instrumentationPath: string): Promise<void>;
|
|
97
|
+
export declare function runInstrumentation(runner: ModuleImporter, instrumentationPath: string): Promise<void>;
|
|
58
98
|
/**
|
|
59
99
|
* Report a request error via the instrumentation handler.
|
|
60
100
|
*
|
|
61
101
|
* No-op if no onRequestError handler is registered.
|
|
102
|
+
*
|
|
103
|
+
* Reads the handler from globalThis so this function works correctly regardless
|
|
104
|
+
* of which environment it is called from.
|
|
62
105
|
*/
|
|
63
106
|
export declare function reportRequestError(error: Error, request: {
|
|
64
107
|
path: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instrumentation.d.ts","sourceRoot":"","sources":["../../src/server/instrumentation.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"instrumentation.d.ts","sourceRoot":"","sources":["../../src/server/instrumentation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAIH;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACtC;AAcD;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAQnE;AAED;;;;;GAKG;AACH,MAAM,WAAW,qBAAqB;IACpC,4CAA4C;IAC5C,UAAU,EAAE,cAAc,GAAG,YAAY,CAAC;IAC1C,gCAAgC;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,qBAAqB;IACrB,SAAS,EAAE,QAAQ,GAAG,OAAO,GAAG,QAAQ,GAAG,YAAY,CAAC;IACxD,yCAAyC;IACzC,gBAAgB,CAAC,EAAE,WAAW,GAAG,OAAO,GAAG,SAAS,CAAC;CACtD;AAED,MAAM,MAAM,qBAAqB,GAAG,CAClC,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,EAC1E,OAAO,EAAE,qBAAqB,KAC3B,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAE1B;;;;GAIG;AACH,wBAAgB,wBAAwB,IAAI,qBAAqB,GAAG,IAAI,CAEvE;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,cAAc,EACtB,mBAAmB,EAAE,MAAM,GAC1B,OAAO,CAAC,IAAI,CAAC,CAoBf;AAED;;;;;;;GAOG;AACH,wBAAsB,kBAAkB,CACtC,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,EAC1E,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,IAAI,CAAC,CAYf"}
|
|
@@ -11,6 +11,29 @@
|
|
|
11
11
|
*
|
|
12
12
|
* References:
|
|
13
13
|
* - https://nextjs.org/docs/app/building-your-application/optimizing/instrumentation
|
|
14
|
+
*
|
|
15
|
+
* ## App Router
|
|
16
|
+
*
|
|
17
|
+
* For App Router, `register()` is baked directly into the generated RSC entry
|
|
18
|
+
* as a top-level `await` at module evaluation time (see `entries/app-rsc-entry.ts`
|
|
19
|
+
* `generateRscEntry`). This means it runs inside the Worker process (or RSC
|
|
20
|
+
* Vite environment) — the same process that handles requests — before any
|
|
21
|
+
* request is served. `runInstrumentation()` is NOT called from `configureServer`
|
|
22
|
+
* for App Router.
|
|
23
|
+
*
|
|
24
|
+
* The `onRequestError` handler is stored on `globalThis` so it is visible across
|
|
25
|
+
* the RSC and SSR Vite environments (separate module graphs, same Node.js process).
|
|
26
|
+
* With `@cloudflare/vite-plugin` it runs entirely inside the Worker, so
|
|
27
|
+
* `globalThis` is the Worker's global — also correct.
|
|
28
|
+
*
|
|
29
|
+
* ## Pages Router
|
|
30
|
+
*
|
|
31
|
+
* Pages Router has no RSC entry, so `configureServer()` is the right place to
|
|
32
|
+
* call `register()`. `runInstrumentation()` accepts a `ModuleRunner` (created
|
|
33
|
+
* via `createDirectRunner()`) rather than `server.ssrLoadModule()` so it is
|
|
34
|
+
* safe when `@cloudflare/vite-plugin` is present — that plugin replaces the
|
|
35
|
+
* SSR environment's hot channel, causing `ssrLoadModule()` to crash with
|
|
36
|
+
* `TypeError: Cannot read properties of undefined (reading 'outsideEmitter')`.
|
|
14
37
|
*/
|
|
15
38
|
import fs from "node:fs";
|
|
16
39
|
import path from "node:path";
|
|
@@ -37,35 +60,45 @@ export function findInstrumentationFile(root) {
|
|
|
37
60
|
}
|
|
38
61
|
return null;
|
|
39
62
|
}
|
|
40
|
-
/** Module-level reference to the onRequestError handler. */
|
|
41
|
-
let _onRequestError = null;
|
|
42
63
|
/**
|
|
43
64
|
* Get the registered onRequestError handler (if any).
|
|
65
|
+
*
|
|
66
|
+
* Reads from globalThis so it works across Vite environment boundaries.
|
|
44
67
|
*/
|
|
45
68
|
export function getOnRequestErrorHandler() {
|
|
46
|
-
return
|
|
69
|
+
return globalThis.__VINEXT_onRequestErrorHandler__ ?? null;
|
|
47
70
|
}
|
|
48
71
|
/**
|
|
49
|
-
* Load and execute the instrumentation file.
|
|
72
|
+
* Load and execute the instrumentation file via a ModuleRunner.
|
|
50
73
|
*
|
|
51
|
-
*
|
|
52
|
-
* 1. Loads the instrumentation module via
|
|
53
|
-
* 2. Calls the `register()` function if exported
|
|
54
|
-
* 3. Stores the `onRequestError()` handler
|
|
74
|
+
* Called once during Pages Router server startup (`configureServer`). It:
|
|
75
|
+
* 1. Loads the instrumentation module via `runner.import()`.
|
|
76
|
+
* 2. Calls the `register()` function if exported.
|
|
77
|
+
* 3. Stores the `onRequestError()` handler on `globalThis` so it is visible
|
|
78
|
+
* to all Vite environment module graphs (SSR and the host process share
|
|
79
|
+
* the same Node.js `globalThis`).
|
|
55
80
|
*
|
|
56
|
-
*
|
|
81
|
+
* **App Router** does not use this function. For App Router, `register()` is
|
|
82
|
+
* emitted as a top-level `await` inside the generated RSC entry module so it
|
|
83
|
+
* runs in the same Worker/environment as request handling.
|
|
84
|
+
*
|
|
85
|
+
* @param runner - A ModuleRunner created via `createDirectRunner()`. Must be
|
|
86
|
+
* the same long-lived runner used for middleware and SSR so the module graph
|
|
87
|
+
* is shared. Safe with all Vite plugin combinations, including
|
|
88
|
+
* `@cloudflare/vite-plugin`, because it never touches the hot channel.
|
|
57
89
|
* @param instrumentationPath - Absolute path to the instrumentation file
|
|
58
90
|
*/
|
|
59
|
-
export async function runInstrumentation(
|
|
91
|
+
export async function runInstrumentation(runner, instrumentationPath) {
|
|
60
92
|
try {
|
|
61
|
-
const mod = await
|
|
93
|
+
const mod = await runner.import(instrumentationPath);
|
|
62
94
|
// Call register() if exported
|
|
63
95
|
if (typeof mod.register === "function") {
|
|
64
96
|
await mod.register();
|
|
65
97
|
}
|
|
66
|
-
// Store onRequestError handler
|
|
98
|
+
// Store onRequestError handler on globalThis so environments can reach the
|
|
99
|
+
// same handler.
|
|
67
100
|
if (typeof mod.onRequestError === "function") {
|
|
68
|
-
|
|
101
|
+
globalThis.__VINEXT_onRequestErrorHandler__ = mod.onRequestError;
|
|
69
102
|
}
|
|
70
103
|
}
|
|
71
104
|
catch (err) {
|
|
@@ -76,12 +109,16 @@ export async function runInstrumentation(server, instrumentationPath) {
|
|
|
76
109
|
* Report a request error via the instrumentation handler.
|
|
77
110
|
*
|
|
78
111
|
* No-op if no onRequestError handler is registered.
|
|
112
|
+
*
|
|
113
|
+
* Reads the handler from globalThis so this function works correctly regardless
|
|
114
|
+
* of which environment it is called from.
|
|
79
115
|
*/
|
|
80
116
|
export async function reportRequestError(error, request, context) {
|
|
81
|
-
|
|
117
|
+
const handler = getOnRequestErrorHandler();
|
|
118
|
+
if (!handler)
|
|
82
119
|
return;
|
|
83
120
|
try {
|
|
84
|
-
await
|
|
121
|
+
await handler(error, request, context);
|
|
85
122
|
}
|
|
86
123
|
catch (reportErr) {
|
|
87
124
|
console.error("[vinext] onRequestError handler threw:", reportErr instanceof Error ? reportErr.message : String(reportErr));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instrumentation.js","sourceRoot":"","sources":["../../src/server/instrumentation.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"instrumentation.js","sourceRoot":"","sources":["../../src/server/instrumentation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAEH,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAU7B,2CAA2C;AAC3C,MAAM,qBAAqB,GAAG;IAC5B,oBAAoB;IACpB,qBAAqB;IACrB,oBAAoB;IACpB,qBAAqB;IACrB,wBAAwB;IACxB,yBAAyB;IACzB,wBAAwB;IACxB,yBAAyB;CAC1B,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,uBAAuB,CAAC,IAAY;IAClD,KAAK,MAAM,IAAI,IAAI,qBAAqB,EAAE,CAAC;QACzC,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACvC,IAAI,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC5B,OAAO,QAAQ,CAAC;QAClB,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAyBD;;;;GAIG;AACH,MAAM,UAAU,wBAAwB;IACtC,OAAO,UAAU,CAAC,gCAAgC,IAAI,IAAI,CAAC;AAC7D,CAAC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,MAAsB,EACtB,mBAA2B;IAE3B,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,mBAAmB,CAA4B,CAAC;QAEhF,8BAA8B;QAC9B,IAAI,OAAO,GAAG,CAAC,QAAQ,KAAK,UAAU,EAAE,CAAC;YACvC,MAAM,GAAG,CAAC,QAAQ,EAAE,CAAC;QACvB,CAAC;QAED,2EAA2E;QAC3E,gBAAgB;QAChB,IAAI,OAAO,GAAG,CAAC,cAAc,KAAK,UAAU,EAAE,CAAC;YAChD,UAAU,CAAC,gCAAgC,GAAG,GAAG,CAAC,cAAuC,CAAC;QACzF,CAAC;IACH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CACX,0CAA0C,EAC1C,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CACjD,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,KAAY,EACZ,OAA0E,EAC1E,OAA8B;IAE9B,MAAM,OAAO,GAAG,wBAAwB,EAAE,CAAC;IAC5C,IAAI,CAAC,OAAO;QAAE,OAAO;IAEpB,IAAI,CAAC;QACH,MAAM,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IACzC,CAAC;IAAC,OAAO,SAAS,EAAE,CAAC;QACnB,OAAO,CAAC,KAAK,CACX,wCAAwC,EACxC,SAAS,YAAY,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CACnE,CAAC;IACJ,CAAC;AACH,CAAC","sourcesContent":["/**\n * instrumentation.ts support\n *\n * Next.js supports an `instrumentation.ts` file at the project root that\n * exports a `register()` function. This function is called once when the\n * server starts, before any request handling. It's the recommended way to\n * set up observability tools (Sentry, Datadog, OpenTelemetry, etc.).\n *\n * Optionally, it can also export `onRequestError()` which is called when\n * an unhandled error occurs during request handling.\n *\n * References:\n * - https://nextjs.org/docs/app/building-your-application/optimizing/instrumentation\n *\n * ## App Router\n *\n * For App Router, `register()` is baked directly into the generated RSC entry\n * as a top-level `await` at module evaluation time (see `entries/app-rsc-entry.ts`\n * `generateRscEntry`). This means it runs inside the Worker process (or RSC\n * Vite environment) — the same process that handles requests — before any\n * request is served. `runInstrumentation()` is NOT called from `configureServer`\n * for App Router.\n *\n * The `onRequestError` handler is stored on `globalThis` so it is visible across\n * the RSC and SSR Vite environments (separate module graphs, same Node.js process).\n * With `@cloudflare/vite-plugin` it runs entirely inside the Worker, so\n * `globalThis` is the Worker's global — also correct.\n *\n * ## Pages Router\n *\n * Pages Router has no RSC entry, so `configureServer()` is the right place to\n * call `register()`. `runInstrumentation()` accepts a `ModuleRunner` (created\n * via `createDirectRunner()`) rather than `server.ssrLoadModule()` so it is\n * safe when `@cloudflare/vite-plugin` is present — that plugin replaces the\n * SSR environment's hot channel, causing `ssrLoadModule()` to crash with\n * `TypeError: Cannot read properties of undefined (reading 'outsideEmitter')`.\n */\n\nimport fs from \"node:fs\";\nimport path from \"node:path\";\n/**\n * Minimal duck-typed interface for the module runner passed to\n * `runInstrumentation`. Only `.import()` is used — this avoids requiring\n * callers (including tests) to provide a full `ModuleRunner` instance.\n */\nexport interface ModuleImporter {\n import(id: string): Promise<unknown>;\n}\n\n/** Possible instrumentation file names. */\nconst INSTRUMENTATION_FILES = [\n \"instrumentation.ts\",\n \"instrumentation.tsx\",\n \"instrumentation.js\",\n \"instrumentation.mjs\",\n \"src/instrumentation.ts\",\n \"src/instrumentation.tsx\",\n \"src/instrumentation.js\",\n \"src/instrumentation.mjs\",\n];\n\n/**\n * Find the instrumentation file in the project root.\n */\nexport function findInstrumentationFile(root: string): string | null {\n for (const file of INSTRUMENTATION_FILES) {\n const fullPath = path.join(root, file);\n if (fs.existsSync(fullPath)) {\n return fullPath;\n }\n }\n return null;\n}\n\n/**\n * The onRequestError handler type from Next.js instrumentation.\n *\n * Called when an unhandled error occurs during request handling.\n * Provides the error, the request info, and an error context.\n */\nexport interface OnRequestErrorContext {\n /** The route path (e.g., '/blog/[slug]') */\n routerKind: \"Pages Router\" | \"App Router\";\n /** The matched route pattern */\n routePath: string;\n /** The route type */\n routeType: \"render\" | \"route\" | \"action\" | \"middleware\";\n /** HTTP status code that will be sent */\n revalidateReason?: \"on-demand\" | \"stale\" | undefined;\n}\n\nexport type OnRequestErrorHandler = (\n error: Error,\n request: { path: string; method: string; headers: Record<string, string> },\n context: OnRequestErrorContext,\n) => void | Promise<void>;\n\n/**\n * Get the registered onRequestError handler (if any).\n *\n * Reads from globalThis so it works across Vite environment boundaries.\n */\nexport function getOnRequestErrorHandler(): OnRequestErrorHandler | null {\n return globalThis.__VINEXT_onRequestErrorHandler__ ?? null;\n}\n\n/**\n * Load and execute the instrumentation file via a ModuleRunner.\n *\n * Called once during Pages Router server startup (`configureServer`). It:\n * 1. Loads the instrumentation module via `runner.import()`.\n * 2. Calls the `register()` function if exported.\n * 3. Stores the `onRequestError()` handler on `globalThis` so it is visible\n * to all Vite environment module graphs (SSR and the host process share\n * the same Node.js `globalThis`).\n *\n * **App Router** does not use this function. For App Router, `register()` is\n * emitted as a top-level `await` inside the generated RSC entry module so it\n * runs in the same Worker/environment as request handling.\n *\n * @param runner - A ModuleRunner created via `createDirectRunner()`. Must be\n * the same long-lived runner used for middleware and SSR so the module graph\n * is shared. Safe with all Vite plugin combinations, including\n * `@cloudflare/vite-plugin`, because it never touches the hot channel.\n * @param instrumentationPath - Absolute path to the instrumentation file\n */\nexport async function runInstrumentation(\n runner: ModuleImporter,\n instrumentationPath: string,\n): Promise<void> {\n try {\n const mod = await runner.import(instrumentationPath) as Record<string, unknown>;\n\n // Call register() if exported\n if (typeof mod.register === \"function\") {\n await mod.register();\n }\n\n // Store onRequestError handler on globalThis so environments can reach the\n // same handler.\n if (typeof mod.onRequestError === \"function\") {\n\t\t\tglobalThis.__VINEXT_onRequestErrorHandler__ = mod.onRequestError as OnRequestErrorHandler;\n }\n } catch (err) {\n console.error(\n \"[vinext] Failed to load instrumentation:\",\n err instanceof Error ? err.message : String(err),\n );\n }\n}\n\n/**\n * Report a request error via the instrumentation handler.\n *\n * No-op if no onRequestError handler is registered.\n *\n * Reads the handler from globalThis so this function works correctly regardless\n * of which environment it is called from.\n */\nexport async function reportRequestError(\n error: Error,\n request: { path: string; method: string; headers: Record<string, string> },\n context: OnRequestErrorContext,\n): Promise<void> {\n const handler = getOnRequestErrorHandler();\n\tif (!handler) return;\n\n try {\n await handler(error, request, context);\n } catch (reportErr) {\n console.error(\n \"[vinext] onRequestError handler threw:\",\n reportErr instanceof Error ? reportErr.message : String(reportErr),\n );\n }\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Shared middleware matching code generator.
|
|
3
3
|
*
|
|
4
|
-
* Both the App Router RSC entry (app-
|
|
4
|
+
* Both the App Router RSC entry (entries/app-rsc-entry.ts) and the Pages Router
|
|
5
5
|
* production entry (index.ts) need middleware matching logic inlined as
|
|
6
6
|
* generated JavaScript strings. This module provides a single source of
|
|
7
7
|
* truth to prevent the implementations from diverging.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Shared middleware matching code generator.
|
|
3
3
|
*
|
|
4
|
-
* Both the App Router RSC entry (app-
|
|
4
|
+
* Both the App Router RSC entry (entries/app-rsc-entry.ts) and the Pages Router
|
|
5
5
|
* production entry (index.ts) need middleware matching logic inlined as
|
|
6
6
|
* generated JavaScript strings. This module provides a single source of
|
|
7
7
|
* truth to prevent the implementations from diverging.
|