vinext 0.1.8 → 0.2.1

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 (285) hide show
  1. package/README.md +51 -30
  2. package/dist/build/css-url-assets.d.ts +3 -1
  3. package/dist/build/css-url-assets.js +18 -1
  4. package/dist/build/inject-pregenerated-paths.d.ts +7 -0
  5. package/dist/build/inject-pregenerated-paths.js +21 -0
  6. package/dist/build/layout-classification.js +1 -1
  7. package/dist/build/nitro-route-rules.js +1 -1
  8. package/dist/build/pages-client-assets-module.d.ts +11 -0
  9. package/dist/build/pages-client-assets-module.js +27 -0
  10. package/dist/build/prerender-server-entry.d.ts +1 -0
  11. package/dist/build/prerender-server-entry.js +49 -0
  12. package/dist/build/prerender-server-pool.d.ts +44 -0
  13. package/dist/build/prerender-server-pool.js +194 -0
  14. package/dist/build/prerender.d.ts +2 -1
  15. package/dist/build/prerender.js +98 -27
  16. package/dist/build/report.d.ts +13 -2
  17. package/dist/build/report.js +99 -2
  18. package/dist/build/run-prerender.d.ts +7 -0
  19. package/dist/build/run-prerender.js +12 -2
  20. package/dist/build/standalone.js +2 -0
  21. package/dist/cache/cache-adapters-virtual.js +3 -3
  22. package/dist/check.d.ts +4 -6
  23. package/dist/check.js +48 -11
  24. package/dist/cli-args.d.ts +1 -2
  25. package/dist/cli-args.js +1 -1
  26. package/dist/cli-dev-config.d.ts +12 -0
  27. package/dist/cli-dev-config.js +23 -0
  28. package/dist/cli.js +112 -96
  29. package/dist/{server → client}/dev-error-overlay-store.d.ts +1 -1
  30. package/dist/{server → client}/dev-error-overlay-store.js +1 -1
  31. package/dist/{server → client}/dev-error-overlay.d.ts +1 -1
  32. package/dist/{server → client}/dev-error-overlay.js +2 -2
  33. package/dist/client/navigation-runtime.d.ts +2 -0
  34. package/dist/client/navigation-runtime.js +3 -1
  35. package/dist/client/vinext-next-data.d.ts +4 -1
  36. package/dist/client/window-next.d.ts +2 -1
  37. package/dist/cloudflare/index.d.ts +2 -2
  38. package/dist/cloudflare/index.js +2 -2
  39. package/dist/config/config-matchers.js +45 -19
  40. package/dist/config/next-config.d.ts +41 -9
  41. package/dist/config/next-config.js +60 -3
  42. package/dist/config/prerender.d.ts +34 -0
  43. package/dist/config/prerender.js +55 -0
  44. package/dist/entries/app-browser-entry.js +5 -1
  45. package/dist/entries/app-rsc-entry.d.ts +5 -3
  46. package/dist/entries/app-rsc-entry.js +44 -10
  47. package/dist/entries/app-rsc-manifest.js +2 -0
  48. package/dist/entries/pages-client-entry.d.ts +3 -0
  49. package/dist/entries/pages-client-entry.js +28 -3
  50. package/dist/entries/pages-server-entry.js +23 -6
  51. package/dist/image/image-adapters-virtual.d.ts +59 -0
  52. package/dist/image/image-adapters-virtual.js +59 -0
  53. package/dist/index.d.ts +33 -0
  54. package/dist/index.js +482 -120
  55. package/dist/init-cloudflare.d.ts +43 -0
  56. package/dist/init-cloudflare.js +839 -0
  57. package/dist/init-platform.d.ts +40 -0
  58. package/dist/init-platform.js +195 -0
  59. package/dist/init.d.ts +16 -38
  60. package/dist/init.js +209 -99
  61. package/dist/node_modules/.pnpm/am-i-vibing@0.5.0/node_modules/am-i-vibing/dist/detector-1yx2Hoe0.js +294 -0
  62. package/dist/node_modules/.pnpm/process-ancestry@0.1.0/node_modules/process-ancestry/dist/index.js +94 -0
  63. package/dist/{cloudflare → packages/cloudflare}/src/cache/cdn-adapter.runtime.js +1 -1
  64. package/dist/{cloudflare → packages/cloudflare}/src/cache/kv-data-adapter.runtime.d.ts +2 -2
  65. package/dist/{cloudflare → packages/cloudflare}/src/cache/kv-data-adapter.runtime.js +9 -2
  66. package/dist/packages/cloudflare/src/deploy-config.js +150 -0
  67. package/dist/packages/cloudflare/src/deploy-help.js +55 -0
  68. package/dist/packages/cloudflare/src/deploy.js +272 -0
  69. package/dist/{cloudflare → packages/cloudflare/src}/tpr.d.ts +4 -41
  70. package/dist/{cloudflare → packages/cloudflare/src}/tpr.js +44 -20
  71. package/dist/plugins/ast-scope.d.ts +16 -0
  72. package/dist/plugins/ast-scope.js +62 -0
  73. package/dist/plugins/ast-utils.d.ts +27 -1
  74. package/dist/plugins/ast-utils.js +32 -1
  75. package/dist/plugins/css-module-imports.d.ts +14 -0
  76. package/dist/plugins/css-module-imports.js +59 -0
  77. package/dist/plugins/extensionless-dynamic-import.js +2 -2
  78. package/dist/plugins/fonts.js +1 -1
  79. package/dist/plugins/ignore-dynamic-requests.d.ts +11 -0
  80. package/dist/plugins/ignore-dynamic-requests.js +530 -0
  81. package/dist/plugins/og-assets.js +2 -1
  82. package/dist/plugins/optimize-imports.js +1 -1
  83. package/dist/plugins/rsc-reference-validation-normalizer.d.ts +12 -0
  84. package/dist/plugins/rsc-reference-validation-normalizer.js +48 -0
  85. package/dist/plugins/sass.d.ts +17 -1
  86. package/dist/plugins/sass.js +74 -1
  87. package/dist/plugins/styled-jsx.d.ts +16 -0
  88. package/dist/plugins/styled-jsx.js +149 -0
  89. package/dist/plugins/typeof-window.d.ts +1 -1
  90. package/dist/plugins/typeof-window.js +28 -56
  91. package/dist/routing/app-route-graph.d.ts +23 -2
  92. package/dist/routing/app-route-graph.js +138 -38
  93. package/dist/routing/file-matcher.d.ts +11 -1
  94. package/dist/routing/file-matcher.js +18 -3
  95. package/dist/routing/pages-router.js +2 -2
  96. package/dist/server/api-handler.js +9 -14
  97. package/dist/server/app-browser-action-result.d.ts +4 -1
  98. package/dist/server/app-browser-action-result.js +8 -1
  99. package/dist/server/app-browser-entry.js +198 -57
  100. package/dist/server/app-browser-interception-context.d.ts +1 -0
  101. package/dist/server/app-browser-interception-context.js +4 -2
  102. package/dist/server/app-browser-navigation-controller.d.ts +2 -0
  103. package/dist/server/app-browser-navigation-controller.js +60 -31
  104. package/dist/server/app-browser-server-action-client.d.ts +1 -1
  105. package/dist/server/app-browser-server-action-client.js +8 -7
  106. package/dist/server/app-browser-state.d.ts +12 -1
  107. package/dist/server/app-browser-state.js +25 -8
  108. package/dist/server/app-browser-visible-commit.d.ts +6 -1
  109. package/dist/server/app-browser-visible-commit.js +42 -24
  110. package/dist/server/app-elements-wire.d.ts +9 -2
  111. package/dist/server/app-elements-wire.js +8 -1
  112. package/dist/server/app-elements.d.ts +2 -2
  113. package/dist/server/app-elements.js +4 -3
  114. package/dist/server/app-fallback-renderer.d.ts +2 -1
  115. package/dist/server/app-fallback-renderer.js +10 -6
  116. package/dist/server/app-hydration-cache-publication.d.ts +11 -0
  117. package/dist/server/app-hydration-cache-publication.js +43 -0
  118. package/dist/server/app-middleware.d.ts +4 -3
  119. package/dist/server/app-middleware.js +8 -3
  120. package/dist/server/app-optimistic-routing.js +11 -4
  121. package/dist/server/app-page-boundary.js +2 -1
  122. package/dist/server/app-page-cache-finalizer.d.ts +1 -0
  123. package/dist/server/app-page-cache-finalizer.js +5 -4
  124. package/dist/server/app-page-cache-render.d.ts +1 -0
  125. package/dist/server/app-page-cache-render.js +8 -4
  126. package/dist/server/app-page-cache.d.ts +1 -0
  127. package/dist/server/app-page-cache.js +27 -7
  128. package/dist/server/app-page-dispatch.d.ts +1 -0
  129. package/dist/server/app-page-dispatch.js +26 -8
  130. package/dist/server/app-page-element-builder.d.ts +2 -1
  131. package/dist/server/app-page-element-builder.js +59 -4
  132. package/dist/server/app-page-execution.js +2 -1
  133. package/dist/server/app-page-probe.js +5 -0
  134. package/dist/server/app-page-render-identity.d.ts +2 -0
  135. package/dist/server/app-page-render-identity.js +3 -2
  136. package/dist/server/app-page-render.d.ts +2 -0
  137. package/dist/server/app-page-render.js +85 -16
  138. package/dist/server/app-page-request.d.ts +14 -0
  139. package/dist/server/app-page-request.js +69 -4
  140. package/dist/server/app-page-response.d.ts +7 -0
  141. package/dist/server/app-page-response.js +16 -4
  142. package/dist/server/app-page-route-wiring.d.ts +8 -1
  143. package/dist/server/app-page-route-wiring.js +32 -18
  144. package/dist/server/app-page-segment-state.d.ts +2 -1
  145. package/dist/server/app-page-segment-state.js +3 -1
  146. package/dist/server/app-page-stream.d.ts +7 -1
  147. package/dist/server/app-page-stream.js +3 -1
  148. package/dist/server/app-route-handler-execution.js +5 -1
  149. package/dist/server/app-route-handler-response.js +1 -0
  150. package/dist/server/app-route-handler-runtime.js +1 -1
  151. package/dist/server/app-route-tree-prefetch.d.ts +43 -0
  152. package/dist/server/app-route-tree-prefetch.js +187 -0
  153. package/dist/server/app-router-entry.js +9 -2
  154. package/dist/server/app-rsc-cache-busting.d.ts +2 -1
  155. package/dist/server/app-rsc-cache-busting.js +9 -4
  156. package/dist/server/app-rsc-handler.d.ts +7 -0
  157. package/dist/server/app-rsc-handler.js +148 -39
  158. package/dist/server/app-rsc-render-mode.d.ts +3 -2
  159. package/dist/server/app-rsc-render-mode.js +4 -1
  160. package/dist/server/app-rsc-request-normalization.d.ts +6 -6
  161. package/dist/server/app-rsc-request-normalization.js +10 -8
  162. package/dist/server/app-segment-config.d.ts +11 -0
  163. package/dist/server/app-segment-config.js +62 -6
  164. package/dist/server/app-server-action-execution.d.ts +1 -0
  165. package/dist/server/app-server-action-execution.js +61 -30
  166. package/dist/server/app-ssr-entry.d.ts +3 -0
  167. package/dist/server/app-ssr-entry.js +13 -5
  168. package/dist/server/app-ssr-stream.d.ts +7 -3
  169. package/dist/server/app-ssr-stream.js +10 -6
  170. package/dist/server/app-visited-response-cache.d.ts +6 -0
  171. package/dist/server/app-visited-response-cache.js +3 -1
  172. package/dist/server/cache-control.d.ts +3 -1
  173. package/dist/server/cache-control.js +13 -1
  174. package/dist/server/client-trace-metadata.js +26 -0
  175. package/dist/server/default-global-not-found-module.d.ts +14 -0
  176. package/dist/server/default-global-not-found-module.js +14 -0
  177. package/dist/server/dev-route-files.js +4 -0
  178. package/dist/server/dev-server.d.ts +11 -1
  179. package/dist/server/dev-server.js +94 -35
  180. package/dist/server/dev-stack-sourcemap.d.ts +1 -1
  181. package/dist/server/dev-stack-sourcemap.js +1 -1
  182. package/dist/server/fetch-handler.d.ts +2 -0
  183. package/dist/server/fetch-handler.js +18 -0
  184. package/dist/server/headers.d.ts +7 -15
  185. package/dist/server/headers.js +11 -18
  186. package/dist/server/image-optimization.d.ts +51 -1
  187. package/dist/server/image-optimization.js +52 -2
  188. package/dist/server/implicit-tags.js +1 -1
  189. package/dist/server/isr-cache.d.ts +3 -2
  190. package/dist/server/isr-cache.js +9 -5
  191. package/dist/server/metadata-routes.d.ts +3 -1
  192. package/dist/server/metadata-routes.js +12 -2
  193. package/dist/server/middleware-runtime.js +6 -1
  194. package/dist/server/navigation-planner.d.ts +1 -0
  195. package/dist/server/navigation-planner.js +14 -3
  196. package/dist/server/pages-api-route.js +2 -2
  197. package/dist/server/pages-asset-tags.d.ts +4 -6
  198. package/dist/server/pages-asset-tags.js +12 -12
  199. package/dist/server/pages-client-assets.d.ts +12 -0
  200. package/dist/server/pages-client-assets.js +10 -0
  201. package/dist/server/pages-data-route.d.ts +4 -2
  202. package/dist/server/pages-data-route.js +18 -4
  203. package/dist/server/pages-dev-module-url.d.ts +2 -1
  204. package/dist/server/pages-dev-module-url.js +6 -3
  205. package/dist/server/pages-node-compat.d.ts +19 -1
  206. package/dist/server/pages-node-compat.js +81 -4
  207. package/dist/server/pages-page-data.d.ts +33 -1
  208. package/dist/server/pages-page-data.js +62 -33
  209. package/dist/server/pages-page-handler.d.ts +2 -1
  210. package/dist/server/pages-page-handler.js +38 -19
  211. package/dist/server/pages-page-response.d.ts +8 -0
  212. package/dist/server/pages-page-response.js +7 -3
  213. package/dist/server/pages-request-pipeline.d.ts +9 -5
  214. package/dist/server/pages-request-pipeline.js +55 -7
  215. package/dist/server/pages-router-entry.d.ts +30 -0
  216. package/dist/server/pages-router-entry.js +108 -0
  217. package/dist/server/prerender-manifest.d.ts +3 -1
  218. package/dist/server/prerender-route-params.js +1 -1
  219. package/dist/server/prod-server.d.ts +5 -3
  220. package/dist/server/prod-server.js +68 -39
  221. package/dist/server/request-pipeline.js +2 -1
  222. package/dist/server/seed-cache.js +4 -4
  223. package/dist/shims/app-router-scroll-state.d.ts +1 -0
  224. package/dist/shims/app-router-scroll-state.js +1 -0
  225. package/dist/shims/app-router-scroll.js +2 -1
  226. package/dist/shims/cache-handler.js +8 -1
  227. package/dist/shims/cache.js +22 -15
  228. package/dist/shims/cdn-cache.js +1 -1
  229. package/dist/shims/dynamic-preload-chunks.js +2 -1
  230. package/dist/shims/fetch-cache.d.ts +3 -1
  231. package/dist/shims/fetch-cache.js +77 -52
  232. package/dist/shims/form.d.ts +4 -2
  233. package/dist/shims/form.js +37 -43
  234. package/dist/shims/headers.d.ts +7 -1
  235. package/dist/shims/headers.js +17 -3
  236. package/dist/shims/image.js +75 -14
  237. package/dist/shims/internal/app-prefetch-fetch-queue.d.ts +10 -0
  238. package/dist/shims/internal/app-prefetch-fetch-queue.js +61 -0
  239. package/dist/shims/internal/app-route-detection.d.ts +2 -17
  240. package/dist/shims/internal/app-route-detection.js +4 -17
  241. package/dist/shims/internal/hybrid-client-route-owner-direct.d.ts +23 -0
  242. package/dist/shims/internal/hybrid-client-route-owner-direct.js +51 -0
  243. package/dist/shims/internal/hybrid-client-route-owner.d.ts +3 -15
  244. package/dist/shims/internal/hybrid-client-route-owner.js +40 -58
  245. package/dist/shims/internal/pages-data-fetch-dedup.d.ts +10 -5
  246. package/dist/shims/internal/pages-data-fetch-dedup.js +84 -14
  247. package/dist/shims/internal/pages-data-target.d.ts +18 -12
  248. package/dist/shims/internal/pages-data-target.js +97 -13
  249. package/dist/shims/internal/pages-router-components.d.ts +7 -0
  250. package/dist/shims/internal/pages-router-components.js +13 -0
  251. package/dist/shims/layout-segment-context.d.ts +4 -1
  252. package/dist/shims/layout-segment-context.js +18 -4
  253. package/dist/shims/link.d.ts +1 -1
  254. package/dist/shims/link.js +224 -58
  255. package/dist/shims/navigation.d.ts +19 -3
  256. package/dist/shims/navigation.js +245 -47
  257. package/dist/shims/request-context.js +18 -0
  258. package/dist/shims/root-params.d.ts +15 -1
  259. package/dist/shims/root-params.js +21 -1
  260. package/dist/shims/router.d.ts +5 -7
  261. package/dist/shims/router.js +387 -102
  262. package/dist/shims/server.js +3 -2
  263. package/dist/shims/slot.js +3 -6
  264. package/dist/shims/unified-request-context.js +1 -0
  265. package/dist/typegen.js +1 -1
  266. package/dist/utils/client-runtime-metadata.d.ts +2 -18
  267. package/dist/utils/client-runtime-metadata.js +31 -22
  268. package/dist/utils/dev-stack-sourcemap-endpoint.d.ts +4 -0
  269. package/dist/{server → utils}/dev-stack-sourcemap-endpoint.js +1 -1
  270. package/dist/utils/domain-locale.d.ts +6 -3
  271. package/dist/{server → utils}/middleware-request-headers.d.ts +1 -1
  272. package/dist/{server → utils}/middleware-request-headers.js +3 -3
  273. package/dist/utils/project.d.ts +48 -2
  274. package/dist/utils/project.js +225 -4
  275. package/dist/utils/protocol-headers.d.ts +23 -0
  276. package/dist/utils/protocol-headers.js +23 -0
  277. package/dist/utils/react-version.d.ts +4 -0
  278. package/dist/utils/react-version.js +44 -0
  279. package/dist/utils/vite-version.d.ts +2 -0
  280. package/dist/utils/vite-version.js +11 -1
  281. package/package.json +47 -2
  282. package/dist/deploy.d.ts +0 -197
  283. package/dist/deploy.js +0 -1040
  284. package/dist/server/dev-stack-sourcemap-endpoint.d.ts +0 -4
  285. /package/dist/{cloudflare → packages/cloudflare}/src/utils/cache-control-metadata.js +0 -0
@@ -0,0 +1,187 @@
1
+ import { NEXTJS_DEPLOYMENT_ID_HEADER } from "./headers.js";
2
+ import { getDeploymentId } from "../utils/deployment-id.js";
3
+ import { VINEXT_RSC_CONTENT_TYPE, VINEXT_RSC_VARY_HEADER, applyRscCompatibilityIdHeader } from "./app-rsc-cache-busting.js";
4
+ //#region src/server/app-route-tree-prefetch.ts
5
+ const PARENT_INLINED_INTO_SELF = 32;
6
+ const INLINED_INTO_CHILD = 64;
7
+ const HEAD_INLINED_INTO_SELF = 128;
8
+ const PAGE_SEGMENT = "__PAGE__";
9
+ const SLOT_SEGMENT = "(__SLOT__)";
10
+ const SEGMENT_INLINE_SIZE = 1;
11
+ const SEGMENT_OUTLINE_SIZE = 4096;
12
+ const DEFAULT_SEGMENT_INLINE_THRESHOLD = 2048;
13
+ const HEAD_INLINE_SIZE = 1;
14
+ const DEFAULT_MAX_INLINE_BUNDLE_SIZE = 10240;
15
+ const NEXT_DID_POSTPONE_HEADER = "x-nextjs-postponed";
16
+ function isRouteTreePrefetchRequest(request) {
17
+ return request.headers.get("RSC") === "1" && request.headers.get("Next-Router-Prefetch") === "1" && request.headers.get("Next-Router-Segment-Prefetch") === "/_tree";
18
+ }
19
+ function createNode(segment, module) {
20
+ const { name, param } = routeTreeSegment(segment);
21
+ return {
22
+ name,
23
+ param,
24
+ prefetchSize: estimatePrefetchSize(module) ?? ((module === null || module === void 0) && segment !== PAGE_SEGMENT ? SEGMENT_INLINE_SIZE : null),
25
+ prefetchHints: 0,
26
+ slots: null
27
+ };
28
+ }
29
+ function ensureSlots(node) {
30
+ if (node.slots === null) node.slots = {};
31
+ return node.slots;
32
+ }
33
+ function addChild(node, key, child) {
34
+ ensureSlots(node)[key] = child;
35
+ }
36
+ function routeTreeSegment(segment) {
37
+ if (segment.startsWith(":")) {
38
+ const rest = segment.slice(1);
39
+ if (rest.endsWith("+")) return dynamicRouteTreeSegment(rest.slice(0, -1), "c");
40
+ if (rest.endsWith("*")) return dynamicRouteTreeSegment(rest.slice(0, -1), "oc");
41
+ return dynamicRouteTreeSegment(rest, "d");
42
+ }
43
+ if (segment.startsWith("[[...") && segment.endsWith("]]")) return dynamicRouteTreeSegment(segment.slice(5, -2), "oc");
44
+ if (segment.startsWith("[...") && segment.endsWith("]")) return dynamicRouteTreeSegment(segment.slice(4, -1), "c");
45
+ if (segment.startsWith("[") && segment.endsWith("]")) return dynamicRouteTreeSegment(segment.slice(1, -1), "d");
46
+ return {
47
+ name: segment,
48
+ param: null
49
+ };
50
+ }
51
+ function dynamicRouteTreeSegment(name, type) {
52
+ return {
53
+ name,
54
+ param: {
55
+ key: null,
56
+ siblings: null,
57
+ type
58
+ }
59
+ };
60
+ }
61
+ function explicitPrefetchSize(module) {
62
+ if (typeof module !== "object" || module === null) return null;
63
+ const value = module.prefetchSize;
64
+ if (value === "large") return SEGMENT_OUTLINE_SIZE;
65
+ if (value === "small") return SEGMENT_INLINE_SIZE;
66
+ return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : null;
67
+ }
68
+ function estimatePrefetchSize(module) {
69
+ const explicitSize = explicitPrefetchSize(module);
70
+ if (explicitSize !== null) return explicitSize;
71
+ if (typeof module !== "object" || module === null) return null;
72
+ return typeof module.default === "function" ? SEGMENT_INLINE_SIZE : null;
73
+ }
74
+ function layoutModuleByTreePosition(route) {
75
+ const layouts = route.layouts ?? [];
76
+ const positions = route.layoutTreePositions ?? [];
77
+ const byPosition = /* @__PURE__ */ new Map();
78
+ for (const [index, position] of positions.entries()) byPosition.set(position, layouts[index]);
79
+ return byPosition;
80
+ }
81
+ function modulesByTreePosition(modules, positions) {
82
+ const byPosition = /* @__PURE__ */ new Map();
83
+ for (const [index, position] of (positions ?? []).entries()) byPosition.set(position, modules?.[index]);
84
+ return byPosition;
85
+ }
86
+ async function buildTree(route) {
87
+ const layoutsByPosition = layoutModuleByTreePosition(route);
88
+ const root = createNode("", layoutsByPosition.get(0));
89
+ const nodesByPosition = new Map([[0, root]]);
90
+ let current = root;
91
+ for (const [index, segment] of route.routeSegments.entries()) {
92
+ const position = index + 1;
93
+ const child = createNode(segment, layoutsByPosition.get(position));
94
+ addChild(current, "children", child);
95
+ nodesByPosition.set(position, child);
96
+ current = child;
97
+ }
98
+ addChild(current, "children", createNode(PAGE_SEGMENT, route.page));
99
+ for (const slot of Object.values(route.slots ?? {})) {
100
+ const ownerPosition = slot.layoutIndex === void 0 || slot.layoutIndex < 0 ? route.routeSegments.length : route.layoutTreePositions?.[slot.layoutIndex] ?? route.routeSegments.length;
101
+ const owner = nodesByPosition.get(ownerPosition) ?? current;
102
+ const slotRoot = createNode(SLOT_SEGMENT, slot.layout);
103
+ let slotCurrent = slotRoot;
104
+ const slotConfigLayoutsByPosition = modulesByTreePosition(slot.configLayouts, slot.configLayoutTreePositions);
105
+ const slotRouteSegments = slot.routeSegments ?? [];
106
+ for (const [index, segment] of slotRouteSegments.entries()) {
107
+ const position = index + 1;
108
+ const child = createNode(segment, slotConfigLayoutsByPosition.get(position));
109
+ addChild(slotCurrent, "children", child);
110
+ slotCurrent = child;
111
+ }
112
+ addChild(slotCurrent, "children", createNode(PAGE_SEGMENT, slot.page ?? slot.default));
113
+ addChild(owner, slot.name, slotRoot);
114
+ }
115
+ return root;
116
+ }
117
+ function computePrefetchHints(node, parentGzipSize, headInlineState, config) {
118
+ const currentGzipSize = node.prefetchSize;
119
+ const sizeToInline = currentGzipSize !== null && currentGzipSize < config.maxSize ? currentGzipSize : null;
120
+ let didInlineIntoChild = false;
121
+ let acceptingChildInlinedBytes = 0;
122
+ let smallestChildInlinedBytes = Number.POSITIVE_INFINITY;
123
+ let hasChildren = false;
124
+ for (const child of Object.values(node.slots ?? {})) {
125
+ hasChildren = true;
126
+ const childInlinedBytes = computePrefetchHints(child, didInlineIntoChild ? null : sizeToInline, headInlineState, config);
127
+ if ((child.prefetchHints & PARENT_INLINED_INTO_SELF) !== 0) {
128
+ didInlineIntoChild = true;
129
+ acceptingChildInlinedBytes = childInlinedBytes;
130
+ } else if (!didInlineIntoChild && childInlinedBytes < smallestChildInlinedBytes) smallestChildInlinedBytes = childInlinedBytes;
131
+ }
132
+ if (!hasChildren) smallestChildInlinedBytes = 0;
133
+ let hints = node.prefetchHints;
134
+ if (didInlineIntoChild) hints |= INLINED_INTO_CHILD;
135
+ let inlinedBytes = didInlineIntoChild ? acceptingChildInlinedBytes : smallestChildInlinedBytes;
136
+ const isBundleTerminal = !didInlineIntoChild;
137
+ if (!headInlineState.inlined && isBundleTerminal && node.name === PAGE_SEGMENT && inlinedBytes + HEAD_INLINE_SIZE < config.maxBundleSize) {
138
+ hints |= HEAD_INLINED_INTO_SELF;
139
+ inlinedBytes += HEAD_INLINE_SIZE;
140
+ headInlineState.inlined = true;
141
+ }
142
+ if (parentGzipSize !== null) {
143
+ if (inlinedBytes + parentGzipSize < config.maxBundleSize) {
144
+ hints |= PARENT_INLINED_INTO_SELF;
145
+ inlinedBytes += parentGzipSize;
146
+ }
147
+ }
148
+ node.prefetchHints = hints;
149
+ return inlinedBytes;
150
+ }
151
+ function stripMutableFields(node) {
152
+ const slots = node.slots === null ? null : Object.fromEntries(Object.entries(node.slots).map(([key, child]) => [key, stripMutableFields(child)]));
153
+ return {
154
+ name: node.name,
155
+ param: node.param,
156
+ prefetchHints: node.prefetchHints,
157
+ slots
158
+ };
159
+ }
160
+ function resolvePrefetchInliningConfig(config) {
161
+ if (config) return config;
162
+ return {
163
+ maxBundleSize: DEFAULT_MAX_INLINE_BUNDLE_SIZE,
164
+ maxSize: DEFAULT_SEGMENT_INLINE_THRESHOLD
165
+ };
166
+ }
167
+ async function createRouteTreePrefetchResponse(route, options = {}) {
168
+ const tree = await buildTree(route);
169
+ computePrefetchHints(tree, null, { inlined: false }, resolvePrefetchInliningConfig(options.prefetchInlining));
170
+ const headers = new Headers({
171
+ "Cache-Control": "no-store",
172
+ "Content-Type": VINEXT_RSC_CONTENT_TYPE,
173
+ [NEXT_DID_POSTPONE_HEADER]: "2",
174
+ Vary: VINEXT_RSC_VARY_HEADER
175
+ });
176
+ applyRscCompatibilityIdHeader(headers);
177
+ const deploymentId = options.deploymentId ?? getDeploymentId();
178
+ if (deploymentId) headers.set(NEXTJS_DEPLOYMENT_ID_HEADER, deploymentId);
179
+ const payload = {
180
+ tree: stripMutableFields(tree),
181
+ staleTime: -1
182
+ };
183
+ if (options.buildId) payload.buildId = options.buildId;
184
+ return new Response(`0:${JSON.stringify(payload)}\n`, { headers });
185
+ }
186
+ //#endregion
187
+ export { createRouteTreePrefetchResponse, isRouteTreePrefetchRequest };
@@ -1,14 +1,16 @@
1
1
  import "./server-globals.js";
2
2
  import { runWithExecutionContext } from "../shims/request-context.js";
3
- import { VINEXT_PRERENDER_ROUTE_PARAMS_HEADER } from "./headers.js";
3
+ import { VINEXT_PRERENDER_ROUTE_PARAMS_HEADER } from "../utils/protocol-headers.js";
4
4
  import { badRequestResponse, notFoundResponse, notFoundStaticAssetResponse } from "./http-error-responses.js";
5
5
  import { isOpenRedirectShaped } from "./open-redirect.js";
6
6
  import { cloneRequestWithHeaders, filterInternalHeaders } from "./request-pipeline.js";
7
7
  import { assetPrefixPathname, isNextStaticPath } from "../utils/asset-prefix.js";
8
+ import { getImageOptimizer, handleConfiguredImageOptimization, isImageOptimizationPath } from "./image-optimization.js";
8
9
  import { finalizeMissingStaticAssetResponse, resolveStaticAssetSignal } from "./worker-utils.js";
9
10
  import { readTrustedPrerenderRouteParams, serializePrerenderRouteParamsHeader } from "./prerender-route-params.js";
10
- import rscHandler, { __assetPrefix, __basePath } from "virtual:vinext-rsc-entry";
11
+ import rscHandler, { __assetPrefix, __basePath, __imageAllowedWidths, __imageConfig } from "virtual:vinext-rsc-entry";
11
12
  import { registerConfiguredCacheAdapters } from "virtual:vinext-cache-adapters";
13
+ import { registerConfiguredImageOptimizer } from "virtual:vinext-image-adapters";
12
14
  //#region src/server/app-router-entry.ts
13
15
  const __workerBasePath = typeof __basePath === "string" ? __basePath : "";
14
16
  const __workerAssetPathPrefix = assetPrefixPathname(typeof __assetPrefix === "string" ? __assetPrefix : "");
@@ -17,7 +19,12 @@ var app_router_entry_default = { async fetch(request, env, ctx) {
17
19
  } };
18
20
  async function handleRequest(request, env, ctx) {
19
21
  registerConfiguredCacheAdapters(env);
22
+ registerConfiguredImageOptimizer(env);
20
23
  const url = new URL(request.url);
24
+ if (isImageOptimizationPath(url.pathname) && env?.ASSETS && getImageOptimizer()) {
25
+ const assetFetcher = env.ASSETS;
26
+ return handleConfiguredImageOptimization(request, (assetPath) => Promise.resolve(assetFetcher.fetch(new Request(new URL(assetPath, request.url)))), __imageAllowedWidths, __imageConfig);
27
+ }
21
28
  if (isOpenRedirectShaped(url.pathname)) return notFoundResponse();
22
29
  try {
23
30
  decodeURIComponent(url.pathname);
@@ -24,6 +24,7 @@ type ResolveInvalidRscCacheBustingRequestOptions = {
24
24
  };
25
25
  declare function getVinextRscCompatibilityId(): string | null;
26
26
  declare function applyRscCompatibilityIdHeader(headers: Headers, compatibilityId?: string | null | undefined): void;
27
+ declare function applyRscDeploymentIdHeader(headers: Headers): void;
27
28
  declare function isRscCompatibilityIdCompatible(responseCompatibilityId: string | null | undefined, clientCompatibilityId?: string | null | undefined): boolean;
28
29
  type RscCompatibilityNavigationDecision = {
29
30
  kind: "compatible";
@@ -61,4 +62,4 @@ declare function createServerActionRequestUrl(href: string): string;
61
62
  declare function createRscRedirectLocation(location: string, request: Request): Promise<string>;
62
63
  declare function resolveInvalidRscCacheBustingRequest(options: ResolveInvalidRscCacheBustingRequestOptions): Promise<Response | null>;
63
64
  //#endregion
64
- export { VINEXT_RSC_CACHE_BUSTING_SEARCH_PARAM, VINEXT_RSC_COMPATIBILITY_ID_HEADER, VINEXT_RSC_CONTENT_TYPE, VINEXT_RSC_RENDER_MODE_HEADER, VINEXT_RSC_VARY_HEADER, applyRscCompatibilityIdHeader, computeRscCacheBustingSearchParam, createRscRedirectLocation, createRscRequestHeaders, createRscRequestUrl, createServerActionRequestUrl, getVinextRscCompatibilityId, hasRscCacheBustingSearchParam, isRscCompatibilityIdCompatible, resolveHardNavigationTargetFromRscResponse, resolveInvalidRscCacheBustingRequest, resolveRscCompatibilityNavigationDecision, setRscCacheBustingSearchParam, stripRscCacheBustingSearchParam, stripRscSuffix };
65
+ export { VINEXT_RSC_CACHE_BUSTING_SEARCH_PARAM, VINEXT_RSC_COMPATIBILITY_ID_HEADER, VINEXT_RSC_CONTENT_TYPE, VINEXT_RSC_RENDER_MODE_HEADER, VINEXT_RSC_VARY_HEADER, applyRscCompatibilityIdHeader, applyRscDeploymentIdHeader, computeRscCacheBustingSearchParam, createRscRedirectLocation, createRscRequestHeaders, createRscRequestUrl, createServerActionRequestUrl, getVinextRscCompatibilityId, hasRscCacheBustingSearchParam, isRscCompatibilityIdCompatible, resolveHardNavigationTargetFromRscResponse, resolveInvalidRscCacheBustingRequest, resolveRscCompatibilityNavigationDecision, setRscCacheBustingSearchParam, stripRscCacheBustingSearchParam, stripRscSuffix };
@@ -1,7 +1,7 @@
1
- import { NEXT_ROUTER_PREFETCH_HEADER, NEXT_ROUTER_SEGMENT_PREFETCH_HEADER, NEXT_ROUTER_STATE_TREE_HEADER, NEXT_URL_HEADER, VINEXT_CLIENT_REUSE_MANIFEST_HEADER, VINEXT_INTERCEPTION_CONTEXT_HEADER, VINEXT_MOUNTED_SLOTS_HEADER, VINEXT_RSC_RENDER_MODE_HEADER } from "./headers.js";
1
+ import { NEXTJS_DEPLOYMENT_ID_HEADER, NEXT_ROUTER_PREFETCH_HEADER, NEXT_ROUTER_SEGMENT_PREFETCH_HEADER, NEXT_ROUTER_STATE_TREE_HEADER, NEXT_URL_HEADER, VINEXT_CLIENT_REUSE_MANIFEST_HEADER, VINEXT_INTERCEPTION_CONTEXT_HEADER, VINEXT_MOUNTED_SLOTS_HEADER, VINEXT_RSC_RENDER_MODE_HEADER } from "./headers.js";
2
2
  import { fnv1a64 } from "../utils/hash.js";
3
3
  import { parseAppRscRenderMode } from "./app-rsc-render-mode.js";
4
- import { applyDeploymentIdHeader } from "../utils/deployment-id.js";
4
+ import { applyDeploymentIdHeader, getDeploymentId } from "../utils/deployment-id.js";
5
5
  //#region src/server/app-rsc-cache-busting.ts
6
6
  /**
7
7
  * RSC cache-busting hashes cover the headers that make an RSC payload vary.
@@ -44,6 +44,11 @@ function applyRscCompatibilityIdHeader(headers, compatibilityId = getVinextRscCo
44
44
  if (normalized) headers.set(VINEXT_RSC_COMPATIBILITY_ID_HEADER, normalized);
45
45
  else headers.delete(VINEXT_RSC_COMPATIBILITY_ID_HEADER);
46
46
  }
47
+ function applyRscDeploymentIdHeader(headers) {
48
+ const deploymentId = getDeploymentId();
49
+ if (deploymentId) headers.set(NEXTJS_DEPLOYMENT_ID_HEADER, deploymentId);
50
+ else headers.delete(NEXTJS_DEPLOYMENT_ID_HEADER);
51
+ }
47
52
  function isRscCompatibilityIdCompatible(responseCompatibilityId, clientCompatibilityId = getVinextRscCompatibilityId()) {
48
53
  const normalizedResponseCompatibilityId = normalizeCompatibilityId(responseCompatibilityId);
49
54
  const normalizedClientCompatibilityId = normalizeCompatibilityId(clientCompatibilityId);
@@ -184,7 +189,7 @@ async function resolveInvalidRscCacheBustingRequest(options) {
184
189
  const url = new URL(options.request.url);
185
190
  const actualHash = url.searchParams.get(VINEXT_RSC_CACHE_BUSTING_SEARCH_PARAM);
186
191
  const expectedHash = await computeRscCacheBustingSearchParam(options.request.headers);
187
- if (actualHash === null && expectedHash === "") return null;
192
+ if (actualHash === null && expectedHash === "" && url.pathname.endsWith(".rsc")) return null;
188
193
  const acceptedHashes = new Set([expectedHash]);
189
194
  if (actualHash !== null && actualHash !== expectedHash) {
190
195
  acceptedHashes.add(computeLegacyRscCacheBustingSearchParam(options.request.headers));
@@ -203,4 +208,4 @@ async function resolveInvalidRscCacheBustingRequest(options) {
203
208
  });
204
209
  }
205
210
  //#endregion
206
- export { VINEXT_RSC_CACHE_BUSTING_SEARCH_PARAM, VINEXT_RSC_COMPATIBILITY_ID_HEADER, VINEXT_RSC_CONTENT_TYPE, VINEXT_RSC_RENDER_MODE_HEADER, VINEXT_RSC_VARY_HEADER, applyRscCompatibilityIdHeader, computeRscCacheBustingSearchParam, createRscRedirectLocation, createRscRequestHeaders, createRscRequestUrl, createServerActionRequestUrl, getVinextRscCompatibilityId, hasRscCacheBustingSearchParam, isRscCompatibilityIdCompatible, resolveHardNavigationTargetFromRscResponse, resolveInvalidRscCacheBustingRequest, resolveRscCompatibilityNavigationDecision, setRscCacheBustingSearchParam, stripRscCacheBustingSearchParam, stripRscSuffix };
211
+ export { VINEXT_RSC_CACHE_BUSTING_SEARCH_PARAM, VINEXT_RSC_COMPATIBILITY_ID_HEADER, VINEXT_RSC_CONTENT_TYPE, VINEXT_RSC_RENDER_MODE_HEADER, VINEXT_RSC_VARY_HEADER, applyRscCompatibilityIdHeader, applyRscDeploymentIdHeader, computeRscCacheBustingSearchParam, createRscRedirectLocation, createRscRequestHeaders, createRscRequestUrl, createServerActionRequestUrl, getVinextRscCompatibilityId, hasRscCacheBustingSearchParam, isRscCompatibilityIdCompatible, resolveHardNavigationTargetFromRscResponse, resolveInvalidRscCacheBustingRequest, resolveRscCompatibilityNavigationDecision, setRscCacheBustingSearchParam, stripRscCacheBustingSearchParam, stripRscSuffix };
@@ -6,6 +6,7 @@ import { AppMiddlewareContext, ApplyAppMiddlewareResult } from "./app-middleware
6
6
  import { AppRscRenderMode } from "./app-rsc-render-mode.js";
7
7
  import { AppPagePprFallbackCacheShell } from "./app-ppr-fallback-shell.js";
8
8
  import { AppPrerenderRootParamNamesMap, AppPrerenderStaticParamsMap } from "./app-prerender-endpoints.js";
9
+ import { AppRouteTreePrefetchRoute, PrefetchInliningConfig } from "./app-route-tree-prefetch.js";
9
10
  import { ReactFormState } from "react-dom/client";
10
11
 
11
12
  //#region src/server/app-rsc-handler.d.ts
@@ -16,6 +17,7 @@ type AppRscMiddlewareContext = AppMiddlewareContext;
16
17
  type RunAppMiddlewareOptions = {
17
18
  cleanPathname: string;
18
19
  context: AppRscMiddlewareContext;
20
+ hadBasePath: boolean;
19
21
  isDataRequest: boolean;
20
22
  request: Request;
21
23
  };
@@ -23,12 +25,15 @@ type AppRscHandlerRoute = {
23
25
  __loadPage?: unknown;
24
26
  __loadRouteHandler?: unknown;
25
27
  isDynamic: boolean;
28
+ layouts?: readonly unknown[];
29
+ layoutTreePositions?: readonly number[];
26
30
  params?: readonly string[];
27
31
  page?: unknown;
28
32
  pattern: string;
29
33
  rootParamNames?: readonly string[];
30
34
  routeHandler?: unknown;
31
35
  routeSegments: readonly string[];
36
+ slots?: AppRouteTreePrefetchRoute["slots"];
32
37
  };
33
38
  type AppRscRouteMatch<TRoute> = {
34
39
  params: AppPageParams;
@@ -62,6 +67,7 @@ type DispatchMatchedPageOptions<TRoute> = {
62
67
  staticParamsValidationParams?: AppPageParams;
63
68
  rootParams?: RootParams;
64
69
  request: Request;
70
+ renderedPathAndSearch?: string | null;
65
71
  route: TRoute;
66
72
  scriptNonce?: string;
67
73
  searchParams: URLSearchParams;
@@ -188,6 +194,7 @@ type CreateAppRscHandlerOptions<TRoute extends AppRscHandlerRoute> = {
188
194
  matchRoute: (pathname: string) => AppRscRouteMatch<TRoute> | null;
189
195
  runMiddleware?: (options: RunAppMiddlewareOptions) => Promise<ApplyAppMiddlewareResult>;
190
196
  publicFiles: ReadonlySet<string>;
197
+ prefetchInlining?: PrefetchInliningConfig;
191
198
  renderNotFound: (options: RenderNotFoundOptions<TRoute>) => Promise<Response | null>;
192
199
  renderPagesFallback?: (options: RenderPagesFallbackOptions) => Promise<Response | null>;
193
200
  rootParamNamesByPattern?: RootParamNamesMap;