@qzsy/vinext 0.1.11 → 0.1.80

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 (225) hide show
  1. package/README.md +19 -5
  2. package/dist/build/inject-pregenerated-paths.d.ts +4 -0
  3. package/dist/build/inject-pregenerated-paths.js +18 -0
  4. package/dist/build/pages-client-assets-module.d.ts +11 -0
  5. package/dist/build/pages-client-assets-module.js +27 -0
  6. package/dist/build/prerender.d.ts +2 -1
  7. package/dist/build/prerender.js +11 -4
  8. package/dist/build/report.d.ts +2 -1
  9. package/dist/build/report.js +2 -1
  10. package/dist/build/run-prerender.d.ts +7 -0
  11. package/dist/build/run-prerender.js +9 -0
  12. package/dist/build/standalone.js +2 -0
  13. package/dist/check.d.ts +18 -0
  14. package/dist/check.js +77 -19
  15. package/dist/cli-dev-config.d.ts +12 -0
  16. package/dist/cli-dev-config.js +23 -0
  17. package/dist/cli.js +64 -28
  18. package/dist/{server → client}/dev-error-overlay-store.d.ts +1 -1
  19. package/dist/{server → client}/dev-error-overlay-store.js +1 -1
  20. package/dist/{server → client}/dev-error-overlay.d.ts +1 -1
  21. package/dist/{server → client}/dev-error-overlay.js +2 -2
  22. package/dist/cloudflare/deploy-config.d.ts +51 -0
  23. package/dist/cloudflare/deploy-config.js +153 -0
  24. package/dist/cloudflare/index.d.ts +1 -1
  25. package/dist/cloudflare/index.js +1 -1
  26. package/dist/cloudflare/project.d.ts +41 -0
  27. package/dist/cloudflare/project.js +243 -0
  28. package/dist/cloudflare/tpr.js +1 -1
  29. package/dist/config/config-matchers.js +14 -10
  30. package/dist/config/next-config.d.ts +6 -3
  31. package/dist/config/next-config.js +47 -1
  32. package/dist/config/server-external-packages.d.ts +4 -0
  33. package/dist/config/server-external-packages.js +91 -0
  34. package/dist/deploy.d.ts +2 -122
  35. package/dist/deploy.js +20 -793
  36. package/dist/entries/app-rsc-entry.d.ts +2 -1
  37. package/dist/entries/app-rsc-entry.js +70 -12
  38. package/dist/entries/app-rsc-manifest.js +8 -0
  39. package/dist/entries/pages-client-entry.d.ts +1 -0
  40. package/dist/entries/pages-client-entry.js +2 -1
  41. package/dist/entries/pages-server-entry.js +6 -2
  42. package/dist/image/image-adapters-virtual.d.ts +59 -0
  43. package/dist/image/image-adapters-virtual.js +50 -0
  44. package/dist/index.d.ts +12 -0
  45. package/dist/index.js +158 -109
  46. package/dist/init-cloudflare.d.ts +43 -0
  47. package/dist/init-cloudflare.js +1000 -0
  48. package/dist/init-platform.d.ts +38 -0
  49. package/dist/init-platform.js +150 -0
  50. package/dist/init.d.ts +14 -37
  51. package/dist/init.js +205 -95
  52. package/dist/node_modules/.pnpm/am-i-vibing@0.5.0/node_modules/am-i-vibing/dist/detector-1yx2Hoe0.js +294 -0
  53. package/dist/node_modules/.pnpm/process-ancestry@0.1.0/node_modules/process-ancestry/dist/index.js +94 -0
  54. package/dist/{cloudflare → packages/cloudflare}/src/cache/cdn-adapter.runtime.js +1 -1
  55. package/dist/{cloudflare → packages/cloudflare}/src/cache/kv-data-adapter.runtime.d.ts +2 -2
  56. package/dist/{cloudflare → packages/cloudflare}/src/cache/kv-data-adapter.runtime.js +1 -1
  57. package/dist/plugins/ast-scope.d.ts +16 -0
  58. package/dist/plugins/ast-scope.js +62 -0
  59. package/dist/plugins/ast-utils.js +3 -0
  60. package/dist/plugins/css-module-imports.d.ts +14 -0
  61. package/dist/plugins/css-module-imports.js +59 -0
  62. package/dist/plugins/ignore-dynamic-requests.d.ts +11 -0
  63. package/dist/plugins/ignore-dynamic-requests.js +530 -0
  64. package/dist/plugins/middleware-server-only.d.ts +8 -6
  65. package/dist/plugins/middleware-server-only.js +8 -7
  66. package/dist/plugins/optimize-imports.js +1 -1
  67. package/dist/plugins/typeof-window.d.ts +1 -1
  68. package/dist/plugins/typeof-window.js +28 -56
  69. package/dist/routing/app-route-graph.d.ts +13 -2
  70. package/dist/routing/app-route-graph.js +116 -32
  71. package/dist/routing/app-router.d.ts +5 -0
  72. package/dist/routing/app-router.js +5 -0
  73. package/dist/routing/file-matcher.d.ts +8 -0
  74. package/dist/routing/file-matcher.js +10 -1
  75. package/dist/routing/pages-router.js +2 -2
  76. package/dist/server/app-browser-action-result.d.ts +2 -1
  77. package/dist/server/app-browser-action-result.js +5 -1
  78. package/dist/server/app-browser-entry.js +17 -12
  79. package/dist/server/app-browser-history-controller.d.ts +2 -1
  80. package/dist/server/app-browser-history-controller.js +6 -2
  81. package/dist/server/app-browser-interception-context.d.ts +1 -0
  82. package/dist/server/app-browser-interception-context.js +4 -2
  83. package/dist/server/app-browser-navigation-controller.js +1 -0
  84. package/dist/server/app-browser-server-action-client.js +2 -3
  85. package/dist/server/app-browser-state.d.ts +1 -0
  86. package/dist/server/app-browser-state.js +3 -2
  87. package/dist/server/app-fallback-renderer.d.ts +3 -2
  88. package/dist/server/app-fallback-renderer.js +12 -7
  89. package/dist/server/app-middleware.d.ts +2 -3
  90. package/dist/server/app-middleware.js +3 -2
  91. package/dist/server/app-optimistic-routing.js +1 -1
  92. package/dist/server/app-page-boundary-render.d.ts +1 -0
  93. package/dist/server/app-page-boundary-render.js +12 -3
  94. package/dist/server/app-page-cache-finalizer.d.ts +1 -0
  95. package/dist/server/app-page-cache-finalizer.js +10 -3
  96. package/dist/server/app-page-cache-render.d.ts +1 -0
  97. package/dist/server/app-page-cache-render.js +8 -4
  98. package/dist/server/app-page-cache.d.ts +1 -0
  99. package/dist/server/app-page-cache.js +4 -1
  100. package/dist/server/app-page-dispatch.d.ts +11 -3
  101. package/dist/server/app-page-dispatch.js +55 -15
  102. package/dist/server/app-page-element-builder.d.ts +5 -1
  103. package/dist/server/app-page-element-builder.js +57 -20
  104. package/dist/server/app-page-head.d.ts +12 -0
  105. package/dist/server/app-page-head.js +42 -19
  106. package/dist/server/app-page-params.d.ts +2 -1
  107. package/dist/server/app-page-params.js +8 -1
  108. package/dist/server/app-page-probe.d.ts +1 -0
  109. package/dist/server/app-page-probe.js +6 -1
  110. package/dist/server/app-page-render-identity.d.ts +1 -0
  111. package/dist/server/app-page-render-identity.js +1 -1
  112. package/dist/server/app-page-render.d.ts +4 -1
  113. package/dist/server/app-page-render.js +8 -3
  114. package/dist/server/app-page-request.d.ts +22 -1
  115. package/dist/server/app-page-request.js +89 -13
  116. package/dist/server/app-page-route-wiring.d.ts +6 -1
  117. package/dist/server/app-page-route-wiring.js +31 -15
  118. package/dist/server/app-page-search-params-observation.d.ts +4 -2
  119. package/dist/server/app-page-search-params-observation.js +11 -7
  120. package/dist/server/app-page-segment-state.js +2 -0
  121. package/dist/server/app-route-handler-dispatch.js +1 -0
  122. package/dist/server/app-route-handler-execution.js +7 -2
  123. package/dist/server/app-route-handler-response.js +1 -0
  124. package/dist/server/app-route-handler-runtime.js +1 -1
  125. package/dist/server/app-route-module-loader.d.ts +2 -0
  126. package/dist/server/app-route-module-loader.js +1 -0
  127. package/dist/server/app-router-entry.d.ts +12 -0
  128. package/dist/server/app-router-entry.js +22 -8
  129. package/dist/server/app-router-image-optimization.d.ts +37 -0
  130. package/dist/server/app-router-image-optimization.js +40 -0
  131. package/dist/server/app-rsc-errors.js +7 -1
  132. package/dist/server/app-rsc-handler.js +27 -14
  133. package/dist/server/app-rsc-route-matching.d.ts +7 -0
  134. package/dist/server/app-rsc-route-matching.js +36 -3
  135. package/dist/server/app-segment-config.d.ts +12 -0
  136. package/dist/server/app-segment-config.js +91 -5
  137. package/dist/server/app-server-action-execution.d.ts +5 -0
  138. package/dist/server/app-server-action-execution.js +94 -33
  139. package/dist/server/app-ssr-entry.js +12 -1
  140. package/dist/server/app-static-generation.d.ts +1 -0
  141. package/dist/server/app-static-generation.js +1 -0
  142. package/dist/server/client-trace-metadata.js +26 -0
  143. package/dist/server/default-global-not-found-module.d.ts +14 -0
  144. package/dist/server/default-global-not-found-module.js +14 -0
  145. package/dist/server/dev-server.js +8 -15
  146. package/dist/server/dev-stack-sourcemap.d.ts +1 -1
  147. package/dist/server/dev-stack-sourcemap.js +1 -1
  148. package/dist/server/headers.d.ts +5 -15
  149. package/dist/server/headers.js +4 -15
  150. package/dist/server/image-optimization.d.ts +51 -1
  151. package/dist/server/image-optimization.js +52 -2
  152. package/dist/server/isr-cache.d.ts +1 -1
  153. package/dist/server/isr-cache.js +2 -2
  154. package/dist/server/middleware-runtime.js +6 -1
  155. package/dist/server/navigation-planner.d.ts +1 -0
  156. package/dist/server/navigation-planner.js +14 -3
  157. package/dist/server/pages-asset-tags.d.ts +4 -6
  158. package/dist/server/pages-asset-tags.js +12 -12
  159. package/dist/server/pages-client-assets.d.ts +12 -0
  160. package/dist/server/pages-client-assets.js +10 -0
  161. package/dist/server/pages-page-data.d.ts +23 -1
  162. package/dist/server/pages-page-data.js +43 -24
  163. package/dist/server/pages-page-handler.d.ts +2 -1
  164. package/dist/server/pages-page-handler.js +10 -4
  165. package/dist/server/pages-request-pipeline.d.ts +2 -0
  166. package/dist/server/pages-request-pipeline.js +25 -1
  167. package/dist/server/prerender-manifest.d.ts +3 -1
  168. package/dist/server/prerender-route-params.js +1 -1
  169. package/dist/server/prod-server.d.ts +1 -1
  170. package/dist/server/prod-server.js +47 -25
  171. package/dist/server/request-pipeline.js +1 -0
  172. package/dist/server/seed-cache.js +4 -4
  173. package/dist/server/worker-utils.d.ts +2 -1
  174. package/dist/server/worker-utils.js +7 -1
  175. package/dist/shims/app-router-scroll-state.d.ts +1 -0
  176. package/dist/shims/app-router-scroll-state.js +1 -0
  177. package/dist/shims/app-router-scroll.js +2 -1
  178. package/dist/shims/cache.js +19 -15
  179. package/dist/shims/cdn-cache.js +1 -1
  180. package/dist/shims/dynamic-preload-chunks.js +2 -1
  181. package/dist/shims/error-boundary.d.ts +19 -1
  182. package/dist/shims/error-boundary.js +11 -1
  183. package/dist/shims/form.d.ts +3 -1
  184. package/dist/shims/form.js +37 -43
  185. package/dist/shims/headers.d.ts +9 -1
  186. package/dist/shims/headers.js +31 -6
  187. package/dist/shims/image-optimization-url.d.ts +4 -0
  188. package/dist/shims/image-optimization-url.js +33 -1
  189. package/dist/shims/image.js +46 -13
  190. package/dist/shims/internal/app-route-detection.d.ts +2 -17
  191. package/dist/shims/internal/app-route-detection.js +4 -17
  192. package/dist/shims/internal/hybrid-client-route-owner-direct.d.ts +23 -0
  193. package/dist/shims/internal/hybrid-client-route-owner-direct.js +51 -0
  194. package/dist/shims/internal/hybrid-client-route-owner.d.ts +2 -5
  195. package/dist/shims/internal/hybrid-client-route-owner.js +9 -60
  196. package/dist/shims/internal/pages-router-components.d.ts +7 -0
  197. package/dist/shims/internal/pages-router-components.js +13 -0
  198. package/dist/shims/link.js +23 -16
  199. package/dist/shims/metadata.d.ts +3 -2
  200. package/dist/shims/metadata.js +8 -4
  201. package/dist/shims/navigation.js +4 -2
  202. package/dist/shims/root-params.d.ts +15 -1
  203. package/dist/shims/root-params.js +21 -1
  204. package/dist/shims/router.d.ts +2 -5
  205. package/dist/shims/router.js +41 -22
  206. package/dist/shims/server.js +3 -2
  207. package/dist/typegen.js +6 -5
  208. package/dist/utils/client-runtime-metadata.d.ts +2 -18
  209. package/dist/utils/client-runtime-metadata.js +31 -22
  210. package/dist/utils/dev-stack-sourcemap-endpoint.d.ts +4 -0
  211. package/dist/{server → utils}/dev-stack-sourcemap-endpoint.js +1 -1
  212. package/dist/utils/domain-locale.d.ts +6 -3
  213. package/dist/{server → utils}/middleware-request-headers.d.ts +1 -1
  214. package/dist/{server → utils}/middleware-request-headers.js +2 -2
  215. package/dist/utils/path.d.ts +2 -1
  216. package/dist/utils/path.js +1 -1
  217. package/dist/utils/project.d.ts +9 -1
  218. package/dist/utils/project.js +21 -4
  219. package/dist/utils/protocol-headers.d.ts +17 -0
  220. package/dist/utils/protocol-headers.js +17 -0
  221. package/dist/utils/react-version.d.ts +4 -0
  222. package/dist/utils/react-version.js +44 -0
  223. package/package.json +28 -24
  224. package/dist/server/dev-stack-sourcemap-endpoint.d.ts +0 -4
  225. /package/dist/{cloudflare → packages/cloudflare}/src/utils/cache-control-metadata.js +0 -0
@@ -43,7 +43,8 @@ type AppRouterConfig = {
43
43
  */
44
44
  reactMaxHeadersLength?: number; /** Maximum in-memory cache size in bytes. 0 disables the default memory cache. */
45
45
  cacheMaxMemorySize?: number; /** Inline app CSS into production HTML (from experimental.inlineCss). */
46
- inlineCss?: boolean; /** Enables Next.js Cache Components semantics for App Router document HTML. */
46
+ inlineCss?: boolean; /** Enable standalone route-miss 404 handling (from experimental.globalNotFound). */
47
+ globalNotFound?: boolean; /** Enables Next.js Cache Components semantics for App Router document HTML. */
47
48
  cacheComponents?: boolean; /** Whether the RSC build discovered any server references. Defaults to true. */
48
49
  hasServerActions?: boolean; /** Internationalization routing config for middleware matcher locale handling. */
49
50
  i18n?: NextI18nConfig | null;
@@ -1,6 +1,7 @@
1
1
  import { normalizePathSeparators } from "../utils/path.js";
2
2
  import { resolveEntryPath } from "./runtime-entry-module.js";
3
3
  import { isProxyFile } from "../server/middleware.js";
4
+ import { DEFAULT_DEVICE_SIZES, DEFAULT_IMAGE_SIZES } from "../server/image-optimization.js";
4
5
  import { buildAppRscManifestCode } from "./app-rsc-manifest.js";
5
6
  import { generateDevOriginCheckCode } from "../server/dev-origin-check.js";
6
7
  import { randomUUID } from "node:crypto";
@@ -16,7 +17,7 @@ import { randomUUID } from "node:crypto";
16
17
  */
17
18
  const DEFAULT_EXPIRE_TIME = 31536e3;
18
19
  const DEFAULT_REACT_MAX_HEADERS_LENGTH = 6e3;
19
- const middlewareRequestHeadersPath = resolveEntryPath("../server/middleware-request-headers.js", import.meta.url);
20
+ const middlewareRequestHeadersPath = resolveEntryPath("../utils/middleware-request-headers.js", import.meta.url);
20
21
  const normalizePathModulePath = resolveEntryPath("../server/normalize-path.js", import.meta.url);
21
22
  const appRouteHandlerDispatchPath = resolveEntryPath("../server/app-route-handler-dispatch.js", import.meta.url);
22
23
  const appRouteHandlerResponsePath = resolveEntryPath("../server/app-route-handler-response.js", import.meta.url);
@@ -82,11 +83,19 @@ function generateRscEntry(appDir, routes, middlewarePath, metadataRoutes, global
82
83
  const hasPagesDir = config?.hasPagesDir ?? false;
83
84
  const publicFiles = config?.publicFiles ?? [];
84
85
  const draftModeSecret = config?.draftModeSecret ?? randomUUID();
86
+ const imageAllowedWidths = [...config?.imageConfig?.deviceSizes ?? DEFAULT_DEVICE_SIZES, ...config?.imageConfig?.imageSizes ?? DEFAULT_IMAGE_SIZES];
87
+ const imageConfig = {
88
+ qualities: config?.imageConfig?.qualities,
89
+ dangerouslyAllowSVG: config?.imageConfig?.dangerouslyAllowSVG,
90
+ dangerouslyAllowLocalIP: config?.imageConfig?.dangerouslyAllowLocalIP,
91
+ contentDispositionType: config?.imageConfig?.contentDispositionType,
92
+ contentSecurityPolicy: config?.imageConfig?.contentSecurityPolicy
93
+ };
85
94
  const { imports, routeEntries, metaRouteEntries, generateStaticParamsEntries, rootParamNameEntries, rootNotFoundVar, rootForbiddenVar, rootUnauthorizedVar, rootLayoutVars, globalErrorVar, globalNotFoundImportSpecifier } = buildAppRscManifestCode({
86
95
  routes,
87
96
  metadataRoutes,
88
97
  globalErrorPath,
89
- globalNotFoundPath: config?.globalNotFoundPath ?? null
98
+ globalNotFoundPath: config?.globalNotFound === true ? config.globalNotFoundPath ?? null : null
90
99
  });
91
100
  const loadPrerenderPagesRoutesCode = hasPagesDir ? `
92
101
  async function __loadPrerenderPagesRoutes() {
@@ -123,6 +132,8 @@ ${instrumentationPath ? `import * as _instrumentation from ${JSON.stringify(norm
123
132
  import { ensureInstrumentationRegistered as __ensureInstrumentationRegistered } from ${JSON.stringify(instrumentationRuntimePath)};` : ""}
124
133
  import { createAppRscHandler } from "vinext/server/app-rsc-handler";
125
134
  import { registerConfiguredCacheAdapters as __registerConfiguredCacheAdapters } from "virtual:vinext-cache-adapters";
135
+ import __pagesClientAssets from "virtual:vinext-pages-client-assets";
136
+ import { setPagesClientAssets as __setPagesClientAssets } from "vinext/server/pages-client-assets";
126
137
  import { decodePathParams as __decodePathParams } from ${JSON.stringify(normalizePathModulePath)};
127
138
  import { buildRequestHeadersFromMiddlewareResponse as __buildRequestHeadersFromMiddlewareResponse } from ${JSON.stringify(middlewareRequestHeadersPath)};
128
139
  ${hasPagesDir ? `import {
@@ -245,6 +256,11 @@ function __resolveRouteFetchCacheMode(route) {
245
256
  return __resolveAppPageFetchCacheMode({
246
257
  layouts: route.layouts,
247
258
  page: route.page,
259
+ parallelSegments: Object.values(route.slots ?? {}).flatMap((slot) => [
260
+ slot.layout,
261
+ ...(slot.configLayouts ?? []),
262
+ slot.page ?? slot.default,
263
+ ]),
248
264
  });
249
265
  }
250
266
 
@@ -252,6 +268,11 @@ function __resolveRouteDynamicConfig(route) {
252
268
  return __resolveAppPageSegmentConfig({
253
269
  layouts: route.layouts,
254
270
  page: route.page,
271
+ parallelSegments: Object.values(route.slots ?? {}).flatMap((slot) => [
272
+ slot.layout,
273
+ ...(slot.configLayouts ?? []),
274
+ slot.page ?? slot.default,
275
+ ]),
255
276
  }).dynamicConfig ?? null;
256
277
  }
257
278
 
@@ -259,6 +280,11 @@ function __resolveRouteRuntime(route) {
259
280
  return __resolveAppPageSegmentConfig({
260
281
  layouts: route.layouts,
261
282
  page: route.page,
283
+ parallelSegments: Object.values(route.slots ?? {}).flatMap((slot) => [
284
+ slot.layout,
285
+ ...(slot.configLayouts ?? []),
286
+ slot.page ?? slot.default,
287
+ ]),
262
288
  }).runtime ?? null;
263
289
  }
264
290
 
@@ -339,6 +365,7 @@ const __fallbackRenderer = __createAppFallbackRenderer({
339
365
  },
340
366
  globalErrorModule: ${globalErrorVar ? globalErrorVar : "null"},
341
367
  loadGlobalNotFoundModule: __loadGlobalNotFoundModule,
368
+ globalNotFoundEnabled: ${config?.globalNotFound === true},
342
369
  metadataRoutes,
343
370
  ssrLoader() {
344
371
  return import.meta.viteRsc.loadModule("ssr", "index");
@@ -400,7 +427,7 @@ const __i18nConfig = ${JSON.stringify(i18nConfig)};
400
427
  const __configRedirects = ${JSON.stringify(redirects)};
401
428
  const __configRewrites = ${JSON.stringify(rewrites)};
402
429
  const __configHeaders = ${JSON.stringify(headers)};
403
- const __imageConfig = ${JSON.stringify(config?.imageConfig)};
430
+ const __runtimeImageConfig = ${JSON.stringify(config?.imageConfig)};
404
431
  const __publicFiles = new Set(${JSON.stringify(publicFiles)});
405
432
  const __allowedOrigins = ${JSON.stringify(allowedOrigins)};
406
433
  const __expireTime = ${JSON.stringify(expireTime)};
@@ -411,6 +438,8 @@ const __reactMaxHeadersLength = ${JSON.stringify(reactMaxHeadersLength)};
411
438
  // mirrors the embedded \`__basePath\` pattern (and Pages Router's
412
439
  // \`vinextConfig\` export). Empty string when unset.
413
440
  export const __assetPrefix = ${JSON.stringify(assetPrefix)};
441
+ export const __imageAllowedWidths = ${JSON.stringify(imageAllowedWidths)};
442
+ export const __imageConfig = ${JSON.stringify(imageConfig)};
414
443
  export const __inlineCss = ${JSON.stringify(inlineCss)};
415
444
  export const __hasPagesDir = ${JSON.stringify(hasPagesDir)};
416
445
  export const getRenderedConcreteUrlPathsForRoute = __getRenderedConcreteUrlPathsForRoute;
@@ -459,6 +488,7 @@ const rootParamNamesMap = {
459
488
  ${rootParamNameEntries.join("\n")}
460
489
  };
461
490
 
491
+ __setPagesClientAssets(__pagesClientAssets);
462
492
  export default createAppRscHandler({
463
493
  basePath: __basePath,
464
494
  buildId: process.env.__VINEXT_BUILD_ID ?? null,
@@ -473,7 +503,7 @@ export default createAppRscHandler({
473
503
  },` : ""}
474
504
  configRedirects: __configRedirects,
475
505
  configRewrites: __configRewrites,
476
- imageConfig: __imageConfig,
506
+ imageConfig: __runtimeImageConfig,
477
507
  isDev: process.env.NODE_ENV !== "production",
478
508
  draftModeSecret: __draftModeSecret,
479
509
  dispatchMatchedPage({
@@ -505,13 +535,32 @@ export default createAppRscHandler({
505
535
  const PageComponent = route.page?.default;
506
536
  const __segmentConfig = __resolveAppPageSegmentConfig({
507
537
  layouts: route.layouts,
538
+ layoutTreePositions: route.layoutTreePositions,
508
539
  page: route.page,
509
- parallelPages: Object.values(route.slots ?? {}).map((slot) => slot.page),
540
+ parallelBranches: Object.values(route.slots ?? {}).map((slot) => ({
541
+ layout: slot.layout,
542
+ configLayouts: slot.configLayouts,
543
+ configLayoutTreePositions: slot.configLayoutTreePositions,
544
+ page: slot.page ?? slot.default,
545
+ routeSegments: slot.routeSegments,
546
+ })),
547
+ parallelPages: Object.values(route.slots ?? {}).map((slot) => slot.page ?? slot.default),
548
+ routeSegments: route.routeSegments,
510
549
  });
511
550
  const __generateStaticParams = __resolveAppPageGenerateStaticParamsSources({
512
551
  layouts: route.layouts,
513
552
  layoutTreePositions: route.layoutTreePositions,
514
553
  page: route.page,
554
+ parallelBranches: Object.values(route.slots ?? {}).map((slot) => ({
555
+ layout: slot.layout,
556
+ configLayouts: slot.configLayouts,
557
+ configLayoutTreePositions: slot.configLayoutTreePositions,
558
+ page: slot.page ?? slot.default,
559
+ paramNames: slot.slotParamNames,
560
+ patternParts: slot.slotPatternParts,
561
+ routeSegments: slot.routeSegments,
562
+ })),
563
+ routePatternParts: route.patternParts,
515
564
  routeSegments: route.routeSegments,
516
565
  });
517
566
  const _asyncRouteParams = makeThenableParams(params);
@@ -520,7 +569,7 @@ export default createAppRscHandler({
520
569
  ensureRouteLoaded: __ensureRouteLoaded,
521
570
  clientTraceMetadata: __clientTraceMetadata,
522
571
  reactMaxHeadersLength: __reactMaxHeadersLength,
523
- buildPageElement(targetRoute, targetParams, targetOpts, targetSearchParams, layoutParamAccess) {
572
+ buildPageElement(targetRoute, targetParams, targetOpts, targetSearchParams, layoutParamAccess, buildOptions) {
524
573
  return buildPageElements(targetRoute, targetParams, cleanPathname, {
525
574
  opts: targetOpts,
526
575
  searchParams: targetSearchParams,
@@ -528,6 +577,8 @@ export default createAppRscHandler({
528
577
  request,
529
578
  mountedSlotsHeader,
530
579
  renderMode,
580
+ observeMetadataSearchParamsAccess: buildOptions?.observeMetadataSearchParamsAccess === true,
581
+ observePageSearchParamsAccess: buildOptions?.observePageSearchParamsAccess === true,
531
582
  }, layoutParamAccess, displayPathname);
532
583
  },
533
584
  clientReuseManifest,
@@ -598,7 +649,7 @@ export default createAppRscHandler({
598
649
  route,
599
650
  });
600
651
  },
601
- async probePage() {
652
+ async probePage(probeSearchParams = searchParams) {
602
653
  const __probeIntercept = findIntercept(cleanPathname, interceptionContext);
603
654
  // The intercepting-route page module is lazy (page: null + __pageLoader).
604
655
  // Resolve it before probing so buildAppPageProbes inspects the real page
@@ -613,21 +664,21 @@ export default createAppRscHandler({
613
664
  route,
614
665
  pageComponent: PageComponent,
615
666
  asyncRouteParams: _asyncRouteParams,
616
- searchParams,
667
+ searchParams: probeSearchParams,
617
668
  intercept: __probeIntercept,
618
669
  isRscRequest,
619
670
  matchedParams: params,
620
671
  makeThenableParams,
621
672
  }));
622
673
  },
623
- renderErrorBoundaryPage(renderErr) {
674
+ renderErrorBoundaryPage(renderErr, errorOrigin) {
624
675
  const __activeIntercept = findIntercept(cleanPathname, interceptionContext);
625
676
  return __fallbackRenderer.renderErrorBoundary(route, renderErr, isRscRequest, request, params, scriptNonce, middlewareContext, {
626
677
  isEdgeRuntime: __isEdgeRuntime(__segmentConfig.runtime),
627
678
  sourcePageSegments: __activeIntercept?.slotKey === __SIBLING_PAGE_INTERCEPT_SLOT_KEY
628
679
  ? __activeIntercept.sourcePageSegments
629
680
  : null,
630
- });
681
+ }, errorOrigin);
631
682
  },
632
683
  renderHttpAccessFallbackPage(statusCode, opts, currentMiddlewareContext) {
633
684
  const __activeIntercept = findIntercept(cleanPathname, interceptionContext);
@@ -777,7 +828,7 @@ export default createAppRscHandler({
777
828
  const __actionMatch = matchRoute(cleanPathname);
778
829
  if (__actionMatch) await __ensureRouteLoaded(__actionMatch.route);
779
830
  const __actionIsEdgeRuntime = __actionMatch
780
- ? __isEdgeRuntime(__resolveAppPageSegmentConfig({ layouts: __actionMatch.route.layouts, page: __actionMatch.route.page }).runtime)
831
+ ? __isEdgeRuntime(__resolveRouteRuntime(__actionMatch.route))
781
832
  : false;
782
833
  return __handleServerActionRscRequest({
783
834
  actionId,
@@ -795,6 +846,8 @@ export default createAppRscHandler({
795
846
  request: actionRequest,
796
847
  mountedSlotsHeader: actionMountedSlotsHeader,
797
848
  renderMode: actionRenderMode,
849
+ observeMetadataSearchParamsAccess,
850
+ observePageSearchParamsAccess,
798
851
  }) {
799
852
  return buildPageElements(actionRoute, actionParams, actionCleanPathname, {
800
853
  opts: interceptOpts,
@@ -803,6 +856,8 @@ export default createAppRscHandler({
803
856
  request: actionRequest,
804
857
  mountedSlotsHeader: actionMountedSlotsHeader,
805
858
  renderMode: actionRenderMode,
859
+ observeMetadataSearchParamsAccess: observeMetadataSearchParamsAccess === true,
860
+ observePageSearchParamsAccess: observePageSearchParamsAccess === true,
806
861
  });
807
862
  },
808
863
  cleanPathname,
@@ -828,6 +883,7 @@ export default createAppRscHandler({
828
883
  },
829
884
  createTemporaryReferenceSet,
830
885
  decodeReply,
886
+ draftModeSecret: __draftModeSecret,
831
887
  findIntercept(pathnameToMatch) {
832
888
  return findIntercept(pathnameToMatch, interceptionContext);
833
889
  },
@@ -871,6 +927,8 @@ export default createAppRscHandler({
871
927
  return {
872
928
  interceptionContext,
873
929
  interceptLayouts: intercept.interceptLayouts,
930
+ interceptLayoutSegments: intercept.interceptLayoutSegments,
931
+ interceptBranchSegments: intercept.interceptBranchSegments,
874
932
  interceptSlotId: intercept.slotId,
875
933
  interceptSlotKey: intercept.slotKey,
876
934
  interceptSourceMatchedUrl: interceptionContext,
@@ -910,7 +968,7 @@ export default createAppRscHandler({
910
968
  },` : ""}
911
969
  publicFiles: __publicFiles,
912
970
  renderNotFound({ isRscRequest, matchedParams, middlewareContext, request, route, scriptNonce }) {
913
- const __isEdge = route ? __isEdgeRuntime(__resolveAppPageSegmentConfig({ layouts: route.layouts, page: route.page }).runtime) : false;
971
+ const __isEdge = route ? __isEdgeRuntime(__resolveRouteRuntime(route)) : false;
914
972
  return __fallbackRenderer.renderNotFound(route, isRscRequest, request, matchedParams, scriptNonce, middlewareContext, { isEdgeRuntime: __isEdge });
915
973
  },
916
974
  ${hasPagesDir ? `async renderPagesFallback({ allowRscDocumentFallback, appRouteMatch, isDataRequest, isRscRequest, matchKind, middlewareContext, pathname, pagesDataRequest, request, url }) {
@@ -74,6 +74,7 @@ function registerRouteModules(routes, imports) {
74
74
  if (slot.pagePath) imports.getLazyLoaderVar(slot.pagePath);
75
75
  if (slot.defaultPath) imports.getLazyLoaderVar(slot.defaultPath);
76
76
  if (slot.layoutPath) imports.getLazyLoaderVar(slot.layoutPath);
77
+ for (const layoutPath of slot.configLayoutPaths ?? []) imports.getLazyLoaderVar(layoutPath);
77
78
  if (slot.loadingPath) imports.getLazyLoaderVar(slot.loadingPath);
78
79
  if (slot.errorPath) imports.getLazyLoaderVar(slot.errorPath);
79
80
  for (const ir of slot.interceptingRoutes) {
@@ -112,6 +113,8 @@ function buildRouteEntries(routes, imports) {
112
113
  slotId: ${JSON.stringify(ir.slotId ?? null)},
113
114
  interceptLayouts: ${moduleArray(ir.layoutPaths.length)},
114
115
  __loadInterceptLayouts: ${lazyLoaderArray(ir.layoutPaths, imports)},
116
+ interceptLayoutSegments: ${JSON.stringify(ir.layoutSegments ?? [])},
117
+ interceptBranchSegments: ${JSON.stringify(ir.branchSegments ?? [])},
115
118
  page: null,
116
119
  __pageLoader: ${imports.getLazyLoaderVar(ir.pagePath)},
117
120
  params: ${JSON.stringify(ir.params)},
@@ -124,6 +127,8 @@ function buildRouteEntries(routes, imports) {
124
127
  sourcePageSegments: ${JSON.stringify(ir.sourcePageSegments)},
125
128
  interceptLayouts: ${moduleArray(ir.layoutPaths.length)},
126
129
  __loadInterceptLayouts: ${lazyLoaderArray(ir.layoutPaths, imports)},
130
+ interceptLayoutSegments: ${JSON.stringify(ir.layoutSegments ?? [])},
131
+ interceptBranchSegments: ${JSON.stringify(ir.branchSegments ?? [])},
127
132
  page: null,
128
133
  __pageLoader: ${imports.getLazyLoaderVar(ir.pagePath)},
129
134
  params: ${JSON.stringify(ir.params)},
@@ -137,6 +142,9 @@ function buildRouteEntries(routes, imports) {
137
142
  __loadDefault: ${slot.defaultPath ? imports.getLazyLoaderVar(slot.defaultPath) : "null"},
138
143
  layout: null,
139
144
  __loadLayout: ${slot.layoutPath ? imports.getLazyLoaderVar(slot.layoutPath) : "null"},
145
+ configLayouts: ${moduleArray(slot.configLayoutPaths?.length ?? 0)},
146
+ __loadConfigLayouts: ${lazyLoaderArray(slot.configLayoutPaths ?? [], imports)},
147
+ configLayoutTreePositions: ${JSON.stringify(slot.configLayoutTreePositions ?? [])},
140
148
  loading: null,
141
149
  __loadLoading: ${slot.loadingPath ? imports.getLazyLoaderVar(slot.loadingPath) : "null"},
142
150
  error: null,
@@ -6,6 +6,7 @@ import { VinextLinkPrefetchRoute } from "../client/vinext-next-data.js";
6
6
  declare function generateClientEntry(pagesDir: string, nextConfig: ResolvedNextConfig, fileMatcher: ReturnType<typeof createValidFileMatcher>, options?: {
7
7
  appPrefetchRoutes?: readonly VinextLinkPrefetchRoute[];
8
8
  instrumentationClientPath?: string | null;
9
+ reactPreamble?: boolean;
9
10
  }): Promise<string>;
10
11
  //#endregion
11
12
  export { generateClientEntry };
@@ -2,6 +2,7 @@ import { normalizePathSeparators } from "../utils/path.js";
2
2
  import { findFileWithExts } from "../routing/file-matcher.js";
3
3
  import { patternToNextFormat } from "../routing/route-validation.js";
4
4
  import { apiRouter, pagesRouter } from "../routing/pages-router.js";
5
+ import "./pages-entry-helpers.js";
5
6
  //#region src/entries/pages-client-entry.ts
6
7
  /**
7
8
  * Pages Router client hydration entry generator.
@@ -46,7 +47,7 @@ async function generateClientEntry(pagesDir, nextConfig, fileMatcher, options =
46
47
  return ` ${JSON.stringify(nextFormatPattern)}: () => import(${JSON.stringify(absPath)})`;
47
48
  });
48
49
  const appFileBase = appFilePath ? normalizePathSeparators(appFilePath) : void 0;
49
- return `${instrumentationClientPath ? `import ${JSON.stringify(normalizePathSeparators(instrumentationClientPath))};\n` : ""}
50
+ return `${instrumentationClientPath ? `import ${JSON.stringify(normalizePathSeparators(instrumentationClientPath))};\n` : ""}${options.reactPreamble === false ? "" : "import \"@vitejs/plugin-react/preamble\";\n"}
50
51
  import "vinext/instrumentation-client";
51
52
  import React from "react";
52
53
  import { hydrateRoot } from "react-dom/client";
@@ -3,6 +3,7 @@ import { findFileWithExts } from "../routing/file-matcher.js";
3
3
  import { apiRouter, pagesRouter } from "../routing/pages-router.js";
4
4
  import { resolveEntryPath } from "./runtime-entry-module.js";
5
5
  import { isProxyFile } from "../server/middleware.js";
6
+ import "./pages-entry-helpers.js";
6
7
  //#region src/entries/pages-server-entry.ts
7
8
  /**
8
9
  * Pages Router server entry generator.
@@ -127,6 +128,8 @@ import Router, { setSSRContext, wrapWithRouterContext, getPagesNavigationIsReady
127
128
  import { _runWithCacheState } from "vinext/shims/cache-request-state";
128
129
  import { configureMemoryCacheHandler as __configureMemoryCacheHandler } from "vinext/shims/cache-handler";
129
130
  import { registerConfiguredCacheAdapters as __registerConfiguredCacheAdapters } from "virtual:vinext-cache-adapters";
131
+ import __pagesClientAssets from "virtual:vinext-pages-client-assets";
132
+ import { setPagesClientAssets as __setPagesClientAssets } from "vinext/server/pages-client-assets";
130
133
  import { runWithPrivateCache } from "vinext/cache-runtime";
131
134
  import { ensureFetchPatch, runWithFetchCache } from "vinext/fetch-cache";
132
135
  import "vinext/router-state";
@@ -163,7 +166,7 @@ export const buildId = ${buildIdJson};
163
166
  export function normalizeDataRequest(request) {
164
167
  return __normalizePagesDataRequest(request, buildId);
165
168
  }
166
- const __hasMiddleware = ${JSON.stringify(Boolean(middlewarePath))};
169
+ export const hasMiddleware = ${JSON.stringify(Boolean(middlewarePath))};
167
170
 
168
171
  // Full resolved config for production server (embedded at build time)
169
172
  export const vinextConfig = ${vinextConfigJson};
@@ -270,6 +273,7 @@ export function matchApiRoute(url, request) {
270
273
  // All next/*-derived values are passed as closures so the handler module
271
274
  // stays importable in test environments (the root vite.config.ts only
272
275
  // aliases vinext/shims/*, not next/*).
276
+ __setPagesClientAssets(__pagesClientAssets);
273
277
  const _renderPage = __createPagesPageHandler({
274
278
  pageRoutes,
275
279
  errorPageRoute: _errorPageRoute,
@@ -285,7 +289,7 @@ const _renderPage = __createPagesPageHandler({
285
289
  disableOptimizedLoading: vinextConfig.disableOptimizedLoading,
286
290
  },
287
291
  buildId,
288
- hasMiddleware: __hasMiddleware,
292
+ hasMiddleware,
289
293
  appAssetPath: _appAssetPath,
290
294
  hasRewrites:
291
295
  vinextConfig.rewrites.beforeFiles.length > 0 ||
@@ -0,0 +1,59 @@
1
+ //#region src/image/image-adapters-virtual.d.ts
2
+ /**
3
+ * Code generation for the `virtual:vinext-image-adapters` module, resolved by
4
+ * the vinext vite plugin from the user's `images` config ({@link VinextImageConfig}).
5
+ *
6
+ * The generated module exports `registerConfiguredImageOptimizer(env)`, which the
7
+ * server entries call on each request. It self-guards (the optimizer instantiates
8
+ * once per isolate) and is a no-op when nothing is configured. Registration is
9
+ * resilient: a factory that throws (e.g. a Cloudflare Images adapter on the
10
+ * Node.js server, where the `IMAGES` binding can't exist) is logged and skipped
11
+ * rather than failing every request, so the same config can be registered from
12
+ * every runtime/router entry. When no optimizer is registered, image requests
13
+ * fall back to serving the original asset unoptimized.
14
+ *
15
+ * Descriptor `options` are inlined into the generated module and forwarded to the
16
+ * factory at runtime, so a config-time builder like `imagesOptimizer({ binding })`
17
+ * never touches the Workers runtime — instantiation is deferred to the first
18
+ * request.
19
+ *
20
+ * This mirrors the cache-adapter pattern in `cache/cache-adapters-virtual.ts`.
21
+ */
22
+ /**
23
+ * A serializable pointer to an image optimizer adapter module — the shape of the
24
+ * `images.optimizer` slot in the vinext() plugin config. Produced by an adapter
25
+ * builder (e.g. `imagesOptimizer(...)` from `@vinext/cloudflare/images/images-optimizer`)
26
+ * or written by hand. `options` must be JSON-serializable: it is inlined into the
27
+ * generated registration module and forwarded to the adapter factory at runtime.
28
+ */
29
+ type ImageAdapterDescriptor<O extends Record<string, unknown> = Record<string, unknown>> = {
30
+ /**
31
+ * Module specifier (or absolute path, e.g. from `require.resolve(...)`) whose
32
+ * default export is an image optimizer factory.
33
+ */
34
+ adapter: string; /** JSON-serializable options forwarded to the factory at runtime. */
35
+ options?: O;
36
+ };
37
+ /**
38
+ * The `images` option of the vinext() plugin: declaratively register the
39
+ * server-side image optimizer (transform backend) instead of wiring `env.IMAGES`
40
+ * into a custom worker entry.
41
+ *
42
+ * This is complementary to the `images` field in `next.config.js`, which
43
+ * configures the standard Next.js image options (`remotePatterns`, `deviceSizes`,
44
+ * `dangerouslyAllowSVG`, etc.). Those continue to be read from next.config; this
45
+ * option only selects the runtime transform backend, which can't be expressed as
46
+ * serializable next.config data.
47
+ */
48
+ type VinextImageConfig = {
49
+ /** Server-side image optimizer adapter (the `/_next/image` transform backend). */optimizer?: ImageAdapterDescriptor;
50
+ };
51
+ /** Public virtual module id imported by the server entries. */
52
+ declare const VIRTUAL_IMAGE_ADAPTERS = "virtual:vinext-image-adapters";
53
+ /**
54
+ * Generate the source of the `virtual:vinext-image-adapters` module for the
55
+ * given config. Always exports `registerConfiguredImageOptimizer(env)`.
56
+ */
57
+ declare function generateImageAdaptersModule(images?: VinextImageConfig): string;
58
+ //#endregion
59
+ export { VIRTUAL_IMAGE_ADAPTERS, VinextImageConfig, generateImageAdaptersModule };
@@ -0,0 +1,50 @@
1
+ //#region src/image/image-adapters-virtual.ts
2
+ /** Public virtual module id imported by the server entries. */
3
+ const VIRTUAL_IMAGE_ADAPTERS = "virtual:vinext-image-adapters";
4
+ /**
5
+ * Serialize descriptor options into a JS expression for inlining. Plain JSON is
6
+ * a valid JS literal; `undefined` when there are no options. Throws a clear
7
+ * config-time error (not a runtime one) if options are not serializable.
8
+ */
9
+ function inlineOptions(adapter, options) {
10
+ if (options === void 0) return "undefined";
11
+ try {
12
+ return JSON.stringify(options);
13
+ } catch (cause) {
14
+ throw new Error(`[vinext] image adapter "${adapter}" options must be JSON-serializable.`, { cause });
15
+ }
16
+ }
17
+ /**
18
+ * Generate the source of the `virtual:vinext-image-adapters` module for the
19
+ * given config. Always exports `registerConfiguredImageOptimizer(env)`.
20
+ */
21
+ function generateImageAdaptersModule(images) {
22
+ const optimizer = images?.optimizer;
23
+ if (!optimizer?.adapter) return [
24
+ "// vinext: no images.optimizer adapter configured — registration is a no-op.",
25
+ "export function registerConfiguredImageOptimizer() {}",
26
+ ""
27
+ ].join("\n");
28
+ return [
29
+ "// vinext: generated from the `images` option in your vinext() plugin config.",
30
+ `import __vinextImageOptimizerFactory from ${JSON.stringify(optimizer.adapter)};`,
31
+ `import { setImageOptimizer } from "vinext/server/image-optimization";`,
32
+ "",
33
+ "// A factory that throws (e.g. a missing binding on an incompatible runtime)",
34
+ "// is logged and skipped so images fall back to unoptimized passthrough.",
35
+ "let __vinextImageOptimizerRegistered = false;",
36
+ "",
37
+ "export function registerConfiguredImageOptimizer(env) {",
38
+ " if (__vinextImageOptimizerRegistered) return;",
39
+ " __vinextImageOptimizerRegistered = true;",
40
+ " try {",
41
+ ` setImageOptimizer(__vinextImageOptimizerFactory({ env, options: ${inlineOptions(optimizer.adapter, optimizer.options)} }));`,
42
+ " } catch (error) {",
43
+ " console.warn(\"[vinext] failed to initialize the configured image optimizer; serving images unoptimized.\", error);",
44
+ " }",
45
+ "}",
46
+ ""
47
+ ].join("\n");
48
+ }
49
+ //#endregion
50
+ export { VIRTUAL_IMAGE_ADAPTERS, generateImageAdaptersModule };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { NextConfig, NextConfigInput } from "./config/next-config.js";
2
2
  import { AppStaticExportOptions, StaticExportOptions, StaticExportResult, staticExportApp, staticExportPages } from "./build/static-export.js";
3
3
  import { VinextCacheConfig } from "./cache/cache-adapters-virtual.js";
4
+ import { VinextImageConfig } from "./image/image-adapters-virtual.js";
4
5
  import { PluginOption } from "vite";
5
6
  import { Options } from "@vitejs/plugin-react";
6
7
 
@@ -97,6 +98,17 @@ type VinextOptions = {
97
98
  * })
98
99
  */
99
100
  cache?: VinextCacheConfig;
101
+ /**
102
+ * Configure the server-side image optimizer declaratively. The adapter factory
103
+ * receives the host `env`, allowing bindings such as Cloudflare Images to be
104
+ * used by both built-in and custom worker entrypoints that forward `env`.
105
+ *
106
+ * @example
107
+ * import { imagesOptimizer } from "@vinext/cloudflare/images/images-optimizer";
108
+ *
109
+ * vinext({ images: { optimizer: imagesOptimizer() } })
110
+ */
111
+ images?: VinextImageConfig;
100
112
  /**
101
113
  * Experimental vinext-only feature flags.
102
114
  */