@stacksjs/stx 0.2.303 → 0.2.305

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 (271) hide show
  1. package/dist/api-client.d.ts +26 -0
  2. package/dist/api-client.js +22 -0
  3. package/dist/api-handler.d.ts +6 -0
  4. package/dist/api-handler.js +3 -0
  5. package/dist/app-shell.js +11 -2
  6. package/dist/application-layers.d.ts +30 -0
  7. package/dist/application-layers.js +202 -0
  8. package/dist/build.js +9 -1
  9. package/dist/{chunk-rdg1n42s.js → chunk-00rtz7nw.js} +2 -2
  10. package/dist/chunk-02hm88m5.js +2 -0
  11. package/dist/chunk-044mychj.js +2 -0
  12. package/dist/{chunk-7eea1cse.js → chunk-09zjty4k.js} +1 -1
  13. package/dist/{chunk-7nfn7nj9.js → chunk-0gz0rhvs.js} +1 -1
  14. package/dist/chunk-113y4ywy.js +2 -0
  15. package/dist/{chunk-jsfch50r.js → chunk-1c2j4eby.js} +1 -1
  16. package/dist/{chunk-2m6x8tcx.js → chunk-1jbjrc0w.js} +2 -2
  17. package/dist/{chunk-m6wz1hf5.js → chunk-2h94c5hm.js} +2 -2
  18. package/dist/{chunk-mjpqz66q.js → chunk-2ver2s2y.js} +1 -1
  19. package/dist/chunk-3eervtf9.js +2 -0
  20. package/dist/{chunk-2rp09y5j.js → chunk-4evbx7sz.js} +1 -1
  21. package/dist/chunk-4jgr954p.js +2 -0
  22. package/dist/chunk-4mrhxtn3.js +18 -0
  23. package/dist/chunk-57ea6ye2.js +2 -0
  24. package/dist/{chunk-7eg7ep8f.js → chunk-5tefa8qb.js} +2 -2
  25. package/dist/{chunk-683tfkz4.js → chunk-64djh88a.js} +1 -1
  26. package/dist/{chunk-btrmvj2y.js → chunk-695fkras.js} +1 -1
  27. package/dist/{chunk-y7dcdjav.js → chunk-6zt2y7q3.js} +2 -2
  28. package/dist/chunk-7gqbr8nr.js +2 -0
  29. package/dist/{chunk-x4prtyjs.js → chunk-7kw3grq5.js} +1 -1
  30. package/dist/chunk-7m4yhzhb.js +6 -0
  31. package/dist/{chunk-7jebw3ea.js → chunk-7skk34dh.js} +2 -2
  32. package/dist/chunk-8ee62a9q.js +2 -0
  33. package/dist/{chunk-jj6yp7gm.js → chunk-8jam44my.js} +1 -1
  34. package/dist/chunk-8z0n5mtg.js +2 -0
  35. package/dist/chunk-92zzryxw.js +2 -0
  36. package/dist/{chunk-3bc8bqw2.js → chunk-9368t9jm.js} +1 -1
  37. package/dist/{chunk-3jwmcf4k.js → chunk-9c835qjn.js} +1 -1
  38. package/dist/chunk-9nf3hgvq.js +7 -0
  39. package/dist/chunk-a87jqtmd.js +2 -0
  40. package/dist/{chunk-5d9cy7a0.js → chunk-awj7yy37.js} +1 -1
  41. package/dist/chunk-b4xwbh8a.js +2 -0
  42. package/dist/{chunk-1evf3bdg.js → chunk-bd9wrcq1.js} +205 -19
  43. package/dist/chunk-bezqaxqt.js +2 -0
  44. package/dist/chunk-bk95q0bw.js +12 -0
  45. package/dist/{chunk-q25mr70f.js → chunk-c131k3mt.js} +1 -1
  46. package/dist/chunk-c1ae6afc.js +30 -0
  47. package/dist/{chunk-6btbgxh1.js → chunk-c79nfdyj.js} +1 -1
  48. package/dist/{chunk-cfgpk6bh.js → chunk-cbgh359m.js} +1 -1
  49. package/dist/{chunk-weqpt9nt.js → chunk-cr8v8k53.js} +1 -1
  50. package/dist/{chunk-p3wwm6k4.js → chunk-d19tvdvv.js} +1 -1
  51. package/dist/{chunk-nb1zdh1y.js → chunk-d3srvh3q.js} +1 -1
  52. package/dist/{chunk-rqrfq305.js → chunk-d57gb0v2.js} +1 -1
  53. package/dist/{chunk-1xyhk1wr.js → chunk-d5cqnwdd.js} +1 -1
  54. package/dist/chunk-dgpjxmhs.js +2 -0
  55. package/dist/chunk-dvvx1wny.js +3 -0
  56. package/dist/chunk-eans1ct0.js +43 -0
  57. package/dist/{chunk-ctz53mbz.js → chunk-ej8mv2k6.js} +1 -1
  58. package/dist/{chunk-zn6xcc0a.js → chunk-ek8cgwcg.js} +2 -2
  59. package/dist/{chunk-dv3z80gt.js → chunk-env6knrs.js} +1 -1
  60. package/dist/chunk-er848s6f.js +2 -0
  61. package/dist/{chunk-rf10fkrf.js → chunk-ess2pgt5.js} +1 -1
  62. package/dist/chunk-f1cgyd2h.js +3 -0
  63. package/dist/{chunk-hp3rjwnb.js → chunk-f325jzsk.js} +2 -2
  64. package/dist/{chunk-0tbgvp70.js → chunk-fczfdsab.js} +21 -5
  65. package/dist/chunk-fg0nf7cv.js +3754 -0
  66. package/dist/{chunk-xdq52pwj.js → chunk-fp7ms6e7.js} +1 -1
  67. package/dist/{chunk-qg6pg6ze.js → chunk-fqq5k9ve.js} +1 -1
  68. package/dist/{chunk-5t0w4h6z.js → chunk-g912mb7x.js} +1 -1
  69. package/dist/chunk-g97atepq.js +2 -0
  70. package/dist/{chunk-wj25qt72.js → chunk-gbwhbasw.js} +1 -1
  71. package/dist/chunk-gecmqs6p.js +17 -0
  72. package/dist/{chunk-cratkhhb.js → chunk-ghw5p1yk.js} +1 -1
  73. package/dist/{chunk-f0g2q51j.js → chunk-gssbag3e.js} +1 -1
  74. package/dist/{chunk-c9vhtjtr.js → chunk-gt8ja700.js} +2 -2
  75. package/dist/chunk-hftqr8ej.js +2 -0
  76. package/dist/{chunk-ftvmk1nj.js → chunk-hg2afckn.js} +1 -1
  77. package/dist/{chunk-hhnzd03k.js → chunk-hrcxfvh1.js} +1 -1
  78. package/dist/chunk-hzav4hyd.js +2 -0
  79. package/dist/{chunk-29gjwajm.js → chunk-jfzfrmzy.js} +1 -1
  80. package/dist/{chunk-ddqkj56r.js → chunk-jp2f8yzw.js} +1 -1
  81. package/dist/{chunk-ry3a2674.js → chunk-jsg1rthc.js} +1 -1
  82. package/dist/chunk-jxxv18a0.js +5 -0
  83. package/dist/{chunk-95t0k8cz.js → chunk-k23r03qj.js} +1 -1
  84. package/dist/{chunk-6b4k8fay.js → chunk-kxavsh3m.js} +1 -1
  85. package/dist/{chunk-4tffxxpd.js → chunk-m31n9pkr.js} +1 -1
  86. package/dist/{chunk-fj6fbqgb.js → chunk-m3a20mmb.js} +1 -1
  87. package/dist/chunk-m537zgay.js +2 -0
  88. package/dist/chunk-m8n0s4tk.js +28 -0
  89. package/dist/{chunk-j21csh4j.js → chunk-mbmqpaq1.js} +1 -1
  90. package/dist/{chunk-whm6bybj.js → chunk-mv5fdcwc.js} +3 -3
  91. package/dist/{chunk-y9nyqcha.js → chunk-mwh3ymwc.js} +1 -1
  92. package/dist/{chunk-51g95yts.js → chunk-mygq61f5.js} +2 -2
  93. package/dist/chunk-n99ajrwv.js +2 -0
  94. package/dist/chunk-ncrfrp95.js +2 -0
  95. package/dist/chunk-nqq7y7m9.js +3 -0
  96. package/dist/chunk-nws8fbde.js +2 -0
  97. package/dist/{chunk-q6xfyasj.js → chunk-pcvayb2f.js} +1 -1
  98. package/dist/chunk-phcvbqzn.js +2 -0
  99. package/dist/{chunk-nvxv2wxv.js → chunk-ppyz9623.js} +1 -1
  100. package/dist/{chunk-jb2r696a.js → chunk-qev11kg8.js} +1 -1
  101. package/dist/{chunk-6njgsr6w.js → chunk-qeyw5za9.js} +1 -1
  102. package/dist/chunk-qpzxgkc5.js +2 -0
  103. package/dist/chunk-qt2dmyq5.js +2 -0
  104. package/dist/chunk-r2k2sewg.js +2 -0
  105. package/dist/chunk-r808fpme.js +2 -0
  106. package/dist/chunk-rrankpmj.js +3 -0
  107. package/dist/chunk-rvyfyc43.js +2 -0
  108. package/dist/{chunk-3p0zgfgz.js → chunk-rzevgemj.js} +2 -2
  109. package/dist/{chunk-f62fh1fw.js → chunk-s3dnk3gc.js} +2 -2
  110. package/dist/{chunk-aa6kt84c.js → chunk-sart9ehj.js} +1 -1
  111. package/dist/chunk-sen2cxqm.js +2 -0
  112. package/dist/{chunk-jptkc64r.js → chunk-t3qb9s6s.js} +2 -2
  113. package/dist/{chunk-w8yac9xp.js → chunk-t41aaehf.js} +1 -1
  114. package/dist/{chunk-qjkzpd68.js → chunk-t51mwjyq.js} +1 -1
  115. package/dist/chunk-t8fqjb25.js +19 -0
  116. package/dist/{chunk-c6b5nqct.js → chunk-ta398s3d.js} +287 -352
  117. package/dist/chunk-tc6gqeha.js +2 -0
  118. package/dist/chunk-tt4r8q4v.js +2 -0
  119. package/dist/chunk-twbw18vs.js +2 -0
  120. package/dist/{chunk-6rzwef28.js → chunk-vd5xvsnv.js} +1 -1
  121. package/dist/chunk-w6d91maa.js +4 -0
  122. package/dist/{chunk-dcxtrqfy.js → chunk-wfffa8zm.js} +1 -1
  123. package/dist/chunk-wjdfhfj6.js +2 -0
  124. package/dist/chunk-wnamjw6n.js +3 -0
  125. package/dist/{chunk-22p0ezj6.js → chunk-wx13qmaw.js} +1 -1
  126. package/dist/chunk-x10mrzgp.js +2 -0
  127. package/dist/chunk-xd5ahrtn.js +2 -0
  128. package/dist/chunk-xsfwcj6x.js +2 -0
  129. package/dist/{chunk-91007tan.js → chunk-xwxdwqn9.js} +1 -1
  130. package/dist/{chunk-634gaa9d.js → chunk-xz3evxqp.js} +1 -1
  131. package/dist/chunk-xzgvcrnz.js +2 -0
  132. package/dist/{chunk-v8474ah4.js → chunk-y4nzmkea.js} +1 -1
  133. package/dist/{chunk-6w8fa3b8.js → chunk-ya5m5vbn.js} +1 -1
  134. package/dist/chunk-yd7jyyr7.js +2 -0
  135. package/dist/{chunk-ew6tr7b1.js → chunk-ydgdq45a.js} +2 -2
  136. package/dist/{chunk-ps20v1ah.js → chunk-ym3r8ktq.js} +1 -1
  137. package/dist/chunk-yyyxt326.js +2 -0
  138. package/dist/{chunk-yfwyvh02.js → chunk-ze44hhxb.js} +2 -2
  139. package/dist/{chunk-mdf3jbe6.js → chunk-zhcs8m2a.js} +2 -2
  140. package/dist/{chunk-f9d27v49.js → chunk-zs5y7xnt.js} +1 -1
  141. package/dist/chunk-zs95z9tf.js +2 -0
  142. package/dist/cli.js +14 -14
  143. package/dist/client-script-bundler.js +22 -11
  144. package/dist/component-contract-checks.d.ts +19 -0
  145. package/dist/component-contract-checks.js +147 -0
  146. package/dist/component-contract.d.ts +20 -0
  147. package/dist/component-contract.js +108 -0
  148. package/dist/component-model.d.ts +29 -0
  149. package/dist/component-model.js +59 -0
  150. package/dist/component-registry.js +7 -64
  151. package/dist/component-renderer.d.ts +1 -26
  152. package/dist/component-renderer.js +4 -239
  153. package/dist/component-resolution.d.ts +21 -0
  154. package/dist/component-resolution.js +118 -0
  155. package/dist/component-tags.d.ts +9 -0
  156. package/dist/component-tags.js +174 -0
  157. package/dist/composable-loader.d.ts +2 -13
  158. package/dist/composable-loader.js +15 -26
  159. package/dist/composables/index.d.ts +1 -0
  160. package/dist/composables/index.js +1 -0
  161. package/dist/composables/use-fetch.d.ts +117 -42
  162. package/dist/composables/use-fetch.js +47 -4
  163. package/dist/composition-api.d.ts +43 -19
  164. package/dist/config.d.ts +1 -1
  165. package/dist/config.js +46 -4
  166. package/dist/craft-entry.js +1 -1
  167. package/dist/craft.js +1 -1
  168. package/dist/database.js +1 -1
  169. package/dist/dev-server/serve-app.js +57 -17
  170. package/dist/dev-server/serve-file.js +8 -1
  171. package/dist/expressions.js +1 -1
  172. package/dist/imported-signals.js +1 -1
  173. package/dist/includes.js +27 -3
  174. package/dist/index.d.ts +11 -0
  175. package/dist/index.js +7 -0
  176. package/dist/manifest.d.ts +6 -0
  177. package/dist/misc-directives.d.ts +2 -0
  178. package/dist/misc-directives.js +39 -1
  179. package/dist/process.js +18 -1
  180. package/dist/production-builder.d.ts +4 -0
  181. package/dist/production-builder.js +47 -8
  182. package/dist/production-server.d.ts +4 -1
  183. package/dist/production-server.js +119 -71
  184. package/dist/pwa.js +2 -2
  185. package/dist/render.js +9 -2
  186. package/dist/route-response-cache.d.ts +7 -0
  187. package/dist/route-response-cache.js +72 -0
  188. package/dist/route-rules.d.ts +17 -0
  189. package/dist/route-rules.js +40 -0
  190. package/dist/router.d.ts +1 -0
  191. package/dist/runtime-config-loader.d.ts +5 -0
  192. package/dist/runtime-config-loader.js +42 -0
  193. package/dist/runtime-config-server.d.ts +26 -0
  194. package/dist/runtime-config-server.js +77 -0
  195. package/dist/runtime-config-types.d.ts +2 -0
  196. package/dist/runtime-config-types.js +0 -0
  197. package/dist/runtime-config.d.ts +5 -0
  198. package/dist/runtime-config.js +9 -0
  199. package/dist/runtime-globals.js +3 -0
  200. package/dist/serve.js +32 -10
  201. package/dist/server-api.d.ts +27 -0
  202. package/dist/server-api.js +181 -0
  203. package/dist/server-data.d.ts +17 -0
  204. package/dist/server-data.js +40 -0
  205. package/dist/signal-processing.js +2 -2
  206. package/dist/signals.js +138 -15
  207. package/dist/ssg.js +2 -2
  208. package/dist/stx-virtual-ts.d.ts +6 -0
  209. package/dist/stx-virtual-ts.js +31 -7
  210. package/dist/stx.d.ts +28 -0
  211. package/dist/template-compiler.d.ts +1 -0
  212. package/dist/template-compiler.js +1 -1
  213. package/dist/template-hydrator.js +15 -4
  214. package/dist/typecheck.d.ts +1 -0
  215. package/dist/typecheck.js +4 -3
  216. package/dist/types/config-types.d.ts +17 -0
  217. package/dist/utils.js +15 -5
  218. package/dist/variable-extractor.d.ts +1 -1
  219. package/dist/variable-extractor.js +12 -1
  220. package/dist/visual-testing.js +1 -1
  221. package/dist/vue-template.js +19 -41
  222. package/package.json +5 -5
  223. package/stx.d.ts +28 -0
  224. package/dist/chunk-0p44z42s.js +0 -2
  225. package/dist/chunk-2jd9bxmf.js +0 -2
  226. package/dist/chunk-2yp8ang5.js +0 -2
  227. package/dist/chunk-35x7s4cr.js +0 -2
  228. package/dist/chunk-3bqz5zre.js +0 -2
  229. package/dist/chunk-48p0k8y7.js +0 -2
  230. package/dist/chunk-4b625drg.js +0 -2
  231. package/dist/chunk-593kby1d.js +0 -2
  232. package/dist/chunk-5nac67r4.js +0 -18
  233. package/dist/chunk-70cf5h11.js +0 -2
  234. package/dist/chunk-78akhaws.js +0 -2
  235. package/dist/chunk-9a4q74r6.js +0 -2
  236. package/dist/chunk-9f5329rv.js +0 -2
  237. package/dist/chunk-9rv7akqq.js +0 -30
  238. package/dist/chunk-apjy1a72.js +0 -12
  239. package/dist/chunk-b3p3bzax.js +0 -3
  240. package/dist/chunk-c5hk1fxt.js +0 -2
  241. package/dist/chunk-c9rs5g1s.js +0 -2
  242. package/dist/chunk-dkd0bg8g.js +0 -2
  243. package/dist/chunk-dxhtry04.js +0 -2
  244. package/dist/chunk-ehp6fez3.js +0 -2
  245. package/dist/chunk-em3jb1dn.js +0 -4
  246. package/dist/chunk-ev4djb0p.js +0 -2
  247. package/dist/chunk-frejnjh9.js +0 -2
  248. package/dist/chunk-fvcr26a0.js +0 -22
  249. package/dist/chunk-g6ttsdz1.js +0 -2
  250. package/dist/chunk-gd73rpks.js +0 -2
  251. package/dist/chunk-ggwnrdqz.js +0 -17
  252. package/dist/chunk-h3t6fjba.js +0 -2
  253. package/dist/chunk-jc57j887.js +0 -2
  254. package/dist/chunk-jw248h1d.js +0 -2
  255. package/dist/chunk-k5xtf38q.js +0 -3
  256. package/dist/chunk-m78y5qys.js +0 -19
  257. package/dist/chunk-mc4rtf5d.js +0 -2
  258. package/dist/chunk-mx2wcb15.js +0 -2
  259. package/dist/chunk-p4w3wjbv.js +0 -2
  260. package/dist/chunk-pm3k8dyk.js +0 -2
  261. package/dist/chunk-qr59yfq9.js +0 -2
  262. package/dist/chunk-qsmdvy1z.js +0 -2
  263. package/dist/chunk-rsxmjfxq.js +0 -3754
  264. package/dist/chunk-s4sp78fn.js +0 -2
  265. package/dist/chunk-v2fp9vkh.js +0 -2
  266. package/dist/chunk-vwnnbzsp.js +0 -2
  267. package/dist/chunk-w0g99tx9.js +0 -2
  268. package/dist/chunk-x2pk87q2.js +0 -3
  269. package/dist/chunk-xn0asg46.js +0 -2
  270. package/dist/chunk-xwmw1wtk.js +0 -2
  271. package/dist/chunk-zdx9s3z0.js +0 -28
package/dist/index.d.ts CHANGED
@@ -1,6 +1,10 @@
1
1
  /// <reference path="./stx.d.ts" />
2
+ export type { RuntimeConfigDefaults, PublicRuntimeConfig } from './runtime-config-types';
3
+ export type { ServerApiOptions, ServerApiRoute } from './server-api';
4
+ export type { ApiHandlerContext } from './api-handler';
2
5
  export type { Store, StoreOptions, PersistOptions, DefineStoreOptions } from './state-management';
3
6
  export type { StxComponentInstance, EmitFn } from './composition-api';
7
+ export type { ModelSignal, ModelOptions, ModelModifiers } from './component-model';
4
8
  export type { VNode } from './jsx-runtime';
5
9
  export type { StxApp, StxApp as App, StxAppPlugin, StxPluginInput, StxAppConfig } from './app';
6
10
  export type { StxPlugin, PluginContext, PluginSetupContext } from './plugin-system';
@@ -20,6 +24,9 @@ export type {
20
24
  // ============================================================
21
25
  // Explicit re-exports to resolve wildcard ambiguities
22
26
  export { type BuildResult } from './build-optimizer';
27
+ export { useServerData } from './server-data';
28
+ export { useRuntimeConfig, useServerRuntimeConfig } from './runtime-config-server';
29
+ export { clearServerData } from './composables/use-fetch';
23
30
  // Exported for servers as well as the static build: SSR inlines the runtime
24
31
  // once per *request*, which is the same waste in a worse form.
25
32
  export { EXTERNALIZED_ASSET_DIR, externalizeHtml, externalizeSharedAssets, type ExternalizedAsset, type ExternalizeHtmlResult, type ExternalizeResult } from './build-externalize';
@@ -190,6 +197,9 @@ export * from './process';
190
197
  export * from './production-build';
191
198
  export * from './production-builder';
192
199
  export * from './production-server';
200
+ export * from './route-rules';
201
+ export { createServerApi, discoverServerApi, generateApiTypes } from './server-api';
202
+ export { defineApiHandler } from './api-handler';
193
203
  export * from './release';
194
204
  export * from './router';
195
205
  export * from './scaffolding';
@@ -265,6 +275,7 @@ export * from './spa-shell';
265
275
  export * from './vue-template';
266
276
  export { processServerBindings } from './server-bindings';
267
277
  export { provide, inject, setGlobalProvide, defineEmits, defineExpose, defineSlots, nextTick, onErrorCaptured, handleError, useSlots, useAttrs, createProvideContext, generateCompositionRuntime } from './composition-api';
278
+ export { useModel } from './component-model';
268
279
  export { jsx, jsxs, jsxDEV, Fragment, renderToString, renderToStream, renderToDOM, Show, For, Portal, h } from './jsx-runtime';
269
280
  export { createApp, createApp as createStxApp, defineCustomElement } from './app';
270
281
  export * from './dynamic-components';
package/dist/index.js CHANGED
@@ -1,3 +1,6 @@
1
+ export { useServerData } from "./server-data.js";
2
+ export { useRuntimeConfig, useServerRuntimeConfig } from "./runtime-config-server.js";
3
+ export { clearServerData } from "./composables/use-fetch.js";
1
4
  export { EXTERNALIZED_ASSET_DIR, externalizeHtml, externalizeSharedAssets } from "./build-externalize.js";
2
5
  export { externalizeRepeatedAssets } from "./build-externalize-repeated.js";
3
6
  export {
@@ -100,6 +103,9 @@ export * from "./process.js";
100
103
  export * from "./production-build.js";
101
104
  export * from "./production-builder.js";
102
105
  export * from "./production-server.js";
106
+ export * from "./route-rules.js";
107
+ export { createServerApi, discoverServerApi, generateApiTypes } from "./server-api.js";
108
+ export { defineApiHandler } from "./api-handler.js";
103
109
  export * from "./release.js";
104
110
  export * from "./router.js";
105
111
  export * from "./scaffolding.js";
@@ -151,6 +157,7 @@ export * from "./spa-shell.js";
151
157
  export * from "./vue-template.js";
152
158
  export { processServerBindings } from "./server-bindings.js";
153
159
  export { provide, inject, setGlobalProvide, defineEmits, defineExpose, defineSlots, nextTick, onErrorCaptured, handleError, useSlots, useAttrs, createProvideContext, generateCompositionRuntime } from "./composition-api.js";
160
+ export { useModel } from "./component-model.js";
154
161
  export { jsx, jsxs, jsxDEV, Fragment, renderToString, renderToStream, renderToDOM, Show, For, Portal, h } from "./jsx-runtime.js";
155
162
  export { createApp, createApp as createStxApp, defineCustomElement } from "./app.js";
156
163
  export * from "./dynamic-components.js";
@@ -1,3 +1,5 @@
1
+ import type { RouteRules } from './route-rules';
2
+ import type { ServerApiRoute } from './server-api';
1
3
  /**
2
4
  * Generate a build manifest from compiled pages and assets.
3
5
  */
@@ -20,6 +22,7 @@ export declare interface ManifestRoute {
20
22
  fragmentPath: string
21
23
  isDynamic: boolean
22
24
  hasParams: boolean
25
+ prerendered?: boolean
23
26
  }
24
27
  /**
25
28
  * Asset entries in the build manifest.
@@ -38,4 +41,7 @@ export declare interface BuildManifest {
38
41
  routes: ManifestRoute[]
39
42
  assets: ManifestAssets
40
43
  outputDir: string
44
+ routeRules?: RouteRules
45
+ routerContainer?: string
46
+ apiRoutes?: ServerApiRoute[]
41
47
  }
@@ -41,6 +41,8 @@ export declare function processMemoDirective(template: string): string;
41
41
  * The client-side runtime will automatically bind these to ref objects.
42
42
  */
43
43
  export declare function processRefAttributes(template: string): string;
44
+ /** Keep the caller of a projected ref explicit after slot content is flattened. */
45
+ export declare function markProjectedRefs(template: string, receiver: string): string;
44
46
  /**
45
47
  * Add x-cloak to HTML elements whose own text contains an unresolved {{ }}
46
48
  * expression. Those were preserved for client-side evaluation (signals, loop
@@ -1,5 +1,5 @@
1
1
  import { errorLogger } from "./error-handling.js";
2
- import { mightContainOwnTextMustache } from "./html-masking.js";
2
+ import { mightContainOwnTextMustache, scanAtElementPosition } from "./html-masking.js";
3
3
  import { createSafeFunction, isExpressionSafe } from "./safe-evaluator.js";
4
4
  export function processJsonDirective(template, context) {
5
5
  let result = template;
@@ -139,6 +139,44 @@ export function processRefAttributes(template) {
139
139
  result = result.replace(/(<[a-zA-Z][a-zA-Z0-9-]*\b[^>]*?)\sref="([^"]+)"/g, '$1 data-stx-ref="$2"');
140
140
  return result;
141
141
  }
142
+ export function markProjectedRefs(template, receiver) {
143
+ if (!/\bref\s*=/.test(template))
144
+ return template;
145
+ const tagPattern = /<\/?([a-zA-Z][\w-]*)\b(?:"[^"]*"|'[^']*'|[^'">])*>/y, tags = scanAtElementPosition(template, (html, index) => {
146
+ tagPattern.lastIndex = index;
147
+ const match = tagPattern.exec(html);
148
+ if (!match || /^(?:script|style)$/i.test(match[1]))
149
+ return -1;
150
+ return tagPattern.lastIndex;
151
+ }), ancestors = [];
152
+ let scopedDepth = 0, cursor = 0;
153
+ const output = [];
154
+ for (const { start, end, token } of tags) {
155
+ const name = /^<\/?([\w-]+)/.exec(token)[1].toLowerCase();
156
+ if (token.startsWith("</")) {
157
+ let ancestor;
158
+ while (ancestor = ancestors.pop()) {
159
+ if (ancestor.scoped)
160
+ scopedDepth--;
161
+ if (ancestor.name === name)
162
+ break;
163
+ }
164
+ continue;
165
+ }
166
+ const scoped = /\sdata-stx-scope\s*=/.test(token);
167
+ if (!scopedDepth && !scoped && /\s(?:ref|@ref|:ref|x-ref|data-stx-ref)\s*=/.test(token) && !/\sdata-stx-ref-caller\s*=/.test(token)) {
168
+ output.push(template.slice(cursor, start), token.replace(/\s*\/?>$/, (ending) => ` data-stx-ref-caller="${receiver}"${ending}`));
169
+ cursor = end;
170
+ }
171
+ if (!VOID_TAGS.has(name) && !/\/>$/.test(token)) {
172
+ ancestors.push({ name, scoped });
173
+ if (scoped)
174
+ scopedDepth++;
175
+ }
176
+ }
177
+ output.push(template.slice(cursor));
178
+ return output.join("");
179
+ }
142
180
  const VOID_TAGS = new Set([
143
181
  "area",
144
182
  "base",
package/dist/process.js CHANGED
@@ -43,6 +43,9 @@ import { dedupeScopedStyles, processScopedStyles } from "./style-scoping.js";
43
43
  import { injectColorModeBootScript, normalizeCriticalHeadOrder } from "./color-mode-boot.js";
44
44
  import { buildIdFragment } from "./build-id.js";
45
45
  import { applyHeadInjections, createHeadInjections } from "./head-injection.js";
46
+ import { serverDataScope, serverDataTag } from "./server-data.js";
47
+ import { prepareRuntimeConfig } from "./runtime-config-loader.js";
48
+ import { injectRuntimeConfig } from "./runtime-config-server.js";
46
49
  import { applyHtmlAttrs, cloakStyleFragment, ensureDocumentShell, hasDocumentShell, injectConfigHeadTags, mergeHtmlAttrs, metaDedupKey, startsDocument } from "./document-shell.js";
47
50
  import { hasSignalsSyntax, convertSignalDirectivesToAttributes, convertSignalLoopsToAttributes, preEvalLiteralReactiveIfs, processSignals } from "./signal-processing.js";
48
51
  import { processComponents } from "./component-renderer.js";
@@ -278,6 +281,11 @@ export async function processDirectives(template, context, filePath, options, de
278
281
  if (context.__stx_signals_gate === void 0)
279
282
  context.__stx_signals_gate = usesSignalsInScript(template, filePath);
280
283
  const isTopLevel = !context.__stxProcessingDepth;
284
+ serverDataScope(context);
285
+ for (const dependency of options._layerGraph?.configDependencies ?? [])
286
+ dependencies.add(dependency);
287
+ if (isTopLevel && options.runtimeConfig)
288
+ await prepareRuntimeConfig(context, filePath, options.runtimeConfig);
281
289
  if (isTopLevel) {
282
290
  initializeComponentClientFactories(context);
283
291
  context.__stx_head_injections = createHeadInjections();
@@ -365,7 +373,7 @@ export async function processDirectives(template, context, filePath, options, de
365
373
  frameworkScript = await getFrameworkComposableScript(result);
366
374
  } catch {}
367
375
  try {
368
- const { getComposableScript } = await importOnce("stx/composable-loader", () => import("./composable-loader.js")), resolvedComposablesDir = options.composablesDir, pending = [modulesTag, storeTag, frameworkScript].filter((text) => text !== null), composableCode = await getComposableScript(resolvedComposablesDir, result, pending);
376
+ const { getComposableScript } = await importOnce("stx/composable-loader", () => import("./composable-loader.js")), resolvedComposablesDir = options.composablesDir, pending = [modulesTag, storeTag, frameworkScript].filter((text) => text !== null), composableCode = await getComposableScript(options._layerComposableDirs ?? resolvedComposablesDir, result, pending);
369
377
  if (composableCode)
370
378
  composableTag = `<script data-stx-composables>${composableCode}</script>`;
371
379
  } catch {}
@@ -388,6 +396,15 @@ ${tag}`).join("");
388
396
  else if (isTopLevel)
389
397
  result = dedupeScopedStyles(result);
390
398
  result = result.replace(/\x00STX_ESCAPED_AT\x00/g, "@");
399
+ if (isTopLevel && context.__stx_runtime_config)
400
+ result = injectRuntimeConfig(result, context.__stx_runtime_config);
401
+ if (isTopLevel && !context.__stx_defer_server_data) {
402
+ const dataTag = serverDataTag(context);
403
+ if (dataTag) {
404
+ const head = /<head\b[^>]*>/i.exec(result), at = head ? head.index + head[0].length : 0;
405
+ result = result.slice(0, at) + dataTag + result.slice(at);
406
+ }
407
+ }
391
408
  return result;
392
409
  });
393
410
  } catch (error) {
@@ -1,4 +1,6 @@
1
1
  import { type ManifestAssets } from './manifest';
2
+ import { type RouteRules } from './route-rules';
3
+ import { type ServerApiOptions } from './server-api';
2
4
  /**
3
5
  * Build the stx application for production.
4
6
  *
@@ -30,6 +32,8 @@ export declare interface ProductionBuildOptions {
30
32
  partialsDir?: string
31
33
  layoutsDir?: string
32
34
  publicDir?: string
35
+ routeRules?: RouteRules
36
+ serverApi?: boolean | ServerApiOptions
33
37
  }
34
38
  /**
35
39
  * Result of a production build.
@@ -10,6 +10,12 @@ import { applyHtmlAttrs, ensureDocumentShell } from "./document-shell.js";
10
10
  import { extractContainerContent } from "./app-shell.js";
11
11
  import { injectCss } from "./dev-server/ts-css.js";
12
12
  import { loadStxConfig } from "./config.js";
13
+ import { createRouteRuleResolver } from "./route-rules.js";
14
+ import { hydrateTemplateStream } from "./template-hydrator.js";
15
+ import { buildServerApi, discoverServerApi } from "./server-api.js";
16
+ import { resolveRuntimeConfig } from "./runtime-config-server.js";
17
+ import { generateRuntimeConfigTypes } from "./runtime-config-loader.js";
18
+ import { layerManifest } from "./application-layers.js";
13
19
  const PUBLIC_ASSET_BLOCKLIST = new Set([
14
20
  ".DS_Store",
15
21
  "Thumbs.db",
@@ -46,11 +52,11 @@ function copyPublicAssets(srcDir, destDir) {
46
52
  export async function buildForProduction(options = {}) {
47
53
  const startTime = Date.now(), root = path.resolve(options.root || process.cwd()), outputDir = path.resolve(root, options.outputDir || ".output");
48
54
  console.log("[stx build] Starting production build...");
49
- let projectConfig = {};
50
- try {
51
- projectConfig = await loadStxConfig();
52
- } catch {}
53
- const componentsDir = options.componentsDir ?? projectConfig.componentsDir ?? "components", partialsDir = options.partialsDir ?? projectConfig.partialsDir ?? "partials", layoutsDir = options.layoutsDir ?? projectConfig.layoutsDir ?? "layouts", publicDir = options.publicDir ?? projectConfig.publicDir ?? "public", headConfigDefault = projectConfig.app?.head || {}, colorModeConfig = projectConfig.app?.colorMode, routerContainer = projectConfig.router?.container || "main";
55
+ const projectConfig = await loadStxConfig(root), componentsDir = path.resolve(root, options.componentsDir ?? projectConfig.componentsDir ?? "components"), partialsDir = path.resolve(root, options.partialsDir ?? projectConfig.partialsDir ?? "partials"), layoutsDir = path.resolve(root, options.layoutsDir ?? projectConfig.layoutsDir ?? "layouts"), publicDir = options.publicDir ?? projectConfig.publicDir ?? "public", headConfigDefault = projectConfig.app?.head || {}, colorModeConfig = projectConfig.app?.colorMode, routerContainer = projectConfig.router?.container || "main", routeRules = options.routeRules ?? projectConfig.routeRules ?? {}, resolveRule = createRouteRuleResolver(routeRules), serverApi = options.serverApi ?? projectConfig.serverApi, apiOptions = typeof serverApi === "object" ? serverApi : {};
56
+ if (serverApi)
57
+ discoverServerApi(root, apiOptions);
58
+ if (projectConfig.runtimeConfig)
59
+ resolveRuntimeConfig(projectConfig.runtimeConfig, {});
54
60
  if (fs.existsSync(outputDir))
55
61
  fs.rmSync(outputDir, { recursive: !0 });
56
62
  const dirs = [
@@ -62,7 +68,7 @@ export async function buildForProduction(options = {}) {
62
68
  for (const dir of dirs)
63
69
  fs.mkdirSync(dir, { recursive: !0 });
64
70
  console.log("[stx build] Discovering routes...");
65
- const allRoutes = createRouter(root), excludeDirs = ["components", "layouts", "partials"], routes = allRoutes.filter((r) => {
71
+ const allRoutes = createRouter(root, { pagesDirs: projectConfig._layerPageDirs }), excludeDirs = ["components", "layouts", "partials"], routes = allRoutes.filter((r) => {
66
72
  return !excludeDirs.some((dir) => r.pattern.startsWith(`/${dir}/`) || r.pattern === `/${dir}`);
67
73
  });
68
74
  console.log(`[stx build] Found ${routes.length} page routes (${allRoutes.length - routes.length} non-page files excluded)`);
@@ -74,9 +80,13 @@ export async function buildForProduction(options = {}) {
74
80
  console.log(`[stx build] Router: ${routerAsset.filename} (${(routerAsset.content.length / 1024).toFixed(1)}KB)`);
75
81
  console.log("[stx build] Compiling templates...");
76
82
  const compiledPages = [], manifestRoutes = [];
77
- for (const route of routes)
83
+ for (const route of routes) {
84
+ const rule = resolveRule(route.pattern), prerendered = rule.rendering === "prerender";
85
+ if (prerendered && (route.pattern.includes(":") || route.pattern.includes("[")))
86
+ throw Error(`Cannot prerender parameter route ${route.pattern}; use dynamic rendering (explicit path enumeration is not supported here)`);
78
87
  try {
79
88
  const compiled = await compileTemplate(route.filePath, route.pattern, {
89
+ configDir: root,
80
90
  componentsDir,
81
91
  partialsDir,
82
92
  layoutsDir,
@@ -102,6 +112,21 @@ export async function buildForProduction(options = {}) {
102
112
  }
103
113
  compiled.html = compiled.html.replace(/<style data-css="generated">[\s\S]*?<\/style>\s*/g, "");
104
114
  compiled.html = await injectCss(compiled.html);
115
+ if (prerendered) {
116
+ const rendered = await hydrateTemplateStream(compiled, {
117
+ params: {},
118
+ request: new Request(`http://stx.build${route.pattern}`),
119
+ method: "GET",
120
+ __stx_strict_hydration: !0
121
+ });
122
+ if (rendered.redirect || rendered.cookies?.length || rendered.boundaries?.length || rendered.headers && Object.keys(rendered.headers).length)
123
+ throw Error(`Prerendered route ${route.pattern} cannot set response headers/cookies, redirect or stream`);
124
+ compiled.html = rendered.html;
125
+ compiled.status = rendered.status ?? compiled.status;
126
+ compiled.hasServerScripts = !1;
127
+ compiled.serverScriptContent = [];
128
+ compiled.placeholders = {};
129
+ }
105
130
  compiled.fragment = extractContainerContent(compiled.html, routerContainer);
106
131
  const safeRouteName = route.pattern === "/" ? "index" : route.pattern.slice(1).replace(/\//g, "-").replace(/[[\]]/g, "_"), compiledPath = path.join("server", "pages", `${safeRouteName}.compiled.json`), fragmentPath = path.join("server", "fragments", `${safeRouteName}.html`);
107
132
  await Bun.write(path.join(outputDir, compiledPath), JSON.stringify(compiled, null, 2));
@@ -111,12 +136,16 @@ export async function buildForProduction(options = {}) {
111
136
  compiledPath,
112
137
  fragmentPath,
113
138
  isDynamic: compiled.hasServerScripts,
114
- hasParams: route.pattern.includes(":") || route.pattern.includes("[")
139
+ hasParams: route.pattern.includes(":") || route.pattern.includes("["),
140
+ prerendered
115
141
  });
116
142
  console.log(`[stx build] \u2713 ${route.pattern}`);
117
143
  } catch (error) {
144
+ if (Object.keys(rule).length)
145
+ throw error;
118
146
  console.error(`[stx build] \u2717 ${route.pattern}:`, error instanceof Error ? error.message : error);
119
147
  }
148
+ }
120
149
  const userPublicSrc = path.resolve(root, publicDir);
121
150
  if (fs.existsSync(userPublicSrc)) {
122
151
  const { copied, bytes } = copyPublicAssets(userPublicSrc, path.join(outputDir, "public"));
@@ -133,6 +162,16 @@ export async function buildForProduction(options = {}) {
133
162
  runtime: runtimeAsset.filename,
134
163
  router: routerAsset.filename
135
164
  }, manifest = generateManifest(manifestRoutes, assets, outputDir);
165
+ manifest.routeRules = routeRules;
166
+ manifest.routerContainer = routerContainer;
167
+ if (serverApi)
168
+ manifest.apiRoutes = await buildServerApi(root, outputDir, apiOptions);
169
+ if (projectConfig.runtimeConfig) {
170
+ await Bun.write(path.join(outputDir, "server/runtime-config.json"), JSON.stringify(projectConfig.runtimeConfig));
171
+ await generateRuntimeConfigTypes(root, projectConfig.runtimeConfig);
172
+ }
173
+ if (projectConfig._layerGraph)
174
+ await Bun.write(path.join(outputDir, "server/layers.json"), JSON.stringify(layerManifest(projectConfig._layerGraph), null, 2));
136
175
  writeManifest(manifest, outputDir);
137
176
  const duration = Date.now() - startTime;
138
177
  console.log(`
@@ -1,3 +1,4 @@
1
+ import { type RuntimeConfigDefaults } from './runtime-config-server';
1
2
  /**
2
3
  * Start the production server.
3
4
  *
@@ -7,13 +8,15 @@
7
8
  * - Static pages: served directly (zero processing)
8
9
  * - Dynamic pages: hydrated with request-time data
9
10
  */
10
- export declare function startProductionServer(options?: ProductionServerOptions): Promise<{ port: number, stop: () => void }>;
11
+ export declare function startProductionServer(options?: ProductionServerOptions): Promise<{ port: number, stop: () => void, invalidate: (pathname?: string) => void }>;
11
12
  /**
12
13
  * Production server configuration.
13
14
  */
14
15
  export declare interface ProductionServerOptions {
15
16
  outputDir?: string
16
17
  port?: number
18
+ runtimeConfig?: RuntimeConfigDefaults
17
19
  onRequest?: (req: Request) => Response | Promise<Response> | null | Promise<null>
18
20
  apiRoutes?: Record<string, (req: Request) => Response | Promise<Response>>
21
+ apiRouter?: { handleRequest: (request: Request) => Response | Promise<Response> }
19
22
  }
@@ -2,13 +2,17 @@ import fs from "node:fs";
2
2
  import path from "node:path";
3
3
  import { serve } from "bun";
4
4
  import { loadManifest } from "./manifest.js";
5
- import { hydrateTemplateStream, hydrateFragment } from "./template-hydrator.js";
6
- import { extractLayoutMetadata } from "./app-shell.js";
5
+ import { hydrateTemplateStream } from "./template-hydrator.js";
6
+ import { extractContainerContent, extractLayoutMetadata } from "./app-shell.js";
7
7
  import { pageShipsSignalsRuntime } from "./runtime-injection.js";
8
8
  import { patternToRegex } from "stx-router";
9
9
  import { compressResponse } from "./compression.js";
10
10
  import { actionRedirectResponse, isActionableMethod } from "./page-action.js";
11
11
  import { FRAGMENT_CACHE_CONTROL, isSpaNavRequest, spaNavVaryHeaders } from "./spa-nav.js";
12
+ import { createRouteRuleResolver } from "./route-rules.js";
13
+ import { RouteResponseCache } from "./route-response-cache.js";
14
+ import { productionApiDispatcher } from "./server-api.js";
15
+ import { injectRuntimeConfig, resolveRuntimeConfig, withRuntimeConfig } from "./runtime-config-server.js";
12
16
  const MIME_TYPES = {
13
17
  ".js": "application/javascript",
14
18
  ".mjs": "application/javascript",
@@ -39,22 +43,26 @@ const MIME_TYPES = {
39
43
  ".eot": "application/vnd.ms-fontobject"
40
44
  };
41
45
  export async function startProductionServer(options = {}) {
42
- const outputDir = path.resolve(options.outputDir || ".output"), port = options.port || 3000, manifest = loadManifest(outputDir);
46
+ const outputDir = path.resolve(options.outputDir || ".output"), port = options.port ?? 3000, manifest = loadManifest(outputDir);
43
47
  if (!manifest) {
44
48
  console.error("[stx] No build manifest found. Run `stx build` first.");
45
49
  process.exit(1);
46
50
  }
47
51
  console.log(`[stx] Production server loading ${manifest.routes.length} routes...`);
48
- const compiledTemplates = new Map, fragmentCache = new Map, layoutMetadataCache = new Map, runtimeCache = new Map;
52
+ const resolveRule = createRouteRuleResolver(manifest.routeRules), responseCache = new RouteResponseCache, handleApi = productionApiDispatcher(outputDir, manifest.apiRoutes ?? []), configFile = Bun.file(path.join(outputDir, "server/runtime-config.json")), runtimeDefaults = options.runtimeConfig ?? (await configFile.exists() ? await configFile.json() : void 0), runtimeConfig = runtimeDefaults ? resolveRuntimeConfig(runtimeDefaults) : void 0, compiledTemplates = new Map, fragmentCache = new Map, layoutMetadataCache = new Map, runtimeCache = new Map;
49
53
  for (const route of manifest.routes)
50
54
  try {
51
55
  const compiledPath = path.join(outputDir, route.compiledPath), compiled = JSON.parse(await Bun.file(compiledPath).text());
56
+ if (runtimeConfig)
57
+ compiled.html = injectRuntimeConfig(compiled.html, runtimeConfig);
52
58
  compiledTemplates.set(route.pattern, compiled);
53
59
  layoutMetadataCache.set(route.pattern, extractLayoutMetadata(compiled.html));
54
60
  runtimeCache.set(route.pattern, pageShipsSignalsRuntime(compiled.html));
55
61
  const fragmentPath = path.join(outputDir, route.fragmentPath);
56
- if (await Bun.file(fragmentPath).exists())
57
- fragmentCache.set(route.pattern, await Bun.file(fragmentPath).text());
62
+ if (await Bun.file(fragmentPath).exists()) {
63
+ const fragment = await Bun.file(fragmentPath).text();
64
+ fragmentCache.set(route.pattern, runtimeConfig ? injectRuntimeConfig(fragment, runtimeConfig) : fragment);
65
+ }
58
66
  } catch (error) {
59
67
  console.warn(`[stx] Failed to load route ${route.pattern}:`, error);
60
68
  }
@@ -68,15 +76,23 @@ export async function startProductionServer(options = {}) {
68
76
  const server = serve({
69
77
  port,
70
78
  async fetch(request) {
71
- return compressResponse(request, await (async () => {
79
+ return compressResponse(request, await withRuntimeConfig(runtimeConfig ?? resolveRuntimeConfig(), async () => {
72
80
  const pathname = new URL(request.url).pathname;
73
81
  if (options.onRequest) {
74
82
  const response = await options.onRequest(request);
75
83
  if (response)
76
84
  return response;
77
85
  }
86
+ if (options.apiRouter) {
87
+ const response = await options.apiRouter.handleRequest(request);
88
+ if (response.status !== 404)
89
+ return response;
90
+ }
78
91
  if (options.apiRoutes?.[pathname])
79
92
  return options.apiRoutes[pathname](request);
93
+ const apiResponse = await handleApi(request);
94
+ if (apiResponse)
95
+ return apiResponse;
80
96
  if ((request.method === "GET" || request.method === "HEAD") && pathname !== "/") {
81
97
  const publicRoot = path.resolve(outputDir, "public");
82
98
  let safePathname;
@@ -127,82 +143,114 @@ export async function startProductionServer(options = {}) {
127
143
  }
128
144
  return new Response("Not Found", { status: 404 });
129
145
  }
130
- if (isSpaNav) {
131
- const fragment = fragmentCache.get(matchedRoute.pattern);
132
- if (fragment) {
133
- const layoutMetadata = layoutMetadataCache.get(matchedRoute.pattern);
134
- return new Response(fragment, {
146
+ const rule = resolveRule(pathname), controlled = Object.keys(rule).length > 0;
147
+ return responseCache.respond(request, rule.cache, async () => {
148
+ const candidate = compiledTemplates.get(matchedRoute.pattern);
149
+ if (isSpaNav && request.method === "GET" && candidate && !candidate.hasServerScripts && Object.keys(candidate.placeholders).length === 0) {
150
+ const fragment = fragmentCache.get(matchedRoute.pattern);
151
+ if (fragment) {
152
+ const layoutMetadata = layoutMetadataCache.get(matchedRoute.pattern);
153
+ return new Response(fragment, {
154
+ status: candidate.status ?? 200,
155
+ headers: {
156
+ "Content-Type": "text/html",
157
+ "X-STX-Fragment": "true",
158
+ ...runtimeCache.has(matchedRoute.pattern) ? { "X-STX-Runtime": runtimeCache.get(matchedRoute.pattern) ? "true" : "false" } : {},
159
+ ...layoutMetadata ? {
160
+ "X-STX-Layout": layoutMetadata.layout,
161
+ "X-STX-Layout-Group": layoutMetadata.group
162
+ } : {},
163
+ ...spaNavVaryHeaders(),
164
+ ...rule.cache ? {} : { "Cache-Control": FRAGMENT_CACHE_CONTROL }
165
+ }
166
+ });
167
+ }
168
+ }
169
+ const isMutating = isActionableMethod(request.method), compiled = compiledTemplates.get(matchedRoute.pattern);
170
+ if (!compiled) {
171
+ const errorPage = exactRoutes.get("/500") || null;
172
+ if (errorPage) {
173
+ const compiledError = compiledTemplates.get(errorPage.pattern);
174
+ if (compiledError)
175
+ return new Response(compiledError.html, {
176
+ status: 500,
177
+ headers: { "Content-Type": "text/html" }
178
+ });
179
+ }
180
+ return new Response("Internal Server Error", { status: 500 });
181
+ }
182
+ if (matchedRoute.prerendered && isMutating)
183
+ return new Response("Prerendered pages do not accept actions", { status: 405, headers: { Allow: "GET, HEAD" } });
184
+ if (!isMutating && !compiled.hasServerScripts && Object.keys(compiled.placeholders).length === 0)
185
+ return new Response(compiled.html, {
186
+ status: compiled.status ?? 200,
135
187
  headers: {
136
188
  "Content-Type": "text/html",
137
- "X-STX-Fragment": "true",
138
- ...runtimeCache.has(matchedRoute.pattern) ? { "X-STX-Runtime": runtimeCache.get(matchedRoute.pattern) ? "true" : "false" } : {},
139
- ...layoutMetadata ? {
140
- "X-STX-Layout": layoutMetadata.layout,
141
- "X-STX-Layout-Group": layoutMetadata.group
142
- } : {},
143
189
  ...spaNavVaryHeaders(),
144
- "Cache-Control": FRAGMENT_CACHE_CONTROL
190
+ "Cache-Control": "public, max-age=60"
145
191
  }
146
192
  });
147
- }
148
- }
149
- const isMutating = isActionableMethod(request.method), compiled = compiledTemplates.get(matchedRoute.pattern);
150
- if (!compiled) {
151
- const errorPage = exactRoutes.get("/500") || null;
152
- if (errorPage) {
153
- const compiledError = compiledTemplates.get(errorPage.pattern);
154
- if (compiledError)
155
- return new Response(compiledError.html, {
156
- status: 500,
157
- headers: { "Content-Type": "text/html" }
193
+ try {
194
+ const { html, boundaries, redirect, cookies, status, headers: pageHeaders } = await hydrateTemplateStream(compiled, {
195
+ params,
196
+ request,
197
+ method: request.method,
198
+ __stx_strict_hydration: controlled,
199
+ __stx_runtime_config: runtimeConfig
200
+ });
201
+ if (redirect)
202
+ return actionRedirectResponse(redirect, cookies, pageHeaders);
203
+ if (boundaries && boundaries.length > 0) {
204
+ const { renderStreamingPage, streamToResponse } = await import("./streaming.js"), headers = new Headers({ ...spaNavVaryHeaders(), ...pageHeaders, "Cache-Control": "private, no-store" });
205
+ for (const cookie of cookies ?? [])
206
+ headers.append("Set-Cookie", cookie);
207
+ if (isSpaNav && !isMutating) {
208
+ const layout = extractLayoutMetadata(html);
209
+ headers.set("X-STX-Fragment", "true");
210
+ headers.set("X-STX-Runtime", pageShipsSignalsRuntime(html) ? "true" : "false");
211
+ headers.set("X-STX-Layout", layout.layout);
212
+ headers.set("X-STX-Layout-Group", layout.group);
213
+ }
214
+ return streamToResponse(renderStreamingPage(isSpaNav && !isMutating ? extractContainerContent(html, manifest.routerContainer || "main") : html, boundaries, { timeoutMs: 30000 }), {
215
+ status: status ?? compiled.status ?? 200,
216
+ headers
158
217
  });
159
- }
160
- return new Response("Internal Server Error", { status: 500 });
161
- }
162
- if (!isMutating && !compiled.hasServerScripts && Object.keys(compiled.placeholders).length === 0)
163
- return new Response(compiled.html, {
164
- status: compiled.status ?? 200,
165
- headers: {
218
+ }
219
+ const headers = new Headers({
166
220
  "Content-Type": "text/html",
167
221
  ...spaNavVaryHeaders(),
168
- "Cache-Control": "public, max-age=60"
222
+ ...rule.cache ? {} : { "Cache-Control": "private, no-store" }
223
+ });
224
+ for (const cookie of cookies ?? [])
225
+ headers.append("Set-Cookie", cookie);
226
+ for (const [name, value] of Object.entries(pageHeaders ?? {}))
227
+ headers.set(name, value);
228
+ headers.set("Vary", spaNavVaryHeaders(headers.get("Vary")).Vary);
229
+ if (isSpaNav && !isMutating) {
230
+ const layout = extractLayoutMetadata(html);
231
+ headers.set("X-STX-Fragment", "true");
232
+ headers.set("X-STX-Runtime", pageShipsSignalsRuntime(html) ? "true" : "false");
233
+ headers.set("X-STX-Layout", layout.layout);
234
+ headers.set("X-STX-Layout-Group", layout.group);
235
+ return new Response(extractContainerContent(html, manifest.routerContainer || "main"), { status: status ?? compiled.status ?? 200, headers });
169
236
  }
170
- });
171
- try {
172
- const { html, boundaries, redirect, cookies, status, headers: pageHeaders } = await hydrateTemplateStream(compiled, {
173
- params,
174
- request,
175
- method: request.method
176
- });
177
- if (redirect)
178
- return actionRedirectResponse(redirect, cookies, pageHeaders);
179
- if (boundaries && boundaries.length > 0) {
180
- const { renderStreamingPage, streamToResponse } = await import("./streaming.js");
181
- return streamToResponse(renderStreamingPage(html, boundaries, { timeoutMs: 30000 }), {
182
- status: status ?? compiled.status ?? 200,
183
- headers: { "Cache-Control": "no-cache", ...pageHeaders }
237
+ return new Response(html, { status: status ?? compiled.status ?? 200, headers });
238
+ } catch (error) {
239
+ console.error(`[stx] Hydration error for ${pathname}:`, error);
240
+ if (controlled)
241
+ return new Response("Internal Server Error", { status: 500 });
242
+ return new Response(compiled.html, {
243
+ headers: { "Content-Type": "text/html" }
184
244
  });
185
245
  }
186
- const headers = new Headers({
187
- "Content-Type": "text/html",
188
- ...spaNavVaryHeaders(),
189
- "Cache-Control": "no-cache"
190
- });
191
- for (const cookie of cookies ?? [])
192
- headers.append("Set-Cookie", cookie);
193
- for (const [name, value] of Object.entries(pageHeaders ?? {}))
194
- headers.set(name, value);
195
- return new Response(html, { status: status ?? compiled.status ?? 200, headers });
196
- } catch (error) {
197
- console.error(`[stx] Hydration error for ${pathname}:`, error);
198
- return new Response(compiled.html, {
199
- headers: { "Content-Type": "text/html" }
200
- });
201
- }
202
- })());
246
+ });
247
+ }));
203
248
  }
204
249
  });
205
- console.log(`[stx] Production server running at http://localhost:${port}`);
250
+ console.log(`[stx] Production server running at http://localhost:${server.port}`);
206
251
  console.log(`[stx] Serving ${manifest.routes.length} routes (${compiledTemplates.size} pre-loaded)`);
207
- return { port, stop: () => server.stop() };
252
+ return { port: server.port, stop: () => {
253
+ responseCache.invalidate();
254
+ server.stop();
255
+ }, invalidate: (pathname) => responseCache.invalidate(pathname) };
208
256
  }