vinext 0.1.2 → 0.1.3

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.
Files changed (199) hide show
  1. package/dist/build/prerender.d.ts +9 -1
  2. package/dist/build/prerender.js +41 -12
  3. package/dist/build/run-prerender.d.ts +10 -2
  4. package/dist/build/run-prerender.js +15 -1
  5. package/dist/client/app-nav-failure-handler.d.ts +8 -0
  6. package/dist/client/app-nav-failure-handler.js +44 -0
  7. package/dist/client/vinext-next-data.d.ts +18 -1
  8. package/dist/client/window-next.d.ts +2 -1
  9. package/dist/client/window-next.js +12 -1
  10. package/dist/cloudflare/src/cache/cdn-adapter.runtime.js +6 -1
  11. package/dist/config/config-matchers.js +73 -14
  12. package/dist/config/next-config.d.ts +46 -4
  13. package/dist/config/next-config.js +147 -48
  14. package/dist/deploy.d.ts +30 -11
  15. package/dist/deploy.js +180 -99
  16. package/dist/entries/app-browser-entry.d.ts +9 -3
  17. package/dist/entries/app-browser-entry.js +21 -3
  18. package/dist/entries/app-rsc-entry.d.ts +2 -0
  19. package/dist/entries/app-rsc-entry.js +64 -5
  20. package/dist/entries/app-rsc-manifest.js +2 -0
  21. package/dist/entries/app-ssr-entry.js +1 -1
  22. package/dist/entries/pages-client-entry.js +53 -8
  23. package/dist/entries/pages-server-entry.js +41 -5
  24. package/dist/index.js +200 -62
  25. package/dist/plugins/extensionless-dynamic-import.d.ts +6 -0
  26. package/dist/plugins/extensionless-dynamic-import.js +152 -0
  27. package/dist/plugins/optimize-imports.d.ts +2 -1
  28. package/dist/plugins/optimize-imports.js +11 -9
  29. package/dist/plugins/postcss.js +7 -7
  30. package/dist/plugins/typeof-window.d.ts +14 -0
  31. package/dist/plugins/typeof-window.js +150 -0
  32. package/dist/routing/app-route-graph.d.ts +2 -1
  33. package/dist/routing/app-route-graph.js +44 -14
  34. package/dist/routing/file-matcher.d.ts +10 -1
  35. package/dist/routing/file-matcher.js +22 -1
  36. package/dist/routing/pages-router.js +3 -3
  37. package/dist/routing/utils.d.ts +35 -6
  38. package/dist/routing/utils.js +59 -7
  39. package/dist/server/api-handler.d.ts +6 -1
  40. package/dist/server/api-handler.js +21 -15
  41. package/dist/server/app-browser-action-result.d.ts +19 -6
  42. package/dist/server/app-browser-action-result.js +19 -10
  43. package/dist/server/app-browser-entry.js +167 -90
  44. package/dist/server/app-browser-error.d.ts +10 -6
  45. package/dist/server/app-browser-error.js +43 -8
  46. package/dist/server/app-browser-hydration.d.ts +2 -0
  47. package/dist/server/app-browser-hydration.js +1 -0
  48. package/dist/server/app-browser-navigation-controller.d.ts +4 -2
  49. package/dist/server/app-browser-navigation-controller.js +23 -2
  50. package/dist/server/app-browser-server-action-navigation.d.ts +6 -0
  51. package/dist/server/app-browser-server-action-navigation.js +9 -0
  52. package/dist/server/app-browser-stream.js +86 -43
  53. package/dist/server/app-elements-wire.d.ts +6 -1
  54. package/dist/server/app-elements-wire.js +14 -4
  55. package/dist/server/app-elements.d.ts +2 -2
  56. package/dist/server/app-elements.js +2 -2
  57. package/dist/server/app-fallback-renderer.d.ts +1 -0
  58. package/dist/server/app-fallback-renderer.js +3 -1
  59. package/dist/server/app-optimistic-routing.js +2 -2
  60. package/dist/server/app-page-boundary-render.d.ts +1 -0
  61. package/dist/server/app-page-boundary-render.js +27 -14
  62. package/dist/server/app-page-cache-render.d.ts +53 -0
  63. package/dist/server/app-page-cache-render.js +91 -0
  64. package/dist/server/app-page-cache.d.ts +16 -2
  65. package/dist/server/app-page-cache.js +62 -1
  66. package/dist/server/app-page-dispatch.d.ts +26 -0
  67. package/dist/server/app-page-dispatch.js +149 -92
  68. package/dist/server/app-page-element-builder.d.ts +1 -0
  69. package/dist/server/app-page-element-builder.js +5 -2
  70. package/dist/server/app-page-execution.d.ts +6 -1
  71. package/dist/server/app-page-execution.js +21 -1
  72. package/dist/server/app-page-probe.d.ts +1 -0
  73. package/dist/server/app-page-probe.js +4 -0
  74. package/dist/server/app-page-render-observation.d.ts +3 -1
  75. package/dist/server/app-page-render-observation.js +17 -1
  76. package/dist/server/app-page-render.d.ts +12 -1
  77. package/dist/server/app-page-render.js +42 -4
  78. package/dist/server/app-page-request.d.ts +2 -0
  79. package/dist/server/app-page-request.js +2 -1
  80. package/dist/server/app-page-route-wiring.d.ts +3 -1
  81. package/dist/server/app-page-route-wiring.js +14 -5
  82. package/dist/server/app-page-stream.d.ts +15 -3
  83. package/dist/server/app-page-stream.js +11 -5
  84. package/dist/server/app-pages-bridge.d.ts +18 -0
  85. package/dist/server/app-pages-bridge.js +22 -5
  86. package/dist/server/app-ppr-fallback-shell-render.d.ts +17 -0
  87. package/dist/server/app-ppr-fallback-shell-render.js +26 -0
  88. package/dist/server/app-ppr-fallback-shell.d.ts +13 -1
  89. package/dist/server/app-ppr-fallback-shell.js +8 -1
  90. package/dist/server/app-route-handler-dispatch.js +9 -2
  91. package/dist/server/app-route-handler-policy.d.ts +1 -0
  92. package/dist/server/app-router-entry.js +5 -0
  93. package/dist/server/app-rsc-cache-busting.js +2 -0
  94. package/dist/server/app-rsc-handler.d.ts +25 -0
  95. package/dist/server/app-rsc-handler.js +154 -54
  96. package/dist/server/app-rsc-route-matching.d.ts +3 -0
  97. package/dist/server/app-rsc-route-matching.js +2 -0
  98. package/dist/server/app-segment-config.d.ts +9 -1
  99. package/dist/server/app-segment-config.js +12 -3
  100. package/dist/server/app-server-action-execution.d.ts +1 -0
  101. package/dist/server/app-server-action-execution.js +42 -13
  102. package/dist/server/app-ssr-entry.d.ts +2 -0
  103. package/dist/server/app-ssr-entry.js +83 -10
  104. package/dist/server/cache-control.js +4 -0
  105. package/dist/server/dev-server.d.ts +2 -2
  106. package/dist/server/dev-server.js +244 -51
  107. package/dist/server/hybrid-route-priority.d.ts +22 -0
  108. package/dist/server/hybrid-route-priority.js +33 -0
  109. package/dist/server/image-optimization.d.ts +18 -9
  110. package/dist/server/image-optimization.js +37 -23
  111. package/dist/server/implicit-tags.d.ts +2 -1
  112. package/dist/server/implicit-tags.js +4 -1
  113. package/dist/server/navigation-planner.d.ts +133 -30
  114. package/dist/server/navigation-planner.js +114 -0
  115. package/dist/server/navigation-trace.d.ts +8 -1
  116. package/dist/server/navigation-trace.js +8 -1
  117. package/dist/server/pages-api-route.d.ts +6 -0
  118. package/dist/server/pages-api-route.js +13 -2
  119. package/dist/server/pages-asset-tags.d.ts +2 -1
  120. package/dist/server/pages-asset-tags.js +6 -2
  121. package/dist/server/pages-data-route.d.ts +8 -1
  122. package/dist/server/pages-data-route.js +11 -2
  123. package/dist/server/pages-get-initial-props.d.ts +54 -4
  124. package/dist/server/pages-get-initial-props.js +43 -1
  125. package/dist/server/pages-node-compat.js +2 -2
  126. package/dist/server/pages-page-data.d.ts +11 -2
  127. package/dist/server/pages-page-data.js +204 -33
  128. package/dist/server/pages-page-handler.d.ts +4 -2
  129. package/dist/server/pages-page-handler.js +59 -22
  130. package/dist/server/pages-page-response.d.ts +2 -1
  131. package/dist/server/pages-page-response.js +7 -4
  132. package/dist/server/pages-request-pipeline.d.ts +1 -0
  133. package/dist/server/pages-request-pipeline.js +73 -36
  134. package/dist/server/pregenerated-concrete-paths.d.ts +1 -17
  135. package/dist/server/pregenerated-concrete-paths.js +2 -19
  136. package/dist/server/prerender-manifest.d.ts +33 -0
  137. package/dist/server/prerender-manifest.js +54 -0
  138. package/dist/server/prerender-route-params.d.ts +1 -2
  139. package/dist/server/prod-server.js +9 -3
  140. package/dist/server/request-pipeline.d.ts +3 -15
  141. package/dist/server/request-pipeline.js +58 -47
  142. package/dist/server/rsc-stream-hints.d.ts +5 -1
  143. package/dist/server/rsc-stream-hints.js +6 -1
  144. package/dist/server/seed-cache.js +10 -18
  145. package/dist/shims/app-router-scroll-state.d.ts +3 -1
  146. package/dist/shims/app-router-scroll-state.js +14 -2
  147. package/dist/shims/app-router-scroll.d.ts +3 -0
  148. package/dist/shims/app-router-scroll.js +28 -18
  149. package/dist/shims/cache-runtime.js +3 -2
  150. package/dist/shims/cache.d.ts +1 -0
  151. package/dist/shims/cache.js +1 -1
  152. package/dist/shims/cdn-cache.d.ts +5 -5
  153. package/dist/shims/dynamic-preload-chunks.js +6 -4
  154. package/dist/shims/error-boundary.d.ts +2 -0
  155. package/dist/shims/error-boundary.js +7 -0
  156. package/dist/shims/error.js +3 -2
  157. package/dist/shims/error.react-server.d.ts +9 -0
  158. package/dist/shims/error.react-server.js +6 -0
  159. package/dist/shims/fetch-cache.d.ts +3 -1
  160. package/dist/shims/fetch-cache.js +45 -20
  161. package/dist/shims/hash-scroll.js +6 -1
  162. package/dist/shims/headers.js +29 -4
  163. package/dist/shims/internal/als-registry.js +28 -1
  164. package/dist/shims/internal/app-route-detection.js +8 -17
  165. package/dist/shims/internal/hybrid-client-route-owner.d.ts +31 -0
  166. package/dist/shims/internal/hybrid-client-route-owner.js +143 -0
  167. package/dist/shims/internal/navigation-untracked.d.ts +35 -0
  168. package/dist/shims/internal/navigation-untracked.js +55 -0
  169. package/dist/shims/internal/pages-data-target.d.ts +7 -2
  170. package/dist/shims/internal/pages-data-target.js +17 -8
  171. package/dist/shims/internal/pages-router-accessor.d.ts +19 -0
  172. package/dist/shims/internal/pages-router-accessor.js +13 -0
  173. package/dist/shims/internal/router-context.d.ts +2 -1
  174. package/dist/shims/internal/router-context.js +3 -1
  175. package/dist/shims/link.js +12 -5
  176. package/dist/shims/navigation.d.ts +8 -2
  177. package/dist/shims/navigation.js +61 -31
  178. package/dist/shims/ppr-fallback-shell.d.ts +5 -1
  179. package/dist/shims/ppr-fallback-shell.js +28 -7
  180. package/dist/shims/router.d.ts +13 -2
  181. package/dist/shims/router.js +419 -128
  182. package/dist/shims/server.d.ts +16 -1
  183. package/dist/shims/server.js +44 -12
  184. package/dist/shims/unified-request-context.js +1 -0
  185. package/dist/utils/built-asset-url.d.ts +4 -0
  186. package/dist/utils/built-asset-url.js +11 -0
  187. package/dist/utils/commonjs-loader.d.ts +16 -0
  188. package/dist/utils/commonjs-loader.js +100 -0
  189. package/dist/utils/deployment-id.d.ts +8 -0
  190. package/dist/utils/deployment-id.js +22 -0
  191. package/dist/utils/html-limited-bots.d.ts +18 -1
  192. package/dist/utils/html-limited-bots.js +23 -1
  193. package/dist/utils/parse-cookie.d.ts +13 -0
  194. package/dist/utils/parse-cookie.js +52 -0
  195. package/dist/utils/path.d.ts +7 -1
  196. package/dist/utils/path.js +9 -1
  197. package/package.json +2 -2
  198. package/dist/shims/internal/parse-cookie-header.d.ts +0 -14
  199. package/dist/shims/internal/parse-cookie-header.js +0 -30
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { detectPackageManager } from "./utils/project.js";
2
- import { normalizePathSeparators, stripViteModuleQuery } from "./utils/path.js";
2
+ import { normalizePathSeparators, stripJsExtension, stripViteModuleQuery } from "./utils/path.js";
3
3
  import { normalizePathnameForRouteMatchStrict } from "./routing/utils.js";
4
- import { buildViteResolveExtensions, createValidFileMatcher, findFileWithExts } from "./routing/file-matcher.js";
4
+ import { buildViteResolveExtensions, createValidFileMatcher, findFileWithExts, normalizeViteResolveExtensions } from "./routing/file-matcher.js";
5
5
  import { apiRouter, invalidateRouteCache, matchRoute, pagesRouter } from "./routing/pages-router.js";
6
6
  import { INTERNAL_HEADERS, NEXTJS_DEPLOYMENT_ID_HEADER, VINEXT_INTERNAL_HEADERS, VINEXT_MW_CTX_HEADER, VINEXT_TIMING_HEADER } from "./server/headers.js";
7
7
  import { normalizePath as normalizePath$1 } from "./server/normalize-path.js";
@@ -10,13 +10,13 @@ import { filterInternalHeaders, isOpenRedirectShaped, normalizeTrailingSlash } f
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";
13
- import { appRouteGraph, appRouter, invalidateAppRouteCache } from "./routing/app-router.js";
13
+ import { appRouteGraph, appRouter, invalidateAppRouteCache, matchAppRoute } from "./routing/app-router.js";
14
14
  import { findInstrumentationClientFile, findInstrumentationFile, runInstrumentation } from "./server/instrumentation.js";
15
15
  import { isUnknownRecord } from "./utils/record.js";
16
16
  import { logRequest, now } from "./server/request-log.js";
17
17
  import { createSSRHandler } from "./server/dev-server.js";
18
18
  import { handleApiRoute } from "./server/api-handler.js";
19
- import { isImageOptimizationPath } from "./server/image-optimization.js";
19
+ import { DEFAULT_DEVICE_SIZES, DEFAULT_IMAGE_SIZES, isImageOptimizationPath, resolveDevImageRedirect } from "./server/image-optimization.js";
20
20
  import { installSocketErrorBackstop } from "./server/socket-error-backstop.js";
21
21
  import { scanMetadataFiles } from "./server/metadata-routes.js";
22
22
  import { shouldInvalidateAppRouteFile } from "./server/dev-route-files.js";
@@ -25,11 +25,11 @@ import { validateDevRequest } from "./server/dev-origin-check.js";
25
25
  import { generateRscEntry } from "./entries/app-rsc-entry.js";
26
26
  import { generateSsrEntry } from "./entries/app-ssr-entry.js";
27
27
  import { VIRTUAL_CACHE_ADAPTERS, generateCacheAdaptersModule } from "./cache/cache-adapters-virtual.js";
28
- import { generateBrowserEntry, isLinkPrefetchRoute, toLinkPrefetchRoute } from "./entries/app-browser-entry.js";
28
+ import { generateBrowserEntry, isLinkPrefetchRoute, toDocumentOnlyAppRoute, toLinkPrefetchRoute } from "./entries/app-browser-entry.js";
29
29
  import { collectRouteClassificationManifest } from "./build/route-classification-manifest.js";
30
30
  import { planRouteClassificationInjection } from "./build/route-classification-injector.js";
31
31
  import { PHASE_DEVELOPMENT_SERVER, PHASE_PRODUCTION_BUILD } from "./shims/constants.js";
32
- import { ASSET_PREFIX_URL_DIR, resolveAssetUrlPrefix, resolveAssetsDir } from "./utils/asset-prefix.js";
32
+ import { resolveAssetsDir } from "./utils/asset-prefix.js";
33
33
  import { RESOLVED_VIRTUAL_GOOGLE_FONTS, VIRTUAL_GOOGLE_FONTS, createGoogleFontsPlugin, createLocalFontsPlugin, generateGoogleFontsVirtualModule, parseStaticObjectLiteral } from "./plugins/fonts.js";
34
34
  import { getViteMajorVersion } from "./utils/vite-version.js";
35
35
  import { createRscCompatibilityId, findNextConfigPath, loadNextConfig, resolveNextConfig, resolveNextConfigInput } from "./config/next-config.js";
@@ -40,6 +40,8 @@ import { emitNextClientRuntimeManifests } from "./build/next-client-runtime-mani
40
40
  import { collectInlineCssManifest, injectInlineCssManifestGlobal } from "./build/inline-css.js";
41
41
  import { installDevStackSourcemapMiddleware } from "./server/dev-stack-sourcemap.js";
42
42
  import { runPagesRequest } from "./server/pages-request-pipeline.js";
43
+ import { pagesRouteHasPriorityOverAppRoute, validateHybridRouteConflicts } from "./server/hybrid-route-priority.js";
44
+ import { renderVinextBuiltUrl } from "./utils/built-asset-url.js";
43
45
  import { asyncHooksStubPlugin } from "./plugins/async-hooks-stub.js";
44
46
  import { clientReferenceDedupPlugin } from "./plugins/client-reference-dedup.js";
45
47
  import { dataUrlCssPlugin } from "./plugins/css-data-url.js";
@@ -65,7 +67,9 @@ import { stripServerExports } from "./plugins/strip-server-exports.js";
65
67
  import { removeConsoleCalls } from "./plugins/remove-console.js";
66
68
  import { createImportMetaUrlPlugin } from "./plugins/import-meta-url.js";
67
69
  import { createRequireContextPlugin } from "./plugins/require-context.js";
70
+ import { createExtensionlessDynamicImportPlugin } from "./plugins/extensionless-dynamic-import.js";
68
71
  import { createWasmModuleImportPlugin } from "./plugins/wasm-module-import.js";
72
+ import { getTypeofWindowReplacement, replaceTypeofWindow } from "./plugins/typeof-window.js";
69
73
  import { hasMdxFiles } from "./utils/mdx-scan.js";
70
74
  import { scanPublicFileRoutes } from "./utils/public-routes.js";
71
75
  import { staticExportApp, staticExportPages } from "./build/static-export.js";
@@ -84,17 +88,6 @@ function isInsideDirectory(dir, filePath) {
84
88
  const relativePath = path.relative(dir, filePath);
85
89
  return relativePath !== "" && !relativePath.startsWith("..") && !path.isAbsolute(relativePath);
86
90
  }
87
- function hasModuleLevelUseServerDirective(body) {
88
- for (const node of body) {
89
- if (node.type !== "ExpressionStatement") break;
90
- const directive = node.directive;
91
- const expression = node.expression;
92
- const value = typeof directive === "string" ? directive : expression?.type === "Literal" ? expression.value : void 0;
93
- if (value === "use server") return true;
94
- if (typeof value !== "string") break;
95
- }
96
- return false;
97
- }
98
91
  function hasServerOnlyMarkerImport(code) {
99
92
  if (!code.includes("server-only")) return false;
100
93
  let ast;
@@ -103,7 +96,6 @@ function hasServerOnlyMarkerImport(code) {
103
96
  } catch {
104
97
  return false;
105
98
  }
106
- if (hasModuleLevelUseServerDirective(ast.body)) return false;
107
99
  function walk(node) {
108
100
  if (!node) return false;
109
101
  if (Array.isArray(node)) return node.some((child) => walk(child));
@@ -314,49 +306,52 @@ function isVirtualEntryFacade(id, virtualId) {
314
306
  return cleanId === virtualId || cleanId.endsWith("/" + virtualId) || cleanId.endsWith("\\" + virtualId);
315
307
  }
316
308
  /**
317
- * Returns true when `code` starts with a React `"use client"` or `"use server"`
318
- * directive (after stripping leading comments, hashbang, and whitespace).
309
+ * Returns the leading React `"use client"` or `"use server"` directive after
310
+ * stripping leading comments, hashbang, and whitespace.
319
311
  *
320
312
  * Used by `vinext:jsx-in-js` to opt `.js` files inside `node_modules` into the
321
313
  * JSX transform. We mirror `@vitejs/plugin-rsc`'s detection by looking at the
322
314
  * directive prologue rather than scanning the whole file — `code.includes`
323
315
  * alone would match incidental occurrences in template literals or comments.
324
316
  */
325
- function hasReactDirective(code) {
317
+ function getLeadingReactDirective(code) {
326
318
  let i = 0;
327
319
  const len = code.length;
328
320
  if (code.charCodeAt(0) === 65279) i = 1;
329
321
  if (code[i] === "#" && code[i + 1] === "!") {
330
322
  const nl = code.indexOf("\n", i);
331
- if (nl === -1) return false;
323
+ if (nl === -1) return null;
332
324
  i = nl + 1;
333
325
  }
334
326
  while (i < len) {
335
327
  while (i < len && /\s/.test(code[i] ?? "")) i++;
336
- if (i >= len) return false;
328
+ if (i >= len) return null;
337
329
  if (code[i] === "/" && code[i + 1] === "/") {
338
330
  const nl = code.indexOf("\n", i + 2);
339
- if (nl === -1) return false;
331
+ if (nl === -1) return null;
340
332
  i = nl + 1;
341
333
  continue;
342
334
  }
343
335
  if (code[i] === "/" && code[i + 1] === "*") {
344
336
  const end = code.indexOf("*/", i + 2);
345
- if (end === -1) return false;
337
+ if (end === -1) return null;
346
338
  i = end + 2;
347
339
  continue;
348
340
  }
349
341
  const quote = code[i];
350
- if (quote !== "\"" && quote !== "'") return false;
342
+ if (quote !== "\"" && quote !== "'") return null;
351
343
  const closing = code.indexOf(quote, i + 1);
352
- if (closing === -1) return false;
344
+ if (closing === -1) return null;
353
345
  const directive = code.slice(i + 1, closing);
354
- if (directive === "use client" || directive === "use server") return true;
346
+ if (directive === "use client" || directive === "use server") return directive;
355
347
  i = closing + 1;
356
348
  while (i < len && (code[i] === ";" || code[i] === " " || code[i] === " ")) i++;
357
349
  if (code[i] === "\n") i++;
358
350
  }
359
- return false;
351
+ return null;
352
+ }
353
+ function hasReactDirective(code) {
354
+ return getLeadingReactDirective(code) !== null;
360
355
  }
361
356
  function generateRootParamsModule(rootParamNames) {
362
357
  const names = Array.from(new Set(rootParamNames)).filter(isValidExportIdentifier).sort();
@@ -382,7 +377,9 @@ function generateRootParamsModule(rootParamNames) {
382
377
  const _reactServerShims = new Map([
383
378
  ["next/navigation", "navigation"],
384
379
  ["next/navigation.js", "navigation"],
385
- ["next/dist/client/components/navigation", "navigation"]
380
+ ["next/dist/client/components/navigation", "navigation"],
381
+ ["next/error", "error"],
382
+ ["next/error.js", "error"]
386
383
  ]);
387
384
  const clientManualChunks = createClientManualChunks(_shimsDir);
388
385
  const clientCodeSplittingConfig = createClientCodeSplittingConfig(clientManualChunks);
@@ -438,7 +435,7 @@ function vinext(options = {}) {
438
435
  * __NEXT_DATA__ to determine which page to hydrate.
439
436
  */
440
437
  async function generateClientEntry$1() {
441
- const appPrefetchRoutes = hasAppDir ? (await appRouter(appDir, nextConfig?.pageExtensions, fileMatcher)).filter(isLinkPrefetchRoute).map(toLinkPrefetchRoute) : [];
438
+ const appPrefetchRoutes = hasAppDir ? (await appRouter(appDir, nextConfig?.pageExtensions, fileMatcher)).map((route) => isLinkPrefetchRoute(route) ? toLinkPrefetchRoute(route) : toDocumentOnlyAppRoute(route)) : [];
442
439
  return generateClientEntry(pagesDir, nextConfig, fileMatcher, {
443
440
  appPrefetchRoutes,
444
441
  instrumentationClientPath
@@ -560,7 +557,7 @@ function vinext(options = {}) {
560
557
  for (const [key, value] of Object.entries(dotenvVars)) if (process.env[key] === void 0) process.env[key] = value;
561
558
  let resolvedNodeEnv;
562
559
  if (mode === "test") resolvedNodeEnv = "test";
563
- else if (env?.command === "build") resolvedNodeEnv = "production";
560
+ else if (env?.command === "build" || env?.isPreview === true) resolvedNodeEnv = "production";
564
561
  else resolvedNodeEnv = "development";
565
562
  if (process.env.NODE_ENV !== resolvedNodeEnv) process.env.NODE_ENV = resolvedNodeEnv;
566
563
  let baseDir;
@@ -589,7 +586,7 @@ function vinext(options = {}) {
589
586
  }
590
587
  rawConfig = await resolveNextConfigInput(options.nextConfig, phase);
591
588
  } else rawConfig = await loadNextConfig(root, phase);
592
- nextConfig = await resolveNextConfig(rawConfig, root);
589
+ nextConfig = await resolveNextConfig(rawConfig, root, { dev: env?.command === "serve" && env?.isPreview !== true });
593
590
  const sharedBuildId = process.env.__VINEXT_SHARED_BUILD_ID;
594
591
  if (sharedBuildId && sharedBuildId.length > 0) nextConfig = {
595
592
  ...nextConfig,
@@ -617,6 +614,8 @@ function vinext(options = {}) {
617
614
  defines["process.env.__NEXT_CLIENT_ROUTER_STATIC_STALETIME"] = JSON.stringify(String(nextConfig.staleTimes.static));
618
615
  defines["process.env.__VINEXT_PREFETCH_INLINING"] = JSON.stringify(nextConfig.prefetchInlining ? "true" : "false");
619
616
  defines["process.env.__NEXT_GESTURE_TRANSITION"] = JSON.stringify(nextConfig.gestureTransition);
617
+ defines["process.env.__NEXT_APP_NAV_FAIL_HANDLING"] = JSON.stringify(nextConfig.appNavFailHandling);
618
+ defines["process.env.__NEXT_SCROLL_RESTORATION"] = JSON.stringify(nextConfig.scrollRestoration ? "true" : "false");
620
619
  defines["process.env.__VINEXT_TRAILING_SLASH"] = JSON.stringify(nextConfig.trailingSlash ? "true" : "false");
621
620
  defines["process.env.__VINEXT_IMAGE_REMOTE_PATTERNS"] = JSON.stringify(JSON.stringify(nextConfig.images?.remotePatterns ?? []));
622
621
  defines["process.env.__VINEXT_IMAGE_DOMAINS"] = JSON.stringify(JSON.stringify(nextConfig.images?.domains ?? []));
@@ -643,6 +642,7 @@ function vinext(options = {}) {
643
642
  ];
644
643
  defines["process.env.__VINEXT_IMAGE_DEVICE_SIZES"] = JSON.stringify(JSON.stringify(deviceSizes));
645
644
  defines["process.env.__VINEXT_IMAGE_SIZES"] = JSON.stringify(JSON.stringify(imageSizes));
645
+ defines["process.env.__VINEXT_IMAGE_QUALITIES"] = JSON.stringify(JSON.stringify(nextConfig.images?.qualities ?? null));
646
646
  }
647
647
  defines["process.env.__VINEXT_IMAGE_DANGEROUSLY_ALLOW_SVG"] = JSON.stringify(String(nextConfig.images?.dangerouslyAllowSVG ?? false));
648
648
  defines["process.env.__VINEXT_IMAGE_DANGEROUSLY_ALLOW_LOCAL_IP"] = JSON.stringify(String(nextConfig.images?.dangerouslyAllowLocalIP ?? false));
@@ -681,7 +681,6 @@ function vinext(options = {}) {
681
681
  "next/web-vitals": path.join(shimsDir, "web-vitals"),
682
682
  "next/amp": path.join(shimsDir, "amp"),
683
683
  "next/offline": path.join(shimsDir, "offline"),
684
- "next/error": path.join(shimsDir, "error"),
685
684
  "next/constants": path.join(shimsDir, "constants"),
686
685
  "next/dist/shared/lib/app-router-context.shared-runtime": path.join(shimsDir, "internal", "app-router-context"),
687
686
  "next/dist/shared/lib/app-router-context": path.join(shimsDir, "internal", "app-router-context"),
@@ -791,7 +790,6 @@ function vinext(options = {}) {
791
790
  ...nextConfig.aliases,
792
791
  ...nextShimMap
793
792
  },
794
- extensions: buildViteResolveExtensions(nextConfig.pageExtensions),
795
793
  dedupe: [
796
794
  "react",
797
795
  "react-dom",
@@ -803,12 +801,15 @@ function vinext(options = {}) {
803
801
  ...viteMajorVersion >= 8 ? { oxc: { jsx: { runtime: "automatic" } } } : { esbuild: { jsx: "automatic" } },
804
802
  define: defines,
805
803
  ...nextConfig.basePath ? { base: nextConfig.basePath + "/" } : {},
806
- ...nextConfig.assetPrefix ? { experimental: { renderBuiltUrl: (filename) => {
807
- const urlPrefix = resolveAssetUrlPrefix(nextConfig.assetPrefix);
808
- const dirPrefix = resolveAssetsDir(nextConfig.assetPrefix) + "/";
809
- return urlPrefix + (filename.startsWith(dirPrefix) ? filename.slice(dirPrefix.length) : filename.startsWith(`_next/static/`) ? filename.slice(ASSET_PREFIX_URL_DIR.length + 1) : filename);
810
- } } } : {},
804
+ ...nextConfig.assetPrefix || nextConfig.deploymentId ? { experimental: { renderBuiltUrl: (filename, context) => renderVinextBuiltUrl(filename, nextConfig.assetPrefix, nextConfig.deploymentId, context.hostType) } } : {},
811
805
  css: {
806
+ ...nextConfig.useLightningcss ? {
807
+ transformer: "lightningcss",
808
+ lightningcss: {
809
+ ...nextConfig.lightningCssFeatures.include ? { include: nextConfig.lightningCssFeatures.include } : {},
810
+ ...nextConfig.lightningCssFeatures.exclude ? { exclude: nextConfig.lightningCssFeatures.exclude } : {}
811
+ }
812
+ } : {},
812
813
  ...postcssOverride ? { postcss: postcssOverride } : {},
813
814
  preprocessorOptions: (() => {
814
815
  const tildeImporter = createSassTildeImporter(root);
@@ -966,8 +967,29 @@ function vinext(options = {}) {
966
967
  };
967
968
  return viteConfig;
968
969
  },
969
- configResolved(config) {
970
+ configEnvironment(name, config) {
971
+ const configuredExtensions = name === "client" ? nextConfig.resolveExtensions : nextConfig.serverResolveExtensions;
972
+ const extensions = configuredExtensions === null ? buildViteResolveExtensions(nextConfig.pageExtensions, config.resolve?.extensions) : normalizeViteResolveExtensions(configuredExtensions);
973
+ config.resolve ??= {};
974
+ config.resolve.extensions = extensions;
975
+ return null;
976
+ },
977
+ async configResolved(config) {
970
978
  sassComposesLoader.setResolvedConfig(config);
979
+ if (config.command === "build" && hasAppDir && hasPagesDir) {
980
+ const [appRoutes, pageRoutes, apiRoutes] = await Promise.all([
981
+ appRouter(appDir, nextConfig?.pageExtensions, fileMatcher),
982
+ pagesRouter(pagesDir, nextConfig?.pageExtensions, fileMatcher),
983
+ apiRouter(pagesDir, nextConfig?.pageExtensions, fileMatcher)
984
+ ]);
985
+ validateHybridRouteConflicts([...pageRoutes, ...apiRoutes].map((route) => ({
986
+ ...route,
987
+ sourcePath: path.relative(root, route.filePath)
988
+ })), appRoutes.filter((route) => route.pagePath !== null || route.routePath !== null).map((route) => ({
989
+ ...route,
990
+ sourcePath: path.relative(root, route.pagePath ?? route.routePath)
991
+ })));
992
+ }
971
993
  if (hasAppDir) {
972
994
  const ssrEnv = config.environments?.ssr;
973
995
  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));
@@ -989,10 +1011,11 @@ function vinext(options = {}) {
989
1011
  }));
990
1012
  },
991
1013
  resolveId: {
992
- filter: { id: /(?:next\/|virtual:vinext-|^@vercel\/og(?:\.js)?$)/ },
1014
+ filter: { id: /(?:next\/|vinext\/shims\/|virtual:vinext-|@vercel\/og(?:\.js)?$)/ },
993
1015
  handler(id, importer) {
994
1016
  const cleanId = id.startsWith("\0") ? id.slice(1) : id;
995
1017
  if (isVercelOgImport(cleanId) && !isVinextOgShimImporter(importer)) return resolveShimModulePath(_shimsDir, "og");
1018
+ if (cleanId.startsWith("vinext/shims/")) return resolveShimModulePath(_shimsDir, stripJsExtension(stripViteModuleQuery(cleanId.slice(13))));
996
1019
  if (cleanId === VIRTUAL_SERVER_ENTRY) return RESOLVED_SERVER_ENTRY;
997
1020
  if (cleanId === VIRTUAL_CLIENT_ENTRY) return RESOLVED_CLIENT_ENTRY;
998
1021
  if (cleanId.endsWith("/virtual:vinext-server-entry") || cleanId.endsWith("\\virtual:vinext-server-entry")) return RESOLVED_SERVER_ENTRY;
@@ -1038,7 +1061,13 @@ function vinext(options = {}) {
1038
1061
  reactMaxHeadersLength: nextConfig?.reactMaxHeadersLength,
1039
1062
  cacheMaxMemorySize: nextConfig?.cacheMaxMemorySize,
1040
1063
  inlineCss: nextConfig?.inlineCss,
1064
+ cacheComponents: nextConfig?.cacheComponents,
1041
1065
  i18n: nextConfig?.i18n,
1066
+ imageConfig: {
1067
+ deviceSizes: nextConfig?.images?.deviceSizes,
1068
+ imageSizes: nextConfig?.images?.imageSizes,
1069
+ qualities: nextConfig?.images?.qualities
1070
+ },
1042
1071
  hasPagesDir,
1043
1072
  publicFiles: scanPublicFileRoutes(root),
1044
1073
  globalNotFoundPath,
@@ -1050,7 +1079,17 @@ function vinext(options = {}) {
1050
1079
  if (id === RESOLVED_APP_SSR_ENTRY && hasAppDir) return generateSsrEntry(hasPagesDir);
1051
1080
  if (id === RESOLVED_APP_BROWSER_ENTRY && hasAppDir) {
1052
1081
  const graph = await appRouteGraph(appDir, nextConfig?.pageExtensions, fileMatcher);
1053
- return generateBrowserEntry(graph.routes, graph.routeManifest);
1082
+ const pagesPrefetchRoutes = hasPagesDir ? [...(await pagesRouter(pagesDir, nextConfig?.pageExtensions, fileMatcher)).map((route) => ({
1083
+ canPrefetchLoadingShell: false,
1084
+ isDynamic: route.isDynamic,
1085
+ patternParts: [...route.patternParts]
1086
+ })), ...(await apiRouter(pagesDir, nextConfig?.pageExtensions, fileMatcher)).map((route) => ({
1087
+ canPrefetchLoadingShell: false,
1088
+ documentOnly: true,
1089
+ isDynamic: route.isDynamic,
1090
+ patternParts: [...route.patternParts]
1091
+ }))] : [];
1092
+ return generateBrowserEntry(graph.routes, graph.routeManifest, pagesPrefetchRoutes, nextConfig.rewrites);
1054
1093
  }
1055
1094
  if (id.startsWith("\0virtual:vinext-google-fonts?")) return generateGoogleFontsVirtualModule(id, _fontGoogleShimPath);
1056
1095
  },
@@ -1257,11 +1296,65 @@ function vinext(options = {}) {
1257
1296
  if (mod) env.moduleGraph.invalidateModule(mod);
1258
1297
  }
1259
1298
  }
1299
+ function invalidateHybridClientEntries() {
1300
+ if (!hasAppDir || !hasPagesDir) return;
1301
+ for (const env of Object.values(server.environments)) for (const id of [RESOLVED_CLIENT_ENTRY, RESOLVED_APP_BROWSER_ENTRY]) {
1302
+ const mod = env.moduleGraph.getModuleById(id);
1303
+ if (mod) env.moduleGraph.invalidateModule(mod);
1304
+ }
1305
+ server.ws.send({ type: "full-reload" });
1306
+ }
1307
+ function invalidatePagesServerEntry() {
1308
+ for (const env of Object.values(server.environments)) {
1309
+ const mod = env.moduleGraph.getModuleById(RESOLVED_SERVER_ENTRY);
1310
+ if (mod) env.moduleGraph.invalidateModule(mod);
1311
+ }
1312
+ pagesRunner?.clearCache();
1313
+ }
1260
1314
  function invalidateAppRoutingModules() {
1261
1315
  invalidateAppRouteCache();
1262
1316
  invalidateRscEntryModule();
1263
1317
  invalidateRootParamsModule();
1264
1318
  }
1319
+ let hybridRouteValidation = Promise.resolve();
1320
+ let hybridRouteValidationError = null;
1321
+ function sendHybridRouteValidationError(error) {
1322
+ server.ws.send({
1323
+ type: "error",
1324
+ err: {
1325
+ message: error.message,
1326
+ stack: error.stack ?? error.message
1327
+ }
1328
+ });
1329
+ }
1330
+ server.ws.on("connection", () => {
1331
+ if (hybridRouteValidationError) sendHybridRouteValidationError(hybridRouteValidationError);
1332
+ });
1333
+ function revalidateHybridRoutes() {
1334
+ if (!hasAppDir || !hasPagesDir) return;
1335
+ hybridRouteValidation = hybridRouteValidation.catch(() => {}).then(async () => {
1336
+ const [appRoutes, pageRoutes, apiRoutes] = await Promise.all([
1337
+ appRouter(appDir, nextConfig?.pageExtensions, fileMatcher),
1338
+ pagesRouter(pagesDir, nextConfig?.pageExtensions, fileMatcher),
1339
+ apiRouter(pagesDir, nextConfig?.pageExtensions, fileMatcher)
1340
+ ]);
1341
+ validateHybridRouteConflicts([...pageRoutes, ...apiRoutes].map((route) => ({
1342
+ ...route,
1343
+ sourcePath: path.relative(root, route.filePath)
1344
+ })), appRoutes.filter((route) => route.pagePath !== null || route.routePath !== null).map((route) => ({
1345
+ ...route,
1346
+ sourcePath: path.relative(root, route.pagePath ?? route.routePath)
1347
+ })));
1348
+ if (hybridRouteValidationError) {
1349
+ hybridRouteValidationError = null;
1350
+ server.ws.send({ type: "full-reload" });
1351
+ }
1352
+ }).catch((error) => {
1353
+ const err = error instanceof Error ? error : new Error(String(error));
1354
+ hybridRouteValidationError = err;
1355
+ sendHybridRouteValidationError(err);
1356
+ });
1357
+ }
1265
1358
  let appRouteTypeGeneration = null;
1266
1359
  let appRouteTypeGenerationPending = false;
1267
1360
  function warnRouteTypeGenerationFailure(error) {
@@ -1286,21 +1379,42 @@ function vinext(options = {}) {
1286
1379
  });
1287
1380
  }
1288
1381
  regenerateAppRouteTypes();
1382
+ revalidateHybridRoutes();
1289
1383
  server.httpServer?.on("connection", (socket) => {
1290
1384
  socket.on("error", () => {});
1291
1385
  });
1292
1386
  server.watcher.on("add", (filePath) => {
1293
- if (hasPagesDir && filePath.startsWith(pagesDir) && pageExtensions.test(filePath)) invalidateRouteCache(pagesDir);
1387
+ let routeChanged = false;
1388
+ if (hasPagesDir && filePath.startsWith(pagesDir) && pageExtensions.test(filePath)) {
1389
+ invalidateRouteCache(pagesDir);
1390
+ routeChanged = true;
1391
+ }
1294
1392
  if (hasAppDir && shouldInvalidateAppRouteFile(appDir, filePath, fileMatcher)) {
1295
1393
  invalidateAppRoutingModules();
1296
1394
  regenerateAppRouteTypes();
1395
+ routeChanged = true;
1396
+ }
1397
+ if (routeChanged) {
1398
+ invalidatePagesServerEntry();
1399
+ invalidateHybridClientEntries();
1400
+ revalidateHybridRoutes();
1297
1401
  }
1298
1402
  });
1299
1403
  server.watcher.on("unlink", (filePath) => {
1300
- if (hasPagesDir && filePath.startsWith(pagesDir) && pageExtensions.test(filePath)) invalidateRouteCache(pagesDir);
1404
+ let routeChanged = false;
1405
+ if (hasPagesDir && filePath.startsWith(pagesDir) && pageExtensions.test(filePath)) {
1406
+ invalidateRouteCache(pagesDir);
1407
+ routeChanged = true;
1408
+ }
1301
1409
  if (hasAppDir && shouldInvalidateAppRouteFile(appDir, filePath, fileMatcher)) {
1302
1410
  invalidateAppRoutingModules();
1303
1411
  regenerateAppRouteTypes();
1412
+ routeChanged = true;
1413
+ }
1414
+ if (routeChanged) {
1415
+ invalidatePagesServerEntry();
1416
+ invalidateHybridClientEntries();
1417
+ revalidateHybridRoutes();
1304
1418
  }
1305
1419
  });
1306
1420
  server.middlewares.use((req, res, next) => {
@@ -1377,6 +1491,7 @@ function vinext(options = {}) {
1377
1491
  const handlePagesMiddleware = async (req, res, next) => {
1378
1492
  try {
1379
1493
  let url = req.url ?? "/";
1494
+ const originalRequestUrl = url;
1380
1495
  if (!hasPagesDir) return next();
1381
1496
  if (url.startsWith("/@") || url.startsWith("/__vite") || url.startsWith("/node_modules")) return next();
1382
1497
  if (url.split("?")[0].endsWith(".rsc")) return next();
@@ -1394,20 +1509,12 @@ function vinext(options = {}) {
1394
1509
  return;
1395
1510
  }
1396
1511
  if (isImageOptimizationPath(url.split("?")[0])) {
1397
- const rawImgUrl = new URLSearchParams(url.split("?")[1] ?? "").get("url");
1398
- const imgUrl = rawImgUrl?.replaceAll("\\", "/") ?? null;
1399
- if (!imgUrl || !imgUrl.startsWith("/") || imgUrl.startsWith("//") || imgUrl.startsWith("/@") || imgUrl.startsWith("/__vite") || imgUrl.startsWith("/node_modules")) {
1400
- res.writeHead(400);
1401
- res.end(!rawImgUrl ? "Missing url parameter" : "Only relative URLs allowed");
1402
- return;
1403
- }
1404
- const resolvedImg = new URL(imgUrl, `http://${req.headers.host || "localhost"}`);
1405
- if (resolvedImg.origin !== `http://${req.headers.host || "localhost"}`) {
1512
+ const encodedLocation = resolveDevImageRedirect(new URL(url, `http://${req.headers.host || "localhost"}`), [...nextConfig.images?.deviceSizes ?? DEFAULT_DEVICE_SIZES, ...nextConfig.images?.imageSizes ?? DEFAULT_IMAGE_SIZES], nextConfig.images?.qualities);
1513
+ if (!encodedLocation) {
1406
1514
  res.writeHead(400);
1407
- res.end("Only relative URLs allowed");
1515
+ res.end("Invalid image optimization parameters");
1408
1516
  return;
1409
1517
  }
1410
- const encodedLocation = resolvedImg.pathname + resolvedImg.search;
1411
1518
  res.writeHead(302, { Location: encodedLocation });
1412
1519
  res.end();
1413
1520
  return;
@@ -1470,7 +1577,7 @@ function vinext(options = {}) {
1470
1577
  }
1471
1578
  if (pathname.includes(".") && !pathname.endsWith(".html")) return next();
1472
1579
  if (hasCloudflarePlugin) return next();
1473
- const rawHeaders = new Headers(Object.fromEntries(Object.entries(req.headers).filter(([, v]) => v !== void 0).map(([k, v]) => [k, Array.isArray(v) ? v.join(", ") : String(v)])));
1580
+ const rawHeaders = new Headers(Object.fromEntries(Object.entries(req.headers).filter(([k, v]) => v !== void 0 && !k.startsWith(":")).map(([k, v]) => [k, Array.isArray(v) ? v.join(", ") : String(v)])));
1474
1581
  const isDataRequest = rawHeaders.get("x-nextjs-data") === "1";
1475
1582
  const nodeRequestHeaders = filterInternalHeaders(rawHeaders);
1476
1583
  for (const header of INTERNAL_HEADERS) delete req.headers[header];
@@ -1559,12 +1666,22 @@ function vinext(options = {}) {
1559
1666
  };
1560
1667
  if (pipelineResult.type === "api") {
1561
1668
  const apiRoutes = await apiRouter(pagesDir, nextConfig?.pageExtensions, fileMatcher);
1562
- if (matchRoute(pipelineResult.apiUrl, apiRoutes)) {
1669
+ const apiMatch = matchRoute(pipelineResult.apiUrl, apiRoutes);
1670
+ if (apiMatch && hasAppDir && appDir) {
1671
+ const appRoutes = await appRouter(appDir, nextConfig?.pageExtensions, fileMatcher);
1672
+ const appMatch = matchAppRoute(pipelineResult.apiUrl, appRoutes);
1673
+ if (appMatch && !pagesRouteHasPriorityOverAppRoute(apiMatch.route, appMatch.route)) return next();
1674
+ }
1675
+ if (apiMatch) {
1563
1676
  flushStagedHeaders();
1564
1677
  flushRequestHeaders();
1565
1678
  if (pipelineResult.middlewareStatus !== void 0) req.__vinextMiddlewareStatus = pipelineResult.middlewareStatus;
1566
1679
  }
1567
- if (await handleApiRoute(getPagesRunner(), req, res, pipelineResult.apiUrl, apiRoutes)) return;
1680
+ if (await handleApiRoute(getPagesRunner(), req, res, pipelineResult.apiUrl, apiRoutes, {
1681
+ basePath: nextConfig?.basePath,
1682
+ i18n: nextConfig?.i18n,
1683
+ trailingSlash: nextConfig?.trailingSlash
1684
+ })) return;
1568
1685
  if (hasAppDir) return next();
1569
1686
  res.statusCode = 404;
1570
1687
  res.end("404 - API route not found");
@@ -1572,13 +1689,19 @@ function vinext(options = {}) {
1572
1689
  }
1573
1690
  {
1574
1691
  const routes = await pagesRouter(pagesDir, nextConfig?.pageExtensions, fileMatcher);
1575
- if (!matchRoute(pipelineResult.resolvedUrl.split("?")[0], routes) && hasAppDir) return next();
1576
- const handler = createSSRHandler(server, getPagesRunner(), routes, pagesDir, nextConfig?.i18n, fileMatcher, nextConfig?.basePath ?? "", nextConfig?.trailingSlash ?? false, middlewarePath !== null, (nextConfig?.rewrites.beforeFiles.length ?? 0) > 0 || (nextConfig?.rewrites.afterFiles.length ?? 0) > 0 || (nextConfig?.rewrites.fallback.length ?? 0) > 0, nextConfig?.clientTraceMetadata);
1692
+ const resolvedPathname = pipelineResult.resolvedUrl.split("#", 1)[0].split("?", 1)[0];
1693
+ const renderMatch = matchRoute(resolvedPathname, routes);
1694
+ if (hasAppDir && appDir) {
1695
+ if (!renderMatch) return next();
1696
+ const appMatch = matchAppRoute(resolvedPathname, await appRouter(appDir, nextConfig?.pageExtensions, fileMatcher));
1697
+ if (appMatch && !pagesRouteHasPriorityOverAppRoute(renderMatch.route, appMatch.route)) return next();
1698
+ }
1699
+ const handler = createSSRHandler(server, getPagesRunner(), routes, pagesDir, nextConfig?.i18n, fileMatcher, nextConfig?.basePath ?? "", nextConfig?.trailingSlash ?? false, middlewarePath !== null, (nextConfig?.rewrites.beforeFiles.length ?? 0) > 0 || (nextConfig?.rewrites.afterFiles.length ?? 0) > 0 || (nextConfig?.rewrites.fallback.length ?? 0) > 0, nextConfig?.clientTraceMetadata, nextConfig?.htmlLimitedBots);
1577
1700
  flushStagedHeaders();
1578
1701
  flushRequestHeaders();
1579
1702
  if (pipelineResult.middlewareStatus !== void 0) req.__vinextMiddlewareStatus = pipelineResult.middlewareStatus;
1580
1703
  req.url = pipelineResult.resolvedUrl;
1581
- await handler(req, res, pipelineResult.resolvedUrl, req.__vinextMiddlewareStatus, pipelineResult.isDataReq);
1704
+ await handler(req, res, pipelineResult.resolvedUrl, req.__vinextMiddlewareStatus, pipelineResult.isDataReq, originalRequestUrl);
1582
1705
  }
1583
1706
  } catch (e) {
1584
1707
  next(e);
@@ -1600,6 +1723,7 @@ function vinext(options = {}) {
1600
1723
  handler(code, id) {
1601
1724
  if (this.environment?.name !== "client") return null;
1602
1725
  if (id.startsWith("\0")) return null;
1726
+ if (getLeadingReactDirective(code) === "use server") return null;
1603
1727
  if (!hasServerOnlyMarkerImport(code)) return null;
1604
1728
  throw new Error(`You're importing a module that depends on "server-only". This API is only available in Server Components in the App Router, but this module is reachable from a client bundle.`);
1605
1729
  }
@@ -1643,6 +1767,16 @@ function vinext(options = {}) {
1643
1767
  }
1644
1768
  }
1645
1769
  },
1770
+ {
1771
+ name: "vinext:typeof-window",
1772
+ enforce: "post",
1773
+ transform: {
1774
+ filter: { code: /typeof\s+window/ },
1775
+ handler(code) {
1776
+ return replaceTypeofWindow(code, getTypeofWindowReplacement(this.environment));
1777
+ }
1778
+ }
1779
+ },
1646
1780
  {
1647
1781
  name: "vinext:compiler-define-server",
1648
1782
  configEnvironment(name) {
@@ -1845,6 +1979,7 @@ function vinext(options = {}) {
1845
1979
  }
1846
1980
  },
1847
1981
  createImportMetaUrlPlugin({ getRoot: () => root }),
1982
+ createExtensionlessDynamicImportPlugin(),
1848
1983
  createRequireContextPlugin(),
1849
1984
  createOgInlineFetchAssetsPlugin(),
1850
1985
  createOgAssetsPlugin(),
@@ -1861,6 +1996,9 @@ function vinext(options = {}) {
1861
1996
  const outDir = options.dir;
1862
1997
  if (!outDir) return;
1863
1998
  const imageConfig = {
1999
+ deviceSizes: nextConfig?.images?.deviceSizes,
2000
+ imageSizes: nextConfig?.images?.imageSizes,
2001
+ qualities: nextConfig?.images?.qualities,
1864
2002
  dangerouslyAllowSVG: nextConfig?.images?.dangerouslyAllowSVG,
1865
2003
  contentDispositionType: nextConfig?.images?.contentDispositionType,
1866
2004
  contentSecurityPolicy: nextConfig?.images?.contentSecurityPolicy
@@ -0,0 +1,6 @@
1
+ import { Plugin } from "vite";
2
+
3
+ //#region src/plugins/extensionless-dynamic-import.d.ts
4
+ declare function createExtensionlessDynamicImportPlugin(): Plugin;
5
+ //#endregion
6
+ export { createExtensionlessDynamicImportPlugin };