@farm.js/core 0.1.82 → 0.1.84

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 (253) hide show
  1. package/dist/{agent-mcp.d-C2Su3x4D.d.ts → agent-mcp.d-7uKdOttc.d.ts} +1 -1
  2. package/dist/{agent-mcp.d-Yak-LqRd.d.mts → agent-mcp.d-LChlR2au.d.mts} +1 -1
  3. package/dist/agent-runtime.d.mts +2 -1
  4. package/dist/agent-runtime.d.ts +2 -1
  5. package/dist/{analyzer-RPU2KG4J.mjs → analyzer-7RNO3XKC.mjs} +2 -2
  6. package/dist/analyzer-PFKA5NI6.cjs +17 -0
  7. package/dist/api/node.d.mts +4 -3
  8. package/dist/api/node.d.ts +4 -3
  9. package/dist/api/route-manager.d.mts +4 -3
  10. package/dist/api/route-manager.d.ts +4 -3
  11. package/dist/api/runtime.d.mts +3 -2
  12. package/dist/api/runtime.d.ts +3 -2
  13. package/dist/api.d.mts +5 -4
  14. package/dist/api.d.ts +5 -4
  15. package/dist/{app-manifest.d-DZyXaICz.d.ts → app-manifest.d-CRp21oAz.d.ts} +1 -1
  16. package/dist/{app-manifest.d-BcyOFMrg.d.mts → app-manifest.d-QMdmqqCr.d.mts} +1 -1
  17. package/dist/app-markdown.d.mts +3 -2
  18. package/dist/app-markdown.d.ts +3 -2
  19. package/dist/{app.d-CIoXsAbN.d.ts → app.d-CVPu_hoD.d.ts} +34 -4
  20. package/dist/{app.d-C0ePpuaG.d.mts → app.d-eSm7jgoc.d.mts} +34 -4
  21. package/dist/{chunk-B2PGVHBG.cjs → chunk-22BTYPIX.cjs} +4 -4
  22. package/dist/{chunk-BCTHOQPP.cjs → chunk-3OKSEJ33.cjs} +98 -10
  23. package/dist/{chunk-QSMUMK7Y.mjs → chunk-3WM7VBGW.mjs} +2 -2
  24. package/dist/{chunk-XMHERKSE.mjs → chunk-42IBGQTN.mjs} +5 -12
  25. package/dist/{chunk-RMPUEH5T.cjs → chunk-57EEWWUS.cjs} +2 -2
  26. package/dist/{chunk-Q2VOT3K2.cjs → chunk-5I4ZGKP2.cjs} +395 -333
  27. package/dist/{chunk-TPA2PV5J.mjs → chunk-5V6HSJFG.mjs} +24 -1
  28. package/dist/{chunk-RMLR5RMH.mjs → chunk-BCCCPFHQ.mjs} +92 -4
  29. package/dist/{chunk-LM2ZDNDD.cjs → chunk-BOEDYXAX.cjs} +30 -25
  30. package/dist/{chunk-NRCKBDYP.mjs → chunk-BRDGINBB.mjs} +153 -47
  31. package/dist/chunk-BUQR7KKO.mjs +17 -0
  32. package/dist/{chunk-63ZE6B6M.mjs → chunk-BZY3SRRD.mjs} +1 -1
  33. package/dist/{chunk-724WT3NI.mjs → chunk-CRE642TW.mjs} +1 -1
  34. package/dist/{chunk-JK26IMT7.cjs → chunk-CVZY4TLW.cjs} +1 -1
  35. package/dist/{chunk-ZIZRIZLP.mjs → chunk-CWUQBECF.mjs} +3 -1
  36. package/dist/{chunk-DAXU2NBE.mjs → chunk-DFDQGHPU.mjs} +104 -42
  37. package/dist/{chunk-AIPZDBP6.cjs → chunk-DSWSDDP2.cjs} +844 -553
  38. package/dist/{chunk-DRO3NXA3.cjs → chunk-EBSL5TW7.cjs} +203 -93
  39. package/dist/{chunk-CJDBTTLB.mjs → chunk-EDBIBO67.mjs} +18 -13
  40. package/dist/{chunk-BBVLOEND.cjs → chunk-F7JVO3OZ.cjs} +4 -4
  41. package/dist/chunk-FZ7OUN5M.cjs +30 -0
  42. package/dist/chunk-GLNVLCUH.cjs +426 -0
  43. package/dist/{chunk-5MMKNW7Q.cjs → chunk-H7REG7OX.cjs} +15 -8
  44. package/dist/{chunk-N2EFMN2K.cjs → chunk-HOQ2MYBJ.cjs} +10 -10
  45. package/dist/{chunk-OP5VI4TP.mjs → chunk-I5CVJ24H.mjs} +1 -1
  46. package/dist/{chunk-I4DR3HCH.mjs → chunk-INU4K4U4.mjs} +5 -5
  47. package/dist/{chunk-4X7LSGM6.mjs → chunk-IRJSZAJB.mjs} +1 -1
  48. package/dist/{chunk-EX6ZSN5P.cjs → chunk-IZYFP7IN.cjs} +17 -24
  49. package/dist/chunk-J6RFB324.cjs +17 -0
  50. package/dist/{chunk-47I2MYIR.mjs → chunk-KXVMWLTC.mjs} +484 -193
  51. package/dist/{chunk-UVV3I5QA.cjs → chunk-L2GUEYHR.cjs} +29 -6
  52. package/dist/{chunk-VMBIKDKW.cjs → chunk-L3BSHASB.cjs} +6 -4
  53. package/dist/chunk-L5HDCDFT.mjs +426 -0
  54. package/dist/{chunk-GXLNARPO.mjs → chunk-M5XU22PQ.mjs} +1 -1
  55. package/dist/chunk-M6AJZ4XR.mjs +30 -0
  56. package/dist/chunk-MAPHNGTF.cjs +98 -0
  57. package/dist/{chunk-RE5E2G5S.cjs → chunk-MNUYXZV7.cjs} +2 -18
  58. package/dist/{chunk-C3VCYOU4.mjs → chunk-MUUDHWQZ.mjs} +1 -1
  59. package/dist/{chunk-YSU3WCW6.mjs → chunk-MYSH5Y4E.mjs} +1 -1
  60. package/dist/{chunk-OMB7UGVW.mjs → chunk-NLHSKKTT.mjs} +14 -9
  61. package/dist/{chunk-ARORZ3MH.cjs → chunk-OFVBMS6I.cjs} +439 -333
  62. package/dist/{chunk-5MUFW5UU.cjs → chunk-OP7BIEUW.cjs} +2 -2
  63. package/dist/{chunk-I4WZRG73.mjs → chunk-RB5IGN3N.mjs} +13 -6
  64. package/dist/chunk-RJBUI5AN.mjs +18 -0
  65. package/dist/chunk-RQ6XX5IN.mjs +98 -0
  66. package/dist/{chunk-EJCVG25Z.mjs → chunk-S3R4JDRO.mjs} +17 -9
  67. package/dist/{chunk-WFVSAT7Y.cjs → chunk-T7HGXF7D.cjs} +3 -3
  68. package/dist/{chunk-HHQEKLZL.cjs → chunk-USMRAC72.cjs} +36 -31
  69. package/dist/{chunk-SM2SYWAR.cjs → chunk-XJDB564A.cjs} +18 -10
  70. package/dist/{chunk-EL2Z6YFZ.mjs → chunk-XLULEFRW.mjs} +180 -70
  71. package/dist/{chunk-6BPFIYGY.cjs → chunk-YU6VL7H5.cjs} +3 -3
  72. package/dist/{chunk-CD5Z7RR5.cjs → chunk-Z37PDUJR.cjs} +4 -4
  73. package/dist/{cli-runtime.d-Hnvvadz7.d.mts → cli-runtime.d-C7aMfoTq.d.mts} +8 -6
  74. package/dist/{cli-runtime.d-I0MphTbc.d.ts → cli-runtime.d-DaElKjaL.d.ts} +8 -6
  75. package/dist/{client-component.d-DapRqtSC.d.mts → client-component.d-DLMCzmUx.d.mts} +1 -1
  76. package/dist/{client-component.d-5QEvtJsg.d.ts → client-component.d-DLknFP8l.d.ts} +1 -1
  77. package/dist/{client-plugins.d-DcmDzcSC.d.ts → client-plugins.d-BVXjyIkY.d.ts} +14 -0
  78. package/dist/{client-plugins.d-C1WM3ieD.d.mts → client-plugins.d-BwKwuO_0.d.mts} +14 -0
  79. package/dist/client-plugins.d.mts +2 -1
  80. package/dist/client-plugins.d.ts +2 -1
  81. package/dist/client.cjs +4 -3
  82. package/dist/client.d.mts +10 -9
  83. package/dist/client.d.ts +10 -9
  84. package/dist/client.mjs +3 -2
  85. package/dist/config.d.mts +2 -1
  86. package/dist/config.d.ts +2 -1
  87. package/dist/desktop.d.mts +3 -2
  88. package/dist/desktop.d.ts +3 -2
  89. package/dist/{devtools-5B7NZE6F.cjs → devtools-4SVIRV4P.cjs} +7 -7
  90. package/dist/{devtools-C5GXZZ7E.mjs → devtools-MWQA5LVN.mjs} +5 -5
  91. package/dist/docs.cjs +10 -9
  92. package/dist/docs.d.mts +15 -6
  93. package/dist/docs.d.ts +15 -6
  94. package/dist/docs.mjs +9 -8
  95. package/dist/environment/vite.cjs +5 -5
  96. package/dist/environment/vite.d.mts +1 -0
  97. package/dist/environment/vite.d.ts +1 -0
  98. package/dist/environment/vite.mjs +4 -4
  99. package/dist/{generate-route-types.d-CaGMIaNI.d.mts → generate-route-types.d-BFOMM8Ef.d.mts} +3 -0
  100. package/dist/{generate-route-types.d-B76M5R11.d.ts → generate-route-types.d-C2m8myHb.d.ts} +3 -0
  101. package/dist/{handler.d-B8bPCBzl.d.mts → handler.d-BKTWzzNA.d.mts} +1 -1
  102. package/dist/{handler.d-Cliwo6Nu.d.ts → handler.d-Dzpyg3-N.d.ts} +1 -1
  103. package/dist/{headers.d-CVwSpSGX.d.mts → headers.d-5opjyhXw.d.mts} +1 -1
  104. package/dist/{headers.d-C_btqjV6.d.ts → headers.d-PZyXcDAH.d.ts} +1 -1
  105. package/dist/index.cjs +32 -29
  106. package/dist/{index.d-DFuMZk9-.d.mts → index.d-C0Mie66f.d.mts} +1 -1
  107. package/dist/{index.d-hOEbMcLk.d.ts → index.d-DV2q-0mE.d.ts} +1 -1
  108. package/dist/index.d.mts +26 -25
  109. package/dist/index.d.ts +26 -25
  110. package/dist/index.mjs +32 -29
  111. package/dist/integrations/orm.d.mts +2 -1
  112. package/dist/integrations/orm.d.ts +2 -1
  113. package/dist/integrations.d.mts +2 -1
  114. package/dist/integrations.d.ts +2 -1
  115. package/dist/internal/app-markdown-runtime.d.mts +3 -2
  116. package/dist/internal/app-markdown-runtime.d.ts +3 -2
  117. package/dist/internal/build-runtime.cjs +28 -27
  118. package/dist/internal/build-runtime.d.mts +5 -4
  119. package/dist/internal/build-runtime.d.ts +5 -4
  120. package/dist/internal/build-runtime.mjs +27 -26
  121. package/dist/internal/cli-runtime.cjs +9 -9
  122. package/dist/internal/cli-runtime.d.mts +8 -7
  123. package/dist/internal/cli-runtime.d.ts +8 -7
  124. package/dist/internal/cli-runtime.mjs +8 -8
  125. package/dist/internal/client-error-overlay.cjs +4 -4
  126. package/dist/internal/client-error-overlay.mjs +1 -1
  127. package/dist/internal/client-runtime.d.mts +8 -42
  128. package/dist/internal/client-runtime.d.ts +8 -42
  129. package/dist/internal/compression-runtime.d.mts +2 -1
  130. package/dist/internal/compression-runtime.d.ts +2 -1
  131. package/dist/internal/config-runtime.cjs +7 -7
  132. package/dist/internal/config-runtime.d.mts +6 -5
  133. package/dist/internal/config-runtime.d.ts +6 -5
  134. package/dist/internal/config-runtime.mjs +6 -6
  135. package/dist/internal/infra-analytics-runtime.cjs +6 -6
  136. package/dist/internal/infra-analytics-runtime.mjs +4 -4
  137. package/dist/internal/islands-action-client.cjs +18 -0
  138. package/dist/internal/islands-action-client.d.mts +18 -0
  139. package/dist/internal/islands-action-client.d.ts +18 -0
  140. package/dist/internal/islands-action-client.mjs +18 -0
  141. package/dist/internal/islands-runtime.cjs +3 -8
  142. package/dist/internal/islands-runtime.mjs +4 -9
  143. package/dist/internal/islx-actions-client.cjs +4 -3
  144. package/dist/internal/islx-actions-client.mjs +3 -2
  145. package/dist/internal/islx-actions-server.d.mts +0 -2
  146. package/dist/internal/islx-actions-server.d.ts +0 -2
  147. package/dist/internal/islx-client.cjs +13 -1
  148. package/dist/internal/islx-client.d.mts +11 -0
  149. package/dist/internal/islx-client.d.ts +11 -0
  150. package/dist/internal/islx-client.mjs +14 -0
  151. package/dist/internal/metadata-image-runtime.d.mts +1 -0
  152. package/dist/internal/metadata-image-runtime.d.ts +1 -0
  153. package/dist/internal/native-server-fns.cjs +4 -4
  154. package/dist/internal/native-server-fns.mjs +3 -3
  155. package/dist/internal/product-telemetry-runtime.cjs +3 -3
  156. package/dist/internal/product-telemetry-runtime.mjs +2 -2
  157. package/dist/internal/production-runtime.cjs +13 -13
  158. package/dist/internal/production-runtime.d.mts +11 -11
  159. package/dist/internal/production-runtime.d.ts +11 -11
  160. package/dist/internal/production-runtime.mjs +19 -19
  161. package/dist/internal/renderer-islands.cjs +47 -0
  162. package/dist/internal/renderer-islands.d.mts +32 -0
  163. package/dist/internal/renderer-islands.d.ts +32 -0
  164. package/dist/internal/renderer-islands.mjs +47 -0
  165. package/dist/internal/spa-router.d.mts +3 -3
  166. package/dist/internal/spa-router.d.ts +3 -3
  167. package/dist/internal/start-manifest.d.mts +2 -1
  168. package/dist/internal/start-manifest.d.ts +2 -1
  169. package/dist/island-runtime.d-BA7EPo1v.d.ts +38 -0
  170. package/dist/island-runtime.d-BBS_YUSX.d.mts +38 -0
  171. package/dist/markdown.d.mts +2 -1
  172. package/dist/markdown.d.ts +2 -1
  173. package/dist/middleware.d.mts +2 -1
  174. package/dist/middleware.d.ts +2 -1
  175. package/dist/mobile.d.mts +6 -3
  176. package/dist/mobile.d.ts +6 -3
  177. package/dist/{mount.d-DLeYxeRR.d.mts → mount.d-CZ_qL1iS.d.mts} +1 -1
  178. package/dist/{mount.d-CAovYKfs.d.ts → mount.d-gWul1GA1.d.ts} +1 -1
  179. package/dist/{navigation-delegate.d-Chv93QS6.d.mts → navigation-delegate.d-BBTzhJLj.d.mts} +1 -1
  180. package/dist/{navigation-delegate.d-BLM-8Q3Z.d.ts → navigation-delegate.d-BZsYEAet.d.ts} +1 -1
  181. package/dist/navigation.d.mts +5 -5
  182. package/dist/navigation.d.ts +5 -5
  183. package/dist/plugin.cjs +23 -22
  184. package/dist/plugin.d.mts +6 -6
  185. package/dist/plugin.d.ts +6 -6
  186. package/dist/plugin.mjs +22 -21
  187. package/dist/{render-plan.d-BSTjTH8h.d.ts → render-plan.d-AaJsYPX-.d.ts} +1 -1
  188. package/dist/{render-plan.d-CK5Lggyb.d.mts → render-plan.d-bnWxS12w.d.mts} +1 -1
  189. package/dist/renderer-client.cjs +6 -5
  190. package/dist/renderer-client.d.mts +8 -7
  191. package/dist/renderer-client.d.ts +8 -7
  192. package/dist/renderer-client.mjs +2 -1
  193. package/dist/renderer.cjs +12 -2
  194. package/dist/renderer.d.mts +167 -4
  195. package/dist/renderer.d.ts +167 -4
  196. package/dist/renderer.mjs +11 -1
  197. package/dist/{request.d-BhggxQf3.d.mts → request.d-C2HOn3Hi.d.mts} +1 -1
  198. package/dist/{request.d-CyJS9bjm.d.ts → request.d-CAeitOG1.d.ts} +1 -1
  199. package/dist/request.d.mts +3 -2
  200. package/dist/request.d.ts +3 -2
  201. package/dist/{route-rendering.d-BLPPmI5I.d.ts → route-rendering.d-A1dIkUK5.d.ts} +1 -1
  202. package/dist/{route-rendering.d-CUpG2mZJ.d.mts → route-rendering.d-CYA-ulnX.d.mts} +1 -1
  203. package/dist/{router.d-2NQM1Kgw.d.mts → router.d-8lxnzlkr.d.mts} +1 -1
  204. package/dist/{router.d-0X2Ki6rf.d.ts → router.d-A_Yt6jYz.d.ts} +1 -1
  205. package/dist/{routes.d-CCccJRrp.d.mts → routes.d-BWvpUoYu.d.mts} +1 -1
  206. package/dist/{routes.d-b7khoRoU.d.ts → routes.d-D7RWvfqL.d.ts} +1 -1
  207. package/dist/routes.d.mts +2 -1
  208. package/dist/routes.d.ts +2 -1
  209. package/dist/{rsc-pipeline-5AOF64FL.cjs → rsc-pipeline-OWBEZ7HB.cjs} +10 -10
  210. package/dist/{rsc-pipeline-DNRLYOJ7.mjs → rsc-pipeline-UT3Z2GDO.mjs} +9 -9
  211. package/dist/{runtime-EHG2FRXZ.mjs → runtime-F5I3WY3B.mjs} +12 -12
  212. package/dist/{runtime-ZVHG5SRB.cjs → runtime-SRMQ46SK.cjs} +15 -15
  213. package/dist/{runtime.d-CXuwkUgr.d.ts → runtime.d-BPyvWrgQ.d.ts} +1 -1
  214. package/dist/{runtime.d-CaFXcu_Q.d.mts → runtime.d-C_rZ9_DD.d.mts} +1 -1
  215. package/dist/{server-components-status.d-Cp7zvBm5.d.mts → server-components-status.d-BpxiEMQE.d.mts} +1 -1
  216. package/dist/{server-components-status.d-BdeFD8ZH.d.ts → server-components-status.d-C2UEKJn7.d.ts} +1 -1
  217. package/dist/server-plugins.d.mts +4 -3
  218. package/dist/server-plugins.d.ts +4 -3
  219. package/dist/server-query-call.d-rVM_lsYk.d.mts +15 -0
  220. package/dist/server-query-call.d-rVM_lsYk.d.ts +15 -0
  221. package/dist/server-query-client.cjs +5 -3
  222. package/dist/server-query-client.d.mts +3 -2
  223. package/dist/server-query-client.d.ts +3 -2
  224. package/dist/server-query-client.mjs +5 -3
  225. package/dist/{server-query-runtime.d-DXRNhX_3.d.ts → server-query-runtime.d-BlHd90D0.d.ts} +2 -8
  226. package/dist/{server-query-runtime.d-aP52iuL5.d.mts → server-query-runtime.d-CCLGkQtE.d.mts} +2 -8
  227. package/dist/server.cjs +52 -52
  228. package/dist/server.d.mts +12 -12
  229. package/dist/server.d.ts +12 -12
  230. package/dist/server.mjs +30 -30
  231. package/dist/{spa-router.d-l3G38xHa.d.mts → spa-router.d-BD-6WX1R.d.mts} +2 -2
  232. package/dist/{spa-router.d-Bjgl-Osi.d.ts → spa-router.d-Cw5i_15e.d.ts} +2 -2
  233. package/dist/{ssg.d-DDca17Lc.d.ts → ssg.d-Bifiq0EL.d.ts} +2 -2
  234. package/dist/{ssg.d-RnlHOqUL.d.mts → ssg.d-CCE9aob5.d.mts} +2 -2
  235. package/dist/{store-core.d-BaOUOPf7.d.ts → store-core.d-5tVn5vi1.d.ts} +3 -3
  236. package/dist/{store-core.d-BZjuC6Zc.d.mts → store-core.d-BN2MxSG9.d.mts} +3 -3
  237. package/dist/testing.d.mts +2 -1
  238. package/dist/testing.d.ts +2 -1
  239. package/dist/{utils.d-D8TWmpWo.d.ts → utils.d-BUjpSNIO.d.ts} +1 -1
  240. package/dist/{utils.d-tdzw0_zQ.d.mts → utils.d-wGPLeVbq.d.mts} +1 -1
  241. package/dist/version.cjs +2 -2
  242. package/dist/version.mjs +1 -1
  243. package/dist/vite.cjs +23 -22
  244. package/dist/vite.d.mts +12 -6
  245. package/dist/vite.d.ts +12 -6
  246. package/dist/vite.mjs +22 -21
  247. package/package.json +13 -3
  248. package/dist/analyzer-LV23T6QN.cjs +0 -17
  249. package/dist/chunk-4QENVMG7.mjs +0 -34
  250. package/dist/chunk-AUFEM3FB.mjs +0 -229
  251. package/dist/chunk-S7WZUK3B.cjs +0 -229
  252. package/dist/{chunk-NEKO3HM2.cjs → chunk-4B6YJ5DS.cjs} +2 -2
  253. package/dist/{chunk-CA2HBLXP.mjs → chunk-4EEAPBNV.mjs} +3 -3
@@ -32,16 +32,15 @@ import {
32
32
  import {
33
33
  collectFarmNativeServerFns,
34
34
  findFarmNativeScreenFiles
35
- } from "./chunk-C3VCYOU4.mjs";
35
+ } from "./chunk-MUUDHWQZ.mjs";
36
36
  import {
37
37
  assertFarmDocsAdapterServesNoGuardedPages,
38
38
  compileFarmDocsAdapterEdgeManifest,
39
39
  createFarmDocsAPIHandler,
40
40
  farmDocsAdapterServesGuardedPages,
41
- hasFarmDocsRuntimeAdapter,
42
41
  listFarmDocsAdapterPages,
43
42
  listFarmDocsPagePaths
44
- } from "./chunk-OMB7UGVW.mjs";
43
+ } from "./chunk-NLHSKKTT.mjs";
45
44
  import {
46
45
  FARM_DOCS_LAST_MODIFIED_MANIFEST,
47
46
  createFarmDocsHandler,
@@ -71,7 +70,7 @@ import {
71
70
  getDeployTargetForPreset,
72
71
  hasCustomFarmRouteContext,
73
72
  resolveDeployOutputPath
74
- } from "./chunk-CJDBTTLB.mjs";
73
+ } from "./chunk-EDBIBO67.mjs";
75
74
  import {
76
75
  resolveFarmInstrumentationFile
77
76
  } from "./chunk-QRNYSISP.mjs";
@@ -116,7 +115,7 @@ import {
116
115
  resolveFarmNotFoundComponentPath,
117
116
  resolveFarmRouteRootStrategy,
118
117
  toBakedMarkdownSourcePath
119
- } from "./chunk-NRCKBDYP.mjs";
118
+ } from "./chunk-BRDGINBB.mjs";
120
119
  import {
121
120
  TAILWIND_CSS_BROWSER_TARGET,
122
121
  generateFarmClientPluginEntryCode,
@@ -132,7 +131,14 @@ import {
132
131
  readRouteRenderingDirectiveFromFile,
133
132
  resolveRouteRenderingConfig,
134
133
  resolveRouteRenderingConfigFromFile
135
- } from "./chunk-ZIZRIZLP.mjs";
134
+ } from "./chunk-CWUQBECF.mjs";
135
+ import {
136
+ usesFarmRendererIslands
137
+ } from "./chunk-RQ6XX5IN.mjs";
138
+ import {
139
+ FARM_PRERENDER_ENV,
140
+ _farmWebMCPReportsEnabled
141
+ } from "./chunk-M5XU22PQ.mjs";
136
142
  import {
137
143
  HOISTED_HEAD_ELEMENT,
138
144
  appMiddlewareMayHandlePath,
@@ -145,17 +151,13 @@ import {
145
151
  layoutsCanCoverSamePage,
146
152
  routeBoundaryCoversDirectory,
147
153
  stripRouteGroups
148
- } from "./chunk-CA2HBLXP.mjs";
154
+ } from "./chunk-4EEAPBNV.mjs";
149
155
  import {
150
156
  FARM_NATIVE_TREE_CONTENT_TYPE
151
157
  } from "./chunk-LLZSYFOM.mjs";
152
158
  import {
153
159
  farmPluginMayAffectRuntimePath
154
160
  } from "./chunk-UUMKLGUU.mjs";
155
- import {
156
- FARM_PRERENDER_ENV,
157
- _farmWebMCPReportsEnabled
158
- } from "./chunk-GXLNARPO.mjs";
159
161
  import {
160
162
  FARM_API_CATALOG_PATH,
161
163
  FARM_APP_MANIFEST_LEGACY_PATH,
@@ -163,7 +165,7 @@ import {
163
165
  listFarmBuiltInRoutePaths,
164
166
  resolveFarmApiCatalogInput,
165
167
  resolveFarmAppManifestInput
166
- } from "./chunk-QSMUMK7Y.mjs";
168
+ } from "./chunk-3WM7VBGW.mjs";
167
169
  import {
168
170
  FARM_DEFAULT_MCP_PATH,
169
171
  createFarmDefaultMCPServer,
@@ -171,7 +173,7 @@ import {
171
173
  } from "./chunk-HR4N2K4V.mjs";
172
174
  import {
173
175
  isFarmPreviewDeploymentEnvironment
174
- } from "./chunk-4X7LSGM6.mjs";
176
+ } from "./chunk-IRJSZAJB.mjs";
175
177
  import {
176
178
  FARM_NATIVE_SERVER_FN_PLUGIN
177
179
  } from "./chunk-L4RTTTVE.mjs";
@@ -192,15 +194,20 @@ import {
192
194
  withFarmSourceSnapshot,
193
195
  withFarmSourceSnapshotOf,
194
196
  withPackageClientBoundaryCache
195
- } from "./chunk-EL2Z6YFZ.mjs";
197
+ } from "./chunk-XLULEFRW.mjs";
196
198
  import {
197
199
  generateFarmDocsAdapterClientRuntime,
198
200
  getFarmDocsAdapterConfigModule
199
- } from "./chunk-EJCVG25Z.mjs";
201
+ } from "./chunk-S3R4JDRO.mjs";
200
202
  import {
201
203
  resolveFarmDocsFontAssets,
202
204
  toFarmDocsPublicFontAssets
203
205
  } from "./chunk-NRNAHZ57.mjs";
206
+ import {
207
+ getFarmDocsAdapterRenderer,
208
+ getFarmDocsAdapterUIModule,
209
+ hasFarmDocsRuntimeAdapter
210
+ } from "./chunk-5V6HSJFG.mjs";
204
211
  import {
205
212
  nitroRouteRulesBelowBasePath,
206
213
  routeRulesToNitroRouteRules
@@ -209,9 +216,6 @@ import {
209
216
  applyFarmCspHashesToHtml,
210
217
  createFarmCspNonce
211
218
  } from "./chunk-22W4FNTG.mjs";
212
- import {
213
- resolveFarmServerComponentsMode
214
- } from "./chunk-4QENVMG7.mjs";
215
219
  import {
216
220
  getFarmAppDirectories
217
221
  } from "./chunk-Z3RM3VA2.mjs";
@@ -223,8 +227,9 @@ import {
223
227
  isFarmRendererDisabled,
224
228
  isReactRenderer,
225
229
  loadFarmRendererVitePlugins,
226
- resolveFarmRendererAppSetup
227
- } from "./chunk-RMLR5RMH.mjs";
230
+ resolveFarmRendererAppSetup,
231
+ resolveFarmServerComponentsMode
232
+ } from "./chunk-BCCCPFHQ.mjs";
228
233
  import {
229
234
  applyFarmCronVercelCrons,
230
235
  createFarmCronCloudflareConfig,
@@ -303,7 +308,7 @@ import {
303
308
  } from "./chunk-2I6PUKWJ.mjs";
304
309
  import {
305
310
  FARM_VERSION
306
- } from "./chunk-OP5VI4TP.mjs";
311
+ } from "./chunk-I5CVJ24H.mjs";
307
312
  import {
308
313
  FARM_VIDEO_PLAYER_PATH
309
314
  } from "./chunk-AG27TI6Q.mjs";
@@ -504,6 +509,7 @@ import path2 from "path";
504
509
  var FARM_CLIENT_CSS_HREF_PLACEHOLDER = "/__farm_client_css_href__";
505
510
  var FARM_CLIENT_JS_SRC_PLACEHOLDER = "/__farm_client_js_src__";
506
511
  var FARM_CLIENT_BOOT_SRC_PLACEHOLDER = "/__farm_client_boot_src__";
512
+ var FARM_CLIENT_STYLESHEET_PLACEHOLDER = "__farm_client_stylesheet__";
507
513
  async function hashAndCopy(sourcePath, destinationDir, hashedName) {
508
514
  const fs5 = await import("fs/promises");
509
515
  try {
@@ -527,6 +533,15 @@ async function resolveHashedClientCssHref(clientOutputDir) {
527
533
  );
528
534
  return name ? `/assets/${name}` : "/farm-client.css";
529
535
  }
536
+ async function resolveClientStylesheetLinkHref(clientOutputDir, clientCssHref) {
537
+ const fs5 = await import("fs/promises");
538
+ try {
539
+ const stylesheet = await fs5.stat(path2.join(clientOutputDir, "farm-client.css"));
540
+ return stylesheet.size > 0 ? clientCssHref : null;
541
+ } catch {
542
+ return null;
543
+ }
544
+ }
530
545
  async function findFingerprintedClientEntry(clientOutputDir) {
531
546
  const fs5 = await import("fs/promises");
532
547
  try {
@@ -798,13 +813,15 @@ function collectFarmClientModulePreloads(bundle, options) {
798
813
  ...staticImports(chunk, loaded, [])
799
814
  ].map(index);
800
815
  }
801
- const dynamicFiles = (moduleIds) => {
816
+ const dynamicFiles = (moduleIds, before = []) => {
802
817
  const into = [];
803
- const loaded = new Set(entryLoaded);
818
+ const loaded = /* @__PURE__ */ new Set([...entryLoaded, ...before]);
804
819
  for (const moduleId of moduleIds ?? []) {
820
+ const is = (id) => path4.resolve(id.split("?")[0]) === path4.resolve(moduleId);
805
821
  const chunk = chunks.find(
806
- (candidate) => candidate.isDynamicEntry && candidate.facadeModuleId && path4.resolve(candidate.facadeModuleId.split("?")[0]) === path4.resolve(moduleId)
807
- );
822
+ (candidate) => candidate.isDynamicEntry && candidate.facadeModuleId && is(candidate.facadeModuleId)
823
+ ) ?? // A module another dynamic import shares can land in a common chunk without a facade.
824
+ chunks.find((candidate) => !candidate.isEntry && candidate.moduleIds?.some(is));
808
825
  if (!chunk || loaded.has(chunk.fileName)) continue;
809
826
  loaded.add(chunk.fileName);
810
827
  into.push(chunk.fileName);
@@ -813,11 +830,15 @@ function collectFarmClientModulePreloads(bundle, options) {
813
830
  return into;
814
831
  };
815
832
  const rendererFiles = dynamicFiles(options.rendererModules);
833
+ const rootFiles = dynamicFiles(options.rootModules);
834
+ const actionFiles = dynamicFiles(options.actionModules, rendererFiles);
816
835
  return {
817
836
  files,
818
837
  entry: entryFiles.map(index),
819
838
  router: dynamicFiles(options.routerModules).map(index),
820
839
  ...rendererFiles.length > 0 ? { renderer: rendererFiles.map(index) } : {},
840
+ ...rootFiles.length > 0 ? { root: rootFiles.map(index) } : {},
841
+ ...actionFiles.length > 0 ? { actions: actionFiles.map(index) } : {},
821
842
  modules
822
843
  };
823
844
  }
@@ -826,15 +847,22 @@ function createFarmClientModulePreloadPlugin(options) {
826
847
  name: "farm-client-module-preloads",
827
848
  enforce: "post",
828
849
  async generateBundle(_output, bundle) {
829
- const rendererModules = [];
830
- for (const specifier of options.rendererImports ?? []) {
831
- const resolved = await this.resolve(specifier, options.rendererImporter);
832
- if (resolved) rendererModules.push(resolved.id);
833
- }
850
+ const resolve = async (specifiers) => {
851
+ const ids = [];
852
+ for (const specifier of specifiers ?? []) {
853
+ const resolved = await this.resolve(specifier, options.rendererImporter);
854
+ if (resolved) ids.push(resolved.id);
855
+ }
856
+ return ids;
857
+ };
858
+ const rendererModules = await resolve(options.rendererImports);
859
+ const actionModules = await resolve(options.actionImports);
834
860
  await fs.mkdir(options.buildDir, { recursive: true });
835
861
  await fs.writeFile(
836
862
  path4.join(options.buildDir, FARM_CLIENT_MODULE_PRELOADS_FILE),
837
- JSON.stringify(collectFarmClientModulePreloads(bundle, { ...options, rendererModules }))
863
+ JSON.stringify(
864
+ collectFarmClientModulePreloads(bundle, { ...options, rendererModules, actionModules })
865
+ )
838
866
  );
839
867
  }
840
868
  };
@@ -907,8 +935,10 @@ function resolveFarmDocsClientRoutes(pages, docsPagePaths) {
907
935
  function isStatic(segment) {
908
936
  return segment === "static";
909
937
  }
910
- function generateFarmClientRouteTableModule(table) {
911
- return `export default JSON.parse(${JSON.stringify(JSON.stringify(table))});
938
+ function generateFarmClientRouteTableModule(table, options = {}) {
939
+ const matcher = options.matcher ? `export { createFarmRouter, isFarmRouteActive, matchFarmRoute } from "@farm.js/core/router";
940
+ ` : "";
941
+ return `${matcher}export default JSON.parse(${JSON.stringify(JSON.stringify(table))});
912
942
  `;
913
943
  }
914
944
  async function writeFarmClientRouteTable(buildDir, table) {
@@ -3170,9 +3200,7 @@ async function buildClient(productionVite, config, root, srcDir, outputDir, page
3170
3200
  const layoutAppliesToRoute = routeBoundaryCoversDirectory;
3171
3201
  const routeDirectory = (route) => route.directory ?? route.pattern;
3172
3202
  const islandsMode = resolveFarmServerComponentsMode(config.experimental?.serverComponents) === "islands";
3173
- const adapterOwnsDocsRuntime = Boolean(
3174
- isReactRenderer(config.renderer) && config.docs?.enabled && config.docs.adapter?.server && config.docs.adapter.react
3175
- );
3203
+ const adapterOwnsDocsRuntime = hasFarmDocsRuntimeAdapter(config.docs);
3176
3204
  const docsEntries = config.docs?.enabled ? getFarmDocsRoots(config.docs).map(
3177
3205
  (docsRoot) => `/${docsRoot.entry || "docs"}`.replace(/\/+/g, "/").replace(/\/$/, "") || "/"
3178
3206
  ) : [];
@@ -3423,7 +3451,7 @@ async function buildClient(productionVite, config, root, srcDir, outputDir, page
3423
3451
  adapterOwnsDocsRuntime ? false : isFarmDocsSearchEnabled(config.docs),
3424
3452
  adapterOwnsDocsRuntime ? void 0 : resolveFarmDocsSearchClientModule(root),
3425
3453
  config.docs?.enabled ? getFarmDocsRoots(config.docs).map((docsRoot) => docsRoot.entry) : void 0,
3426
- adapterOwnsDocsRuntime ? config.docs.adapter?.react : void 0,
3454
+ adapterOwnsDocsRuntime ? getFarmDocsAdapterUIModule(config.docs.adapter) : void 0,
3427
3455
  config.i18n,
3428
3456
  config.plugins,
3429
3457
  config.renderer,
@@ -3444,15 +3472,20 @@ async function buildClient(productionVite, config, root, srcDir, outputDir, page
3444
3472
  ) : []
3445
3473
  );
3446
3474
  const entryName = platform === "mobile" ? FARM_MOBILE_CLIENT_ENTRY_NAME : "farm-client";
3447
- const clientEntry = islandsMode && platform === "web" && clientHydrationCode.includes("/*farm-router-stub*/") ? splitFarmClientRouter(clientHydrationCode) : { entry: clientHydrationCode, router: void 0 };
3475
+ const clientEntry = islandsMode && platform === "web" && clientHydrationCode.includes("/*farm-router-stub*/") ? splitFarmClientEntry(clientHydrationCode) : { entry: clientHydrationCode, router: void 0, root: void 0 };
3448
3476
  await fs5.writeFile(clientEntryPath, clientEntry.entry);
3449
3477
  await fs5.writeFile(
3450
3478
  path17.join(clientEntryDir, `${FARM_CLIENT_ROUTE_TABLE_MODULE}.tsx`),
3451
- generateFarmClientRouteTableModule(clientRouteTable)
3479
+ generateFarmClientRouteTableModule(clientRouteTable, {
3480
+ matcher: islandsMode && platform !== "mobile"
3481
+ })
3452
3482
  );
3453
3483
  if (clientEntry.router !== void 0) {
3454
3484
  await fs5.writeFile(path17.join(clientEntryDir, "farm-client-router.tsx"), clientEntry.router);
3455
3485
  }
3486
+ if (clientEntry.root !== void 0) {
3487
+ await fs5.writeFile(path17.join(clientEntryDir, "farm-client-root.tsx"), clientEntry.root);
3488
+ }
3456
3489
  const clientInput = { [entryName]: clientEntryPath };
3457
3490
  if (platform === "web" && canBootFarmIslandsClient(config)) {
3458
3491
  const clientBootPath = path17.join(clientEntryDir, "farm-client-boot.tsx");
@@ -3548,6 +3581,7 @@ async function buildClient(productionVite, config, root, srcDir, outputDir, page
3548
3581
  path17.join(clientEntryDir, "farm-client-router.tsx"),
3549
3582
  path17.join(clientEntryDir, `${FARM_CLIENT_ROUTE_TABLE_MODULE}.tsx`)
3550
3583
  ],
3584
+ rootModules: [path17.join(clientEntryDir, "farm-client-root.tsx")],
3551
3585
  // What the islands entry loads with its first render or hydration (RFC 0010).
3552
3586
  ...islandsMode && isReactRenderer(config.renderer) ? {
3553
3587
  rendererImports: [
@@ -3555,6 +3589,8 @@ async function buildClient(productionVite, config, root, srcDir, outputDir, page
3555
3589
  "react-dom/client",
3556
3590
  "@farm.js/core/internal/islands-runtime"
3557
3591
  ],
3592
+ // What a call's result is handled with, imported on the first (RFC 0013).
3593
+ actionImports: ["@farm.js/core/internal/islands-action-client"],
3558
3594
  rendererImporter: clientEntryPath
3559
3595
  } : {}
3560
3596
  }),
@@ -3565,7 +3601,7 @@ async function buildClient(productionVite, config, root, srcDir, outputDir, page
3565
3601
  importer: clientEntryPath,
3566
3602
  entryName: "farm-client",
3567
3603
  modules: [
3568
- config.docs.adapter.react,
3604
+ getFarmDocsAdapterUIModule(config.docs.adapter),
3569
3605
  getFarmDocsAdapterConfigModule(config.docs)
3570
3606
  ].filter((specifier) => Boolean(specifier))
3571
3607
  })
@@ -3841,18 +3877,27 @@ function loadFarmClientRouteTable() { return null; }
3841
3877
  function prefetchFarmClientRouteTable() {}
3842
3878
  const farmClientRoutesBoot = null;`;
3843
3879
  }
3880
+ const lazy = options.lazyMatcher === true;
3881
+ const toClientRoute = `function(route) {
3882
+ const load = typeof route.loader === "number" ? farmClientRouteLoaders[route.loader] : undefined;
3883
+ return { ...route, navigation: "html-fragment", load: load || null };
3884
+ }`;
3844
3885
  return `${prefetch}
3845
3886
  let clientRoutes = [];
3846
- let clientRouteMatcher = createFarmRouter([]);
3847
- let clientPageRouteMatcher = clientRouteMatcher;
3887
+ ${lazy ? `// The matcher, which loads with the table. Until then the entry matches only the document's own
3888
+ // path (readFarmClientBootRoute).
3889
+ let createFarmRouter = null;
3890
+ let isFarmRouteActive = null;
3891
+ let matchFarmRoute = null;
3892
+ let clientRouteMatcher = null;
3893
+ let clientPageRouteMatcher = null;
3894
+ let farmClientBootRoute = null;` : `let clientRouteMatcher = createFarmRouter([]);
3895
+ let clientPageRouteMatcher = clientRouteMatcher;`}
3848
3896
  let farmClientRouteTableLoad = null;
3849
3897
  let farmClientRouteTableLoaded = false;
3850
3898
 
3851
3899
  function setFarmClientRoutes(routes) {
3852
- clientRoutes = routes.map(function(route) {
3853
- const load = typeof route.loader === "number" ? farmClientRouteLoaders[route.loader] : undefined;
3854
- return { ...route, navigation: "html-fragment", load: load || null };
3855
- });
3900
+ clientRoutes = routes.map(${lazy ? "toFarmClientRoute" : toClientRoute});
3856
3901
  clientRouteMatcher = createFarmRouter(clientRoutes.map(function(route) {
3857
3902
  return { path: route.pattern, meta: route };
3858
3903
  }));
@@ -3862,12 +3907,27 @@ function setFarmClientRoutes(routes) {
3862
3907
  return { path: route.pattern, meta: route };
3863
3908
  }))` : "clientRouteMatcher"};
3864
3909
  }
3910
+ ${lazy ? `
3911
+ function toFarmClientRoute(route) {
3912
+ const load = typeof route.loader === "number" ? farmClientRouteLoaders[route.loader] : undefined;
3913
+ return { ...route, navigation: "html-fragment", load: load || null };
3914
+ }
3865
3915
 
3916
+ // The document's own route, which it names with its params and layouts, until the table loads. A
3917
+ // match for another path waits for the table: the router loads it before it matches.
3918
+ function readFarmClientBootRoute(path) {
3919
+ if (farmClientBootRoute && farmClientBootRoute.path === path) return farmClientBootRoute;
3920
+ throw new Error("[Farm.js] " + path + " cannot be matched before the client route table loads.");
3921
+ }
3922
+ ` : ""}
3866
3923
  // Null once the whole table is in place, else a promise that settles when it is.
3867
3924
  function loadFarmClientRouteTable() {
3868
3925
  if (farmClientRouteTableLoaded) return null;
3869
3926
  return farmClientRouteTableLoad || (farmClientRouteTableLoad = import("./${FARM_CLIENT_ROUTE_TABLE_MODULE}").then(function(module) {
3870
- setFarmClientRoutes(module.default);
3927
+ ${lazy ? ` createFarmRouter = module.createFarmRouter;
3928
+ isFarmRouteActive = module.isFarmRouteActive;
3929
+ matchFarmRoute = module.matchFarmRoute;
3930
+ ` : ""} setFarmClientRoutes(module.default);
3871
3931
  farmClientRouteTableLoaded = true;
3872
3932
  }, function(error) {
3873
3933
  farmClientRouteTableLoad = null;
@@ -3883,8 +3943,9 @@ function prefetchFarmClientRouteTable() {
3883
3943
 
3884
3944
  const farmClientRoutesBoot = (function() {
3885
3945
  const boot = window.__FARM_CLIENT_ROUTES__;
3886
- if (boot && Array.isArray(boot.routes) && boot.path === getFarmRoutePathname(window.location.pathname)) {
3887
- setFarmClientRoutes(boot.routes);
3946
+ if (boot && Array.isArray(boot.routes) && boot.path === getFarmRoutePathname(window.location.pathname)${lazy ? " &&\n boot.params && Array.isArray(boot.layouts)" : ""}) {
3947
+ ${lazy ? ` clientRoutes = boot.routes.map(toFarmClientRoute);
3948
+ farmClientBootRoute = boot;` : " setFarmClientRoutes(boot.routes);"}
3888
3949
  return null;
3889
3950
  }
3890
3951
  return loadFarmClientRouteTable().catch(function(error) {
@@ -3907,7 +3968,75 @@ for (const type of FARM_ROUTE_TABLE_INTENT_EVENTS) {
3907
3968
  document.addEventListener(type, warmFarmClientRouteTable, { capture: true, passive: true });
3908
3969
  }`;
3909
3970
  }
3910
- function generateFarmClientBootRoutesServerSource(tableSource) {
3971
+ function getFarmClientLayoutMatch(pattern) {
3972
+ const groupScope = getRouteGroupScope(pattern);
3973
+ return groupScope ? { pattern, urlPattern: stripRouteGroups(pattern), groupScope } : { pattern };
3974
+ }
3975
+ function generateFarmClientLayoutSelectionSource() {
3976
+ return `function selectFarmClientLayouts(layouts, routePathname, readDirectory) {
3977
+ const normalizedPath = routePathname.replace(/\\/$/, '') || '/';
3978
+ let directory;
3979
+ return layouts.filter(function(layout) {
3980
+ // Route groups add no URL segment: match the layout's URL, then keep a
3981
+ // grouped layout to the pages inside its group directory.
3982
+ const urlPattern = layout.urlPattern || layout.pattern;
3983
+ if (urlPattern !== '/' && !isFarmRouteActive(urlPattern, normalizedPath, { exact: false })) return false;
3984
+ if (!layout.groupScope) return true;
3985
+ if (directory === undefined) directory = readDirectory();
3986
+ return typeof directory === 'string' &&
3987
+ (directory === layout.groupScope || directory.startsWith(layout.groupScope + '/'));
3988
+ });
3989
+ }`;
3990
+ }
3991
+ function generateFarmClientRouteMatchSource(options = {}) {
3992
+ const select = "selectFarmClientLayouts(layoutRoutes, path, function() { return getFarmPageDirectory(pathname); })";
3993
+ return `${generateFarmClientLayoutSelectionSource()}
3994
+ ${options.lazyMatcher ? `
3995
+ // The document's own layouts, which it names, until the table loads (readFarmClientBootRoute).
3996
+ function readFarmClientBootLayouts(path) {
3997
+ const names = readFarmClientBootRoute(path).layouts;
3998
+ return layoutRoutes.filter(function(layout) { return names.includes(layout.pattern); });
3999
+ }
4000
+ ` : ""}
4001
+ // Get applicable layouts for a pathname (sorted by depth, root first)
4002
+ function getApplicableLayouts(pathname) {
4003
+ const path = getFarmRoutePathname(pathname);
4004
+ const applicable = ${options.lazyMatcher ? `clientRouteMatcher
4005
+ ? ${select}
4006
+ : readFarmClientBootLayouts(path)` : select};
4007
+
4008
+ // Sort by depth (root first)
4009
+ applicable.sort(function(a, b) {
4010
+ const depthA = a.pattern.split('/').filter(Boolean).length;
4011
+ const depthB = b.pattern.split('/').filter(Boolean).length;
4012
+ return depthA - depthB;
4013
+ });
4014
+
4015
+ return applicable;
4016
+ }
4017
+
4018
+ function hasHydratableLayout(pathname) {
4019
+ return getApplicableLayouts(pathname).some(function(layout) {
4020
+ return layout.shouldHydrate === true;
4021
+ });
4022
+ }
4023
+
4024
+ // Match pathname to client route
4025
+ function matchRoute(pathname) {
4026
+ const path = getFarmRoutePathname(pathname);
4027
+ ${options.lazyMatcher ? ` if (!clientRouteMatcher) {
4028
+ // Without the document's route either (the table did not load), nothing matches, as with no table.
4029
+ if (!farmClientBootRoute) return null;
4030
+ const boot = readFarmClientBootRoute(path);
4031
+ return clientRoutes.length > 0 ? { route: clientRoutes[0], params: boot.params } : null;
4032
+ }
4033
+ ` : ""} const matched = clientRouteMatcher.match(path);
4034
+ return matched
4035
+ ? { route: matched.route.meta, params: matched.params }
4036
+ : null;
4037
+ }`;
4038
+ }
4039
+ function generateFarmClientBootRoutesServerSource(tableSource, layouts) {
3911
4040
  return `// The client route table (client-route-table.ts), filled in from the client build. The client
3912
4041
  // loads it on its first navigation; a document names the entries its page boots with, found
3913
4042
  // with the client's own matcher, so its page hydrates without the table.
@@ -3927,18 +4056,40 @@ const farmClientRouteTable = (() => {
3927
4056
  return null;
3928
4057
  }
3929
4058
  })();
3930
-
4059
+ ${layouts ? `
4060
+ // The client's layouts (layoutRoutes in the client entry), of which a document names those that
4061
+ // apply at its path.
4062
+ const farmClientLayoutTable = ${JSON.stringify(layouts)};
4063
+ ${generateFarmClientLayoutSelectionSource()}
4064
+
4065
+ // The layouts that apply at a route path, with the page directory the client's
4066
+ // getFarmPageDirectory reads from the route matched there.
4067
+ function getFarmClientBootLayouts(routePathname, matched, page) {
4068
+ const directory = !matched
4069
+ ? null
4070
+ : matched.route.meta.docs && !matched.route.meta.directory
4071
+ ? page ? page.route.meta.directory || page.route.meta.pattern : null
4072
+ : matched.route.meta.directory || matched.route.meta.pattern;
4073
+ return selectFarmClientLayouts(farmClientLayoutTable, routePathname, function() { return directory; })
4074
+ .map(function(layout) { return layout.pattern; });
4075
+ }
4076
+ ` : ""}
3931
4077
  // The entries the client's matchRoute and getFarmPageDirectory read for this route path.
3932
4078
  function getFarmClientBootRoutes(routePathname) {
3933
4079
  if (!farmClientRouteTable || typeof routePathname !== "string") return undefined;
3934
4080
  const routes = [];
3935
4081
  const matched = farmClientRouteTable.routes.match(routePathname);
4082
+ const page = matched && matched.route.meta.docs ? farmClientRouteTable.pages.match(routePathname) : null;
3936
4083
  if (matched) {
3937
4084
  routes.push(matched.route.meta);
3938
- const page = matched.route.meta.docs ? farmClientRouteTable.pages.match(routePathname) : null;
3939
4085
  if (page) routes.push(page.route.meta);
3940
4086
  }
3941
- return { path: routePathname, routes: routes };
4087
+ return { path: routePathname, routes: routes${layouts ? ", params: matched ? matched.params : {}, layouts: getFarmClientBootLayouts(routePathname, matched, page)" : ""} };
4088
+ }
4089
+
4090
+ // A status document's: no route matches at its path.
4091
+ function getFarmClientStatusBootRoutes(routePathname) {
4092
+ return { path: routePathname, routes: []${layouts ? ", params: {}, layouts: getFarmClientBootLayouts(routePathname, null, null)" : ""} };
3942
4093
  }`;
3943
4094
  }
3944
4095
  function generateClientPageDirectorySource() {
@@ -4834,40 +4985,82 @@ function readFarmEntryImports(source) {
4834
4985
  }
4835
4986
  return bindings;
4836
4987
  }
4837
- function splitFarmClientRouter(code) {
4988
+ var FARM_LAZY_ROOT_STUB = `let farmRootLoading = null;
4989
+ function loadFarmRoot() {
4990
+ return farmRootLoading || (farmRootLoading = import("./farm-client-root").catch(function(error) {
4991
+ farmRootLoading = null;
4992
+ throw error;
4993
+ }));
4994
+ }
4995
+ `;
4996
+ var FARM_ROOT_MODULE_EXPORTS = [
4997
+ "createMatchedHydrationRoute",
4998
+ "hydrateFarmRoute",
4999
+ "renderFarmRoute",
5000
+ "farmTreeLayoutsReady",
5001
+ "loadRouteComponent",
5002
+ "createLayoutPageBoundary",
5003
+ "createFarmRouteState"
5004
+ ];
5005
+ function takeFarmEntryRegions(code, kind) {
4838
5006
  const regions = [];
4839
- const eager = code.replace(
4840
- /\/\*farm-router-start\*\/([\s\S]*?)\/\*farm-router-end\*\/\n?/g,
4841
- (_, body2) => {
4842
- regions.push(body2);
5007
+ const rest = code.replace(
5008
+ new RegExp(`/\\*farm-${kind}-start\\*/([\\s\\S]*?)/\\*farm-${kind}-end\\*/\\n?`, "g"),
5009
+ (_, body) => {
5010
+ regions.push(body);
4843
5011
  return "";
4844
5012
  }
4845
5013
  );
4846
- const body = regions.join("\n");
4847
- const moved = readFarmEntryDeclarations(body);
4848
- const usedByRouter = (name) => !moved.has(name) && bindingPattern(name).test(body);
5014
+ return { rest, body: regions.join("\n") };
5015
+ }
5016
+ function splitFarmClientEntry(code) {
5017
+ const router = takeFarmEntryRegions(code, "router");
5018
+ const root = takeFarmEntryRegions(router.rest, "root");
5019
+ const splitsRoot = root.body !== "";
5020
+ const eager = splitsRoot ? root.rest.replace(
5021
+ /\/\*farm-root-stub-start\*\/[\s\S]*?\/\*farm-root-stub-end\*\/\n?/,
5022
+ () => FARM_LAZY_ROOT_STUB
5023
+ ) : root.rest;
5024
+ const declared = {
5025
+ router: readFarmEntryDeclarations(router.body),
5026
+ root: readFarmEntryDeclarations(root.body),
5027
+ entry: readFarmEntryDeclarations(eager)
5028
+ };
4849
5029
  const eagerCode = eager.replace(/^import\s[^;]*;/gm, "");
4850
5030
  const usedByEntry = (name) => bindingPattern(name).test(eagerCode);
4851
- const bindings = readFarmEntryImports(eager).filter((binding) => usedByRouter(binding.local));
4852
- const imports = bindings.filter((binding) => !usedByEntry(binding.local));
4853
- const reexported = bindings.filter((binding) => usedByEntry(binding.local)).map((binding) => binding.local);
4854
- const shared = [
4855
- .../* @__PURE__ */ new Set([
4856
- ...reexported,
4857
- ...[...readFarmEntryDeclarations(eager)].filter((name) => usedByRouter(name))
4858
- ])
4859
- ];
5031
+ const eagerImports = readFarmEntryImports(eager);
5032
+ const fromEntry = /* @__PURE__ */ new Set();
5033
+ const link = (body, own) => {
5034
+ const uses = (name) => !own.has(name) && bindingPattern(name).test(body);
5035
+ const lines = [];
5036
+ const shared = [];
5037
+ for (const binding of eagerImports.filter((candidate) => uses(candidate.local))) {
5038
+ if (usedByEntry(binding.local)) shared.push(binding.local);
5039
+ else lines.push(`import ${binding.clause} from ${binding.from};`);
5040
+ }
5041
+ for (const name of declared.entry) if (uses(name)) shared.push(name);
5042
+ const names = [...new Set(shared)];
5043
+ for (const name of names) fromEntry.add(name);
5044
+ if (names.length > 0) lines.push(`import { ${names.join(", ")} } from "./farm-client-entry";`);
5045
+ return lines;
5046
+ };
5047
+ const routerImports = link(router.body, declared.router);
5048
+ const rootImports = splitsRoot ? link(root.body, declared.root) : [];
5049
+ const crossing = (body, names) => [...names].filter((name) => !declared.entry.has(name) && bindingPattern(name).test(body));
5050
+ const crossed = splitsRoot ? [...crossing(root.body, declared.router), ...crossing(router.body, declared.root)] : [];
5051
+ if (crossed.length > 0) {
5052
+ throw new Error(
5053
+ `The client entry's router and root code use ${crossed.join(", ")} from each other. Keep what both use outside the \`farm-router\` and \`farm-root\` regions.`
5054
+ );
5055
+ }
4860
5056
  return {
4861
5057
  entry: `${eager.replace("/*farm-router-stub*/", FARM_LAZY_ROUTER_STUB)}
4862
- export { ${shared.join(", ")} };
5058
+ export { ${[...fromEntry].join(", ")} };
4863
5059
  `,
4864
- router: [
4865
- ...imports.map((binding) => `import ${binding.clause} from ${binding.from};`),
4866
- `import { ${shared.join(", ")} } from "./farm-client-entry";`,
4867
- body,
4868
- "export { spaRouter };",
4869
- ""
4870
- ].join("\n")
5060
+ router: [...routerImports, router.body, "export { spaRouter };", ""].join("\n"),
5061
+ root: splitsRoot ? [...rootImports, root.body, `export { ${FARM_ROOT_MODULE_EXPORTS.join(", ")} };`, ""].join(
5062
+ "\n"
5063
+ ) : void 0
4871
5064
  };
4872
5065
  }
4873
5066
  var FARM_SEGMENT_NAVIGATION_SERVER_RUNTIME = `
@@ -4897,7 +5090,7 @@ var FARM_DOCUMENT_PARSED_RUNTIME = `function farmDocumentParsed() {
4897
5090
  }
4898
5091
 
4899
5092
  `;
4900
- function generateClientHydrationEntry(clientPages, layoutRoutes, clientRouteSlots, root, srcDir, docsSearchEnabled, docsSearchModuleId, docsEntryPath, docsAdapterReact, i18nConfig = {
5093
+ function generateClientHydrationEntry(clientPages, layoutRoutes, clientRouteSlots, root, srcDir, docsSearchEnabled, docsSearchModuleId, docsEntryPath, docsAdapterUI, i18nConfig = {
4901
5094
  enabled: false,
4902
5095
  basePath: "/",
4903
5096
  locales: ["en"],
@@ -4926,6 +5119,8 @@ function generateClientHydrationEntry(clientPages, layoutRoutes, clientRouteSlot
4926
5119
  );
4927
5120
  const appSetupPath = resolveFarmRendererAppSetup(root, renderer);
4928
5121
  const lazyRenderer = islandValues && platform !== "mobile" && isReactRenderer(renderer) && clientRouteSlots.length === 0;
5122
+ const lazyRoot = islandValues && platform !== "mobile";
5123
+ const lazyMatcher = lazyRoot && clientPages.length > 0;
4929
5124
  const rendererClientImports = lazyRenderer ? `import { holdFarmIslandInteractions, restorePagePosition, watchFarmIslandTriggers } from "@farm.js/core/internal/client-runtime";` : isReactRenderer(renderer) ? `import React from "react";
4930
5125
  import { createRoot, hydrateRoot } from "react-dom/client";
4931
5126
  import { restorePagePosition } from "@farm.js/core/internal/client-runtime";` : (
@@ -4962,6 +5157,7 @@ const React = { ...__farmRendererClient };`
4962
5157
  ).join("\n");
4963
5158
  const layoutImportStatements = [];
4964
5159
  const layoutRegistrations = [];
5160
+ const layoutComponents = [];
4965
5161
  const hydratingLayoutPatterns = layoutRoutes.filter((layout) => layout.shouldHydrate).map((layout) => layout.pattern);
4966
5162
  const treeLayoutPatterns = islandValues ? getFarmServerTreeLayoutPatterns(layoutRoutes) : /* @__PURE__ */ new Set();
4967
5163
  layoutRoutes.forEach((layout, index) => {
@@ -4973,13 +5169,23 @@ const React = { ...__farmRendererClient };`
4973
5169
  if (rendersOnClient && !treeLayout) {
4974
5170
  layoutImportStatements.push(`import Layout${index} from "${relativePath}";`);
4975
5171
  }
4976
- const groupScope = getRouteGroupScope(layout.pattern);
4977
- const groupFields = groupScope ? `, urlPattern: ${JSON.stringify(stripRouteGroups(layout.pattern))}, groupScope: ${JSON.stringify(groupScope)}` : "";
5172
+ const { urlPattern, groupScope } = getFarmClientLayoutMatch(layout.pattern);
5173
+ const groupFields = groupScope ? `, urlPattern: ${JSON.stringify(urlPattern)}, groupScope: ${JSON.stringify(groupScope)}` : "";
5174
+ const component = rendersOnClient ? treeLayout ? `getFarmTreeLayoutComponent(${JSON.stringify(layout.pattern)})` : `Layout${index}` : "null";
5175
+ layoutComponents.push(component);
4978
5176
  layoutRegistrations.push(
4979
- ` { pattern: ${JSON.stringify(layout.pattern)}${groupFields}, Component: ${rendersOnClient ? treeLayout ? `getFarmTreeLayoutComponent(${JSON.stringify(layout.pattern)})` : `Layout${index}` : "null"}, shouldHydrate: ${JSON.stringify(layout.shouldHydrate)}, islandStrategy: ${JSON.stringify(layout.islandStrategy)}${treeLayout ? ", serverTree: true" : ""} }`
5177
+ ` { pattern: ${JSON.stringify(layout.pattern)}${groupFields}, Component: ${lazyRoot ? "null" : component}, shouldHydrate: ${JSON.stringify(layout.shouldHydrate)}, islandStrategy: ${JSON.stringify(layout.islandStrategy)}${treeLayout ? ", serverTree: true" : ""} }`
4980
5178
  );
4981
5179
  });
4982
5180
  const layoutImports = layoutImportStatements.join("\n");
5181
+ const layoutComponentsRuntime = lazyRoot && layoutComponents.some((component) => component !== "null") ? `/*farm-root-start*/
5182
+ ${layoutImports}
5183
+ // The layouts' components, which only a page or layout root renders.
5184
+ [${layoutComponents.join(", ")}].forEach(function(Component, index) {
5185
+ layoutRoutes[index].Component = Component;
5186
+ });
5187
+ /*farm-root-end*/
5188
+ ` : "";
4983
5189
  const hasServerTreeLayouts = treeLayoutPatterns.size > 0;
4984
5190
  const i18nRoutingConfig = {
4985
5191
  locales: i18nConfig.locales,
@@ -5036,8 +5242,10 @@ function isFarmDocsPath() {
5036
5242
  }
5037
5243
  `;
5038
5244
  const docsAdapterRuntime = generateFarmDocsAdapterClientRuntime(
5039
- docsAdapterReact,
5040
- docsConfigModule
5245
+ docsAdapterUI,
5246
+ docsConfigModule,
5247
+ // Config resolution keeps an adapter to its UI's renderer, so this is the UI's renderer too.
5248
+ isReactRenderer(renderer) ? void 0 : renderer.client
5041
5249
  );
5042
5250
  if (clientPages.length === 0 && clientRouteSlots.length === 0 && !providerClientCode.hasProviders) {
5043
5251
  return `
@@ -5364,6 +5572,7 @@ installFarmLinkPrefetch();
5364
5572
  }
5365
5573
  });
5366
5574
  const isolatedHydrationEnabled = isolatedBoundaryModules.size > 0;
5575
+ const rendererIslands = isolatedHydrationEnabled && !islandValues && !isReactRenderer(renderer) && getFarmRendererCapabilities(renderer).islands;
5367
5576
  const serverTreeEnabled = isolatedHydrationEnabled && clientPages.some((page) => page.serverTree);
5368
5577
  const islandsRuntimeExports = [
5369
5578
  "createFarmIsolatedHydrationRuntime",
@@ -5403,7 +5612,7 @@ function loadFarmRenderer() {
5403
5612
  }));
5404
5613
  }
5405
5614
  ` : "";
5406
- const isolatedHydrationImport = lazyRenderer ? "" : isolatedHydrationEnabled ? `${islandValues ? `import { createFarmIsolatedHydrationRuntime, createFarmServerPageBoundary, wrapFarmIsolatedClientGraph, createFarmServerTreeElement${hasServerTreeLayouts ? ", createFarmServerTreeLayout" : ""} } from "@farm.js/core/internal/islands-runtime";` : 'import { createFarmIsolatedHydrationRuntime, createFarmServerPageBoundary, wrapFarmIsolatedClientGraph } from "@farm.js/core/internal/isolated-boundary";'}${serverTreeEnabled && !islandValues ? '\nimport { createFarmServerTreeElement } from "@farm.js/core/internal/server-tree";' : ""}` : "";
5615
+ const isolatedHydrationImport = lazyRenderer ? "" : rendererIslands ? 'import { createFarmRendererIslandRuntime } from "@farm.js/core/internal/renderer-islands";' : isolatedHydrationEnabled ? `${islandValues ? `import { createFarmIsolatedHydrationRuntime, createFarmServerPageBoundary, wrapFarmIsolatedClientGraph, createFarmServerTreeElement${hasServerTreeLayouts ? ", createFarmServerTreeLayout" : ""} } from "@farm.js/core/internal/islands-runtime";` : 'import { createFarmIsolatedHydrationRuntime, createFarmServerPageBoundary, wrapFarmIsolatedClientGraph } from "@farm.js/core/internal/isolated-boundary";'}${serverTreeEnabled && !islandValues ? '\nimport { createFarmServerTreeElement } from "@farm.js/core/internal/server-tree";' : ""}` : "";
5407
5616
  const isolatedHydrationRuntime = isolatedHydrationEnabled ? `const farmIsolatedBoundaryLoaders = {
5408
5617
  ${Array.from(isolatedBoundaryModules.entries()).map(
5409
5618
  ([reference, modulePath]) => ` ${JSON.stringify(reference)}: () => import(${JSON.stringify(modulePath)}),`
@@ -5479,7 +5688,15 @@ const farmIsolatedHydrationRuntime = {
5479
5688
  endStream: function(root) {
5480
5689
  whenFarmIslandsRuntime(root, function(runtime) { runtime.endStream(root); });
5481
5690
  },
5482
- };` : `const farmIsolatedHydrationRuntime = createFarmIsolatedHydrationRuntime({
5691
+ };` : rendererIslands ? `const farmIsolatedHydrationRuntime = createFarmRendererIslandRuntime({
5692
+ renderer: React,
5693
+ load: loadFarmIsolatedBoundary,
5694
+ schedule: scheduleFarmIslandHydration,
5695
+ });
5696
+
5697
+ // A hydrating layout keeps a page that doesn't hydrate as server HTML in a plain element. The
5698
+ // renderer's root never renders the page's islands, so the runtime starts them after each render.
5699
+ const FarmServerPage = "div";` : `const farmIsolatedHydrationRuntime = createFarmIsolatedHydrationRuntime({
5483
5700
  ReactRuntime: React,
5484
5701
  hydrateRoot,
5485
5702
  load: loadFarmIsolatedBoundary,
@@ -5497,7 +5714,15 @@ function disposeFarmIsolatedClientBoundaries(scope) {
5497
5714
  async function hydrateFarmIsolatedClientBoundaries(scope = document, signal) {
5498
5715
  await farmIsolatedHydrationRuntime.hydrate(scope, signal);
5499
5716
  }
5500
- ${serverTreeEnabled ? `
5717
+ ${rendererIslands ? `
5718
+ // After a hydrating layout renders another page: release the islands whose markup it replaced,
5719
+ // and start the new page's.
5720
+ async function hydrateFarmLayoutPageIslands(container) {
5721
+ farmIsolatedHydrationRuntime.prune();
5722
+ await hydrateFarmIsolatedClientBoundaries(container);
5723
+ }
5724
+ ` : ""}${serverTreeEnabled ? `
5725
+ /*farm-root-start*/
5501
5726
  // A server-tree page (an async page below a hydrating layout) rebuilds in the layout's root.
5502
5727
  async function createFarmServerTreePageElement(source, pathname) {
5503
5728
  try {
@@ -5511,8 +5736,11 @@ async function createFarmServerTreePageElement(source, pathname) {
5511
5736
  console.warn("[Farm.js] Could not rebuild the server tree of " + pathname + "; its server HTML was kept.", error);
5512
5737
  return null;
5513
5738
  }
5514
- }` : "async function createFarmServerTreePageElement() { return null; }"}` : `async function createFarmServerTreePageElement() { return null; }`;
5515
- const routeClientGraphRuntime = isolatedHydrationEnabled ? `function wrapFarmRouteClientGraph(element) {
5739
+ }
5740
+ /*farm-root-end*/` : "\n/*farm-root-start*/\nasync function createFarmServerTreePageElement() { return null; }\n/*farm-root-end*/"}` : `/*farm-root-start*/
5741
+ async function createFarmServerTreePageElement() { return null; }
5742
+ /*farm-root-end*/`;
5743
+ const routeClientGraphRuntime = isolatedHydrationEnabled && !rendererIslands ? `function wrapFarmRouteClientGraph(element) {
5516
5744
  return wrapFarmIsolatedClientGraph(React, element);
5517
5745
  }` : `function wrapFarmRouteClientGraph(element) { return element; }`;
5518
5746
  clientRouteSlots.forEach((slot, index) => {
@@ -5531,13 +5759,13 @@ async function createFarmServerTreePageElement(source, pathname) {
5531
5759
  return `
5532
5760
  // Farm.js Client Runtime - SPA with Hydration
5533
5761
  ${cssImport}
5534
- ${layoutImports}
5762
+ ${lazyRoot ? "" : layoutImports}
5535
5763
  ${rendererClientImports}
5536
5764
  ${isolatedHydrationImport}
5537
5765
  ${providerClientCode.imports}
5538
5766
  import { createClientCancellation, createClientPluginManager, createPluginlessClientRuntime, getFarmIslandValueHeaders, getHashTargetElement, keepFarmIslandValues, installChunkErrorRecovery, installFarmLinkPrefetch, isFarmBlockedNavigationURL, isFarmExternalNavigationURL, readFarmLinkNavigateOptions, rememberFarmLinkLocale, reconcileFarmDocumentHead, replayFarmQueuedInteraction, runFarmNavigationDelegates, scheduleFarmIslandHydration, createFarmSearchParams, searchParamsToObject, setFarmBasePath, setFarmTrailingSlashPreference, stripFarmBasePath } from "@farm.js/core/internal/client-runtime";
5539
5767
  import { createFarmDeploymentMismatchError, createFarmDeploymentRequestHeaders, isFarmDeploymentMismatchResponse } from "@farm.js/core/deployment";
5540
- import { createFarmRouter, isFarmRouteActive, matchFarmRoute } from "@farm.js/core/router";
5768
+ ${lazyMatcher ? "" : 'import { createFarmRouter, isFarmRouteActive, matchFarmRoute } from "@farm.js/core/router";'}
5541
5769
  ${clientPluginEntry.imports}
5542
5770
  ${clientCachePersistence.imports}
5543
5771
  ${i18nClientRuntime}
@@ -5561,7 +5789,8 @@ ${routeLoaders.join("\n")}
5561
5789
  ${generateFarmClientRouteTableRuntime({
5562
5790
  table: clientPages.length > 0,
5563
5791
  docs: clientPages.some((page) => page.docs),
5564
- streamNavigations: islandValues
5792
+ streamNavigations: islandValues,
5793
+ lazyMatcher
5565
5794
  })}
5566
5795
  ${generateClientPageDirectorySource()}
5567
5796
 
@@ -5577,43 +5806,9 @@ const layoutRoutes = [
5577
5806
  ${layoutRegistrations.join(",\n")}
5578
5807
  ];
5579
5808
 
5580
- // Get applicable layouts for a pathname (sorted by depth, root first)
5581
- function getApplicableLayouts(pathname) {
5582
- const applicable = [];
5583
- const normalizedPath = getFarmRoutePathname(pathname).replace(/\\/$/, '') || '/';
5584
- let directory;
5585
-
5586
- for (const layout of layoutRoutes) {
5587
- // Route groups add no URL segment: match the layout's URL, then keep a
5588
- // grouped layout to the pages inside its group directory.
5589
- const urlPattern = layout.urlPattern || layout.pattern;
5590
- if (urlPattern !== '/' && !isFarmRouteActive(urlPattern, normalizedPath, { exact: false })) continue;
5591
- if (layout.groupScope) {
5592
- if (directory === undefined) directory = getFarmPageDirectory(pathname);
5593
- if (
5594
- typeof directory !== 'string' ||
5595
- (directory !== layout.groupScope && !directory.startsWith(layout.groupScope + '/'))
5596
- ) continue;
5597
- }
5598
- applicable.push(layout);
5599
- }
5600
-
5601
- // Sort by depth (root first)
5602
- applicable.sort(function(a, b) {
5603
- const depthA = a.pattern.split('/').filter(Boolean).length;
5604
- const depthB = b.pattern.split('/').filter(Boolean).length;
5605
- return depthA - depthB;
5606
- });
5607
-
5608
- return applicable;
5609
- }
5610
-
5611
- function hasHydratableLayout(pathname) {
5612
- return getApplicableLayouts(pathname).some(function(layout) {
5613
- return layout.shouldHydrate === true;
5614
- });
5615
- }
5809
+ ${generateFarmClientRouteMatchSource({ lazyMatcher })}
5616
5810
 
5811
+ ${layoutComponentsRuntime}/*farm-root-start*/
5617
5812
  ${FARM_LAYOUT_ELEMENT_CLIENT_SOURCE}
5618
5813
  // Wrap a page element with applicable layouts
5619
5814
  function wrapWithLayouts(pageElement, pathname, params) {
@@ -5679,15 +5874,9 @@ function prepareFarmTreeLayouts(pathname, params, source) {
5679
5874
  );
5680
5875
  }` : `function farmTreeLayoutsReady() { return true; }
5681
5876
  async function prepareFarmTreeLayouts() { return true; }`}
5877
+ /*farm-root-end*/
5682
5878
 
5683
- // Match pathname to client route
5684
- function matchRoute(pathname) {
5685
- const matched = clientRouteMatcher.match(getFarmRoutePathname(pathname));
5686
- return matched
5687
- ? { route: matched.route.meta, params: matched.params }
5688
- : null;
5689
- }
5690
-
5879
+ /*farm-root-start*/
5691
5880
  async function loadRouteComponent(route) {
5692
5881
  if (!route.load) return null;${lazyRenderer ? `
5693
5882
  // A page component renders with React DOM, which loads beside it (RFC 0010).
@@ -5816,6 +6005,7 @@ function renderFarmRoute(root, route) {
5816
6005
  if (route.layouts.length > 0 && typeof root.renderRoute === "function") root.renderRoute(route);
5817
6006
  else root.render(route.element);
5818
6007
  }
6008
+ /*farm-root-end*/
5819
6009
 
5820
6010
  /*farm-router-start*/
5821
6011
  function matchesRoutePrefix(pathname, pattern) {
@@ -6168,8 +6358,7 @@ ${lazyRenderer ? ` // React DOM and islx load with what first renders or hydrat
6168
6358
  ${isolatedHydrationEnabled ? `// Not cancelled with the page: a navigation disposes the islands it removes, and one in a
6169
6359
  // layout it keeps still waits for its trigger, as on a page of islands only.
6170
6360
  const isolatedHydration =
6171
- !hasHydratableLayout(pathname) &&
6172
- document.querySelector('f-island[src]')
6361
+ ${rendererIslands ? "" : "!hasHydratableLayout(pathname) &&\n "}document.querySelector('f-island[src]')
6173
6362
  ? hydrateFarmIsolatedClientBoundaries(document)
6174
6363
  : Promise.resolve();
6175
6364
  await Promise.all([pageHydration, isolatedHydration]);` : "await pageHydration;"}
@@ -6199,7 +6388,10 @@ function scheduleFarmRouteHydration(matched, pathname, container, serverProps) {
6199
6388
  }
6200
6389
  const searchParams = searchParamsToObject(new URLSearchParams(window.location.search));
6201
6390
  const shouldHydrate = !isHydrated && Boolean(container.innerHTML.trim());
6202
- const routeState = await createMatchedHydrationRoute(
6391
+ // The code that renders the root loads when its strategy is due (RFC 0013).
6392
+ const farmRoot = await loadFarmRoot();
6393
+ if (hydrationController.signal.aborted || !container.isConnected) return;
6394
+ const routeState = await farmRoot.createMatchedHydrationRoute(
6203
6395
  matched,
6204
6396
  pathname,
6205
6397
  searchParams,
@@ -6219,7 +6411,7 @@ function scheduleFarmRouteHydration(matched, pathname, container, serverProps) {
6219
6411
  // navigation, that is not a failure, so error hooks never see it.
6220
6412
  if (hydrationController.signal.aborted || !container.isConnected) return;
6221
6413
  if (shouldHydrate) {
6222
- reactRoot = hydrateFarmRoute(container, routeState);
6414
+ reactRoot = farmRoot.hydrateFarmRoute(container, routeState);
6223
6415
  reactRootContainer = container;
6224
6416
  isHydrated = true;
6225
6417
  } else {
@@ -6227,7 +6419,7 @@ function scheduleFarmRouteHydration(matched, pathname, container, serverProps) {
6227
6419
  reactRoot = createRoot(container);
6228
6420
  reactRootContainer = container;
6229
6421
  }
6230
- renderFarmRoute(reactRoot, routeState);
6422
+ farmRoot.renderFarmRoute(reactRoot, routeState);
6231
6423
  }
6232
6424
  await farmClientRuntime.completeHydration(hydrationSession);
6233
6425
  } catch (error) {
@@ -6242,6 +6434,14 @@ function scheduleFarmRouteHydration(matched, pathname, container, serverProps) {
6242
6434
  });
6243
6435
  }
6244
6436
 
6437
+ // The code that renders a page or layout root, which islands mode's web build loads on demand
6438
+ // (RFC 0013) and every other client has here.
6439
+ /*farm-root-stub-start*/
6440
+ function loadFarmRoot() {
6441
+ return Promise.resolve({ ${FARM_ROOT_MODULE_EXPORTS.join(", ")} });
6442
+ }
6443
+ /*farm-root-stub-end*/
6444
+
6245
6445
  /*farm-router-start*/
6246
6446
  // A layout boundary is the same layout when its key matches: islands mode keys it by pattern and
6247
6447
  // params, so a layout whose params change renders again. Other modes compare patterns.
@@ -6517,6 +6717,14 @@ ${islandValues ? ` // Islands mode: navigations name the layouts on screen, and
6517
6717
  }
6518
6718
  const pathname = url.pathname;
6519
6719
  const matched = matchRoute(pathname);
6720
+ // A root that hydrates on load renders with code that loads beside its page (RFC 0013).
6721
+ if (
6722
+ matched &&
6723
+ (matched.route.pageShouldHydrate || hasHydratableLayout(pathname)) &&
6724
+ (matched.route.islandStrategy || "load") === "load"
6725
+ ) {
6726
+ void loadFarmRoot().catch(function() {});
6727
+ }
6520
6728
  const from = this.currentPath;
6521
6729
  if (await this.shouldBlockNavigation({ from, to, action })) {
6522
6730
  if (action === "pop") this.revertBlockedPopState(from);
@@ -6606,23 +6814,22 @@ ${islandValues ? ` // Islands mode: navigations name the layouts on screen, and
6606
6814
  }
6607
6815
  }
6608
6816
 
6609
- if (
6610
- !options.refresh &&
6611
- matched?.route.navigation === "client-render" &&
6612
- farmTreeLayoutsReady(pathname, matched.params)
6613
- ) {
6817
+ // The code that renders a page loads with the navigation to one (RFC 0013).
6818
+ const farmRoot =
6819
+ !options.refresh && matched?.route.navigation === "client-render" ? await loadFarmRoot() : null;
6820
+ if (farmRoot && farmRoot.farmTreeLayoutsReady(pathname, matched.params)) {
6614
6821
  // Navigation itself signals intent, so destination routes load eagerly even
6615
6822
  // when their initial document hydration strategy is deferred.
6616
- const Component = await loadRouteComponent(matched.route);
6823
+ const Component = await farmRoot.loadRouteComponent(matched.route);
6617
6824
  if (!this.isCurrentNavigation(navigation, clientNavigation)) return;
6618
6825
  const params = matched.params;
6619
6826
  const searchParams = searchParamsToObject(url.searchParams);
6620
6827
  const props = { params: params, searchParams: createFarmSearchParams(searchParams) };
6621
6828
  let pageElement = React.createElement(Component, props);
6622
6829
  if (hasHydratableLayout(pathname)) {
6623
- pageElement = createLayoutPageBoundary(matched.route, pageElement);
6830
+ pageElement = farmRoot.createLayoutPageBoundary(matched.route, pageElement);
6624
6831
  }
6625
- const routeState = createFarmRouteState(
6832
+ const routeState = farmRoot.createFarmRouteState(
6626
6833
  pageElement,
6627
6834
  pathname,
6628
6835
  params,
@@ -6645,7 +6852,7 @@ ${islandValues ? ` // Islands mode: navigations name the layouts on screen, and
6645
6852
  if (!reactRoot) {
6646
6853
  setFarmReactRoot(createRoot(container), container);
6647
6854
  }
6648
- renderFarmRoute(reactRoot, routeState);
6855
+ farmRoot.renderFarmRoute(reactRoot, routeState);
6649
6856
  }
6650
6857
  this.currentPath = to;
6651
6858
  });
@@ -6793,12 +7000,22 @@ ${islandValues ? ` // Islands mode: navigations name the layouts on screen, and
6793
7000
  const matched = matchRoute(newPathname);
6794
7001
  const hydrateLayouts = hasHydratableLayout(newPathname);
6795
7002
  const nextPage = newRoot.querySelector("#__farm_page__");
7003
+ // A root that hydrates on load, or one React already renders, renders with code that loads
7004
+ // with the navigation to it (RFC 0013). One that waits for its trigger loads it then.
7005
+ const farmRoot =
7006
+ matched &&
7007
+ (hydrateLayouts || matched.route.pageShouldHydrate) &&
7008
+ ((matched.route.islandStrategy || "load") === "load" ||
7009
+ (hydrateLayouts && reactRoot && reactRootContainer === currentRoot))
7010
+ ? await loadFarmRoot()
7011
+ : null;
7012
+ if (!isNavigationCurrent()) return false;
6796
7013
 
6797
7014
  // If React already owns the shared layout, update that root. React keeps
6798
7015
  // matching layout component instances and their state mounted.
6799
- if (matched && hydrateLayouts && reactRoot && reactRootContainer === currentRoot) {
7016
+ if (matched && hydrateLayouts && reactRoot && reactRootContainer === currentRoot && farmRoot) {
6800
7017
  const searchParams = searchParamsToObject(targetUrl.searchParams);
6801
- const routeState = await createMatchedHydrationRoute(
7018
+ const routeState = await farmRoot.createMatchedHydrationRoute(
6802
7019
  matched,
6803
7020
  newPathname,
6804
7021
  searchParams,
@@ -6808,9 +7025,9 @@ ${islandValues ? ` // Islands mode: navigations name the layouts on screen, and
6808
7025
  );
6809
7026
  if (!isNavigationCurrent()) return false;
6810
7027
  if (routeState) {
6811
- renderFarmRoute(reactRoot, routeState);
7028
+ farmRoot.renderFarmRoute(reactRoot, routeState);
6812
7029
  window.__FARM_ROUTE_SLOTS__ = nextRouteSlots;
6813
- setFarmHydrated();
7030
+ setFarmHydrated();${rendererIslands ? "\n await hydrateFarmLayoutPageIslands(currentRoot);" : ""}
6814
7031
  return true;
6815
7032
  }
6816
7033
  }
@@ -6857,7 +7074,8 @@ ${islandValues ? ` // Islands mode: navigations name the layouts on screen, and
6857
7074
  );
6858
7075
  } else {
6859
7076
  const searchParams = searchParamsToObject(targetUrl.searchParams);
6860
- const routeState = await createMatchedHydrationRoute(
7077
+ // Without a page or layout root to hydrate, there is no route state.
7078
+ const routeState = farmRoot && await farmRoot.createMatchedHydrationRoute(
6861
7079
  matched,
6862
7080
  newPathname,
6863
7081
  searchParams,
@@ -6868,7 +7086,7 @@ ${islandValues ? ` // Islands mode: navigations name the layouts on screen, and
6868
7086
  );
6869
7087
  if (!isNavigationCurrent()) return false;
6870
7088
  if (routeState) {
6871
- setFarmReactRoot(hydrateFarmRoute(pageContainer, routeState), pageContainer);
7089
+ setFarmReactRoot(farmRoot.hydrateFarmRoute(pageContainer, routeState), pageContainer);
6872
7090
  setFarmHydrated();
6873
7091
  }
6874
7092
  }
@@ -6886,7 +7104,7 @@ ${islandValues ? ` // Islands mode: navigations name the layouts on screen, and
6886
7104
  console.error("[Farm.js] Hydrating the page's islands failed:", error);
6887
7105
  });
6888
7106
  }
6889
- }` : `if (matched.route.hasIsolatedClientBoundaries && !hydrateLayouts) {
7107
+ }` : `if (matched.route.hasIsolatedClientBoundaries${rendererIslands ? "" : " && !hydrateLayouts"}) {
6890
7108
  await hydrateFarmIsolatedClientBoundaries(
6891
7109
  isolatedHydrationScope,
6892
7110
  navigation.controller.signal,
@@ -7173,7 +7391,11 @@ async function buildSSRInMemory(productionVite, config, root, routeManager, apiR
7173
7391
  }))
7174
7392
  );
7175
7393
  const instrumentationPath = resolveFarmInstrumentationFile(root, config.srcDir || "src");
7176
- const notFoundPath = resolveFarmNotFoundComponentPath(config, appDirs);
7394
+ const notFoundPath = resolveFarmNotFoundComponentPath(
7395
+ config,
7396
+ appDirs,
7397
+ routeManager.getRendererNotFoundPath()
7398
+ );
7177
7399
  if (notFoundPath) logger.info(`\u{1F4CB} Found custom 404 page: ${notFoundPath}`);
7178
7400
  layoutRoutes.sort((a, b) => {
7179
7401
  const depthA = a.pattern.split("/").filter(Boolean).length;
@@ -7945,17 +8167,16 @@ function generateVirtualEntryCode(apiRoutes, pageRoutes, layoutRoutes, routeSlot
7945
8167
  const hasInfraAnalyticsRuntime = config.analytics !== false && resolveFarmInstrumentationRuntime(preset) === "nodejs";
7946
8168
  const reportsWebMCPCalls = hasInfraAnalyticsRuntime && _farmWebMCPReportsEnabled(config.plugins);
7947
8169
  const hasPrecompiledDocs = Boolean(farmDocsPrecompiledManifest);
7948
- const adapterOwnsDocsRuntime = Boolean(
7949
- isReactRenderer(config.renderer) && config.docs?.enabled && config.docs.adapter?.server && config.docs.adapter.react
7950
- );
8170
+ const adapterOwnsDocsRuntime = hasFarmDocsRuntimeAdapter(config.docs);
7951
8171
  if (config.docs?.enabled && config.docs.roots?.length && !adapterOwnsDocsRuntime) {
7952
8172
  throw new Error(
7953
- "Several docs roots need the docs adapter, which serves the React renderer only; Farm's built-in docs renderer serves a single docs root."
8173
+ "Several docs roots need a docs adapter; Farm's built-in docs renderer serves a single docs root."
7954
8174
  );
7955
8175
  }
7956
8176
  const docsConfigModulePath = adapterOwnsDocsRuntime && !hasPrecompiledDocs && config.docs.configPath && !config.docs.configPath.endsWith(".json") ? config.docs.configPath : void 0;
7957
8177
  const adapterHandler = generateFarmDocsAdapterHandlerArguments(config.docs, docsConfigModulePath);
7958
8178
  const hasIsolatedClientGraphRuntime = isReactRenderer(config.renderer) && isolatedClientBoundaryModules.size > 0;
8179
+ const hasRendererIslandsGraph = isolatedClientBoundaryModules.size > 0 && usesFarmRendererIslands(config);
7959
8180
  const rendererStreamingCapabilities = getFarmRendererStreamingCapabilitiesForRuntime(
7960
8181
  config.renderer,
7961
8182
  getFarmPresetRuntime(preset)
@@ -7994,6 +8215,18 @@ function renderFarmRouteServerTree(element, extra) {
7994
8215
  isolate: isolateFarmRouteServerPage,${farmIslandsMode ? "\n values: true," : ""}
7995
8216
  ...extra,
7996
8217
  });
8218
+ }` : hasRendererIslandsGraph ? `function wrapFarmRouteClientGraph(element) {
8219
+ return typeof ReactDOMServer.wrapClientGraph === "function" ? ReactDOMServer.wrapClientGraph(element) : element;
8220
+ }
8221
+
8222
+ function isolateFarmRouteServerPage(element) {
8223
+ return typeof ReactDOMServer.isolateServerPageGraph === "function" ? ReactDOMServer.isolateServerPageGraph(element) : element;
8224
+ }
8225
+
8226
+ function renderFarmRouteServerTree(element, extra) { return element; }
8227
+
8228
+ function renderFarmServerTreeLayout(Layout, props, outlets) {
8229
+ return React.createElement(Layout, { ...props, ...outlets });
7997
8230
  }` : `function wrapFarmRouteClientGraph(element) { return element; }
7998
8231
 
7999
8232
  function isolateFarmRouteServerPage(element) { return element; }
@@ -8515,7 +8748,7 @@ const isFarmDocsAPIRequest = (requestOrPathname) => {
8515
8748
  return pathname === apiPath || pathname.startsWith(apiPath + "/");
8516
8749
  };` : adapterOwnsDocsRuntime ? `import { ${docsConfigModulePath ? "getFarmDocsConfigModuleRoot, " : ""}isFarmDocsAPIRequest } from "@farm.js/core/docs";
8517
8750
  import { ${config.docs.roots?.length ? "createFarmDocsMultiRuntimeHandler as createFarmDocsAdapterMultiRuntimeHandler" : "createFarmDocsRuntimeHandler as createFarmDocsAdapterRuntimeHandler"} } from ${JSON.stringify(config.docs.adapter.server)};
8518
- import * as FarmDocsAdapterReact from ${JSON.stringify(config.docs.adapter.react)};${docsConfigModulePath ? `
8751
+ import * as FarmDocsAdapterUI from ${JSON.stringify(getFarmDocsAdapterUIModule(config.docs.adapter))};${docsConfigModulePath ? `
8519
8752
  import * as farmDocsConfigModule from ${toVirtualEntryImportSpecifier(docsConfigModulePath)};` : ""}` : `import { createFarmDocsAPIHandler, createFarmDocsHandler, isFarmDocsAPIRequest } from "@farm.js/core/docs";` : "";
8520
8753
  const docsFontImport = config.docs?.enabled && !hasPrecompiledDocs ? `import { resolveFarmLayoutFonts } from "@farm.js/core/font";` : "";
8521
8754
  const docsRuntimeImport = config.docs?.enabled && !hasPrecompiledDocs ? `import { existsSync as farmDocsExistsSync } from "node:fs";
@@ -9031,7 +9264,9 @@ const farmDocsModulePreloadPaths = farmDocsModulePreloads
9031
9264
  ),
9032
9265
  }
9033
9266
  : undefined;
9034
- const farmDocsHandler = ${config.docs?.enabled ? hasPrecompiledDocs ? "farmDocsPrecompiledRuntime.handleDocsRequest" : adapterOwnsDocsRuntime ? `${adapterHandler.factory}(${adapterHandler.config}, {
9267
+ ${adapterOwnsDocsRuntime && !hasPrecompiledDocs ? `// The renderer contract's server exports, for a docs UI that builds its pages with them.
9268
+ const farmDocsAppRenderer = ${isReactRenderer(config.renderer) ? '{ name: "react", createElement: React.createElement, Fragment: React.Fragment, renderToString: ReactDOMServer.renderToString }' : "__farmRendererServer"};
9269
+ ` : ""}const farmDocsHandler = ${config.docs?.enabled ? hasPrecompiledDocs ? "farmDocsPrecompiledRuntime.handleDocsRequest" : adapterOwnsDocsRuntime ? `${adapterHandler.factory}(${adapterHandler.config}, {
9035
9270
  rootDir: farmDocsRuntimeRoot,
9036
9271
  // A production build's content cannot change, so the adapter reads its
9037
9272
  // navigation once instead of scanning the content directory per request.
@@ -9047,7 +9282,10 @@ const farmDocsHandler = ${config.docs?.enabled ? hasPrecompiledDocs ? "farmDocsP
9047
9282
  resolveFarmLayoutFonts(
9048
9283
  getApplicableLayouts(getFarmRoutePathname(pathname)).map((layout) => layout.module),
9049
9284
  ),
9050
- loadReactModule: async () => FarmDocsAdapterReact,
9285
+ loadUIModule: async () => FarmDocsAdapterUI,
9286
+ // The app's renderer, for a UI that builds its pages with it.
9287
+ loadRenderer: async () => farmDocsAppRenderer,${getFarmDocsAdapterRenderer(config.docs.adapter) === "react" ? `
9288
+ loadReactModule: async () => FarmDocsAdapterUI,` : ""}
9051
9289
  // Lists the docs MCP endpoint in /.well-known/ai-catalog.json for the server's lifetime.
9052
9290
  registerMCPServer: registerFarmMCPServer,
9053
9291
  // A page built with this keeps its HTML string, so the preload budget and the response
@@ -9240,7 +9478,7 @@ function renderFarmClientBootstrapScript(canonicalPath, selectedRouteSlots, page
9240
9478
  'window[Symbol.for("farm.searchPreserveRoutes")]=' + serializeFarmInlineValue(farmSearchPreserveRoutes) + ';'` : ""};
9241
9479
  // The client boots at the canonical path when the script below moves it there.
9242
9480
  const bootRoutes = statusDocument
9243
- ? typeof routePathname === "string" ? { path: routePathname, routes: [] } : undefined
9481
+ ? typeof routePathname === "string" ? getFarmClientStatusBootRoutes(routePathname) : undefined
9244
9482
  : getFarmClientBootRoutes(
9245
9483
  typeof canonicalPath === "string" && canonicalPath.startsWith("/")
9246
9484
  ? getFarmRoutePathname(canonicalPath.split(/[?#]/)[0])
@@ -10044,7 +10282,7 @@ function createFarmErrorDocument(html, title, routePathname) {
10044
10282
  ' <meta name="viewport" content="width=device-width, initial-scale=1">\\n' +
10045
10283
  ' <link rel="icon" href="data:,">\\n' +
10046
10284
  ' <title>' + escapedTitle + '</title>\\n' +
10047
- ' <link rel="stylesheet" href="/__farm_client_css_href__">' + renderFarmClientModulePreloads(html) + '\\n' +
10285
+ ' ' + renderFarmClientStylesheet() + renderFarmClientModulePreloads(html) + '\\n' +
10048
10286
  renderFarmRendererHydrationScript() + '\\n' +
10049
10287
  '</head>\\n<body>\\n' +
10050
10288
  ' <div id="root">' + html + '</div>\\n' +
@@ -10055,7 +10293,7 @@ function createFarmErrorDocument(html, title, routePathname) {
10055
10293
 
10056
10294
  let fullHtml = ensureFarmDocumentRoot(ensureFarmDocumentHead(fullDocument));
10057
10295
  fullHtml = fullHtml
10058
- .replace(/<head([^>]*)>/i, function(match, attrs) { return '<head' + attrs + '>\\n <link rel="stylesheet" href="/__farm_client_css_href__">' + renderFarmClientModulePreloads(fullDocument); })
10296
+ .replace(/<head([^>]*)>/i, function(match, attrs) { return '<head' + attrs + '>\\n ' + renderFarmClientStylesheet() + renderFarmClientModulePreloads(fullDocument); })
10059
10297
  // Function replacements: dynamic markup may contain $-sequences ($&, $', $$)
10060
10298
  // that a string replacement would expand, corrupting the document.
10061
10299
  .replace(/<\\/head>/i, function() { return renderFarmRendererHydrationScript() + '\\n</head>'; })
@@ -10079,6 +10317,23 @@ function createFarmErrorDocument(html, title, routePathname) {
10079
10317
  : "<!DOCTYPE html>\\n" + fullHtml;
10080
10318
  }
10081
10319
 
10320
+ // The client stylesheet a document links, filled in from the client build once it has finished
10321
+ // (see buildNitroUniversal): null for an app without CSS, whose empty stylesheet would still hold
10322
+ // the first paint for a round trip. Parsed at runtime, so the bundler cannot fold the stand-in.
10323
+ const farmClientStylesheetHref = (() => {
10324
+ try {
10325
+ return JSON.parse("${FARM_CLIENT_STYLESHEET_PLACEHOLDER}");
10326
+ } catch {
10327
+ return "${FARM_CLIENT_CSS_HREF_PLACEHOLDER}";
10328
+ }
10329
+ })();
10330
+
10331
+ function renderFarmClientStylesheet() {
10332
+ return farmClientStylesheetHref
10333
+ ? '<link rel="stylesheet" href="' + farmClientStylesheetHref + '">'
10334
+ : "";
10335
+ }
10336
+
10082
10337
  // The client modules a page needs before it hydrates, filled in from the client
10083
10338
  // build once it has finished (see buildNitroUniversal).
10084
10339
  const farmClientModulePreloads = (() => {
@@ -10088,7 +10343,10 @@ const farmClientModulePreloads = (() => {
10088
10343
  return null;
10089
10344
  }
10090
10345
  })();
10091
- ${generateFarmClientBootRoutesServerSource(`"${FARM_CLIENT_ROUTE_TABLE_PLACEHOLDER}"`)}
10346
+ ${generateFarmClientBootRoutesServerSource(
10347
+ `"${FARM_CLIENT_ROUTE_TABLE_PLACEHOLDER}"`,
10348
+ farmIslandsMode ? layoutRoutes.map((layout) => getFarmClientLayoutMatch(layout.pattern)) : void 0
10349
+ )}
10092
10350
 
10093
10351
  const farmClientEntryPreloadTags = farmClientModulePreloads
10094
10352
  ? farmClientModulePreloads.entry.map(renderFarmClientModulePreload).join("")
@@ -10098,10 +10356,18 @@ const farmClientEntryPreloadTags = farmClientModulePreloads
10098
10356
  const farmClientRendererPreloadTags = farmClientModulePreloads
10099
10357
  ? (farmClientModulePreloads.renderer || []).map(renderFarmClientModulePreload).join("")
10100
10358
  : "";
10359
+ // Islands mode's entry imports the code that renders a page or layout root when one hydrates (RFC
10360
+ // 0013), so a document that has one lists that code.
10361
+ const farmClientRootPreloadTags = farmClientModulePreloads
10362
+ ? (farmClientModulePreloads.root || []).map(renderFarmClientModulePreload).join("")
10363
+ : "";
10101
10364
  // The client modules a document's markup loads: its islands' boundaries and the
10102
10365
  // client references of its server tree. An island with a deferred strategy loads its
10103
10366
  // module on its own trigger, so it is not preloaded.
10104
10367
  const FARM_CLIENT_MODULE_REFERENCE_PATTERN = /<f-island src="([^"]+)"([^>]*)>|"r":"(\\/[^"]+)"/g;
10368
+ // A server action reference in a document's markup: an action in an island's or a client
10369
+ // component's props (islx's \`{"$":"a",...}\`), or a server form posting one (its \`$F_REF_\` field).
10370
+ const FARM_ACTION_REFERENCE_PATTERN = /"\\$":"a"|name="\\$F_REF_/;
10105
10371
 
10106
10372
  function renderFarmClientModulePreload(index) {
10107
10373
  return '\\n <link rel="modulepreload" href="/' +
@@ -10132,15 +10398,28 @@ function collectFarmClientDocumentModules(markup, pageModule, listed) {
10132
10398
  return indexes;
10133
10399
  }
10134
10400
 
10401
+ // The manifest indexes of islands mode's action client, which handles a call's result (RFC 0013),
10402
+ // for a document whose markup holds an action reference, leaving out those already listed. Its
10403
+ // islands import it on their first call otherwise.
10404
+ function collectFarmClientActionModules(markup, listed) {
10405
+ const actions = farmClientModulePreloads.actions;
10406
+ if (!actions || typeof markup !== "string" || !FARM_ACTION_REFERENCE_PATTERN.test(markup)) return [];
10407
+ return actions.filter((index) => !listed.has(index) && listed.add(index));
10408
+ }
10409
+
10135
10410
  // The modulepreload links for a document: the entry's static imports and, unless it answers a
10136
- // client navigation, the renderer, then the modules its hydrating page and its markup load.
10137
- function renderFarmClientModulePreloads(markup, pageModule, navigation) {
10411
+ // client navigation, the renderer and, when a page or layout root hydrates in it (\`hydratesRoot\`),
10412
+ // the code that renders it; then the modules its hydrating page and its markup load.
10413
+ function renderFarmClientModulePreloads(markup, pageModule, navigation, hydratesRoot) {
10138
10414
  // A nonce policy blocks parser-inserted links without the nonce, and the
10139
10415
  // response filter manages nonces on script elements only, so CSP nonce mode
10140
10416
  // keeps the documents it had.
10141
10417
  if (!farmClientModulePreloads || (farmSecurityConfig.csp && farmSecurityConfig.csp.nonce)) return "";
10418
+ const listed = new Set();
10142
10419
  return farmClientEntryPreloadTags + (navigation ? "" : farmClientRendererPreloadTags) +
10143
- collectFarmClientDocumentModules(markup, pageModule, new Set())
10420
+ (hydratesRoot && !navigation ? farmClientRootPreloadTags : "") +
10421
+ collectFarmClientDocumentModules(markup, pageModule, listed)
10422
+ .concat(collectFarmClientActionModules(markup, listed))
10144
10423
  .map(renderFarmClientModulePreload)
10145
10424
  .join("");
10146
10425
  }
@@ -10162,13 +10441,26 @@ function renderFarmClientBootPreloads(markup, pageModule, root, rootStrategy, na
10162
10441
  ) + '"';
10163
10442
  };
10164
10443
  const entry = farmClientModulePreloads.entry;
10444
+ // The root hydrates with the code that hydrates roots (RFC 0013) and its page's modules.
10165
10445
  const rootModules = root
10166
- ? collectFarmClientDocumentModules(markup, pageModule, new Set(entry))
10446
+ ? (farmClientModulePreloads.root || []).concat(
10447
+ collectFarmClientDocumentModules(
10448
+ markup,
10449
+ pageModule,
10450
+ new Set(entry.concat(farmClientModulePreloads.root || [])),
10451
+ ),
10452
+ )
10167
10453
  : [];
10168
10454
  const waitsForClick = rootStrategy === "interaction";
10455
+ // A call needs a hydrated island, so the action client comes with the renderer.
10456
+ const renderer = navigation
10457
+ ? []
10458
+ : (farmClientModulePreloads.renderer || []).concat(
10459
+ collectFarmClientActionModules(markup, new Set(entry.concat(rootModules))),
10460
+ );
10169
10461
  return attribute("data-farm-preload", waitsForClick ? entry : entry.concat(rootModules)) +
10170
10462
  attribute("data-farm-preload-router", farmClientModulePreloads.router || []) +
10171
- attribute("data-farm-preload-renderer", navigation ? [] : farmClientModulePreloads.renderer || []) +
10463
+ attribute("data-farm-preload-renderer", renderer) +
10172
10464
  (waitsForClick ? attribute("data-farm-preload-root", rootModules) : "");
10173
10465
  }
10174
10466
 
@@ -11150,8 +11442,8 @@ ${config.docs?.enabled ? `async function wrapFarmDocsResponseWithLayouts(request
11150
11442
  }
11151
11443
  html = html.replace(/<[/]head>/i, function() { return renderedRoot.head + "\\n</head>"; });
11152
11444
  }
11153
- if (!html.includes('href="/__farm_client_css_href__"')) {
11154
- const clientStylesheet = ' <link rel="stylesheet" href="/__farm_client_css_href__">\\n';
11445
+ if (farmClientStylesheetHref && !html.includes('href="' + farmClientStylesheetHref + '"')) {
11446
+ const clientStylesheet = ' ' + renderFarmClientStylesheet() + '\\n';
11155
11447
  const firstStyleIndex = html.search(/<style(?:\\s|>)/i);
11156
11448
  html =
11157
11449
  firstStyleIndex >= 0
@@ -12612,10 +12904,9 @@ ${hasServerRuntimeIntegrations ? `
12612
12904
  // A document something hydrates over holds the clicks and submits made before it hydrates,
12613
12905
  // for the client entry to replay, as development does. One that starts with the boot entry
12614
12906
  // holds its own.
12907
+ const farmHydratesRoot = route.shouldHydrate || shouldHydrateLayout;
12615
12908
  const farmHoldsInteractions =
12616
- route.shouldHydrate ||
12617
- shouldHydrateLayout ||
12618
- renderedRouteSlots.some(function(slot) { return slot.hydrates; });
12909
+ farmHydratesRoot || renderedRouteSlots.some(function(slot) { return slot.hydrates; });
12619
12910
  const renderFarmPreHydrationHoldScript = function() {
12620
12911
  return farmHoldsInteractions && !farmBootsClient
12621
12912
  ? stampFarmCspNonce(createPreHydrationClickQueueScript()) + '\\n'
@@ -12634,7 +12925,7 @@ ${hasServerRuntimeIntegrations ? `
12634
12925
  );
12635
12926
  composed = composed
12636
12927
  // Inject CSS link after opening head tag or first meta tag
12637
- .replace(/<head([^>]*)>/i, function(match, attrs) { return '<head' + attrs + '>\\n <link rel="stylesheet" href="/__farm_client_css_href__">' + (farmBootsClient ? "" : renderFarmClientModulePreloads(composed, route.clientModule, farmNavigationRequest)); })
12928
+ .replace(/<head([^>]*)>/i, function(match, attrs) { return '<head' + attrs + '>\\n ' + renderFarmClientStylesheet() + (farmBootsClient ? "" : renderFarmClientModulePreloads(composed, route.clientModule, farmNavigationRequest, farmHydratesRoot)); })
12638
12929
  .replace(/<\\/head>/i, () => renderFarmRendererHydrationScript() + '\\n' + renderFarmPreHydrationHoldScript() + '</head>')
12639
12930
  // Explicit metadata wins over renderer and layout titles. Without
12640
12931
  // explicit metadata, a renderer title wins over the layout title.
@@ -12707,8 +12998,8 @@ ${hasServerRuntimeIntegrations ? `
12707
12998
  (hasFavicon ? '' : ' <link rel="icon" href="data:,">\\n') +
12708
12999
  (suppressDefaultTitle ? '' : ' <title>' + title + '</title>') + metaTags +
12709
13000
  (rendererHead ? '\\n ' + rendererHead : '') + '\\n' +
12710
- ' <link rel="stylesheet" href="/__farm_client_css_href__">\\n' +
12711
- ' <link rel="modulepreload" href="/__farm_client_js_src__">' + renderFarmClientModulePreloads(null, route.clientModule) + '\\n' +
13001
+ ' ' + renderFarmClientStylesheet() + '\\n' +
13002
+ ' <link rel="modulepreload" href="/__farm_client_js_src__">' + renderFarmClientModulePreloads(null, route.clientModule, false, farmHydratesRoot) + '\\n' +
12712
13003
  renderFarmRendererHydrationScript() + '\\n' +
12713
13004
  renderFarmPreHydrationHoldScript() +
12714
13005
  '</head>\\n<body>\\n' + farmEarlyClientScripts + ' <div id="root">';
@@ -12822,7 +13113,6 @@ ${hasServerRuntimeIntegrations ? `
12822
13113
  }
12823
13114
  }
12824
13115
  // A route that hydrates as one root starts with the boot entry only when that root waits.
12825
- const farmHydratesRoot = route.shouldHydrate || shouldHydrateLayout;
12826
13116
  farmBootsClient = farmDocumentBootsClient(
12827
13117
  html,
12828
13118
  (farmHydratesRoot && !route.rootStrategy) || Boolean(pprCacheKey),
@@ -12865,7 +13155,7 @@ ${hasServerRuntimeIntegrations ? `
12865
13155
  \${viewportTags}
12866
13156
  \${hasFavicon ? "" : '<link rel="icon" href="data:,">'}
12867
13157
  \${suppressDefaultTitle ? "" : "<title>" + title + "</title>"}\${metaTags}\${rendererHead ? "\\n " + rendererHead : ""}
12868
- <link rel="stylesheet" href="/__farm_client_css_href__">\${farmBootsClient ? "" : renderFarmClientModulePreloads(html, route.clientModule, farmNavigationRequest)}
13158
+ \${renderFarmClientStylesheet()}\${farmBootsClient ? "" : renderFarmClientModulePreloads(html, route.clientModule, farmNavigationRequest, farmHydratesRoot)}
12869
13159
  \${renderFarmRendererHydrationScript()}
12870
13160
  \${renderFarmPreHydrationHoldScript()}</head>
12871
13161
  <body>
@@ -13226,7 +13516,7 @@ ${farmRendererDisabled ? `
13226
13516
  "<head" + attrs + ">" +
13227
13517
  headContent.replace(/<title\\b[^>]*>[\\s\\S]*?<\\/title>\\s*/gi, "") +
13228
13518
  "\\n <title>" + notFoundMetadata.title + "</title>" + notFoundMetadata.tags + "\\n</head>")
13229
- .replace(/<head([^>]*)>/i, function(match, attrs) { return '<head' + attrs + '>\\n <link rel="stylesheet" href="/__farm_client_css_href__">' + renderFarmClientModulePreloads(fullDocument); })
13519
+ .replace(/<head([^>]*)>/i, function(match, attrs) { return '<head' + attrs + '>\\n ' + renderFarmClientStylesheet() + renderFarmClientModulePreloads(fullDocument); })
13230
13520
  .replace(/<\\/head>/i, () => renderFarmRendererHydrationScript() + '\\n</head>')
13231
13521
  .replace(
13232
13522
  /<\\/body>/i,
@@ -13244,7 +13534,7 @@ ${farmRendererDisabled ? `
13244
13534
  <meta charset="UTF-8">
13245
13535
  \${notFoundMetadata.viewport}
13246
13536
  \${notFoundMetadata.hasFavicon ? "" : '<link rel="icon" href="data:,">'}
13247
- <link rel="stylesheet" href="/__farm_client_css_href__">\${renderFarmClientModulePreloads(html)}
13537
+ \${renderFarmClientStylesheet()}\${renderFarmClientModulePreloads(html)}
13248
13538
  <title>\${notFoundMetadata.title}</title>\${notFoundMetadata.tags}
13249
13539
  \${renderFarmRendererHydrationScript()}
13250
13540
  </head>
@@ -13667,12 +13957,6 @@ async function getFarmDocsPrerenderPages(config, root, preset) {
13667
13957
  }
13668
13958
  return pages2;
13669
13959
  }
13670
- if (!isReactRenderer(config.renderer)) {
13671
- logger.warn(
13672
- `The docs adapter ${JSON.stringify(config.docs.adapter.id)} renders with React; docs.prerender keeps its pages rendering on request with the "${config.renderer.name}" renderer.`
13673
- );
13674
- return [];
13675
- }
13676
13960
  const pages = await listFarmDocsAdapterPages(config.docs, { root, srcDir: config.srcDir });
13677
13961
  if (!pages) {
13678
13962
  logger.warn(
@@ -13690,7 +13974,7 @@ async function listFarmDocsAnalyticsPages(config, root, preset) {
13690
13974
  return await listFarmDocsPagePaths(config.docs, {
13691
13975
  root,
13692
13976
  srcDir: config.srcDir,
13693
- adapter: isReactRenderer(config.renderer) && hasFarmDocsRuntimeAdapter(config.docs)
13977
+ adapter: hasFarmDocsRuntimeAdapter(config.docs)
13694
13978
  });
13695
13979
  } catch (error) {
13696
13980
  logger.warn(
@@ -13859,6 +14143,9 @@ async function buildNitroUniversal(config, routeManager, apiRouteManager, server
13859
14143
  const encodedDocsModulePreloads = encodeFarmDocsModulePreloads(docsModulePreloads);
13860
14144
  const encodedClientModulePreloads = encodeFarmClientModulePreloads(clientModulePreloads);
13861
14145
  const encodedClientRouteTable = encodeFarmBuildJSONPlaceholder(clientRouteTable);
14146
+ const encodedClientStylesheet = encodeFarmBuildJSONPlaceholder(
14147
+ await resolveClientStylesheetLinkHref(clientOutputDir, clientCssHref)
14148
+ );
13862
14149
  const encodedMobileShellClient = shouldBuildFarmMobileClient(config) ? encodeFarmMobileShellClient(
13863
14150
  await finalizeFarmMobileClient({
13864
14151
  buildDir: path17.join(root, distDir),
@@ -13883,6 +14170,9 @@ async function buildNitroUniversal(config, routeManager, apiRouteManager, server
13883
14170
  if (output.code.includes(FARM_CLIENT_ROUTE_TABLE_PLACEHOLDER)) {
13884
14171
  output.code = output.code.split(FARM_CLIENT_ROUTE_TABLE_PLACEHOLDER).join(encodedClientRouteTable);
13885
14172
  }
14173
+ if (output.code.includes(FARM_CLIENT_STYLESHEET_PLACEHOLDER)) {
14174
+ output.code = output.code.split(FARM_CLIENT_STYLESHEET_PLACEHOLDER).join(encodedClientStylesheet);
14175
+ }
13886
14176
  if (output.code.includes(FARM_CLIENT_CSS_HREF_PLACEHOLDER)) {
13887
14177
  output.code = output.code.split(FARM_CLIENT_CSS_HREF_PLACEHOLDER).join(clientCssHref);
13888
14178
  }
@@ -15243,6 +15533,7 @@ async function buildWithProductionNodeEnv(inputConfig, options) {
15243
15533
  ],
15244
15534
  suppressLintOnLink: config.suppressLintOnLink,
15245
15535
  componentExtensions: config.renderer.componentExtensions,
15536
+ renderer: config.renderer,
15246
15537
  i18nConfig: config.i18n
15247
15538
  }).catch((error) => {
15248
15539
  const message = error instanceof Error ? error.message : String(error);