vinext 0.0.46 → 0.0.48
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 +8 -6
- package/dist/build/layout-classification.js +3 -1
- package/dist/build/layout-classification.js.map +1 -1
- package/dist/build/prerender.d.ts +2 -1
- package/dist/build/prerender.js +80 -24
- package/dist/build/prerender.js.map +1 -1
- package/dist/build/report.d.ts +9 -5
- package/dist/build/report.js +17 -7
- package/dist/build/report.js.map +1 -1
- package/dist/build/route-classification-injector.d.ts +35 -0
- package/dist/build/route-classification-injector.js +61 -0
- package/dist/build/route-classification-injector.js.map +1 -0
- package/dist/build/route-classification-manifest.d.ts +1 -1
- package/dist/build/run-prerender.d.ts +5 -0
- package/dist/build/run-prerender.js +4 -1
- package/dist/build/run-prerender.js.map +1 -1
- package/dist/build/server-manifest.js +2 -7
- package/dist/build/server-manifest.js.map +1 -1
- package/dist/build/standalone.js +3 -5
- package/dist/build/standalone.js.map +1 -1
- package/dist/build/static-export.d.ts +1 -1
- package/dist/check.js +45 -29
- package/dist/check.js.map +1 -1
- package/dist/cli-args.d.ts +33 -0
- package/dist/cli-args.js +121 -0
- package/dist/cli-args.js.map +1 -0
- package/dist/cli.js +11 -20
- package/dist/cli.js.map +1 -1
- package/dist/cloudflare/kv-cache-handler.js +29 -9
- package/dist/cloudflare/kv-cache-handler.js.map +1 -1
- package/dist/config/config-matchers.js +46 -37
- package/dist/config/config-matchers.js.map +1 -1
- package/dist/config/next-config.d.ts +4 -2
- package/dist/config/next-config.js +3 -0
- package/dist/config/next-config.js.map +1 -1
- package/dist/deploy.d.ts +18 -2
- package/dist/deploy.js +47 -4
- package/dist/deploy.js.map +1 -1
- package/dist/entries/app-rsc-entry.d.ts +4 -3
- package/dist/entries/app-rsc-entry.js +379 -858
- package/dist/entries/app-rsc-entry.js.map +1 -1
- package/dist/entries/app-rsc-manifest.d.ts +1 -1
- package/dist/entries/app-rsc-manifest.js +6 -1
- package/dist/entries/app-rsc-manifest.js.map +1 -1
- package/dist/entries/pages-client-entry.js +3 -2
- package/dist/entries/pages-client-entry.js.map +1 -1
- package/dist/entries/pages-server-entry.js +19 -61
- package/dist/entries/pages-server-entry.js.map +1 -1
- package/dist/entries/runtime-entry-module.d.ts +12 -3
- package/dist/entries/runtime-entry-module.js +15 -4
- package/dist/entries/runtime-entry-module.js.map +1 -1
- package/dist/index.js +40 -58
- package/dist/index.js.map +1 -1
- package/dist/plugins/fonts.js +54 -32
- package/dist/plugins/fonts.js.map +1 -1
- package/dist/plugins/og-assets.js +15 -16
- package/dist/plugins/og-assets.js.map +1 -1
- package/dist/plugins/rsc-client-shim-excludes.d.ts +2 -1
- package/dist/plugins/rsc-client-shim-excludes.js +11 -1
- package/dist/plugins/rsc-client-shim-excludes.js.map +1 -1
- package/dist/routing/app-route-graph.d.ts +195 -0
- package/dist/routing/app-route-graph.js +1022 -0
- package/dist/routing/app-route-graph.js.map +1 -0
- package/dist/routing/app-router.d.ts +14 -88
- package/dist/routing/app-router.js +21 -712
- package/dist/routing/app-router.js.map +1 -1
- package/dist/routing/file-matcher.d.ts +3 -1
- package/dist/routing/file-matcher.js +6 -1
- package/dist/routing/file-matcher.js.map +1 -1
- package/dist/routing/pages-router.js +10 -19
- package/dist/routing/pages-router.js.map +1 -1
- package/dist/routing/route-matching.d.ts +28 -0
- package/dist/routing/route-matching.js +44 -0
- package/dist/routing/route-matching.js.map +1 -0
- package/dist/routing/route-pattern.js +4 -1
- package/dist/routing/route-pattern.js.map +1 -1
- package/dist/routing/route-trie.d.ts +8 -0
- package/dist/routing/route-trie.js +12 -1
- package/dist/routing/route-trie.js.map +1 -1
- package/dist/routing/route-validation.js +3 -4
- package/dist/routing/route-validation.js.map +1 -1
- package/dist/routing/utils.d.ts +8 -1
- package/dist/routing/utils.js +25 -2
- package/dist/routing/utils.js.map +1 -1
- package/dist/server/app-browser-entry.js +145 -294
- package/dist/server/app-browser-entry.js.map +1 -1
- package/dist/server/app-browser-error.d.ts +3 -4
- package/dist/server/app-browser-error.js +8 -4
- package/dist/server/app-browser-error.js.map +1 -1
- package/dist/server/app-browser-navigation-controller.d.ts +75 -0
- package/dist/server/app-browser-navigation-controller.js +290 -0
- package/dist/server/app-browser-navigation-controller.js.map +1 -0
- package/dist/server/app-browser-state.d.ts +33 -15
- package/dist/server/app-browser-state.js +52 -59
- package/dist/server/app-browser-state.js.map +1 -1
- package/dist/server/app-browser-visible-commit.d.ts +68 -0
- package/dist/server/app-browser-visible-commit.js +182 -0
- package/dist/server/app-browser-visible-commit.js.map +1 -0
- package/dist/server/app-client-reference-preloader.d.ts +15 -0
- package/dist/server/app-client-reference-preloader.js +46 -0
- package/dist/server/app-client-reference-preloader.js.map +1 -0
- package/dist/server/app-elements-wire.d.ts +130 -0
- package/dist/server/app-elements-wire.js +205 -0
- package/dist/server/app-elements-wire.js.map +1 -0
- package/dist/server/app-elements.d.ts +2 -84
- package/dist/server/app-elements.js +4 -107
- package/dist/server/app-elements.js.map +1 -1
- package/dist/server/app-fallback-renderer.d.ts +57 -0
- package/dist/server/app-fallback-renderer.js +79 -0
- package/dist/server/app-fallback-renderer.js.map +1 -0
- package/dist/server/app-hook-warning-suppression.d.ts +7 -0
- package/dist/server/app-hook-warning-suppression.js +12 -0
- package/dist/server/app-hook-warning-suppression.js.map +1 -0
- package/dist/server/app-middleware.d.ts +2 -1
- package/dist/server/app-middleware.js +34 -11
- package/dist/server/app-middleware.js.map +1 -1
- package/dist/server/app-mounted-slots-header.d.ts +17 -0
- package/dist/server/app-mounted-slots-header.js +21 -0
- package/dist/server/app-mounted-slots-header.js.map +1 -0
- package/dist/server/app-page-boundary-render.d.ts +3 -3
- package/dist/server/app-page-boundary-render.js +8 -5
- package/dist/server/app-page-boundary-render.js.map +1 -1
- package/dist/server/app-page-boundary.js +2 -1
- package/dist/server/app-page-boundary.js.map +1 -1
- package/dist/server/app-page-cache.d.ts +19 -4
- package/dist/server/app-page-cache.js +60 -22
- package/dist/server/app-page-cache.js.map +1 -1
- package/dist/server/app-page-dispatch.d.ts +9 -5
- package/dist/server/app-page-dispatch.js +41 -17
- package/dist/server/app-page-dispatch.js.map +1 -1
- package/dist/server/app-page-element-builder.d.ts +61 -0
- package/dist/server/app-page-element-builder.js +142 -0
- package/dist/server/app-page-element-builder.js.map +1 -0
- package/dist/server/app-page-execution.d.ts +23 -5
- package/dist/server/app-page-execution.js +39 -24
- package/dist/server/app-page-execution.js.map +1 -1
- package/dist/server/app-page-head.js +2 -1
- package/dist/server/app-page-head.js.map +1 -1
- package/dist/server/app-page-method.js +2 -5
- package/dist/server/app-page-method.js.map +1 -1
- package/dist/server/app-page-params.d.ts +2 -1
- package/dist/server/app-page-params.js +3 -3
- package/dist/server/app-page-params.js.map +1 -1
- package/dist/server/app-page-probe.d.ts +1 -1
- package/dist/server/app-page-probe.js +5 -1
- package/dist/server/app-page-probe.js.map +1 -1
- package/dist/server/app-page-render.d.ts +6 -2
- package/dist/server/app-page-render.js +118 -30
- package/dist/server/app-page-render.js.map +1 -1
- package/dist/server/app-page-request.d.ts +19 -5
- package/dist/server/app-page-request.js +49 -7
- package/dist/server/app-page-request.js.map +1 -1
- package/dist/server/app-page-response.d.ts +1 -0
- package/dist/server/app-page-response.js +6 -9
- package/dist/server/app-page-response.js.map +1 -1
- package/dist/server/app-page-route-wiring.d.ts +20 -4
- package/dist/server/app-page-route-wiring.js +15 -12
- package/dist/server/app-page-route-wiring.js.map +1 -1
- package/dist/server/app-page-stream.d.ts +7 -0
- package/dist/server/app-page-stream.js +9 -2
- package/dist/server/app-page-stream.js.map +1 -1
- package/dist/server/app-post-middleware-context.d.ts +16 -0
- package/dist/server/app-post-middleware-context.js +28 -0
- package/dist/server/app-post-middleware-context.js.map +1 -0
- package/dist/server/app-prerender-endpoints.js +3 -2
- package/dist/server/app-prerender-endpoints.js.map +1 -1
- package/dist/server/app-request-context.d.ts +22 -0
- package/dist/server/app-request-context.js +30 -0
- package/dist/server/app-request-context.js.map +1 -0
- package/dist/server/app-route-handler-cache.d.ts +1 -0
- package/dist/server/app-route-handler-cache.js +7 -2
- package/dist/server/app-route-handler-cache.js.map +1 -1
- package/dist/server/app-route-handler-dispatch.d.ts +1 -0
- package/dist/server/app-route-handler-dispatch.js +8 -5
- package/dist/server/app-route-handler-dispatch.js.map +1 -1
- package/dist/server/app-route-handler-execution.d.ts +2 -1
- package/dist/server/app-route-handler-execution.js +2 -2
- package/dist/server/app-route-handler-execution.js.map +1 -1
- package/dist/server/app-route-handler-policy.js +13 -13
- package/dist/server/app-route-handler-policy.js.map +1 -1
- package/dist/server/app-route-handler-response.d.ts +4 -2
- package/dist/server/app-route-handler-response.js +9 -7
- package/dist/server/app-route-handler-response.js.map +1 -1
- package/dist/server/app-route-handler-runtime.d.ts +9 -1
- package/dist/server/app-route-handler-runtime.js +11 -1
- package/dist/server/app-route-handler-runtime.js.map +1 -1
- package/dist/server/app-router-entry.js +9 -4
- package/dist/server/app-router-entry.js.map +1 -1
- package/dist/server/app-rsc-cache-busting.d.ts +34 -0
- package/dist/server/app-rsc-cache-busting.js +137 -0
- package/dist/server/app-rsc-cache-busting.js.map +1 -0
- package/dist/server/app-rsc-error-handler.d.ts +21 -0
- package/dist/server/app-rsc-error-handler.js +30 -0
- package/dist/server/app-rsc-error-handler.js.map +1 -0
- package/dist/server/app-rsc-handler.d.ts +117 -0
- package/dist/server/app-rsc-handler.js +271 -0
- package/dist/server/app-rsc-handler.js.map +1 -0
- package/dist/server/app-rsc-request-normalization.d.ts +42 -0
- package/dist/server/app-rsc-request-normalization.js +67 -0
- package/dist/server/app-rsc-request-normalization.js.map +1 -0
- package/dist/server/app-rsc-response-finalizer.d.ts +30 -0
- package/dist/server/app-rsc-response-finalizer.js +38 -0
- package/dist/server/app-rsc-response-finalizer.js.map +1 -0
- package/dist/server/app-rsc-route-matching.js +8 -4
- package/dist/server/app-rsc-route-matching.js.map +1 -1
- package/dist/server/app-segment-config.d.ts +33 -0
- package/dist/server/app-segment-config.js +90 -0
- package/dist/server/app-segment-config.js.map +1 -0
- package/dist/server/app-server-action-execution.d.ts +2 -0
- package/dist/server/app-server-action-execution.js +45 -51
- package/dist/server/app-server-action-execution.js.map +1 -1
- package/dist/server/app-ssr-entry.js +21 -20
- package/dist/server/app-ssr-entry.js.map +1 -1
- package/dist/server/artifact-compatibility.d.ts +44 -0
- package/dist/server/artifact-compatibility.js +82 -0
- package/dist/server/artifact-compatibility.js.map +1 -0
- package/dist/server/cache-control.d.ts +24 -0
- package/dist/server/cache-control.js +33 -0
- package/dist/server/cache-control.js.map +1 -0
- package/dist/server/cache-proof.d.ts +200 -0
- package/dist/server/cache-proof.js +342 -0
- package/dist/server/cache-proof.js.map +1 -0
- package/dist/server/dev-error-overlay-store.d.ts +23 -0
- package/dist/server/dev-error-overlay-store.js +67 -0
- package/dist/server/dev-error-overlay-store.js.map +1 -0
- package/dist/server/dev-error-overlay.d.ts +15 -0
- package/dist/server/dev-error-overlay.js +548 -0
- package/dist/server/dev-error-overlay.js.map +1 -0
- package/dist/server/dev-origin-check.js +8 -4
- package/dist/server/dev-origin-check.js.map +1 -1
- package/dist/server/dev-server.js +1 -6
- package/dist/server/dev-server.js.map +1 -1
- package/dist/server/http-error-responses.d.ts +67 -0
- package/dist/server/http-error-responses.js +77 -0
- package/dist/server/http-error-responses.js.map +1 -0
- package/dist/server/image-optimization.js +2 -1
- package/dist/server/image-optimization.js.map +1 -1
- package/dist/server/instrumentation-runtime.d.ts +44 -0
- package/dist/server/instrumentation-runtime.js +29 -0
- package/dist/server/instrumentation-runtime.js.map +1 -0
- package/dist/server/isr-cache.d.ts +2 -7
- package/dist/server/isr-cache.js +7 -10
- package/dist/server/isr-cache.js.map +1 -1
- package/dist/server/metadata-route-response.js +6 -5
- package/dist/server/metadata-route-response.js.map +1 -1
- package/dist/server/metadata-routes.d.ts +1 -0
- package/dist/server/metadata-routes.js +6 -0
- package/dist/server/metadata-routes.js.map +1 -1
- package/dist/server/middleware-matcher.js +2 -2
- package/dist/server/middleware-matcher.js.map +1 -1
- package/dist/server/middleware-response-headers.js +21 -0
- package/dist/server/middleware-response-headers.js.map +1 -1
- package/dist/server/middleware-runtime.js +3 -3
- package/dist/server/middleware-runtime.js.map +1 -1
- package/dist/server/navigation-trace.d.ts +33 -0
- package/dist/server/navigation-trace.js +35 -0
- package/dist/server/navigation-trace.js.map +1 -0
- package/dist/server/next-error-digest.d.ts +44 -0
- package/dist/server/next-error-digest.js +40 -0
- package/dist/server/next-error-digest.js.map +1 -0
- package/dist/server/pages-api-route.js +2 -1
- package/dist/server/pages-api-route.js.map +1 -1
- package/dist/server/pages-node-compat.js +4 -16
- package/dist/server/pages-node-compat.js.map +1 -1
- package/dist/server/pages-page-data.d.ts +2 -1
- package/dist/server/pages-page-data.js +6 -5
- package/dist/server/pages-page-data.js.map +1 -1
- package/dist/server/pages-page-response.d.ts +3 -8
- package/dist/server/pages-page-response.js +46 -15
- package/dist/server/pages-page-response.js.map +1 -1
- package/dist/server/prod-server.d.ts +6 -0
- package/dist/server/prod-server.js +28 -21
- package/dist/server/prod-server.js.map +1 -1
- package/dist/server/request-pipeline.d.ts +42 -1
- package/dist/server/request-pipeline.js +97 -17
- package/dist/server/request-pipeline.js.map +1 -1
- package/dist/server/rsc-stream-hints.d.ts +3 -1
- package/dist/server/rsc-stream-hints.js +4 -1
- package/dist/server/rsc-stream-hints.js.map +1 -1
- package/dist/server/seed-cache.js +19 -8
- package/dist/server/seed-cache.js.map +1 -1
- package/dist/shims/cache-runtime.d.ts +2 -2
- package/dist/shims/cache-runtime.js +31 -17
- package/dist/shims/cache-runtime.js.map +1 -1
- package/dist/shims/cache.d.ts +15 -3
- package/dist/shims/cache.js +45 -20
- package/dist/shims/cache.js.map +1 -1
- package/dist/shims/error-boundary.d.ts +17 -1
- package/dist/shims/error-boundary.js +31 -1
- package/dist/shims/error-boundary.js.map +1 -1
- package/dist/shims/fetch-cache.d.ts +4 -1
- package/dist/shims/fetch-cache.js +57 -16
- package/dist/shims/fetch-cache.js.map +1 -1
- package/dist/shims/head-state.js +2 -3
- package/dist/shims/head-state.js.map +1 -1
- package/dist/shims/headers.js +4 -44
- package/dist/shims/headers.js.map +1 -1
- package/dist/shims/i18n-state.js +2 -3
- package/dist/shims/i18n-state.js.map +1 -1
- package/dist/shims/image.js +93 -5
- package/dist/shims/image.js.map +1 -1
- package/dist/shims/internal/als-registry.d.ts +15 -0
- package/dist/shims/internal/als-registry.js +55 -0
- package/dist/shims/internal/als-registry.js.map +1 -0
- package/dist/shims/internal/cookie-serialize.d.ts +46 -0
- package/dist/shims/internal/cookie-serialize.js +51 -0
- package/dist/shims/internal/cookie-serialize.js.map +1 -0
- package/dist/shims/link.js +31 -26
- package/dist/shims/link.js.map +1 -1
- package/dist/shims/metadata.d.ts +26 -1
- package/dist/shims/metadata.js +94 -4
- package/dist/shims/metadata.js.map +1 -1
- package/dist/shims/navigation-state.js +2 -3
- package/dist/shims/navigation-state.js.map +1 -1
- package/dist/shims/navigation.d.ts +2 -7
- package/dist/shims/navigation.js +44 -36
- package/dist/shims/navigation.js.map +1 -1
- package/dist/shims/request-context.js +2 -4
- package/dist/shims/request-context.js.map +1 -1
- package/dist/shims/request-state-types.d.ts +1 -1
- package/dist/shims/router-state.js +2 -3
- package/dist/shims/router-state.js.map +1 -1
- package/dist/shims/router.js +2 -2
- package/dist/shims/router.js.map +1 -1
- package/dist/shims/server.js +5 -30
- package/dist/shims/server.js.map +1 -1
- package/dist/shims/slot.d.ts +1 -1
- package/dist/shims/slot.js +5 -4
- package/dist/shims/slot.js.map +1 -1
- package/dist/shims/thenable-params.d.ts +5 -2
- package/dist/shims/thenable-params.js +26 -6
- package/dist/shims/thenable-params.js.map +1 -1
- package/dist/shims/unified-request-context.d.ts +1 -1
- package/dist/shims/unified-request-context.js +3 -14
- package/dist/shims/unified-request-context.js.map +1 -1
- package/dist/shims/use-merged-ref.d.ts +7 -0
- package/dist/shims/use-merged-ref.js +40 -0
- package/dist/shims/use-merged-ref.js.map +1 -0
- package/dist/utils/base-path.d.ts +7 -1
- package/dist/utils/base-path.js +12 -1
- package/dist/utils/base-path.js.map +1 -1
- package/dist/utils/cache-control-metadata.d.ts +6 -0
- package/dist/utils/cache-control-metadata.js +16 -0
- package/dist/utils/cache-control-metadata.js.map +1 -0
- package/dist/utils/safe-json-file.d.ts +18 -0
- package/dist/utils/safe-json-file.js +25 -0
- package/dist/utils/safe-json-file.js.map +1 -0
- package/dist/utils/text-stream.d.ts +29 -0
- package/dist/utils/text-stream.js +66 -0
- package/dist/utils/text-stream.js.map +1 -0
- package/package.json +5 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pages-server-entry.js","names":[],"sources":["../../src/entries/pages-server-entry.ts"],"sourcesContent":["/**\n * Pages Router server entry generator.\n *\n * Generates the virtual SSR server entry module (`virtual:vinext-server-entry`).\n * This is the entry point for `vite build --ssr`. It handles SSR, API routes,\n * middleware, ISR, and i18n for the Pages Router.\n *\n * Extracted from index.ts.\n */\nimport { resolveEntryPath } from \"./runtime-entry-module.js\";\nimport { pagesRouter, apiRouter, type Route } from \"../routing/pages-router.js\";\nimport { createValidFileMatcher } from \"../routing/file-matcher.js\";\nimport { type ResolvedNextConfig } from \"../config/next-config.js\";\nimport { isProxyFile } from \"../server/middleware.js\";\nimport { findFileWithExts } from \"./pages-entry-helpers.js\";\n\nconst _requestContextShimPath = resolveEntryPath(\"../shims/request-context.js\", import.meta.url);\nconst _middlewareRuntimePath = resolveEntryPath(\"../server/middleware-runtime.js\", import.meta.url);\nconst _routeTriePath = resolveEntryPath(\"../routing/route-trie.js\", import.meta.url);\nconst _pagesI18nPath = resolveEntryPath(\"../server/pages-i18n.js\", import.meta.url);\nconst _pagesPageResponsePath = resolveEntryPath(\n \"../server/pages-page-response.js\",\n import.meta.url,\n);\nconst _pagesPageDataPath = resolveEntryPath(\"../server/pages-page-data.js\", import.meta.url);\nconst _pagesNodeCompatPath = resolveEntryPath(\"../server/pages-node-compat.js\", import.meta.url);\nconst _pagesApiRoutePath = resolveEntryPath(\"../server/pages-api-route.js\", import.meta.url);\nconst _isrCachePath = resolveEntryPath(\"../server/isr-cache.js\", import.meta.url);\nconst _cspPath = resolveEntryPath(\"../server/csp.js\", import.meta.url);\n\n/**\n * Generate the virtual SSR server entry module.\n * This is the entry point for `vite build --ssr`.\n */\nexport async function generateServerEntry(\n pagesDir: string,\n nextConfig: ResolvedNextConfig,\n fileMatcher: ReturnType<typeof createValidFileMatcher>,\n middlewarePath: string | null,\n instrumentationPath: string | null,\n): Promise<string> {\n const pageRoutes = await pagesRouter(pagesDir, nextConfig?.pageExtensions, fileMatcher);\n const apiRoutes = await apiRouter(pagesDir, nextConfig?.pageExtensions, fileMatcher);\n\n // Generate import statements using absolute paths since virtual\n // modules don't have a real file location for relative resolution.\n const pageImports = pageRoutes.map((r: Route, i: number) => {\n const absPath = r.filePath.replace(/\\\\/g, \"/\");\n return `import * as page_${i} from ${JSON.stringify(absPath)};`;\n });\n\n const apiImports = apiRoutes.map((r: Route, i: number) => {\n const absPath = r.filePath.replace(/\\\\/g, \"/\");\n return `import * as api_${i} from ${JSON.stringify(absPath)};`;\n });\n\n // Build the route table — include filePath for SSR manifest lookup\n const pageRouteEntries = pageRoutes.map((r: Route, i: number) => {\n const absPath = r.filePath.replace(/\\\\/g, \"/\");\n return ` { pattern: ${JSON.stringify(r.pattern)}, patternParts: ${JSON.stringify(r.patternParts)}, isDynamic: ${r.isDynamic}, params: ${JSON.stringify(r.params)}, module: page_${i}, filePath: ${JSON.stringify(absPath)} }`;\n });\n\n const apiRouteEntries = apiRoutes.map(\n (r: Route, i: number) =>\n ` { pattern: ${JSON.stringify(r.pattern)}, patternParts: ${JSON.stringify(r.patternParts)}, isDynamic: ${r.isDynamic}, params: ${JSON.stringify(r.params)}, module: api_${i} }`,\n );\n\n // Check for _app and _document\n const appFilePath = findFileWithExts(pagesDir, \"_app\", fileMatcher);\n const docFilePath = findFileWithExts(pagesDir, \"_document\", fileMatcher);\n const appImportCode =\n appFilePath !== null\n ? `import { default as AppComponent } from ${JSON.stringify(appFilePath.replace(/\\\\/g, \"/\"))};`\n : `const AppComponent = null;`;\n\n const docImportCode =\n docFilePath !== null\n ? `import { default as DocumentComponent } from ${JSON.stringify(docFilePath.replace(/\\\\/g, \"/\"))};`\n : `const DocumentComponent = null;`;\n\n // Serialize i18n config for embedding in the server entry\n const i18nConfigJson = nextConfig?.i18n\n ? JSON.stringify({\n locales: nextConfig.i18n.locales,\n defaultLocale: nextConfig.i18n.defaultLocale,\n localeDetection: nextConfig.i18n.localeDetection,\n domains: nextConfig.i18n.domains,\n })\n : \"null\";\n\n // Embed the resolved build ID at build time\n const buildIdJson = JSON.stringify(nextConfig?.buildId ?? null);\n\n // Serialize the full resolved config for the production server.\n // This embeds redirects, rewrites, headers, basePath, trailingSlash\n // so prod-server.ts can apply them without loading next.config.js at runtime.\n const vinextConfigJson = JSON.stringify({\n basePath: nextConfig?.basePath ?? \"\",\n trailingSlash: nextConfig?.trailingSlash ?? false,\n redirects: nextConfig?.redirects ?? [],\n rewrites: nextConfig?.rewrites ?? { beforeFiles: [], afterFiles: [], fallback: [] },\n headers: nextConfig?.headers ?? [],\n i18n: nextConfig?.i18n ?? null,\n images: {\n deviceSizes: nextConfig?.images?.deviceSizes,\n imageSizes: nextConfig?.images?.imageSizes,\n dangerouslyAllowSVG: nextConfig?.images?.dangerouslyAllowSVG,\n contentDispositionType: nextConfig?.images?.contentDispositionType,\n contentSecurityPolicy: nextConfig?.images?.contentSecurityPolicy,\n },\n });\n\n // Generate instrumentation code if instrumentation.ts exists.\n // For production (Cloudflare Workers), instrumentation.ts is bundled into the\n // Worker and register() is called as a top-level await at module evaluation time —\n // before any request is handled. This mirrors App Router behavior (generateRscEntry)\n // and matches Next.js semantics: register() runs once on startup in the process\n // that handles requests.\n //\n // The onRequestError handler is stored on globalThis so it is visible across\n // all code within the Worker (same global scope).\n const instrumentationImportCode = instrumentationPath\n ? `import * as _instrumentation from ${JSON.stringify(instrumentationPath.replace(/\\\\/g, \"/\"))};`\n : \"\";\n\n const instrumentationInitCode = instrumentationPath\n ? `// Run instrumentation register() once at module evaluation time — before any\n// requests are handled. Matches Next.js semantics: register() is called once\n// on startup in the process that handles requests.\nif (typeof _instrumentation.register === \"function\") {\n await _instrumentation.register();\n}\n// Store the onRequestError handler on globalThis so it is visible to all\n// code within the Worker (same global scope).\nif (typeof _instrumentation.onRequestError === \"function\") {\n globalThis.__VINEXT_onRequestErrorHandler__ = _instrumentation.onRequestError;\n}`\n : \"\";\n\n // Generate middleware code if middleware.ts exists\n const middlewareImportCode = middlewarePath\n ? `import * as middlewareModule from ${JSON.stringify(middlewarePath.replace(/\\\\/g, \"/\"))};`\n : \"\";\n\n // The matcher config is read from the middleware module at request time.\n // The generated entry only wires the user module into the shared runtime\n // helper; matcher, execution, waitUntil, and result shaping live in normal\n // TypeScript modules so dev/prod paths cannot drift.\n const middlewareExportCode = middlewarePath\n ? `\nexport async function runMiddleware(request, ctx) {\n return __runGeneratedMiddleware({\n basePath: vinextConfig.basePath,\n ctx,\n i18nConfig,\n isProxy: ${JSON.stringify(isProxyFile(middlewarePath))},\n module: middlewareModule,\n request,\n });\n}\n`\n : `\nexport async function runMiddleware() { return { continue: true }; }\n`;\n\n // The server entry is a self-contained module that uses Web-standard APIs\n // (Request/Response, renderToReadableStream) so it runs on Cloudflare Workers.\n return `\nimport React from \"react\";\nimport { renderToReadableStream } from \"react-dom/server.edge\";\nimport { resetSSRHead, getSSRHeadHTML } from \"next/head\";\nimport { flushPreloads } from \"next/dynamic\";\nimport { setSSRContext, wrapWithRouterContext } from \"next/router\";\nimport { _runWithCacheState } from \"next/cache\";\nimport { runWithPrivateCache } from \"vinext/cache-runtime\";\nimport { ensureFetchPatch, runWithFetchCache } from \"vinext/fetch-cache\";\nimport { runWithRequestContext as _runWithUnifiedCtx, createRequestContext as _createUnifiedCtx } from \"vinext/unified-request-context\";\nimport \"vinext/router-state\";\nimport { runWithServerInsertedHTMLState } from \"vinext/navigation-state\";\nimport { runWithHeadState } from \"vinext/head-state\";\nimport \"vinext/i18n-state\";\nimport { setI18nContext } from \"vinext/i18n-context\";\nimport { createNonceAttribute as __createNonceAttribute, safeJsonStringify } from \"vinext/html\";\nimport { getSSRFontLinks as _getSSRFontLinks, getSSRFontStyles as _getSSRFontStylesGoogle, getSSRFontPreloads as _getSSRFontPreloadsGoogle } from \"next/font/google\";\nimport { getSSRFontStyles as _getSSRFontStylesLocal, getSSRFontPreloads as _getSSRFontPreloadsLocal } from \"next/font/local\";\nimport { sanitizeDestination as sanitizeDestinationLocal } from ${JSON.stringify(resolveEntryPath(\"../config/config-matchers.js\", import.meta.url))};\nimport { runWithExecutionContext as _runWithExecutionContext, getRequestExecutionContext as _getRequestExecutionContext } from ${JSON.stringify(_requestContextShimPath)};\nimport { runGeneratedMiddleware as __runGeneratedMiddleware } from ${JSON.stringify(_middlewareRuntimePath)};\nimport { buildRouteTrie as _buildRouteTrie, trieMatch as _trieMatch } from ${JSON.stringify(_routeTriePath)};\nimport { reportRequestError as _reportRequestError } from \"vinext/instrumentation\";\nimport { resolvePagesI18nRequest } from ${JSON.stringify(_pagesI18nPath)};\nimport { createPagesReqRes as __createPagesReqRes } from ${JSON.stringify(_pagesNodeCompatPath)};\nimport { handlePagesApiRoute as __handlePagesApiRoute } from ${JSON.stringify(_pagesApiRoutePath)};\nimport {\n isrGet as __sharedIsrGet,\n isrSet as __sharedIsrSet,\n isrCacheKey as __sharedIsrCacheKey,\n triggerBackgroundRegeneration as __sharedTriggerBackgroundRegeneration,\n} from ${JSON.stringify(_isrCachePath)};\nimport { getScriptNonceFromHeaderSources as __getScriptNonceFromHeaderSources } from ${JSON.stringify(_cspPath)};\nimport { resolvePagesPageData as __resolvePagesPageData } from ${JSON.stringify(_pagesPageDataPath)};\nimport { renderPagesPageResponse as __renderPagesPageResponse } from ${JSON.stringify(_pagesPageResponsePath)};\n${instrumentationImportCode}\n${middlewareImportCode}\n\n${instrumentationInitCode}\n\n// i18n config (embedded at build time)\nconst i18nConfig = ${i18nConfigJson};\n\n// Build ID (embedded at build time)\nconst buildId = ${buildIdJson};\n\n// Full resolved config for production server (embedded at build time)\nexport const vinextConfig = ${vinextConfigJson};\n\nfunction isrGet(key) {\n return __sharedIsrGet(key);\n}\nfunction isrSet(key, data, revalidateSeconds, tags) {\n return __sharedIsrSet(key, data, revalidateSeconds, tags);\n}\nfunction triggerBackgroundRegeneration(key, renderFn, errorContext) {\n return __sharedTriggerBackgroundRegeneration(key, renderFn, errorContext);\n}\nfunction isrCacheKey(router, pathname) {\n return __sharedIsrCacheKey(router, pathname, buildId || undefined);\n}\n\nasync function renderToStringAsync(element) {\n const stream = await renderToReadableStream(element);\n await stream.allReady;\n return new Response(stream).text();\n}\n\nasync function renderIsrPassToStringAsync(element) {\n // The cache-fill render is a second render pass for the same request.\n // Reset render-scoped state so it cannot leak from the streamed response\n // render or affect async work that is still draining from that stream.\n // Keep request identity state (pathname/query/locale/executionContext)\n // intact: this second pass still belongs to the same request.\n return await runWithServerInsertedHTMLState(() =>\n runWithHeadState(() =>\n _runWithCacheState(() =>\n runWithPrivateCache(() => runWithFetchCache(async () => renderToStringAsync(element))),\n ),\n ),\n );\n}\n\n${pageImports.join(\"\\n\")}\n${apiImports.join(\"\\n\")}\n\n${appImportCode}\n${docImportCode}\n\nexport const pageRoutes = [\n${pageRouteEntries.join(\",\\n\")}\n];\nconst _pageRouteTrie = _buildRouteTrie(pageRoutes);\n\nconst apiRoutes = [\n${apiRouteEntries.join(\",\\n\")}\n];\nconst _apiRouteTrie = _buildRouteTrie(apiRoutes);\n\nfunction matchRoute(url, routes) {\n const pathname = url.split(\"?\")[0];\n let normalizedUrl = pathname === \"/\" ? \"/\" : pathname.replace(/\\\\/$/, \"\");\n // NOTE: Do NOT decodeURIComponent here. The pathname is already decoded at\n // the entry point. Decoding again would create a double-decode vector.\n const urlParts = normalizedUrl.split(\"/\").filter(Boolean);\n const trie = routes === pageRoutes ? _pageRouteTrie : _apiRouteTrie;\n return _trieMatch(trie, urlParts);\n}\n\nfunction parseQuery(url) {\n const qs = url.split(\"?\")[1];\n if (!qs) return {};\n const p = new URLSearchParams(qs);\n const q = {};\n for (const [k, v] of p) {\n if (k in q) {\n q[k] = Array.isArray(q[k]) ? q[k].concat(v) : [q[k], v];\n } else {\n q[k] = v;\n }\n }\n return q;\n}\n\nfunction patternToNextFormat(pattern) {\n return pattern\n .replace(/:([\\\\w]+)\\\\*/g, \"[[...$1]]\")\n .replace(/:([\\\\w]+)\\\\+/g, \"[...$1]\")\n .replace(/:([\\\\w]+)/g, \"[$1]\");\n}\n\nfunction collectAssetTags(manifest, moduleIds, scriptNonce) {\n // Fall back to embedded manifest (set by vinext:cloudflare-build for Workers)\n const m = (manifest && Object.keys(manifest).length > 0)\n ? manifest\n : (typeof globalThis !== \"undefined\" && globalThis.__VINEXT_SSR_MANIFEST__) || null;\n const tags = [];\n const seen = new Set();\n const nonceAttr = __createNonceAttribute(scriptNonce);\n\n // Load the set of lazy chunk filenames (only reachable via dynamic imports).\n // These should NOT get <link rel=\"modulepreload\"> or <script type=\"module\">\n // tags — they are fetched on demand when the dynamic import() executes (e.g.\n // chunks behind React.lazy() or next/dynamic boundaries).\n var lazyChunks = (typeof globalThis !== \"undefined\" && globalThis.__VINEXT_LAZY_CHUNKS__) || null;\n var lazySet = lazyChunks && lazyChunks.length > 0 ? new Set(lazyChunks) : null;\n\n // Inject the client entry script if embedded by vinext:cloudflare-build\n if (typeof globalThis !== \"undefined\" && globalThis.__VINEXT_CLIENT_ENTRY__) {\n const entry = globalThis.__VINEXT_CLIENT_ENTRY__;\n seen.add(entry);\n tags.push('<link rel=\"modulepreload\"' + nonceAttr + ' href=\"/' + entry + '\" />');\n tags.push('<script type=\"module\"' + nonceAttr + ' src=\"/' + entry + '\" crossorigin></script>');\n }\n if (m) {\n // Always inject shared chunks (framework, vinext runtime, entry) and\n // page-specific chunks. The manifest maps module file paths to their\n // associated JS/CSS assets.\n //\n // For page-specific injection, the module IDs may be absolute paths\n // while the manifest uses relative paths. Try both the original ID\n // and a suffix match to find the correct manifest entry.\n var allFiles = [];\n\n if (moduleIds && moduleIds.length > 0) {\n // Collect assets for the requested page modules\n for (var mi = 0; mi < moduleIds.length; mi++) {\n var id = moduleIds[mi];\n var files = m[id];\n if (!files) {\n // Absolute path didn't match — try matching by suffix.\n // Manifest keys are relative (e.g. \"pages/about.tsx\") while\n // moduleIds may be absolute (e.g. \"/home/.../pages/about.tsx\").\n for (var mk in m) {\n if (id.endsWith(\"/\" + mk) || id === mk) {\n files = m[mk];\n break;\n }\n }\n }\n if (files) {\n for (var fi = 0; fi < files.length; fi++) allFiles.push(files[fi]);\n }\n }\n\n // Also inject shared chunks that every page needs: framework,\n // vinext runtime, and the entry bootstrap. These are identified\n // by scanning all manifest values for chunk filenames containing\n // known prefixes.\n for (var key in m) {\n var vals = m[key];\n if (!vals) continue;\n for (var vi = 0; vi < vals.length; vi++) {\n var file = vals[vi];\n var basename = file.split(\"/\").pop() || \"\";\n if (\n basename.startsWith(\"framework-\") ||\n basename.startsWith(\"vinext-\") ||\n basename.includes(\"vinext-client-entry\") ||\n basename.includes(\"vinext-app-browser-entry\")\n ) {\n allFiles.push(file);\n }\n }\n }\n } else {\n // No specific modules — include all assets from manifest\n for (var akey in m) {\n var avals = m[akey];\n if (avals) {\n for (var ai = 0; ai < avals.length; ai++) allFiles.push(avals[ai]);\n }\n }\n }\n\n for (var ti = 0; ti < allFiles.length; ti++) {\n var tf = allFiles[ti];\n // Normalize: Vite's SSR manifest values include a leading '/'\n // (from base path), but we prepend '/' ourselves when building\n // href/src attributes. Strip any existing leading slash to avoid\n // producing protocol-relative URLs like \"//assets/chunk.js\".\n // This also ensures consistent keys for the seen-set dedup and\n // lazySet.has() checks (which use values without leading slash).\n if (tf.charAt(0) === '/') tf = tf.slice(1);\n if (seen.has(tf)) continue;\n seen.add(tf);\n if (tf.endsWith(\".css\")) {\n tags.push('<link rel=\"stylesheet\"' + nonceAttr + ' href=\"/' + tf + '\" />');\n } else if (tf.endsWith(\".js\")) {\n // Skip lazy chunks — they are behind dynamic import() boundaries\n // (React.lazy, next/dynamic) and should only be fetched on demand.\n if (lazySet && lazySet.has(tf)) continue;\n tags.push('<link rel=\"modulepreload\"' + nonceAttr + ' href=\"/' + tf + '\" />');\n tags.push('<script type=\"module\"' + nonceAttr + ' src=\"/' + tf + '\" crossorigin></script>');\n }\n }\n }\n return tags.join(\"\\\\n \");\n}\n\n// i18n helpers\nfunction extractLocale(url) {\n if (!i18nConfig) return { locale: undefined, url, hadPrefix: false };\n const pathname = url.split(\"?\")[0];\n const parts = pathname.split(\"/\").filter(Boolean);\n const query = url.includes(\"?\") ? url.slice(url.indexOf(\"?\")) : \"\";\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 return { locale: i18nConfig.defaultLocale, url, hadPrefix: false };\n}\n\nfunction detectLocaleFromHeaders(headers) {\n if (!i18nConfig) return null;\n const acceptLang = headers.get(\"accept-language\");\n if (!acceptLang) return null;\n const langs = acceptLang.split(\",\").map(function(part) {\n const pieces = part.trim().split(\";\");\n const q = pieces[1] ? parseFloat(pieces[1].replace(\"q=\", \"\")) : 1;\n return { lang: pieces[0].trim().toLowerCase(), q: q };\n }).sort(function(a, b) { return b.q - a.q; });\n for (let k = 0; k < langs.length; k++) {\n const lang = langs[k].lang;\n for (let j = 0; j < i18nConfig.locales.length; j++) {\n if (i18nConfig.locales[j].toLowerCase() === lang) return i18nConfig.locales[j];\n }\n const prefix = lang.split(\"-\")[0];\n for (let j = 0; j < i18nConfig.locales.length; j++) {\n const loc = i18nConfig.locales[j].toLowerCase();\n if (loc === prefix || loc.startsWith(prefix + \"-\")) return i18nConfig.locales[j];\n }\n }\n return null;\n}\n\nfunction parseCookieLocaleFromHeader(cookieHeader) {\n if (!i18nConfig || !cookieHeader) return null;\n const match = cookieHeader.match(/(?:^|;\\\\s*)NEXT_LOCALE=([^;]*)/);\n if (!match) return null;\n var value;\n try { value = decodeURIComponent(match[1].trim()); } catch (e) { return null; }\n if (i18nConfig.locales.indexOf(value) !== -1) return value;\n return null;\n}\n\nexport async function renderPage(request, url, manifest, ctx, middlewareHeaders) {\n if (ctx) return _runWithExecutionContext(ctx, () => _renderPage(request, url, manifest, middlewareHeaders));\n return _renderPage(request, url, manifest, middlewareHeaders);\n}\n\nasync function _renderPage(request, url, manifest, middlewareHeaders) {\n const localeInfo = i18nConfig\n ? resolvePagesI18nRequest(\n url,\n i18nConfig,\n request.headers,\n new URL(request.url).hostname,\n vinextConfig.basePath,\n vinextConfig.trailingSlash,\n )\n : { locale: undefined, url, hadPrefix: false, domainLocale: undefined, redirectUrl: undefined };\n const locale = localeInfo.locale;\n const routeUrl = localeInfo.url;\n const currentDefaultLocale = i18nConfig\n ? (localeInfo.domainLocale ? localeInfo.domainLocale.defaultLocale : i18nConfig.defaultLocale)\n : undefined;\n const domainLocales = i18nConfig ? i18nConfig.domains : undefined;\n\n if (localeInfo.redirectUrl) {\n return new Response(null, { status: 307, headers: { Location: localeInfo.redirectUrl } });\n }\n\n const match = matchRoute(routeUrl, pageRoutes);\n if (!match) {\n return new Response(\"<!DOCTYPE html><html><body><h1>404 - Page not found</h1></body></html>\",\n { status: 404, headers: { \"Content-Type\": \"text/html\" } });\n }\n\n const { route, params } = match;\n const __uCtx = _createUnifiedCtx({\n executionContext: _getRequestExecutionContext(),\n });\n return _runWithUnifiedCtx(__uCtx, async () => {\n ensureFetchPatch();\n try {\n const routePattern = patternToNextFormat(route.pattern);\n if (typeof setSSRContext === \"function\") {\n setSSRContext({\n pathname: routePattern,\n query: { ...params, ...parseQuery(routeUrl) },\n asPath: routeUrl,\n locale: locale,\n locales: i18nConfig ? i18nConfig.locales : undefined,\n defaultLocale: currentDefaultLocale,\n domainLocales: domainLocales,\n });\n }\n\n if (i18nConfig) {\n setI18nContext({\n locale: locale,\n locales: i18nConfig.locales,\n defaultLocale: currentDefaultLocale,\n domainLocales: domainLocales,\n hostname: new URL(request.url).hostname,\n });\n }\n\n const pageModule = route.module;\n const PageComponent = pageModule.default;\n if (!PageComponent) {\n return new Response(\"Page has no default export\", { status: 500 });\n }\n const scriptNonce = __getScriptNonceFromHeaderSources(request.headers, middlewareHeaders);\n // Build font Link header early so it's available for ISR cached responses too.\n // Font preloads are module-level state populated at import time and persist across requests.\n var _fontLinkHeader = \"\";\n var _allFp = [];\n try {\n var _fpGoogle = typeof _getSSRFontPreloadsGoogle === \"function\" ? _getSSRFontPreloadsGoogle() : [];\n var _fpLocal = typeof _getSSRFontPreloadsLocal === \"function\" ? _getSSRFontPreloadsLocal() : [];\n _allFp = _fpGoogle.concat(_fpLocal);\n if (_allFp.length > 0) {\n _fontLinkHeader = _allFp.map(function(p) { return \"<\" + p.href + \">; rel=preload; as=font; type=\" + p.type + \"; crossorigin\"; }).join(\", \");\n }\n } catch (e) { /* font preloads not available */ }\n const query = parseQuery(routeUrl);\n const pageDataResult = await __resolvePagesPageData({\n applyRequestContexts() {\n if (typeof setSSRContext === \"function\") {\n setSSRContext({\n pathname: routePattern,\n query: { ...params, ...query },\n asPath: routeUrl,\n locale: locale,\n locales: i18nConfig ? i18nConfig.locales : undefined,\n defaultLocale: currentDefaultLocale,\n domainLocales: domainLocales,\n });\n }\n if (i18nConfig) {\n setI18nContext({\n locale: locale,\n locales: i18nConfig.locales,\n defaultLocale: currentDefaultLocale,\n domainLocales: domainLocales,\n hostname: new URL(request.url).hostname,\n });\n }\n },\n buildId,\n createGsspReqRes() {\n return __createPagesReqRes({ body: undefined, query, request, url: routeUrl });\n },\n createPageElement(currentPageProps) {\n var currentElement = AppComponent\n ? React.createElement(AppComponent, { Component: PageComponent, pageProps: currentPageProps })\n : React.createElement(PageComponent, currentPageProps);\n return wrapWithRouterContext(currentElement);\n },\n fontLinkHeader: _fontLinkHeader,\n i18n: {\n locale: locale,\n locales: i18nConfig ? i18nConfig.locales : undefined,\n defaultLocale: currentDefaultLocale,\n domainLocales: domainLocales,\n },\n isrCacheKey,\n isrGet,\n isrSet,\n pageModule,\n params,\n query,\n renderIsrPassToStringAsync,\n route: {\n isDynamic: route.isDynamic,\n },\n routePattern,\n routeUrl,\n runInFreshUnifiedContext(callback) {\n var revalCtx = _createUnifiedCtx({\n executionContext: _getRequestExecutionContext(),\n });\n return _runWithUnifiedCtx(revalCtx, async () => {\n ensureFetchPatch();\n return callback();\n });\n },\n safeJsonStringify,\n sanitizeDestination: sanitizeDestinationLocal,\n scriptNonce,\n triggerBackgroundRegeneration,\n });\n if (pageDataResult.kind === \"response\") {\n return pageDataResult.response;\n }\n let pageProps = pageDataResult.pageProps;\n var gsspRes = pageDataResult.gsspRes;\n let isrRevalidateSeconds = pageDataResult.isrRevalidateSeconds;\n\n const pageModuleIds = route.filePath ? [route.filePath] : [];\n const assetTags = collectAssetTags(manifest, pageModuleIds, scriptNonce);\n\n return __renderPagesPageResponse({\n assetTags,\n buildId,\n clearSsrContext() {\n if (typeof setSSRContext === \"function\") setSSRContext(null);\n },\n createPageElement(currentPageProps) {\n var currentElement;\n if (AppComponent) {\n currentElement = React.createElement(AppComponent, { Component: PageComponent, pageProps: currentPageProps });\n } else {\n currentElement = React.createElement(PageComponent, currentPageProps);\n }\n return wrapWithRouterContext(currentElement);\n },\n DocumentComponent,\n flushPreloads: typeof flushPreloads === \"function\" ? flushPreloads : undefined,\n fontLinkHeader: _fontLinkHeader,\n fontPreloads: _allFp,\n getFontLinks() {\n try {\n return typeof _getSSRFontLinks === \"function\" ? _getSSRFontLinks() : [];\n } catch (e) {\n return [];\n }\n },\n getFontStyles() {\n try {\n var allFontStyles = [];\n if (typeof _getSSRFontStylesGoogle === \"function\") allFontStyles.push(..._getSSRFontStylesGoogle());\n if (typeof _getSSRFontStylesLocal === \"function\") allFontStyles.push(..._getSSRFontStylesLocal());\n return allFontStyles;\n } catch (e) {\n return [];\n }\n },\n getSSRHeadHTML: typeof getSSRHeadHTML === \"function\" ? getSSRHeadHTML : undefined,\n gsspRes,\n isrCacheKey,\n isrRevalidateSeconds,\n isrSet,\n i18n: {\n locale: locale,\n locales: i18nConfig ? i18nConfig.locales : undefined,\n defaultLocale: currentDefaultLocale,\n domainLocales: domainLocales,\n },\n pageProps,\n params,\n renderDocumentToString(element) {\n return renderToStringAsync(element);\n },\n renderIsrPassToStringAsync,\n renderToReadableStream(element) {\n return renderToReadableStream(element);\n },\n resetSSRHead: typeof resetSSRHead === \"function\" ? resetSSRHead : undefined,\n routePattern,\n routeUrl,\n safeJsonStringify,\n scriptNonce,\n });\n } catch (e) {\n console.error(\"[vinext] SSR error:\", e);\n _reportRequestError(\n e instanceof Error ? e : new Error(String(e)),\n { path: url, method: request.method, headers: Object.fromEntries(request.headers.entries()) },\n { routerKind: \"Pages Router\", routePath: route.pattern, routeType: \"render\" },\n ).catch(() => { /* ignore reporting errors */ });\n return new Response(\"Internal Server Error\", { status: 500 });\n }\n });\n}\n\nexport async function handleApiRoute(request, url) {\n const match = matchRoute(url, apiRoutes);\n return __handlePagesApiRoute({\n match,\n request,\n url,\n reportRequestError(error, routePattern) {\n console.error(\"[vinext] API error:\", error);\n void _reportRequestError(\n error,\n { path: url, method: request.method, headers: Object.fromEntries(request.headers.entries()) },\n { routerKind: \"Pages Router\", routePath: routePattern, routeType: \"route\" },\n );\n },\n });\n}\n\n${middlewareExportCode}\n`;\n}\n"],"mappings":";;;;;;;;;;;;;;AAgBA,MAAM,0BAA0B,iBAAiB,+BAA+B,OAAO,KAAK,IAAI;AAChG,MAAM,yBAAyB,iBAAiB,mCAAmC,OAAO,KAAK,IAAI;AACnG,MAAM,iBAAiB,iBAAiB,4BAA4B,OAAO,KAAK,IAAI;AACpF,MAAM,iBAAiB,iBAAiB,2BAA2B,OAAO,KAAK,IAAI;AACnF,MAAM,yBAAyB,iBAC7B,oCACA,OAAO,KAAK,IACb;AACD,MAAM,qBAAqB,iBAAiB,gCAAgC,OAAO,KAAK,IA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;;;;;;;;;;;;;;;;;;EAyb5B,qBAAqB"}
|
|
1
|
+
{"version":3,"file":"pages-server-entry.js","names":[],"sources":["../../src/entries/pages-server-entry.ts"],"sourcesContent":["/**\n * Pages Router server entry generator.\n *\n * Generates the virtual SSR server entry module (`virtual:vinext-server-entry`).\n * This is the entry point for `vite build --ssr`. It handles SSR, API routes,\n * middleware, ISR, and i18n for the Pages Router.\n *\n * Extracted from index.ts.\n */\nimport { resolveEntryPath, normalizePathSeparators } from \"./runtime-entry-module.js\";\nimport { pagesRouter, apiRouter, type Route } from \"../routing/pages-router.js\";\nimport { createValidFileMatcher } from \"../routing/file-matcher.js\";\nimport { type ResolvedNextConfig } from \"../config/next-config.js\";\nimport { isProxyFile } from \"../server/middleware.js\";\nimport { findFileWithExts } from \"./pages-entry-helpers.js\";\n\nconst _requestContextShimPath = resolveEntryPath(\"../shims/request-context.js\", import.meta.url);\nconst _middlewareRuntimePath = resolveEntryPath(\"../server/middleware-runtime.js\", import.meta.url);\nconst _routeTriePath = resolveEntryPath(\"../routing/route-trie.js\", import.meta.url);\nconst _pagesI18nPath = resolveEntryPath(\"../server/pages-i18n.js\", import.meta.url);\nconst _pagesPageResponsePath = resolveEntryPath(\n \"../server/pages-page-response.js\",\n import.meta.url,\n);\nconst _pagesPageDataPath = resolveEntryPath(\"../server/pages-page-data.js\", import.meta.url);\nconst _pagesNodeCompatPath = resolveEntryPath(\"../server/pages-node-compat.js\", import.meta.url);\nconst _pagesApiRoutePath = resolveEntryPath(\"../server/pages-api-route.js\", import.meta.url);\nconst _isrCachePath = resolveEntryPath(\"../server/isr-cache.js\", import.meta.url);\nconst _cspPath = resolveEntryPath(\"../server/csp.js\", import.meta.url);\n\n/**\n * Generate the virtual SSR server entry module.\n * This is the entry point for `vite build --ssr`.\n */\nexport async function generateServerEntry(\n pagesDir: string,\n nextConfig: ResolvedNextConfig,\n fileMatcher: ReturnType<typeof createValidFileMatcher>,\n middlewarePath: string | null,\n instrumentationPath: string | null,\n): Promise<string> {\n const pageRoutes = await pagesRouter(pagesDir, nextConfig?.pageExtensions, fileMatcher);\n const apiRoutes = await apiRouter(pagesDir, nextConfig?.pageExtensions, fileMatcher);\n\n // Generate import statements using absolute paths since virtual\n // modules don't have a real file location for relative resolution.\n const pageImports = pageRoutes.map((r: Route, i: number) => {\n const absPath = normalizePathSeparators(r.filePath);\n return `import * as page_${i} from ${JSON.stringify(absPath)};`;\n });\n\n const apiImports = apiRoutes.map((r: Route, i: number) => {\n const absPath = normalizePathSeparators(r.filePath);\n return `import * as api_${i} from ${JSON.stringify(absPath)};`;\n });\n\n // Build the route table — include filePath for SSR manifest lookup\n const pageRouteEntries = pageRoutes.map((r: Route, i: number) => {\n const absPath = normalizePathSeparators(r.filePath);\n return ` { pattern: ${JSON.stringify(r.pattern)}, patternParts: ${JSON.stringify(r.patternParts)}, isDynamic: ${r.isDynamic}, params: ${JSON.stringify(r.params)}, module: page_${i}, filePath: ${JSON.stringify(absPath)} }`;\n });\n\n const apiRouteEntries = apiRoutes.map(\n (r: Route, i: number) =>\n ` { pattern: ${JSON.stringify(r.pattern)}, patternParts: ${JSON.stringify(r.patternParts)}, isDynamic: ${r.isDynamic}, params: ${JSON.stringify(r.params)}, module: api_${i} }`,\n );\n\n // Check for _app and _document\n const appFilePath = findFileWithExts(pagesDir, \"_app\", fileMatcher);\n const docFilePath = findFileWithExts(pagesDir, \"_document\", fileMatcher);\n const appImportCode =\n appFilePath !== null\n ? `import { default as AppComponent } from ${JSON.stringify(normalizePathSeparators(appFilePath))};`\n : `const AppComponent = null;`;\n\n const docImportCode =\n docFilePath !== null\n ? `import { default as DocumentComponent } from ${JSON.stringify(normalizePathSeparators(docFilePath))};`\n : `const DocumentComponent = null;`;\n\n // Serialize i18n config for embedding in the server entry\n const i18nConfigJson = nextConfig?.i18n\n ? JSON.stringify({\n locales: nextConfig.i18n.locales,\n defaultLocale: nextConfig.i18n.defaultLocale,\n localeDetection: nextConfig.i18n.localeDetection,\n domains: nextConfig.i18n.domains,\n })\n : \"null\";\n\n // Embed the resolved build ID at build time\n const buildIdJson = JSON.stringify(nextConfig?.buildId ?? null);\n\n // Serialize the full resolved config for the production server.\n // This embeds redirects, rewrites, headers, basePath, trailingSlash\n // so prod-server.ts can apply them without loading next.config.js at runtime.\n const vinextConfigJson = JSON.stringify({\n basePath: nextConfig?.basePath ?? \"\",\n trailingSlash: nextConfig?.trailingSlash ?? false,\n redirects: nextConfig?.redirects ?? [],\n rewrites: nextConfig?.rewrites ?? { beforeFiles: [], afterFiles: [], fallback: [] },\n headers: nextConfig?.headers ?? [],\n expireTime: nextConfig?.expireTime,\n i18n: nextConfig?.i18n ?? null,\n images: {\n deviceSizes: nextConfig?.images?.deviceSizes,\n imageSizes: nextConfig?.images?.imageSizes,\n dangerouslyAllowSVG: nextConfig?.images?.dangerouslyAllowSVG,\n contentDispositionType: nextConfig?.images?.contentDispositionType,\n contentSecurityPolicy: nextConfig?.images?.contentSecurityPolicy,\n },\n });\n\n // Generate instrumentation code if instrumentation.ts exists.\n // For production (Cloudflare Workers), instrumentation.ts is bundled into the\n // Worker and register() is called as a top-level await at module evaluation time —\n // before any request is handled. This mirrors App Router behavior (generateRscEntry)\n // and matches Next.js semantics: register() runs once on startup in the process\n // that handles requests.\n //\n // The onRequestError handler is stored on globalThis so it is visible across\n // all code within the Worker (same global scope).\n const instrumentationImportCode = instrumentationPath\n ? `import * as _instrumentation from ${JSON.stringify(normalizePathSeparators(instrumentationPath))};`\n : \"\";\n\n const instrumentationInitCode = instrumentationPath\n ? `// Run instrumentation register() once at module evaluation time — before any\n// requests are handled. Matches Next.js semantics: register() is called once\n// on startup in the process that handles requests.\nif (typeof _instrumentation.register === \"function\") {\n await _instrumentation.register();\n}\n// Store the onRequestError handler on globalThis so it is visible to all\n// code within the Worker (same global scope).\nif (typeof _instrumentation.onRequestError === \"function\") {\n globalThis.__VINEXT_onRequestErrorHandler__ = _instrumentation.onRequestError;\n}`\n : \"\";\n\n // Generate middleware code if middleware.ts exists\n const middlewareImportCode = middlewarePath\n ? `import * as middlewareModule from ${JSON.stringify(normalizePathSeparators(middlewarePath))};`\n : \"\";\n\n // The matcher config is read from the middleware module at request time.\n // The generated entry only wires the user module into the shared runtime\n // helper; matcher, execution, waitUntil, and result shaping live in normal\n // TypeScript modules so dev/prod paths cannot drift.\n const middlewareExportCode = middlewarePath\n ? `\nexport async function runMiddleware(request, ctx) {\n return __runGeneratedMiddleware({\n basePath: vinextConfig.basePath,\n ctx,\n i18nConfig,\n isProxy: ${JSON.stringify(isProxyFile(middlewarePath))},\n module: middlewareModule,\n request,\n });\n}\n`\n : `\nexport async function runMiddleware() { return { continue: true }; }\n`;\n\n // The server entry is a self-contained module that uses Web-standard APIs\n // (Request/Response, renderToReadableStream) so it runs on Cloudflare Workers.\n return `\nimport React from \"react\";\nimport { renderToReadableStream } from \"react-dom/server.edge\";\nimport { resetSSRHead, getSSRHeadHTML } from \"next/head\";\nimport { flushPreloads } from \"next/dynamic\";\nimport { setSSRContext, wrapWithRouterContext } from \"next/router\";\nimport { _runWithCacheState } from \"next/cache\";\nimport { runWithPrivateCache } from \"vinext/cache-runtime\";\nimport { ensureFetchPatch, runWithFetchCache } from \"vinext/fetch-cache\";\nimport { runWithRequestContext as _runWithUnifiedCtx, createRequestContext as _createUnifiedCtx } from \"vinext/unified-request-context\";\nimport \"vinext/router-state\";\nimport { runWithServerInsertedHTMLState } from \"vinext/navigation-state\";\nimport { runWithHeadState } from \"vinext/head-state\";\nimport \"vinext/i18n-state\";\nimport { setI18nContext } from \"vinext/i18n-context\";\nimport { createNonceAttribute as __createNonceAttribute, safeJsonStringify } from \"vinext/html\";\nimport { getSSRFontLinks as _getSSRFontLinks, getSSRFontStyles as _getSSRFontStylesGoogle, getSSRFontPreloads as _getSSRFontPreloadsGoogle } from \"next/font/google\";\nimport { getSSRFontStyles as _getSSRFontStylesLocal, getSSRFontPreloads as _getSSRFontPreloadsLocal } from \"next/font/local\";\nimport { sanitizeDestination as sanitizeDestinationLocal } from ${JSON.stringify(resolveEntryPath(\"../config/config-matchers.js\", import.meta.url))};\nimport { runWithExecutionContext as _runWithExecutionContext, getRequestExecutionContext as _getRequestExecutionContext } from ${JSON.stringify(_requestContextShimPath)};\nimport { runGeneratedMiddleware as __runGeneratedMiddleware } from ${JSON.stringify(_middlewareRuntimePath)};\nimport { buildRouteTrie as _buildRouteTrie, trieMatch as _trieMatch } from ${JSON.stringify(_routeTriePath)};\nimport { reportRequestError as _reportRequestError } from \"vinext/instrumentation\";\nimport { resolvePagesI18nRequest } from ${JSON.stringify(_pagesI18nPath)};\nimport { createPagesReqRes as __createPagesReqRes } from ${JSON.stringify(_pagesNodeCompatPath)};\nimport { handlePagesApiRoute as __handlePagesApiRoute } from ${JSON.stringify(_pagesApiRoutePath)};\nimport {\n isrGet as __sharedIsrGet,\n isrSet as __sharedIsrSet,\n isrCacheKey as __sharedIsrCacheKey,\n triggerBackgroundRegeneration as __sharedTriggerBackgroundRegeneration,\n} from ${JSON.stringify(_isrCachePath)};\nimport { getScriptNonceFromHeaderSources as __getScriptNonceFromHeaderSources } from ${JSON.stringify(_cspPath)};\nimport { resolvePagesPageData as __resolvePagesPageData } from ${JSON.stringify(_pagesPageDataPath)};\nimport { renderPagesPageResponse as __renderPagesPageResponse } from ${JSON.stringify(_pagesPageResponsePath)};\n${instrumentationImportCode}\n${middlewareImportCode}\n\n${instrumentationInitCode}\n\n// i18n config (embedded at build time)\nconst i18nConfig = ${i18nConfigJson};\n\n// Build ID (embedded at build time)\nconst buildId = ${buildIdJson};\n\n// Full resolved config for production server (embedded at build time)\nexport const vinextConfig = ${vinextConfigJson};\n\nfunction isrGet(key) {\n return __sharedIsrGet(key);\n}\nfunction isrSet(key, data, revalidateSeconds, tags, expireSeconds) {\n return __sharedIsrSet(key, data, revalidateSeconds, tags, expireSeconds);\n}\nfunction triggerBackgroundRegeneration(key, renderFn, errorContext) {\n return __sharedTriggerBackgroundRegeneration(key, renderFn, errorContext);\n}\nfunction isrCacheKey(router, pathname) {\n return __sharedIsrCacheKey(router, pathname, buildId || undefined);\n}\n\nasync function renderToStringAsync(element) {\n const stream = await renderToReadableStream(element);\n await stream.allReady;\n return new Response(stream).text();\n}\n\nasync function renderIsrPassToStringAsync(element) {\n // The cache-fill render is a second render pass for the same request.\n // Reset render-scoped state so it cannot leak from the streamed response\n // render or affect async work that is still draining from that stream.\n // Keep request identity state (pathname/query/locale/executionContext)\n // intact: this second pass still belongs to the same request.\n return await runWithServerInsertedHTMLState(() =>\n runWithHeadState(() =>\n _runWithCacheState(() =>\n runWithPrivateCache(() => runWithFetchCache(async () => renderToStringAsync(element))),\n ),\n ),\n );\n}\n\n${pageImports.join(\"\\n\")}\n${apiImports.join(\"\\n\")}\n\n${appImportCode}\n${docImportCode}\n\nexport const pageRoutes = [\n${pageRouteEntries.join(\",\\n\")}\n];\nconst _pageRouteTrie = _buildRouteTrie(pageRoutes);\n\nconst apiRoutes = [\n${apiRouteEntries.join(\",\\n\")}\n];\nconst _apiRouteTrie = _buildRouteTrie(apiRoutes);\n\nfunction matchRoute(url, routes) {\n const pathname = url.split(\"?\")[0];\n let normalizedUrl = pathname === \"/\" ? \"/\" : pathname.replace(/\\\\/$/, \"\");\n // NOTE: Do NOT decodeURIComponent here. The pathname is already decoded at\n // the entry point. Decoding again would create a double-decode vector.\n const urlParts = normalizedUrl.split(\"/\").filter(Boolean);\n const trie = routes === pageRoutes ? _pageRouteTrie : _apiRouteTrie;\n return _trieMatch(trie, urlParts);\n}\n\nfunction parseQuery(url) {\n const qs = url.split(\"?\")[1];\n if (!qs) return {};\n const p = new URLSearchParams(qs);\n const q = {};\n for (const [k, v] of p) {\n if (k in q) {\n q[k] = Array.isArray(q[k]) ? q[k].concat(v) : [q[k], v];\n } else {\n q[k] = v;\n }\n }\n return q;\n}\n\nfunction patternToNextFormat(pattern) {\n // Match any non-/ param name. Non-greedy with lookahead prevents\n // the +/* suffix being consumed into the param name when the name\n // itself contains + or * internally (e.g. :c++lang → [c++lang]).\n return pattern\n .replace(/:([^\\\\/]+?)\\\\+(?=\\\\/|$)/g, \"[...$1]\")\n .replace(/:([^\\\\/]+?)\\\\*(?=\\\\/|$)/g, \"[[...$1]]\")\n .replace(/:([^\\\\/]+?)(?=\\\\/|$)/g, \"[$1]\");\n}\n\nfunction collectAssetTags(manifest, moduleIds, scriptNonce) {\n // Fall back to embedded manifest (set by vinext:cloudflare-build for Workers)\n const m = (manifest && Object.keys(manifest).length > 0)\n ? manifest\n : (typeof globalThis !== \"undefined\" && globalThis.__VINEXT_SSR_MANIFEST__) || null;\n const tags = [];\n const seen = new Set();\n const nonceAttr = __createNonceAttribute(scriptNonce);\n\n // Load the set of lazy chunk filenames (only reachable via dynamic imports).\n // These should NOT get <link rel=\"modulepreload\"> or <script type=\"module\">\n // tags — they are fetched on demand when the dynamic import() executes (e.g.\n // chunks behind React.lazy() or next/dynamic boundaries).\n var lazyChunks = (typeof globalThis !== \"undefined\" && globalThis.__VINEXT_LAZY_CHUNKS__) || null;\n var lazySet = lazyChunks && lazyChunks.length > 0 ? new Set(lazyChunks) : null;\n\n // Inject the client entry script if embedded by vinext:cloudflare-build\n if (typeof globalThis !== \"undefined\" && globalThis.__VINEXT_CLIENT_ENTRY__) {\n const entry = globalThis.__VINEXT_CLIENT_ENTRY__;\n seen.add(entry);\n tags.push('<link rel=\"modulepreload\"' + nonceAttr + ' href=\"/' + entry + '\" />');\n tags.push('<script type=\"module\"' + nonceAttr + ' src=\"/' + entry + '\" crossorigin></script>');\n }\n if (m) {\n // Always inject shared chunks (framework, vinext runtime, entry) and\n // page-specific chunks. The manifest maps module file paths to their\n // associated JS/CSS assets.\n //\n // For page-specific injection, the module IDs may be absolute paths\n // while the manifest uses relative paths. Try both the original ID\n // and a suffix match to find the correct manifest entry.\n var allFiles = [];\n\n if (moduleIds && moduleIds.length > 0) {\n // Collect assets for the requested page modules\n for (var mi = 0; mi < moduleIds.length; mi++) {\n var id = moduleIds[mi];\n var files = m[id];\n if (!files) {\n // Absolute path didn't match — try matching by suffix.\n // Manifest keys are relative (e.g. \"pages/about.tsx\") while\n // moduleIds may be absolute (e.g. \"/home/.../pages/about.tsx\").\n for (var mk in m) {\n if (id.endsWith(\"/\" + mk) || id === mk) {\n files = m[mk];\n break;\n }\n }\n }\n if (files) {\n for (var fi = 0; fi < files.length; fi++) allFiles.push(files[fi]);\n }\n }\n\n // Also inject shared chunks that every page needs: framework,\n // vinext runtime, and the entry bootstrap. These are identified\n // by scanning all manifest values for chunk filenames containing\n // known prefixes.\n for (var key in m) {\n var vals = m[key];\n if (!vals) continue;\n for (var vi = 0; vi < vals.length; vi++) {\n var file = vals[vi];\n var basename = file.split(\"/\").pop() || \"\";\n if (\n basename.startsWith(\"framework-\") ||\n basename.startsWith(\"vinext-\") ||\n basename.includes(\"vinext-client-entry\") ||\n basename.includes(\"vinext-app-browser-entry\")\n ) {\n allFiles.push(file);\n }\n }\n }\n } else {\n // No specific modules — include all assets from manifest\n for (var akey in m) {\n var avals = m[akey];\n if (avals) {\n for (var ai = 0; ai < avals.length; ai++) allFiles.push(avals[ai]);\n }\n }\n }\n\n for (var ti = 0; ti < allFiles.length; ti++) {\n var tf = allFiles[ti];\n // Normalize: Vite's SSR manifest values include a leading '/'\n // (from base path), but we prepend '/' ourselves when building\n // href/src attributes. Strip any existing leading slash to avoid\n // producing protocol-relative URLs like \"//assets/chunk.js\".\n // This also ensures consistent keys for the seen-set dedup and\n // lazySet.has() checks (which use values without leading slash).\n if (tf.charAt(0) === '/') tf = tf.slice(1);\n if (seen.has(tf)) continue;\n seen.add(tf);\n if (tf.endsWith(\".css\")) {\n tags.push('<link rel=\"stylesheet\"' + nonceAttr + ' href=\"/' + tf + '\" />');\n } else if (tf.endsWith(\".js\")) {\n // Skip lazy chunks — they are behind dynamic import() boundaries\n // (React.lazy, next/dynamic) and should only be fetched on demand.\n if (lazySet && lazySet.has(tf)) continue;\n tags.push('<link rel=\"modulepreload\"' + nonceAttr + ' href=\"/' + tf + '\" />');\n tags.push('<script type=\"module\"' + nonceAttr + ' src=\"/' + tf + '\" crossorigin></script>');\n }\n }\n }\n return tags.join(\"\\\\n \");\n}\n\nexport async function renderPage(request, url, manifest, ctx, middlewareHeaders) {\n if (ctx) return _runWithExecutionContext(ctx, () => _renderPage(request, url, manifest, middlewareHeaders));\n return _renderPage(request, url, manifest, middlewareHeaders);\n}\n\nasync function _renderPage(request, url, manifest, middlewareHeaders) {\n const localeInfo = i18nConfig\n ? resolvePagesI18nRequest(\n url,\n i18nConfig,\n request.headers,\n new URL(request.url).hostname,\n vinextConfig.basePath,\n vinextConfig.trailingSlash,\n )\n : { locale: undefined, url, hadPrefix: false, domainLocale: undefined, redirectUrl: undefined };\n const locale = localeInfo.locale;\n const routeUrl = localeInfo.url;\n const currentDefaultLocale = i18nConfig\n ? (localeInfo.domainLocale ? localeInfo.domainLocale.defaultLocale : i18nConfig.defaultLocale)\n : undefined;\n const domainLocales = i18nConfig ? i18nConfig.domains : undefined;\n\n if (localeInfo.redirectUrl) {\n return new Response(null, { status: 307, headers: { Location: localeInfo.redirectUrl } });\n }\n\n const match = matchRoute(routeUrl, pageRoutes);\n if (!match) {\n return new Response(\"<!DOCTYPE html><html><body><h1>404 - Page not found</h1></body></html>\",\n { status: 404, headers: { \"Content-Type\": \"text/html\" } });\n }\n\n const { route, params } = match;\n const __uCtx = _createUnifiedCtx({\n executionContext: _getRequestExecutionContext(),\n });\n return _runWithUnifiedCtx(__uCtx, async () => {\n ensureFetchPatch();\n try {\n const routePattern = patternToNextFormat(route.pattern);\n if (typeof setSSRContext === \"function\") {\n setSSRContext({\n pathname: routePattern,\n query: { ...params, ...parseQuery(routeUrl) },\n asPath: routeUrl,\n locale: locale,\n locales: i18nConfig ? i18nConfig.locales : undefined,\n defaultLocale: currentDefaultLocale,\n domainLocales: domainLocales,\n });\n }\n\n if (i18nConfig) {\n setI18nContext({\n locale: locale,\n locales: i18nConfig.locales,\n defaultLocale: currentDefaultLocale,\n domainLocales: domainLocales,\n hostname: new URL(request.url).hostname,\n });\n }\n\n const pageModule = route.module;\n const PageComponent = pageModule.default;\n if (!PageComponent) {\n return new Response(\"Page has no default export\", { status: 500 });\n }\n const scriptNonce = __getScriptNonceFromHeaderSources(request.headers, middlewareHeaders);\n // Build font Link header early so it's available for ISR cached responses too.\n // Font preloads are module-level state populated at import time and persist across requests.\n var _fontLinkHeader = \"\";\n var _allFp = [];\n try {\n var _fpGoogle = typeof _getSSRFontPreloadsGoogle === \"function\" ? _getSSRFontPreloadsGoogle() : [];\n var _fpLocal = typeof _getSSRFontPreloadsLocal === \"function\" ? _getSSRFontPreloadsLocal() : [];\n _allFp = _fpGoogle.concat(_fpLocal);\n if (_allFp.length > 0) {\n _fontLinkHeader = _allFp.map(function(p) { return \"<\" + p.href + \">; rel=preload; as=font; type=\" + p.type + \"; crossorigin\"; }).join(\", \");\n }\n } catch (e) { /* font preloads not available */ }\n const query = parseQuery(routeUrl);\n const pageDataResult = await __resolvePagesPageData({\n applyRequestContexts() {\n if (typeof setSSRContext === \"function\") {\n setSSRContext({\n pathname: routePattern,\n query: { ...params, ...query },\n asPath: routeUrl,\n locale: locale,\n locales: i18nConfig ? i18nConfig.locales : undefined,\n defaultLocale: currentDefaultLocale,\n domainLocales: domainLocales,\n });\n }\n if (i18nConfig) {\n setI18nContext({\n locale: locale,\n locales: i18nConfig.locales,\n defaultLocale: currentDefaultLocale,\n domainLocales: domainLocales,\n hostname: new URL(request.url).hostname,\n });\n }\n },\n buildId,\n createGsspReqRes() {\n return __createPagesReqRes({ body: undefined, query, request, url: routeUrl });\n },\n createPageElement(currentPageProps) {\n var currentElement = AppComponent\n ? React.createElement(AppComponent, { Component: PageComponent, pageProps: currentPageProps })\n : React.createElement(PageComponent, currentPageProps);\n return wrapWithRouterContext(currentElement);\n },\n fontLinkHeader: _fontLinkHeader,\n i18n: {\n locale: locale,\n locales: i18nConfig ? i18nConfig.locales : undefined,\n defaultLocale: currentDefaultLocale,\n domainLocales: domainLocales,\n },\n isrCacheKey,\n isrGet,\n isrSet,\n expireSeconds: vinextConfig.expireTime,\n pageModule,\n params,\n query,\n renderIsrPassToStringAsync,\n route: {\n isDynamic: route.isDynamic,\n },\n routePattern,\n routeUrl,\n runInFreshUnifiedContext(callback) {\n var revalCtx = _createUnifiedCtx({\n executionContext: _getRequestExecutionContext(),\n });\n return _runWithUnifiedCtx(revalCtx, async () => {\n ensureFetchPatch();\n return callback();\n });\n },\n safeJsonStringify,\n sanitizeDestination: sanitizeDestinationLocal,\n scriptNonce,\n triggerBackgroundRegeneration,\n });\n if (pageDataResult.kind === \"response\") {\n return pageDataResult.response;\n }\n let pageProps = pageDataResult.pageProps;\n var gsspRes = pageDataResult.gsspRes;\n let isrRevalidateSeconds = pageDataResult.isrRevalidateSeconds;\n\n const pageModuleIds = route.filePath ? [route.filePath] : [];\n const assetTags = collectAssetTags(manifest, pageModuleIds, scriptNonce);\n\n return __renderPagesPageResponse({\n assetTags,\n buildId,\n clearSsrContext() {\n if (typeof setSSRContext === \"function\") setSSRContext(null);\n },\n createPageElement(currentPageProps) {\n var currentElement;\n if (AppComponent) {\n currentElement = React.createElement(AppComponent, { Component: PageComponent, pageProps: currentPageProps });\n } else {\n currentElement = React.createElement(PageComponent, currentPageProps);\n }\n return wrapWithRouterContext(currentElement);\n },\n DocumentComponent,\n flushPreloads: typeof flushPreloads === \"function\" ? flushPreloads : undefined,\n fontLinkHeader: _fontLinkHeader,\n fontPreloads: _allFp,\n getFontLinks() {\n try {\n return typeof _getSSRFontLinks === \"function\" ? _getSSRFontLinks() : [];\n } catch (e) {\n return [];\n }\n },\n getFontStyles() {\n try {\n var allFontStyles = [];\n if (typeof _getSSRFontStylesGoogle === \"function\") allFontStyles.push(..._getSSRFontStylesGoogle());\n if (typeof _getSSRFontStylesLocal === \"function\") allFontStyles.push(..._getSSRFontStylesLocal());\n return allFontStyles;\n } catch (e) {\n return [];\n }\n },\n getSSRHeadHTML: typeof getSSRHeadHTML === \"function\" ? getSSRHeadHTML : undefined,\n gsspRes,\n isrCacheKey,\n expireSeconds: vinextConfig.expireTime,\n isrRevalidateSeconds,\n isrSet,\n i18n: {\n locale: locale,\n locales: i18nConfig ? i18nConfig.locales : undefined,\n defaultLocale: currentDefaultLocale,\n domainLocales: domainLocales,\n },\n pageProps,\n params,\n renderDocumentToString(element) {\n return renderToStringAsync(element);\n },\n renderToReadableStream(element) {\n return renderToReadableStream(element);\n },\n resetSSRHead: typeof resetSSRHead === \"function\" ? resetSSRHead : undefined,\n routePattern,\n routeUrl,\n safeJsonStringify,\n scriptNonce,\n });\n } catch (e) {\n console.error(\"[vinext] SSR error:\", e);\n _reportRequestError(\n e instanceof Error ? e : new Error(String(e)),\n { path: url, method: request.method, headers: Object.fromEntries(request.headers.entries()) },\n { routerKind: \"Pages Router\", routePath: route.pattern, routeType: \"render\" },\n ).catch(() => { /* ignore reporting errors */ });\n return new Response(\"Internal Server Error\", { status: 500 });\n }\n });\n}\n\nexport async function handleApiRoute(request, url) {\n const match = matchRoute(url, apiRoutes);\n return __handlePagesApiRoute({\n match,\n request,\n url,\n reportRequestError(error, routePattern) {\n console.error(\"[vinext] API error:\", error);\n void _reportRequestError(\n error,\n { path: url, method: request.method, headers: Object.fromEntries(request.headers.entries()) },\n { routerKind: \"Pages Router\", routePath: routePattern, routeType: \"route\" },\n );\n },\n });\n}\n\n${middlewareExportCode}\n`;\n}\n"],"mappings":";;;;;;;;;;;;;;AAgBA,MAAM,0BAA0B,iBAAiB,+BAA+B,OAAO,KAAK,IAAI;AAChG,MAAM,yBAAyB,iBAAiB,mCAAmC,OAAO,KAAK,IAAI;AACnG,MAAM,iBAAiB,iBAAiB,4BAA4B,OAAO,KAAK,IAAI;AACpF,MAAM,iBAAiB,iBAAiB,2BAA2B,OAAO,KAAK,IAAI;AACnF,MAAM,yBAAyB,iBAC7B,oCACA,OAAO,KAAK,IACb;AACD,MAAM,qBAAqB,iBAAiB,gCAAgC,OAAO,KAAK,IAAI;AAC5F,MAAM,uBAAuB,iBAA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style backslash path separators to forward slashes.
|
|
4
|
+
*
|
|
5
|
+
* Generated entry modules embed absolute filesystem paths inside `import`
|
|
6
|
+
* statements. On Windows the OS-native paths use `\` which is invalid in JS
|
|
7
|
+
* module specifiers, so every entry generator normalizes paths through this
|
|
8
|
+
* helper before stringifying them into the emitted code.
|
|
9
|
+
*/
|
|
10
|
+
declare function normalizePathSeparators(p: string): string;
|
|
2
11
|
/**
|
|
3
12
|
* Resolve a sibling module path relative to a caller's `import.meta.url`,
|
|
4
13
|
* returning a forward-slash path safe for embedding in generated code.
|
|
5
14
|
*
|
|
6
15
|
* This is the single place that owns the
|
|
7
|
-
* `fileURLToPath(new URL(rel, base))
|
|
8
|
-
* don't duplicate it.
|
|
16
|
+
* `fileURLToPath(new URL(rel, base))` + path-separator normalization idiom so
|
|
17
|
+
* callers don't duplicate it.
|
|
9
18
|
*
|
|
10
19
|
* @param rel - Relative path to the target module (e.g. `"../server/foo.js"`)
|
|
11
20
|
* @param base - The caller's `import.meta.url`
|
|
@@ -21,5 +30,5 @@ declare function resolveEntryPath(rel: string, base: string): string;
|
|
|
21
30
|
*/
|
|
22
31
|
declare function resolveRuntimeEntryModule(name: string): string;
|
|
23
32
|
//#endregion
|
|
24
|
-
export { resolveEntryPath, resolveRuntimeEntryModule };
|
|
33
|
+
export { normalizePathSeparators, resolveEntryPath, resolveRuntimeEntryModule };
|
|
25
34
|
//# sourceMappingURL=runtime-entry-module.d.ts.map
|
|
@@ -2,18 +2,29 @@ import fs from "node:fs";
|
|
|
2
2
|
import { fileURLToPath } from "node:url";
|
|
3
3
|
//#region src/entries/runtime-entry-module.ts
|
|
4
4
|
/**
|
|
5
|
+
* Convert Windows-style backslash path separators to forward slashes.
|
|
6
|
+
*
|
|
7
|
+
* Generated entry modules embed absolute filesystem paths inside `import`
|
|
8
|
+
* statements. On Windows the OS-native paths use `\` which is invalid in JS
|
|
9
|
+
* module specifiers, so every entry generator normalizes paths through this
|
|
10
|
+
* helper before stringifying them into the emitted code.
|
|
11
|
+
*/
|
|
12
|
+
function normalizePathSeparators(p) {
|
|
13
|
+
return p.replace(/\\/g, "/");
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
5
16
|
* Resolve a sibling module path relative to a caller's `import.meta.url`,
|
|
6
17
|
* returning a forward-slash path safe for embedding in generated code.
|
|
7
18
|
*
|
|
8
19
|
* This is the single place that owns the
|
|
9
|
-
* `fileURLToPath(new URL(rel, base))
|
|
10
|
-
* don't duplicate it.
|
|
20
|
+
* `fileURLToPath(new URL(rel, base))` + path-separator normalization idiom so
|
|
21
|
+
* callers don't duplicate it.
|
|
11
22
|
*
|
|
12
23
|
* @param rel - Relative path to the target module (e.g. `"../server/foo.js"`)
|
|
13
24
|
* @param base - The caller's `import.meta.url`
|
|
14
25
|
*/
|
|
15
26
|
function resolveEntryPath(rel, base) {
|
|
16
|
-
return fileURLToPath(new URL(rel, base))
|
|
27
|
+
return normalizePathSeparators(fileURLToPath(new URL(rel, base)));
|
|
17
28
|
}
|
|
18
29
|
/**
|
|
19
30
|
* Resolve a real runtime module for a virtual entry generator.
|
|
@@ -36,6 +47,6 @@ function resolveRuntimeEntryModule(name) {
|
|
|
36
47
|
return resolveEntryPath(`../server/${name}.js`, import.meta.url);
|
|
37
48
|
}
|
|
38
49
|
//#endregion
|
|
39
|
-
export { resolveEntryPath, resolveRuntimeEntryModule };
|
|
50
|
+
export { normalizePathSeparators, resolveEntryPath, resolveRuntimeEntryModule };
|
|
40
51
|
|
|
41
52
|
//# sourceMappingURL=runtime-entry-module.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime-entry-module.js","names":[],"sources":["../../src/entries/runtime-entry-module.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { fileURLToPath } from \"node:url\";\n\n/**\n * Resolve a sibling module path relative to a caller's `import.meta.url`,\n * returning a forward-slash path safe for embedding in generated code.\n *\n * This is the single place that owns the\n * `fileURLToPath(new URL(rel, base))
|
|
1
|
+
{"version":3,"file":"runtime-entry-module.js","names":[],"sources":["../../src/entries/runtime-entry-module.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { fileURLToPath } from \"node:url\";\n\n/**\n * Convert Windows-style backslash path separators to forward slashes.\n *\n * Generated entry modules embed absolute filesystem paths inside `import`\n * statements. On Windows the OS-native paths use `\\` which is invalid in JS\n * module specifiers, so every entry generator normalizes paths through this\n * helper before stringifying them into the emitted code.\n */\nexport function normalizePathSeparators(p: string): string {\n return p.replace(/\\\\/g, \"/\");\n}\n\n/**\n * Resolve a sibling module path relative to a caller's `import.meta.url`,\n * returning a forward-slash path safe for embedding in generated code.\n *\n * This is the single place that owns the\n * `fileURLToPath(new URL(rel, base))` + path-separator normalization idiom so\n * callers don't duplicate it.\n *\n * @param rel - Relative path to the target module (e.g. `\"../server/foo.js\"`)\n * @param base - The caller's `import.meta.url`\n */\nexport function resolveEntryPath(rel: string, base: string): string {\n return normalizePathSeparators(fileURLToPath(new URL(rel, base)));\n}\n\n/**\n * Resolve a real runtime module for a virtual entry generator.\n *\n * During local development we want to point at source files (for example `.ts`),\n * while packed builds only contain emitted `.js` files in `dist/`. Probe the\n * common source/build extensions and fall back to the `.js` path that exists in\n * published packages.\n */\nexport function resolveRuntimeEntryModule(name: string): string {\n for (const ext of [\".ts\", \".js\", \".mts\", \".mjs\"]) {\n const filePath = resolveEntryPath(`../server/${name}${ext}`, import.meta.url);\n if (fs.existsSync(filePath)) {\n return filePath;\n }\n }\n\n return resolveEntryPath(`../server/${name}.js`, import.meta.url);\n}\n"],"mappings":";;;;;;;;;;;AAWA,SAAgB,wBAAwB,GAAmB;AACzD,QAAO,EAAE,QAAQ,OAAO,IAAI;;;;;;;;;;;;;AAc9B,SAAgB,iBAAiB,KAAa,MAAsB;AAClE,QAAO,wBAAwB,cAAc,IAAI,IAAI,KAAK,KAAK,CAAC,CAAC;;;;;;;;;;AAWnE,SAAgB,0BAA0B,MAAsB;AAC9D,MAAK,MAAM,OAAO;EAAC;EAAO;EAAO;EAAQ;EAAO,EAAE;EAChD,MAAM,WAAW,iBAAiB,aAAa,OAAO,OAAO,OAAO,KAAK,IAAI;AAC7E,MAAI,GAAG,WAAW,SAAS,CACzB,QAAO;;AAIX,QAAO,iBAAiB,aAAa,KAAK,MAAM,OAAO,KAAK,IAAI"}
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { detectPackageManager } from "./utils/project.js";
|
|
2
2
|
import { normalizePathnameForRouteMatchStrict } from "./routing/utils.js";
|
|
3
3
|
import { createValidFileMatcher } from "./routing/file-matcher.js";
|
|
4
|
+
import { hasBasePath, removeTrailingSlash } from "./utils/base-path.js";
|
|
4
5
|
import { apiRouter, invalidateRouteCache, matchRoute, pagesRouter } from "./routing/pages-router.js";
|
|
5
6
|
import { buildRequestHeadersFromMiddlewareResponse } from "./server/middleware-request-headers.js";
|
|
6
7
|
import { normalizePath as normalizePath$1 } from "./server/normalize-path.js";
|
|
7
8
|
import { isExternalUrl, matchHeaders, matchRedirect, matchRewrite, proxyExternalRequest, requestContextFromRequest, sanitizeDestination } from "./config/config-matchers.js";
|
|
8
|
-
import {
|
|
9
|
-
import { isOpenRedirectShaped } from "./server/request-pipeline.js";
|
|
9
|
+
import { INTERNAL_HEADERS, filterInternalHeaders, isOpenRedirectShaped } from "./server/request-pipeline.js";
|
|
10
10
|
import { findMiddlewareFile, runMiddleware } from "./server/middleware.js";
|
|
11
11
|
import { generateServerEntry } from "./entries/pages-server-entry.js";
|
|
12
12
|
import { generateClientEntry } from "./entries/pages-client-entry.js";
|
|
@@ -23,8 +23,8 @@ import { validateDevRequest } from "./server/dev-origin-check.js";
|
|
|
23
23
|
import { generateRscEntry } from "./entries/app-rsc-entry.js";
|
|
24
24
|
import { generateSsrEntry } from "./entries/app-ssr-entry.js";
|
|
25
25
|
import { generateBrowserEntry } from "./entries/app-browser-entry.js";
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
26
|
+
import { collectRouteClassificationManifest } from "./build/route-classification-manifest.js";
|
|
27
|
+
import { planRouteClassificationInjection } from "./build/route-classification-injector.js";
|
|
28
28
|
import { PHASE_DEVELOPMENT_SERVER, PHASE_PRODUCTION_BUILD } from "./shims/constants.js";
|
|
29
29
|
import { findNextConfigPath, loadNextConfig, resolveNextConfig, resolveNextConfigInput } from "./config/next-config.js";
|
|
30
30
|
import { precompressAssets } from "./build/precompress.js";
|
|
@@ -34,7 +34,7 @@ import { clientReferenceDedupPlugin } from "./plugins/client-reference-dedup.js"
|
|
|
34
34
|
import { createInstrumentationClientTransformPlugin } from "./plugins/instrumentation-client.js";
|
|
35
35
|
import { createOptimizeImportsPlugin } from "./plugins/optimize-imports.js";
|
|
36
36
|
import { createOgInlineFetchAssetsPlugin, ogAssetsPlugin } from "./plugins/og-assets.js";
|
|
37
|
-
import { VINEXT_OPTIMIZE_DEPS_EXCLUDE, mergeOptimizeDepsExclude } from "./plugins/rsc-client-shim-excludes.js";
|
|
37
|
+
import { SSR_EXTERNAL_REACT_ENTRIES, VINEXT_OPTIMIZE_DEPS_EXCLUDE, mergeOptimizeDepsExclude } from "./plugins/rsc-client-shim-excludes.js";
|
|
38
38
|
import { createServerExternalsManifestPlugin } from "./plugins/server-externals-manifest.js";
|
|
39
39
|
import { RESOLVED_VIRTUAL_GOOGLE_FONTS, VIRTUAL_GOOGLE_FONTS, createGoogleFontsPlugin, createLocalFontsPlugin, generateGoogleFontsVirtualModule, parseStaticObjectLiteral } from "./plugins/fonts.js";
|
|
40
40
|
import { computeLazyChunks } from "./utils/lazy-chunks.js";
|
|
@@ -533,7 +533,7 @@ function vinext(options = {}) {
|
|
|
533
533
|
preflightContinue: true,
|
|
534
534
|
origin: /^https?:\/\/(?:(?:[^:]+\.)?localhost|127\.0\.0\.1|\[::1\])(?::\d+)?$/
|
|
535
535
|
} },
|
|
536
|
-
...hasCloudflarePlugin || hasNitroPlugin ? {} : { ssr: {
|
|
536
|
+
...hasCloudflarePlugin || hasNitroPlugin ? {} : config.ssr?.external === true ? { ssr: { external: true } } : { ssr: {
|
|
537
537
|
external: [
|
|
538
538
|
"react",
|
|
539
539
|
"react-dom",
|
|
@@ -607,7 +607,7 @@ function vinext(options = {}) {
|
|
|
607
607
|
...userSsrExternal === true ? {} : { noExternal: true }
|
|
608
608
|
} },
|
|
609
609
|
optimizeDeps: {
|
|
610
|
-
exclude: mergeOptimizeDepsExclude(incomingExclude, VINEXT_OPTIMIZE_DEPS_EXCLUDE),
|
|
610
|
+
exclude: mergeOptimizeDepsExclude(incomingExclude, VINEXT_OPTIMIZE_DEPS_EXCLUDE, userSsrExternal === true ? SSR_EXTERNAL_REACT_ENTRIES : []),
|
|
611
611
|
entries: optimizeEntries
|
|
612
612
|
},
|
|
613
613
|
build: {
|
|
@@ -692,6 +692,10 @@ function vinext(options = {}) {
|
|
|
692
692
|
return viteConfig;
|
|
693
693
|
},
|
|
694
694
|
configResolved(config) {
|
|
695
|
+
if (hasAppDir) {
|
|
696
|
+
const ssrEnv = config.environments?.ssr;
|
|
697
|
+
if (ssrEnv?.resolve?.external === true && Array.isArray(ssrEnv.resolve.noExternal)) ssrEnv.resolve.noExternal = ssrEnv.resolve.noExternal.filter((entry) => typeof entry !== "string" || !SSR_EXTERNAL_REACT_ENTRIES.includes(entry));
|
|
698
|
+
}
|
|
695
699
|
// @vitejs/plugin-react AND the user also registers it manually, the
|
|
696
700
|
if (reactPluginPromise) {
|
|
697
701
|
const reactRootPlugins = config.plugins.filter((p) => p && typeof p === "object" && "name" in p && typeof p.name === "string" && p.name.startsWith("vite:react"));
|
|
@@ -747,6 +751,7 @@ function vinext(options = {}) {
|
|
|
747
751
|
allowedOrigins: nextConfig?.serverActionsAllowedOrigins,
|
|
748
752
|
allowedDevOrigins: nextConfig?.allowedDevOrigins,
|
|
749
753
|
bodySizeLimit: nextConfig?.serverActionsBodySizeLimit,
|
|
754
|
+
expireTime: nextConfig?.expireTime,
|
|
750
755
|
i18n: nextConfig?.i18n,
|
|
751
756
|
hasPagesDir,
|
|
752
757
|
publicFiles: scanPublicFileRoutes(root)
|
|
@@ -761,60 +766,36 @@ function vinext(options = {}) {
|
|
|
761
766
|
if (this.environment?.name !== "rsc") return;
|
|
762
767
|
if (!rscClassificationManifest) return;
|
|
763
768
|
const enableClassificationDebug = Boolean(process.env.VINEXT_DEBUG_CLASSIFICATION);
|
|
764
|
-
const
|
|
765
|
-
const
|
|
766
|
-
const chunksMentioningStub = [];
|
|
767
|
-
const chunksWithStubBody = [];
|
|
769
|
+
const chunks = [];
|
|
770
|
+
const chunksByFileName = /* @__PURE__ */ new Map();
|
|
768
771
|
for (const chunk of Object.values(bundle)) {
|
|
769
772
|
if (chunk.type !== "chunk") continue;
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
chunk,
|
|
773
|
-
fileName: chunk.fileName
|
|
774
|
-
});
|
|
775
|
-
if (stubRe.test(chunk.code)) chunksWithStubBody.push({
|
|
776
|
-
chunk,
|
|
773
|
+
chunks.push({
|
|
774
|
+
code: chunk.code,
|
|
777
775
|
fileName: chunk.fileName
|
|
778
776
|
});
|
|
777
|
+
chunksByFileName.set(chunk.fileName, chunk);
|
|
779
778
|
}
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
if (!moduleInfo.getModuleInfo(layoutModuleId)) continue;
|
|
801
|
-
let graphResult = graphCache.get(layoutModuleId);
|
|
802
|
-
if (graphResult === void 0) {
|
|
803
|
-
graphResult = classifyLayoutByModuleGraph(layoutModuleId, dynamicShimPaths, moduleInfo);
|
|
804
|
-
graphCache.set(layoutModuleId, graphResult);
|
|
805
|
-
}
|
|
806
|
-
if (isStaticModuleGraphResult(graphResult)) perRoute.set(layoutIdx, moduleGraphReason(graphResult));
|
|
807
|
-
}
|
|
808
|
-
if (perRoute.size > 0) layer2PerRoute.set(routeIdx, perRoute);
|
|
809
|
-
}
|
|
810
|
-
const patchedBody = `function __VINEXT_CLASS(routeIdx) { return (${buildGenerateBundleReplacement(rscClassificationManifest, layer2PerRoute)})(routeIdx); }`;
|
|
811
|
-
const target = chunksWithStubBody[0].chunk;
|
|
812
|
-
target.code = target.code.replace(stubRe, patchedBody);
|
|
813
|
-
if (enableClassificationDebug) {
|
|
814
|
-
const patchedReasonsBody = `function __VINEXT_CLASS_REASONS(routeIdx) { return (${buildReasonsReplacement(rscClassificationManifest, layer2PerRoute)})(routeIdx); }`;
|
|
815
|
-
target.code = target.code.replace(reasonsStubRe, patchedReasonsBody);
|
|
816
|
-
}
|
|
817
|
-
target.map = null;
|
|
779
|
+
const patchPlan = planRouteClassificationInjection({
|
|
780
|
+
canonicalizeLayoutPath: canonicalize,
|
|
781
|
+
chunks,
|
|
782
|
+
dynamicShimPaths,
|
|
783
|
+
enableDebugReasons: enableClassificationDebug,
|
|
784
|
+
manifest: rscClassificationManifest,
|
|
785
|
+
moduleInfo: { getModuleInfo: (moduleId) => {
|
|
786
|
+
const info = this.getModuleInfo(moduleId);
|
|
787
|
+
if (!info) return null;
|
|
788
|
+
return {
|
|
789
|
+
importedIds: info.importedIds ?? [],
|
|
790
|
+
dynamicImportedIds: info.dynamicallyImportedIds ?? []
|
|
791
|
+
};
|
|
792
|
+
} }
|
|
793
|
+
});
|
|
794
|
+
if (patchPlan.kind === "skip") return;
|
|
795
|
+
const target = chunksByFileName.get(patchPlan.fileName);
|
|
796
|
+
if (!target) throw new Error(`vinext: build-time classification — patch target ${patchPlan.fileName} disappeared from the RSC bundle`);
|
|
797
|
+
target.code = patchPlan.code;
|
|
798
|
+
target.map = patchPlan.map;
|
|
818
799
|
rscClassificationManifest = null;
|
|
819
800
|
}
|
|
820
801
|
},
|
|
@@ -1067,14 +1048,15 @@ function vinext(options = {}) {
|
|
|
1067
1048
|
return;
|
|
1068
1049
|
} else if (!nextConfig.trailingSlash && hasTrailing) {
|
|
1069
1050
|
const qs = url.includes("?") ? url.slice(url.indexOf("?")) : "";
|
|
1070
|
-
const dest = bp + pathname
|
|
1051
|
+
const dest = bp + removeTrailingSlash(pathname) + qs;
|
|
1071
1052
|
res.writeHead(308, { Location: dest });
|
|
1072
1053
|
res.end();
|
|
1073
1054
|
return;
|
|
1074
1055
|
}
|
|
1075
1056
|
}
|
|
1076
1057
|
if (hasCloudflarePlugin) return next();
|
|
1077
|
-
const nodeRequestHeaders = new Headers(Object.fromEntries(Object.entries(req.headers).filter(([, v]) => v !== void 0).map(([k, v]) => [k, Array.isArray(v) ? v.join(", ") : String(v)])));
|
|
1058
|
+
const nodeRequestHeaders = filterInternalHeaders(new Headers(Object.fromEntries(Object.entries(req.headers).filter(([, v]) => v !== void 0).map(([k, v]) => [k, Array.isArray(v) ? v.join(", ") : String(v)]))));
|
|
1059
|
+
for (const header of INTERNAL_HEADERS) delete req.headers[header];
|
|
1078
1060
|
const requestOrigin = `http://${req.headers.host || "localhost"}`;
|
|
1079
1061
|
const preMiddlewareReqUrl = new URL(url, requestOrigin);
|
|
1080
1062
|
const preMiddlewareReqCtx = requestContextFromRequest(new Request(preMiddlewareReqUrl, { headers: nodeRequestHeaders }));
|