@stacksjs/stx 0.2.531 → 0.2.533

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 (299) hide show
  1. package/dist/{chunk-ktmacsqc.js → chunk-01343ehq.js} +2 -2
  2. package/dist/chunk-0e5nasyf.js +2 -0
  3. package/dist/chunk-13zbt9py.js +2 -0
  4. package/dist/{chunk-9w2vmfha.js → chunk-1c4t7ncb.js} +2 -2
  5. package/dist/{chunk-gxfnmjzp.js → chunk-1xgs9gd5.js} +2 -2
  6. package/dist/{chunk-hrrxggpx.js → chunk-2bvk0qyd.js} +63 -12
  7. package/dist/{chunk-cp8f1pv4.js → chunk-2h4f37kx.js} +2 -2
  8. package/dist/{chunk-q6e45gnw.js → chunk-2kvbg3t5.js} +3 -3
  9. package/dist/{chunk-8n7qsr17.js → chunk-2n4je46m.js} +2 -2
  10. package/dist/{chunk-xcfhy5bj.js → chunk-33bzhsyw.js} +2 -2
  11. package/dist/{chunk-7ybgfk0m.js → chunk-3nk8cnrm.js} +2 -2
  12. package/dist/{chunk-gsxb0ry9.js → chunk-3r1m3tyr.js} +1 -1
  13. package/dist/chunk-3zs8yxy0.js +2 -0
  14. package/dist/{chunk-d3mssbgp.js → chunk-40hbpz2b.js} +5 -5
  15. package/dist/chunk-4a7v51vh.js +2 -0
  16. package/dist/{chunk-xtknewf7.js → chunk-4hyhr5r7.js} +1 -1
  17. package/dist/{chunk-srcv6wvm.js → chunk-4pxc3r1p.js} +4 -4
  18. package/dist/chunk-4qts8zk7.js +2 -0
  19. package/dist/{chunk-587ehsxn.js → chunk-4r7s3862.js} +2 -2
  20. package/dist/chunk-4y2av4ev.js +2 -0
  21. package/dist/chunk-5g498pdp.js +2 -0
  22. package/dist/chunk-5gq8m2m7.js +2 -0
  23. package/dist/chunk-5wx323bm.js +2 -0
  24. package/dist/{chunk-d2r8t40y.js → chunk-66s4nhp7.js} +2 -2
  25. package/dist/{chunk-d7x6n702.js → chunk-6dtmants.js} +3 -3
  26. package/dist/chunk-6rcxtdh3.js +2 -0
  27. package/dist/{chunk-st79dqpz.js → chunk-6sd4zdtg.js} +1 -1
  28. package/dist/{chunk-zpdq0kx1.js → chunk-6tnh3cyq.js} +1 -1
  29. package/dist/chunk-6va8wt88.js +2 -0
  30. package/dist/chunk-7v2j9bmc.js +2 -0
  31. package/dist/chunk-7zgtdap7.js +2 -0
  32. package/dist/{chunk-rsy1r1t2.js → chunk-843y0pfg.js} +4 -4
  33. package/dist/{chunk-b0tmg1q1.js → chunk-8chxczpj.js} +3 -3
  34. package/dist/{chunk-b7xdk1g4.js → chunk-8m1y1kyr.js} +5 -5
  35. package/dist/chunk-90kzf313.js +2 -0
  36. package/dist/{chunk-m5c2gts6.js → chunk-93n6yv5x.js} +12 -12
  37. package/dist/chunk-94rg5s6c.js +2 -0
  38. package/dist/chunk-9674w2gm.js +2 -0
  39. package/dist/{chunk-tvssmzc2.js → chunk-9p6bt089.js} +3 -3
  40. package/dist/{chunk-kg77xs08.js → chunk-bczcm7jk.js} +2 -2
  41. package/dist/{chunk-v38kqjew.js → chunk-bxsehntq.js} +1 -1
  42. package/dist/{chunk-vg8thz41.js → chunk-c56qtne1.js} +1 -1
  43. package/dist/chunk-d1jxmhph.js +2 -0
  44. package/dist/{chunk-5tj6expd.js → chunk-d7zterbp.js} +2 -2
  45. package/dist/{chunk-mc5agc81.js → chunk-d871008z.js} +4 -4
  46. package/dist/chunk-dekpf1ry.js +2 -0
  47. package/dist/chunk-epa1c4q4.js +2 -0
  48. package/dist/{chunk-95z7yemm.js → chunk-f3q84h7b.js} +2 -2
  49. package/dist/{chunk-mwte3cbe.js → chunk-fqfqyn48.js} +4 -4
  50. package/dist/{chunk-qwpgggkj.js → chunk-gnx0fzne.js} +60 -60
  51. package/dist/chunk-gsc5t942.js +2 -0
  52. package/dist/chunk-gsm1y1kb.js +2 -0
  53. package/dist/chunk-gxedmh17.js +2 -0
  54. package/dist/{chunk-9xq5yer8.js → chunk-h4crv0by.js} +1 -1
  55. package/dist/{chunk-pr5q4wev.js → chunk-hp8g2q2n.js} +1 -1
  56. package/dist/{chunk-38w14qs7.js → chunk-hvpzy98g.js} +1 -1
  57. package/dist/chunk-j9c0yam7.js +2 -0
  58. package/dist/{chunk-12e4a0ab.js → chunk-jbfad9cc.js} +2 -2
  59. package/dist/chunk-jv3jj612.js +2 -0
  60. package/dist/chunk-jvqas8y2.js +2 -0
  61. package/dist/{chunk-z14e2qyn.js → chunk-k3v13vfr.js} +2 -2
  62. package/dist/chunk-kcs7hyep.js +2 -0
  63. package/dist/chunk-kvp0at16.js +2 -0
  64. package/dist/{chunk-31c1g3rt.js → chunk-m011s2ha.js} +3 -3
  65. package/dist/{chunk-2jk0vceh.js → chunk-m56m95gk.js} +2 -2
  66. package/dist/{chunk-7s14bthq.js → chunk-m5fw8jq1.js} +2 -2
  67. package/dist/chunk-m7jmpech.js +2 -0
  68. package/dist/chunk-m8n9wxba.js +2 -0
  69. package/dist/{chunk-fyxydww2.js → chunk-mjdyyekx.js} +2 -2
  70. package/dist/{chunk-ennxrn5g.js → chunk-nd8v4xgb.js} +5 -5
  71. package/dist/chunk-ngma9vzc.js +2 -0
  72. package/dist/{chunk-rtk6n3vh.js → chunk-ngxqydsg.js} +3 -3
  73. package/dist/{chunk-cxxcy624.js → chunk-nmy4x6dx.js} +4 -4
  74. package/dist/chunk-pz1mjgsp.js +2 -0
  75. package/dist/{chunk-er031j13.js → chunk-qfc912e5.js} +2 -2
  76. package/dist/chunk-qk3ptn6h.js +2 -0
  77. package/dist/{chunk-03wggzg8.js → chunk-qmza4327.js} +2 -2
  78. package/dist/{chunk-w3xs6kb9.js → chunk-qqr4rn9p.js} +4 -4
  79. package/dist/chunk-rx4hz615.js +2 -0
  80. package/dist/chunk-shf0hd05.js +2 -0
  81. package/dist/{chunk-3vvppnws.js → chunk-sqb6gkzf.js} +8374 -8374
  82. package/dist/chunk-t1g1sp2z.js +2 -0
  83. package/dist/{chunk-9f3m5ecs.js → chunk-tgc645pa.js} +45 -45
  84. package/dist/{chunk-2dzd2h15.js → chunk-tkvp3rz0.js} +1 -1
  85. package/dist/{chunk-458etq5a.js → chunk-tqnh98j7.js} +3 -3
  86. package/dist/chunk-tr9bjtqx.js +2 -0
  87. package/dist/{chunk-2y6tzn6d.js → chunk-ty1v368m.js} +2 -2
  88. package/dist/{chunk-fmp8dmt0.js → chunk-v4r8nzf3.js} +1 -1
  89. package/dist/{chunk-p8yh7mgr.js → chunk-v9vvzdag.js} +2 -2
  90. package/dist/{chunk-0wvsfs4s.js → chunk-vb4xxpa6.js} +2 -2
  91. package/dist/chunk-vfnerp7h.js +2 -0
  92. package/dist/{chunk-tkeabv04.js → chunk-vhfwnvmc.js} +5 -5
  93. package/dist/{chunk-15r72kw7.js → chunk-vjdj0ex3.js} +1 -1
  94. package/dist/{chunk-9pztpvvk.js → chunk-wh7xn313.js} +1 -1
  95. package/dist/chunk-wjt46tdp.js +2 -0
  96. package/dist/chunk-wxy9re1a.js +2 -0
  97. package/dist/{chunk-kwvexxey.js → chunk-x607yxrc.js} +3 -3
  98. package/dist/{chunk-3zyvhf4p.js → chunk-xey01yna.js} +1 -1
  99. package/dist/{chunk-7b2hj6nt.js → chunk-xwrbrg1q.js} +1 -1
  100. package/dist/{chunk-9sqjmd9a.js → chunk-y18yvcjb.js} +5 -5
  101. package/dist/chunk-ydtnskdv.js +2 -0
  102. package/dist/{chunk-ky25egh1.js → chunk-yw3cqy43.js} +1 -1
  103. package/dist/{chunk-tyts58ks.js → chunk-z9r3tqyr.js} +1 -1
  104. package/dist/chunk-zeve89kw.js +2 -0
  105. package/dist/cli.js +12 -12
  106. package/dist/client/signals-appearance-runtime.d.ts +2 -0
  107. package/dist/client/signals-appearance-runtime.js +283 -0
  108. package/dist/client/signals-authoring-runtime.d.ts +2 -0
  109. package/dist/client/signals-authoring-runtime.js +187 -0
  110. package/dist/client/signals-binding-utils-runtime.d.ts +2 -0
  111. package/dist/client/signals-binding-utils-runtime.js +130 -0
  112. package/dist/client/signals-bootstrap-runtime.d.ts +4 -0
  113. package/dist/client/signals-bootstrap-runtime.js +24 -0
  114. package/dist/client/signals-class-runtime.d.ts +2 -0
  115. package/dist/client/signals-class-runtime.js +69 -0
  116. package/dist/client/signals-component-api-runtime.d.ts +1 -0
  117. package/dist/client/signals-component-api-runtime.js +57 -0
  118. package/dist/client/signals-component-hydration-runtime.d.ts +2 -0
  119. package/dist/client/signals-component-hydration-runtime.js +147 -0
  120. package/dist/client/signals-component-props-runtime.d.ts +2 -0
  121. package/dist/client/signals-component-props-runtime.js +90 -0
  122. package/dist/client/signals-conditional-chain-runtime.d.ts +2 -0
  123. package/dist/client/signals-conditional-chain-runtime.js +39 -0
  124. package/dist/client/signals-conditional-component-runtime.d.ts +2 -0
  125. package/dist/client/signals-conditional-component-runtime.js +82 -0
  126. package/dist/client/signals-container-cleanup-runtime.d.ts +2 -0
  127. package/dist/client/signals-container-cleanup-runtime.js +42 -0
  128. package/dist/client/signals-context-runtime.d.ts +2 -0
  129. package/dist/client/signals-context-runtime.js +48 -0
  130. package/dist/client/signals-cookie-runtime.d.ts +2 -0
  131. package/dist/client/signals-cookie-runtime.js +56 -0
  132. package/dist/client/signals-devtools-runtime.d.ts +2 -0
  133. package/dist/client/signals-devtools-runtime.js +136 -0
  134. package/dist/client/signals-dialog-runtime.d.ts +2 -0
  135. package/dist/client/signals-dialog-runtime.js +195 -0
  136. package/dist/client/signals-dom-ready-runtime.d.ts +2 -0
  137. package/dist/client/signals-dom-ready-runtime.js +306 -0
  138. package/dist/client/signals-drawer-runtime.d.ts +2 -0
  139. package/dist/client/signals-drawer-runtime.js +39 -0
  140. package/dist/client/signals-effect-runtime.d.ts +2 -0
  141. package/dist/client/signals-effect-runtime.js +157 -0
  142. package/dist/client/signals-event-shorthand-runtime.d.ts +2 -0
  143. package/dist/client/signals-event-shorthand-runtime.js +88 -0
  144. package/dist/client/signals-expression-compiler-runtime.d.ts +2 -0
  145. package/dist/client/signals-expression-compiler-runtime.js +59 -0
  146. package/dist/client/signals-expression-runtime.d.ts +2 -0
  147. package/dist/client/signals-expression-runtime.js +67 -0
  148. package/dist/client/signals-fetch-runtime.d.ts +2 -0
  149. package/dist/client/signals-fetch-runtime.js +144 -0
  150. package/dist/client/signals-fetch-transport-runtime.d.ts +2 -0
  151. package/dist/client/signals-fetch-transport-runtime.js +216 -0
  152. package/dist/client/signals-for-runtime.d.ts +2 -0
  153. package/dist/client/signals-for-runtime.js +647 -0
  154. package/dist/client/signals-globals-runtime.d.ts +2 -0
  155. package/dist/client/signals-globals-runtime.js +66 -0
  156. package/dist/client/signals-handler-runtime.d.ts +2 -0
  157. package/dist/client/signals-handler-runtime.js +80 -0
  158. package/dist/client/signals-head-runtime.d.ts +2 -0
  159. package/dist/client/signals-head-runtime.js +92 -0
  160. package/dist/client/signals-helpers-runtime.d.ts +2 -0
  161. package/dist/client/signals-helpers-runtime.js +137 -0
  162. package/dist/client/signals-host-runtime.d.ts +9 -0
  163. package/dist/client/signals-host-runtime.js +132 -0
  164. package/dist/client/signals-hydration-audit-runtime.d.ts +2 -0
  165. package/dist/client/signals-hydration-audit-runtime.js +209 -0
  166. package/dist/client/signals-hydration-runtime.d.ts +2 -0
  167. package/dist/client/signals-hydration-runtime.js +52 -0
  168. package/dist/client/signals-if-chain-runtime.d.ts +2 -0
  169. package/dist/client/signals-if-chain-runtime.js +283 -0
  170. package/dist/client/signals-if-runtime.d.ts +2 -0
  171. package/dist/client/signals-if-runtime.js +346 -0
  172. package/dist/client/signals-kept-runtime.d.ts +2 -0
  173. package/dist/client/signals-kept-runtime.js +62 -0
  174. package/dist/client/signals-lazy-hydration-runtime.d.ts +2 -0
  175. package/dist/client/signals-lazy-hydration-runtime.js +133 -0
  176. package/dist/client/signals-lifecycle-runtime.d.ts +2 -0
  177. package/dist/client/signals-lifecycle-runtime.js +114 -0
  178. package/dist/client/signals-loop-component-remap-runtime.d.ts +2 -0
  179. package/dist/client/signals-loop-component-remap-runtime.js +66 -0
  180. package/dist/client/signals-loop-conditional-runtime.d.ts +2 -0
  181. package/dist/client/signals-loop-conditional-runtime.js +48 -0
  182. package/dist/client/signals-loop-row-runtime.d.ts +2 -0
  183. package/dist/client/signals-loop-row-runtime.js +41 -0
  184. package/dist/client/signals-manifest-hydration-runtime.d.ts +2 -0
  185. package/dist/client/signals-manifest-hydration-runtime.js +82 -0
  186. package/dist/client/signals-model-runtime.d.ts +2 -0
  187. package/dist/client/signals-model-runtime.js +156 -0
  188. package/dist/client/signals-mount-runtime.d.ts +1 -0
  189. package/dist/client/signals-mount-runtime.js +231 -0
  190. package/dist/client/signals-navigation-runtime.d.ts +2 -0
  191. package/dist/client/signals-navigation-runtime.js +198 -0
  192. package/dist/client/signals-optimistic-runtime.d.ts +2 -0
  193. package/dist/client/signals-optimistic-runtime.js +34 -0
  194. package/dist/client/signals-overlay-runtime.d.ts +2 -0
  195. package/dist/client/signals-overlay-runtime.js +352 -0
  196. package/dist/client/signals-pipe-runtime.d.ts +2 -0
  197. package/dist/client/signals-pipe-runtime.js +177 -0
  198. package/dist/client/signals-process-element-runtime.d.ts +1 -0
  199. package/dist/client/signals-process-element-runtime.js +696 -0
  200. package/dist/client/signals-proxy-runtime.d.ts +2 -0
  201. package/dist/client/signals-proxy-runtime.js +78 -0
  202. package/dist/client/signals-public-api-runtime.d.ts +1 -0
  203. package/dist/client/signals-public-api-runtime.js +120 -0
  204. package/dist/client/signals-query-runtime.d.ts +2 -0
  205. package/dist/client/signals-query-runtime.js +351 -0
  206. package/dist/client/signals-reactive-core-bootstrap-runtime.d.ts +1 -0
  207. package/dist/client/signals-reactive-core-bootstrap-runtime.js +30 -0
  208. package/dist/client/signals-reactive-runtime.d.ts +2 -0
  209. package/dist/client/signals-reactive-runtime.js +67 -0
  210. package/dist/client/signals-ref-runtime.d.ts +2 -0
  211. package/dist/client/signals-ref-runtime.js +33 -0
  212. package/dist/client/signals-scope-disposal-runtime.d.ts +2 -0
  213. package/dist/client/signals-scope-disposal-runtime.js +195 -0
  214. package/dist/client/signals-scope-traversal-runtime.d.ts +2 -0
  215. package/dist/client/signals-scope-traversal-runtime.js +42 -0
  216. package/dist/client/signals-show-runtime.d.ts +2 -0
  217. package/dist/client/signals-show-runtime.js +54 -0
  218. package/dist/client/signals-spa-load-control-runtime.d.ts +2 -0
  219. package/dist/client/signals-spa-load-control-runtime.js +42 -0
  220. package/dist/client/signals-spa-load-runtime.d.ts +2 -0
  221. package/dist/client/signals-spa-load-runtime.js +187 -0
  222. package/dist/client/signals-state-runtime.d.ts +2 -0
  223. package/dist/client/signals-state-runtime.js +125 -0
  224. package/dist/client/signals-storage-runtime.d.ts +2 -0
  225. package/dist/client/signals-storage-runtime.js +79 -0
  226. package/dist/client/signals-store-registry-runtime.d.ts +1 -0
  227. package/dist/client/signals-store-registry-runtime.js +461 -0
  228. package/dist/client/signals-style-runtime.d.ts +2 -0
  229. package/dist/client/signals-style-runtime.js +35 -0
  230. package/dist/client/signals-suspense-runtime.d.ts +2 -0
  231. package/dist/client/signals-suspense-runtime.js +59 -0
  232. package/dist/client/signals-timer-runtime.d.ts +2 -0
  233. package/dist/client/signals-timer-runtime.js +378 -0
  234. package/dist/client/signals-toast-runtime.d.ts +2 -0
  235. package/dist/client/signals-toast-runtime.js +206 -0
  236. package/dist/client/signals-tooltip-runtime.d.ts +2 -0
  237. package/dist/client/signals-tooltip-runtime.js +40 -0
  238. package/dist/client/signals-transition-group-runtime.d.ts +2 -0
  239. package/dist/client/signals-transition-group-runtime.js +92 -0
  240. package/dist/client/signals-websocket-runtime.d.ts +2 -0
  241. package/dist/client/signals-websocket-runtime.js +138 -0
  242. package/dist/craft-entry.js +2 -2
  243. package/dist/craft.js +2 -2
  244. package/dist/native/runtime/native-host.js +4 -1
  245. package/dist/pwa.js +3 -3
  246. package/dist/signals-context-runtime.d.ts +2 -0
  247. package/dist/signals-drawer-runtime.d.ts +2 -0
  248. package/dist/signals-host-runtime.d.ts +9 -0
  249. package/dist/signals-loop-conditional-runtime.d.ts +2 -0
  250. package/dist/signals-manifest-hydration-runtime.d.ts +2 -0
  251. package/dist/signals-optimistic-runtime.d.ts +2 -0
  252. package/dist/signals-overlay-runtime.d.ts +2 -0
  253. package/dist/signals-scope-disposal-runtime.d.ts +2 -0
  254. package/dist/signals-spa-load-control-runtime.d.ts +2 -0
  255. package/dist/signals-storage-runtime.d.ts +2 -0
  256. package/dist/signals.js +141 -9900
  257. package/dist/ssg.js +3 -3
  258. package/package.json +5 -5
  259. package/dist/chunk-0zmv31nc.js +0 -2
  260. package/dist/chunk-1cdanx2v.js +0 -2
  261. package/dist/chunk-1wt5fagh.js +0 -2
  262. package/dist/chunk-2936t942.js +0 -2
  263. package/dist/chunk-3dd5zxbt.js +0 -2
  264. package/dist/chunk-3v91cb0g.js +0 -2
  265. package/dist/chunk-4cyjdghc.js +0 -2
  266. package/dist/chunk-5achv4zv.js +0 -2
  267. package/dist/chunk-5yg6m30k.js +0 -2
  268. package/dist/chunk-6qzjyr8e.js +0 -2
  269. package/dist/chunk-785ckss2.js +0 -2
  270. package/dist/chunk-88kjwkza.js +0 -2
  271. package/dist/chunk-8bcvb86w.js +0 -2
  272. package/dist/chunk-8h1zg44w.js +0 -2
  273. package/dist/chunk-8jtyra19.js +0 -2
  274. package/dist/chunk-bnsz09pg.js +0 -2
  275. package/dist/chunk-c9rwnsk7.js +0 -2
  276. package/dist/chunk-csjax0ej.js +0 -2
  277. package/dist/chunk-dd31q423.js +0 -2
  278. package/dist/chunk-dptjyncv.js +0 -2
  279. package/dist/chunk-et8ejd7k.js +0 -2
  280. package/dist/chunk-g1kyy5h1.js +0 -2
  281. package/dist/chunk-h791c7sb.js +0 -2
  282. package/dist/chunk-h88jcr3k.js +0 -2
  283. package/dist/chunk-hvvbppt4.js +0 -2
  284. package/dist/chunk-j4rb9rxx.js +0 -2
  285. package/dist/chunk-ka7qdsha.js +0 -2
  286. package/dist/chunk-m4d99a9r.js +0 -2
  287. package/dist/chunk-m5gdwq1d.js +0 -2
  288. package/dist/chunk-nz5ekyxn.js +0 -2
  289. package/dist/chunk-rchwwcxy.js +0 -2
  290. package/dist/chunk-s5cb4hkj.js +0 -2
  291. package/dist/chunk-t2mjeezd.js +0 -2
  292. package/dist/chunk-vk18649m.js +0 -2
  293. package/dist/chunk-vmfw4svt.js +0 -2
  294. package/dist/chunk-wbv6vjhm.js +0 -2
  295. package/dist/chunk-wpnv0naj.js +0 -2
  296. package/dist/chunk-wv2crxm6.js +0 -2
  297. package/dist/chunk-xda69f13.js +0 -2
  298. package/dist/chunk-ym182eg0.js +0 -2
  299. package/dist/chunk-zah67v44.js +0 -2
@@ -0,0 +1,209 @@
1
+ export const SIGNALS_HYDRATION_AUDIT_RUNTIME = ` // ==========================================================================
2
+ // Post-hydration invariant sweep (stacksjs/stx#1773)
3
+ // ==========================================================================
4
+ //
5
+ // Preserved moustaches are the framework's de-facto error UI: ANY failure in
6
+ // the detect \u2192 extract \u2192 bundle \u2192 ship \u2192 rebind relay collapses into the same
7
+ // visible symptom, literal {{ }} on screen. Eight separate fixes each patched
8
+ // one site's heuristic, and no invariant anywhere asserted the actual
9
+ // requirement \u2014 zero unhydrated scopes after hydration. So every new upstream
10
+ // miss reached users silently and had to be diagnosed from a screenshot.
11
+ //
12
+ // This is that invariant. It runs at the end of both hydration entry points
13
+ // and turns a silent miss into one loud, self-healing event:
14
+ //
15
+ // - an element carrying data-stx-scope whose id isn't in the registry, or
16
+ // that hydration reached but never processed, is reported AND processed
17
+ // with the ambient scope, which is what the walk would have done had the
18
+ // script arrived. That recovers the D2/D3 shapes (a silent early return
19
+ // in the walk, a stale __stx_scope guard) rather than merely naming them.
20
+ // - leftover {{ }} text is reported. Diagnostic only, never auto-fixed:
21
+ // without a scope there is nothing to interpolate against, and a page may
22
+ // legitimately print moustaches.
23
+ //
24
+ // Deliberately quiet in the normal case: nothing is logged when the page has
25
+ // no signals at all, and containers that legitimately show template syntax
26
+ // (<pre>, <code>, <template>, <script>, <style>, <textarea>, and anything
27
+ // under [data-stx-ignore]) are skipped.
28
+
29
+ var AUDIT_SKIP_TAGS = { PRE: 1, CODE: 1, SCRIPT: 1, STYLE: 1, TEXTAREA: 1, TEMPLATE: 1 };
30
+
31
+ // Expressions whose evaluation threw a ReferenceError/TypeError and have not
32
+ // since succeeded. evalAttrExpr swallows those two on purpose \u2014 a signal may
33
+ // not exist yet on an effect's first pass \u2014 which is why a genuinely broken
34
+ // binding produces no diagnostic at all today. The classic case is
35
+ // :if="flag()" where flag is a signal: the auto-unwrap proxy returns the
36
+ // VALUE, calling it throws TypeError, the directive suppresses it, and the
37
+ // element silently stays hidden with no warning anywhere (see CLAUDE.md,
38
+ // "Signals: scripts call, templates don't").
39
+ //
40
+ // Recording rather than warning immediately is what keeps this quiet on
41
+ // working pages: a first-pass failure that later succeeds clears itself, so
42
+ // only expressions still broken when hydration finishes are reported.
43
+ var _exprFailures = {};
44
+ var _exprFailureCount = 0;
45
+
46
+ function noteExprFailure(expr, err) {
47
+ if (_exprFailures[expr] !== undefined) return;
48
+ // Bounded: one runaway loop must not grow this without limit.
49
+ if (_exprFailureCount >= 50) return;
50
+ _exprFailureCount++;
51
+ _exprFailures[expr] = (err && err.message) ? err.message : String(err);
52
+ }
53
+
54
+ function noteExprSuccess(expr) {
55
+ if (_exprFailures[expr] === undefined) return;
56
+ delete _exprFailures[expr];
57
+ _exprFailureCount--;
58
+ }
59
+
60
+ function auditSkipped(node) {
61
+ // Not rendered, not audited. Covers <template> content (a detached
62
+ // DocumentFragment \u2014 which some DOM implementations still walk into) and
63
+ // :if branches parked off-document, neither of which the user can see.
64
+ if (node.isConnected === false) return true;
65
+ for (var p = node.parentNode; p; p = p.parentNode) {
66
+ if (p.nodeType === Node.DOCUMENT_FRAGMENT_NODE) return true;
67
+ if (p.nodeType !== Node.ELEMENT_NODE) continue;
68
+ if (AUDIT_SKIP_TAGS[p.tagName]) return true;
69
+ if (p.hasAttribute && p.hasAttribute('data-stx-ignore')) return true;
70
+ // A :if whose deferred child-binding pass hasn't run yet legitimately holds
71
+ // literal {{ }} that binds a macrotask later \u2014 not a hydration miss (#1773).
72
+ if (p.__stx_if_pending) return true;
73
+ // A deferred island (client=visible|idle|\u2026) is unhydrated ON PURPOSE until
74
+ // its trigger fires, so its {{ }} legitimately stay literal in the meantime
75
+ // \u2014 not a miss (#1746). The stranded-scope pass already skips stx-hydrate;
76
+ // the literal sweep must too.
77
+ if (p.hasAttribute && p.hasAttribute('stx-hydrate') && !p.__stx_hydrated) return true;
78
+ }
79
+ return false;
80
+ }
81
+
82
+ // Whether the element is, or sits inside, a structural directive's source that has
83
+ // not bound yet. Binding replaces the source with a marker and a template,
84
+ // so a :for / :if still on an element in the document has yet to run.
85
+ var UNBOUND_STRUCTURE = [':for', '@for', 'x-for', ':if', '@if', 'x-if', ':else-if', '@else-if', 'x-else-if', ':else', '@else', 'x-else'];
86
+ function inUnboundStructure(el) {
87
+ for (var p = el; p && p.nodeType === Node.ELEMENT_NODE; p = p.parentElement) {
88
+ for (var i = 0; i < UNBOUND_STRUCTURE.length; i++) {
89
+ if (p.hasAttribute(UNBOUND_STRUCTURE[i])) return true;
90
+ }
91
+ }
92
+ return false;
93
+ }
94
+
95
+ function findLiteralMoustaches(root) {
96
+ var found = [];
97
+ if (!root || typeof document.createTreeWalker !== 'function') return found;
98
+ // Read NodeFilter off window, not the bare global: in a real browser they
99
+ // are the same object, but some DOM implementations used for testing expose
100
+ // it only on window, and a bare reference then throws inside the audit.
101
+ var showText = (window.NodeFilter && window.NodeFilter.SHOW_TEXT) || 4;
102
+ var walker = document.createTreeWalker(root, showText, null);
103
+ var node;
104
+ while ((node = walker.nextNode())) {
105
+ // Browsers expose Text.nodeValue as a string, while lightweight DOM and
106
+ // native embedding shims can preserve an assigned number. Diagnostics
107
+ // must normalize the boundary instead of aborting the entire audit on a
108
+ // missing String#indexOf method.
109
+ var text = node.nodeValue == null ? '' : String(node.nodeValue);
110
+ if (text.indexOf('{{') === -1 || text.indexOf('}}') === -1) continue;
111
+ if (auditSkipped(node)) continue;
112
+ found.push(text.trim().slice(0, 80));
113
+ if (found.length >= 5) break;
114
+ }
115
+ return found;
116
+ }
117
+
118
+ // A diagnostic that can break hydration is worse than no diagnostic, so the
119
+ // whole sweep is wrapped and every DOM capability it uses is feature-checked.
120
+ // Minimal document stubs (tests, non-browser embeddings) simply skip it.
121
+ function auditHydration(container, phase) {
122
+ try { auditHydrationUnsafe(container, phase); }
123
+ catch (e) { console.warn('[stx] hydration audit skipped:', e && e.message ? e.message : e); }
124
+ }
125
+
126
+ function auditHydrationUnsafe(container, phase) {
127
+ if (!window.stx || !window.stx._scopes) return;
128
+ var root = container && typeof container.querySelectorAll === 'function' ? container : document.body;
129
+ if (!root || typeof root.querySelectorAll !== 'function') return;
130
+
131
+ // Unregistered / unprocessed scopes \u2014 the unambiguous failure, and the one
132
+ // worth repairing.
133
+ var stranded = [];
134
+ root.querySelectorAll('[data-stx-scope]').forEach(function(el) {
135
+ if (el.__stx_audit_recovered) return;
136
+ // Deferred islands are unhydrated ON PURPOSE until their trigger fires.
137
+ if (el.hasAttribute('stx-hydrate') || el.__stx_hydration_scheduled) return;
138
+ // Inert markup is not a miss: a component inside a :if branch whose
139
+ // deferred pass has not run, or inside a :for / :if source that has not
140
+ // bound, is set up when it does, under its own clone's id. The literal
141
+ // sweep already allowed for the first; recovering the second ran a
142
+ // loop's source against the page's scope.
143
+ if (auditSkipped(el) || inUnboundStructure(el)) return;
144
+ var scopeId = el.getAttribute('data-stx-scope');
145
+ var registered = window.stx._scopes[scopeId];
146
+ if (registered && el.__stx_disposers) return;
147
+ stranded.push({ el: el, id: scopeId, registered: !!registered });
148
+ });
149
+
150
+ if (stranded.length) {
151
+ console.error(
152
+ '[stx] hydration invariant failed after ' + phase + ': '
153
+ + stranded.length + ' scope(s) left unhydrated \u2014 '
154
+ + stranded.map(function(s) {
155
+ return s.id + (s.registered ? ' (registered, never processed)' : ' (not registered)');
156
+ }).join(', ')
157
+ + '. Recovering with the ambient scope; please report with the page that produced it (stacksjs/stx#1773).',
158
+ );
159
+ stranded.forEach(function(s) {
160
+ // Once per element: a repair that itself fails must not loop on the
161
+ // next navigation.
162
+ s.el.__stx_audit_recovered = true;
163
+ try {
164
+ var vars = s.registered ? window.stx._scopes[s.id] : null;
165
+ if (vars) Object.assign(componentScope, vars);
166
+ s.el.__stx_disposers = trackEffects(function() { processElement(s.el, componentScope); });
167
+ s.el.removeAttribute('x-cloak');
168
+ s.el.querySelectorAll('[x-cloak]').forEach(function(c) { c.removeAttribute('x-cloak'); });
169
+ }
170
+ catch (e) {
171
+ console.error('[stx] hydration recovery failed for scope ' + s.id + ':', e);
172
+ }
173
+ });
174
+ }
175
+
176
+ var literals = findLiteralMoustaches(root);
177
+ if (literals.length) {
178
+ console.error(
179
+ '[stx] hydration invariant failed after ' + phase + ': literal {{ }} left in the DOM \u2014 '
180
+ + literals.join(' | ')
181
+ + '. An expression did not bind; see stacksjs/stx#1773. Wrap intentional '
182
+ + 'template syntax in <pre>/<code> or [data-stx-ignore] to exclude it.',
183
+ );
184
+ }
185
+
186
+ // Expressions that threw and never recovered. Reported here rather than at
187
+ // throw time so a first-pass miss that later resolves stays silent.
188
+ var brokenExprs = [];
189
+ for (var expr in _exprFailures) {
190
+ if (Object.prototype.hasOwnProperty.call(_exprFailures, expr))
191
+ brokenExprs.push(expr + ' \u2192 ' + _exprFailures[expr]);
192
+ }
193
+ if (brokenExprs.length) {
194
+ var hint = brokenExprs.some(function(m) { return m.indexOf('is not a function') !== -1; })
195
+ ? ' If one of these calls a signal, drop the parentheses: templates read '
196
+ + 'a signal by bare name (:if="flag"), scripts call it (flag()). Calling '
197
+ + 'the unwrapped value is a TypeError, which directives suppress \u2014 the '
198
+ + 'element just stays hidden.'
199
+ : '';
200
+ console.error(
201
+ '[stx] hydration invariant failed after ' + phase + ': '
202
+ + brokenExprs.length + ' expression(s) never evaluated \u2014 '
203
+ + brokenExprs.slice(0, 5).join(' | ') + '.' + hint,
204
+ );
205
+ _exprFailures = {};
206
+ _exprFailureCount = 0;
207
+ }
208
+ }
209
+ `;
@@ -0,0 +1,2 @@
1
+ /** Dynamic subtree hydration used by the generated client runtime. */
2
+ export declare const SIGNALS_HYDRATION_RUNTIME = " // Hydrate a subtree inserted AFTER initial load \u2014 e.g. a streamed suspense\n // boundary (#1746 Phase 3). Mirrors the SPA re-init pass, scoped to the\n // container: (1) executes the subtree's scoped setup scripts (inert when\n // inserted via innerHTML, so they're cloned into fresh script elements to\n // run), (2) processes any data-stx-scope islands the scripts registered,\n // (3) binds directives across the subtree (content using already-live page\n // signals works too), (4) flushes onMount. Idempotent via the usual guards.\n function hydrateSubtree(container) {\n if (!container || !container.querySelectorAll) return;\n // 1. Run scoped setup scripts so their scopes register.\n var scoped = container.querySelectorAll('script[data-stx-scoped]');\n for (var i = 0; i < scoped.length; i++) {\n var old = scoped[i];\n if (old.__stx_ran) continue;\n var fresh = document.createElement('script');\n for (var a = 0; a < old.attributes.length; a++) fresh.setAttribute(old.attributes[a].name, old.attributes[a].value);\n fresh.textContent = old.textContent;\n fresh.__stx_ran = true;\n if (old.parentNode) old.parentNode.replaceChild(fresh, old);\n }\n // 2. Process scopes registered in this subtree (incl. the container itself).\n var scopeEls = [];\n if (container.matches && container.matches('[data-stx-scope]')) scopeEls.push(container);\n container.querySelectorAll('[data-stx-scope]').forEach(function(el) { scopeEls.push(el); });\n scopeEls.forEach(function(el) {\n if (el.__stx_disposers) return;\n var scopeId = el.getAttribute('data-stx-scope');\n var scopeVars = window.stx._scopes && window.stx._scopes[scopeId];\n if (!scopeVars) return;\n el.__stx_parent_scope = el.__stx_parent_scope\n || resolveComponentCallerScope(el, componentScope);\n bindParentComponentProps(el, el.__stx_parent_scope);\n Object.assign(componentScope, scopeVars);\n el.__stx_disposers = trackEffects(function() { processElement(el, componentScope); });\n if (scopeVars.__mountCallbacks && !scopeVars.__mounted) {\n scopeVars.__mounted = true;\n runMountCallbacks(scopeVars.__mountCallbacks, scopeDestroySink(scopeVars));\n }\n });\n // 3. Bind directives across the subtree.\n processElement(container);\n if (container.removeAttribute) container.removeAttribute('x-cloak');\n container.querySelectorAll('[x-cloak]').forEach(function(c) { c.removeAttribute('x-cloak'); });\n // 4. Flush any global mount callbacks the scripts queued.\n if (mountCallbacks.length) {\n var cbs = mountCallbacks.slice();\n mountCallbacks.length = 0;\n runMountCallbacks(cbs, destroyCallbacks);\n }\n window.dispatchEvent(new CustomEvent('stx:hydrated', { detail: { el: container, trigger: 'stream' } }));\n }\n";
@@ -0,0 +1,52 @@
1
+ export const SIGNALS_HYDRATION_RUNTIME = ` // Hydrate a subtree inserted AFTER initial load \u2014 e.g. a streamed suspense
2
+ // boundary (#1746 Phase 3). Mirrors the SPA re-init pass, scoped to the
3
+ // container: (1) executes the subtree's scoped setup scripts (inert when
4
+ // inserted via innerHTML, so they're cloned into fresh script elements to
5
+ // run), (2) processes any data-stx-scope islands the scripts registered,
6
+ // (3) binds directives across the subtree (content using already-live page
7
+ // signals works too), (4) flushes onMount. Idempotent via the usual guards.
8
+ function hydrateSubtree(container) {
9
+ if (!container || !container.querySelectorAll) return;
10
+ // 1. Run scoped setup scripts so their scopes register.
11
+ var scoped = container.querySelectorAll('script[data-stx-scoped]');
12
+ for (var i = 0; i < scoped.length; i++) {
13
+ var old = scoped[i];
14
+ if (old.__stx_ran) continue;
15
+ var fresh = document.createElement('script');
16
+ for (var a = 0; a < old.attributes.length; a++) fresh.setAttribute(old.attributes[a].name, old.attributes[a].value);
17
+ fresh.textContent = old.textContent;
18
+ fresh.__stx_ran = true;
19
+ if (old.parentNode) old.parentNode.replaceChild(fresh, old);
20
+ }
21
+ // 2. Process scopes registered in this subtree (incl. the container itself).
22
+ var scopeEls = [];
23
+ if (container.matches && container.matches('[data-stx-scope]')) scopeEls.push(container);
24
+ container.querySelectorAll('[data-stx-scope]').forEach(function(el) { scopeEls.push(el); });
25
+ scopeEls.forEach(function(el) {
26
+ if (el.__stx_disposers) return;
27
+ var scopeId = el.getAttribute('data-stx-scope');
28
+ var scopeVars = window.stx._scopes && window.stx._scopes[scopeId];
29
+ if (!scopeVars) return;
30
+ el.__stx_parent_scope = el.__stx_parent_scope
31
+ || resolveComponentCallerScope(el, componentScope);
32
+ bindParentComponentProps(el, el.__stx_parent_scope);
33
+ Object.assign(componentScope, scopeVars);
34
+ el.__stx_disposers = trackEffects(function() { processElement(el, componentScope); });
35
+ if (scopeVars.__mountCallbacks && !scopeVars.__mounted) {
36
+ scopeVars.__mounted = true;
37
+ runMountCallbacks(scopeVars.__mountCallbacks, scopeDestroySink(scopeVars));
38
+ }
39
+ });
40
+ // 3. Bind directives across the subtree.
41
+ processElement(container);
42
+ if (container.removeAttribute) container.removeAttribute('x-cloak');
43
+ container.querySelectorAll('[x-cloak]').forEach(function(c) { c.removeAttribute('x-cloak'); });
44
+ // 4. Flush any global mount callbacks the scripts queued.
45
+ if (mountCallbacks.length) {
46
+ var cbs = mountCallbacks.slice();
47
+ mountCallbacks.length = 0;
48
+ runMountCallbacks(cbs, destroyCallbacks);
49
+ }
50
+ window.dispatchEvent(new CustomEvent('stx:hydrated', { detail: { el: container, trigger: 'stream' } }));
51
+ }
52
+ `;
@@ -0,0 +1,2 @@
1
+ /** Reactive if/else-if/else chain binding for the generated client runtime. */
2
+ export declare const SIGNALS_IF_CHAIN_RUNTIME = " // Reactive if/else-if/else chain. A single effect drives mutual exclusion:\n // on each run it picks the first branch whose condition is truthy (the\n // trailing x-else always matches), inserts that branch, and removes\n // whichever branch was previously shown. One effect for the whole chain\n // means branches can't transiently both render or both vanish in a tick,\n // and a single source signal isn't subscribed N times. See #1734.\n function bindIfChain(chain, passedScope = componentScope) {\n var head = chain[0].el;\n if (head.__stx_if_bound) { console.log('[stx] bindIfChain SKIPPED (head already bound):', head.tagName, chain.map(function(c) { return c.attr; }).join(',')); return; }\n console.log('[stx] bindIfChain entry:', head.tagName, 'branches:', chain.map(function(c) { return c.attr; }).join(','));\n\n var parent = head.parentNode;\n if (!parent) { console.warn('[STX] bindIfChain: head element has no parent, skipping'); return; }\n\n var capturedComponentScope = { ...passedScope };\n\n // Detach every branch up-front, leaving a positional placeholder comment\n // so reinsertion preserves source order. Mark each as a chain member so\n // the parent's snapshot child-iteration skips the detached (non-active)\n // branches instead of bringing their content to life. The active branch\n // is re-inserted below and IS connected, so it processes normally.\n chain.forEach(function(b) {\n preserveConditionalComponentScopes(b.el, capturedComponentScope);\n b.el.__stx_if_bound = true;\n b.el.__stx_chain_member = true;\n b.el.__stx_chain_active = false;\n b.el.__stx_if_visible = state(false);\n b.capturedElementScope = findElementScope(b.el);\n b.placeholder = stxHost.anchor('stx-if-chain');\n stxHost.insert(parent, b.placeholder, b.el);\n b.el.removeAttribute(b.attr);\n // A <template> branch (the wrapper convertSignalDirectivesToAttributes\n // emits for a multi-child / text branch) is INERT \u2014 inserting the element\n // renders nothing, its content lives in a document fragment. Clone that\n // content ONCE into a stable node set we toggle in and out, exactly as\n // bindIf/bindFor already do for template elements. An element branch is\n // its own single node. Without this, a multi-element @else / @else-if\n // branch rendered blank the moment the markup was well-formed enough to\n // survive as a real <template> (the #1784 markup fix). See #1784.\n b.isTemplate = b.el.tagName === 'TEMPLATE';\n // A template branch renders CLONES, re-cloned on every show, and marks\n // where they end -- the same contract the single-template :if got in\n // #1955. Its content was cloned once here and that one node set was\n // toggled in and out, which broke two ways as soon as the branch held a\n // structural directive: a :for inside it replaces its own source element\n // with a placeholder comment and renders rows as SIBLINGS, so hiding\n // removed neither (the rows were never in this list, and the source node\n // it did hold was already detached, so the parentNode guard skipped it)\n // and both branches stayed on screen at once. Re-showing then re-inserted\n // that source element, painting the literal text of its interpolations.\n // An element branch still owns exactly the node it was bound to: whatever\n // a directive inside it renders is inside that element.\n // Snapshot the content BEFORE anything processes it, and clone each show\n // from the snapshot rather than from the live template. A nested :for\n // does not leave content pristine -- processing moves its row source out\n // and the attributes it consumed (x-model, :id) do not come back -- so a\n // second clone taken from the element would arrive already stripped, with\n // no binding and no way to acquire one.\n b.pristine = b.isTemplate ? stxHost.clone(b.el.content) : null;\n b.nodes = b.isTemplate ? [] : [b.el];\n b.endMarker = null;\n stxHost.remove(b.el);\n b.childrenProcessed = false;\n });\n\n // Per-branch evaluator. Evaluated inside the chain effect via with()\n // (like evalLazy) so ONLY the signals the expression actually references\n // register as dependencies \u2014 not every signal in scope. The old form\n // (new Function(...Object.keys(scope)) called with ...Object.values of\n // the unwrap proxy) read every scope value through the proxy to build the\n // positional args, subscribing the effect to ALL scope signals, so it\n // re-ran on every unrelated mutation (#1738). with() only triggers the\n // proxy's get-trap for identifiers the expression names.\n //\n // Two passes, same as bindIf (#1733): proxy pass first (so bare-ref\n // comparisons like count === 0 read the signal as a value), raw-scope\n // retry second (so call-syntax like count() === 0 works \u2014 the proxy\n // would have unwrapped count to a value, making count() throw).\n function evalBranch(b) {\n var expression = b.expr;\n if (/^__[A-Z_]+__$/.test(expression.trim())) return expression;\n var scope = { ...globalHelpers, ...capturedComponentScope, ...(b.capturedElementScope || {}) };\n try {\n var unwrapScope = createExpressionAutoUnwrapProxy(scope, expression);\n // Compiled over the names the expression mentions (see __stxCompileScoped).\n var fn = __stxCompileScoped(unwrapScope, [], 'return ' + expression + '');\n return fn(...__stxArgs(fn, unwrapScope));\n }\ncatch (e1) {\n try {\n var fn2 = __stxCompileScoped(scope, [], 'return ' + expression + '');\n return fn2(...__stxArgs(fn2, scope));\n }\ncatch (e2) {\n if (!(e2 instanceof ReferenceError) && !(e2 instanceof TypeError)) console.warn('[STX] Expression error:', expression, e2);\n return '';\n }\n }\n }\n\n var currentIdx = -1;\n\n effect(function() {\n // Evaluate EVERY branch's condition each run (not for-break) so the\n // reactive tracker registers dependencies on exactly the signals the\n // branch expressions reference \u2014 and on ALL of them, so a transition\n // from a later branch back to an earlier one still re-fires. Then pick\n // the first truthy branch (terminal x-else always matches).\n //\n // Pre-fix (#1738) this used a for-break picker, which only subscribed\n // to signals up to the first truthy branch; to stay correct it then\n // eagerly read EVERY signal in scope \u2014 a sledgehammer that re-ran this\n // effect on every unrelated signal mutation in the scope (50+ no-op\n // runs per page load on real apps). Evaluating all branches subscribes\n // narrowly to just the branch signals instead.\n var pickedIdx = -1;\n for (var i = 0; i < chain.length; i++) {\n var b = chain[i];\n var matched = b.terminal ? true : !!evalBranch(b);\n if (matched && pickedIdx === -1) pickedIdx = i;\n }\n\n console.log('[stx] bindIfChain pick:', pickedIdx, 'of', chain.length, '(', pickedIdx >= 0 ? chain[pickedIdx].attr : 'none', ') prev:', currentIdx);\n if (__stxDevtoolsTracking) {\n var __ifScope = null;\n try { __ifScope = stxHost.scopeOf(head); } catch (e) { __ifScope = null; }\n __stxDevtoolsRecordIf({\n scopeId: __ifScope ? __ifScope.getAttribute('data-stx-scope') : null,\n branches: chain.map(function(c) { return c.attr; }),\n picked: pickedIdx,\n pickedAttr: pickedIdx >= 0 ? chain[pickedIdx].attr : null,\n prev: currentIdx\n });\n }\n if (pickedIdx === currentIdx) return;\n\n // Remove the previously-shown branch. Do NOT disposeSubtreeScopes here:\n // a chain branch is a TOGGLE (re-shown when its condition matches again),\n // not a permanent unmount, and a nested data-stx-scope inside it can't be\n // recreated once deleted from window.stx._scopes (its setup IIFE ran\n // once at page load). Deleting it broke re-show of nested scoped\n // components under reactive conditionals (#1737). Permanent disposal is\n // still handled by bindFor (item removal) and cleanupContainer (SPA nav).\n if (currentIdx !== -1) {\n var gone = chain[currentIdx];\n gone.el.__stx_chain_active = false;\n gone.el.__stx_if_visible.set(false);\n // Unmount what the branch held, as a single :if does, before any of\n // it leaves the page.\n var leavingNodes = gone.nodes.filter(function (n) { return n.parentNode; });\n if (gone.isTemplate && gone.endMarker && gone.endMarker.parentNode) {\n leavingNodes = [];\n for (var walk = gone.placeholder.nextSibling; walk && walk !== gone.endMarker; walk = walk.nextSibling) leavingNodes.push(walk);\n }\n suspendSubtreeScopes(leavingNodes);\n\n if (gone.isTemplate) {\n // Everything this branch rendered goes, not just the clones it owns:\n // a nested :for or :if renders siblings of its own that no clone list\n // contains. The marker bounds the range, so a sibling that belongs to\n // a later branch or to ordinary markup is never touched.\n if (gone.endMarker && gone.endMarker.parentNode) {\n var doomed = gone.placeholder.nextSibling;\n while (doomed && doomed !== gone.endMarker) {\n var nextDoomed = doomed.nextSibling;\n disposeSubtreeEffects(doomed);\n stxHost.remove(doomed);\n doomed = nextDoomed;\n }\n stxHost.remove(gone.endMarker);\n gone.endMarker = null;\n }\n gone.nodes.forEach(function (n) {\n if (!n.parentNode) return;\n disposeSubtreeEffects(n);\n stxHost.remove(n);\n });\n // The next show clones afresh and processes again, so these effects\n // are finished with; leaving them bound only accumulates work (#1954).\n if (typeof gone.el.__stx_chain_disposers === 'function') {\n try { gone.el.__stx_chain_disposers(); }\ncatch (e) { /* a disposer of its own is not this branch's problem */ }\n gone.el.__stx_chain_disposers = null;\n }\n gone.nodes = [];\n gone.childrenProcessed = false;\n }\n else {\n gone.nodes.forEach(function (n) {\n if (!n.parentNode) return;\n // Detached nodes are out of reach of a DOM walk, so a row removed\n // while this branch is hidden could not dispose the effects it was\n // processed with (#1954). Same registry the single-element :if uses.\n var parentEl = n.parentNode;\n if (!parentEl.__stx_detached_if) parentEl.__stx_detached_if = new Set();\n parentEl.__stx_detached_if.add(n);\n stxHost.remove(n);\n });\n }\n }\n\n // Insert + process the newly-picked branch.\n if (pickedIdx !== -1) {\n var pick = chain[pickedIdx];\n pick.el.__stx_chain_active = true;\n // Insert this branch's node(s) before the placeholder's next sibling.\n // The anchor is captured once so the nodes stack in source order.\n var anchor = pick.placeholder.nextSibling;\n var pickHost = pick.placeholder.parentNode;\n if (pick.isTemplate && pick.nodes.length === 0)\n pick.nodes = Array.prototype.slice.call(stxHost.clone(pick.pristine).childNodes);\n pick.nodes.forEach(function (n) {\n if (pickHost.__stx_detached_if) pickHost.__stx_detached_if.delete(n);\n stxHost.insert(pickHost, n, anchor);\n });\n pick.el.__stx_if_visible.set(true);\n // Bound AFTER the clones, so hiding can remove whatever a structural\n // directive inside the branch renders as their sibling.\n if (pick.isTemplate) {\n if (!pick.endMarker) pick.endMarker = stxHost.anchor('stx-if-chain-end');\n stxHost.insert(pickHost, pick.endMarker, anchor);\n }\n pick.el.__stx_shown_at = performance.now();\n // An element branch shown before keeps its bindings and its scopes;\n // the components in it mount again (a template branch is cloned afresh\n // and mounts through hydrateComponentScopes below).\n if (pick.childrenProcessed) {\n var shownNodes = pick.nodes;\n queueMicrotask(function () {\n if (pick.el.__stx_chain_active) peek(function () { resumeSubtreeScopes(shownNodes); });\n });\n }\n if (!pick.childrenProcessed) {\n pick.childrenProcessed = true;\n // Hydrate before the outer scope walk can see the inserted branch.\n // Chromium executes scripts cloned from template.content as soon as\n // they are connected, so deferring this pass allowed the global walk\n // to process projected slot expressions without the loop caller\n // scope. peek() keeps this synchronous pass from subscribing child\n // reads to the current chain effect.\n // Tracked on the branch element: this runs inside the chain effect,\n // where no tracker is active, so without a handle the effects of a\n // branch picked after render survive their row's removal (#1954).\n pick.el.__stx_chain_disposers = trackEffects(function () {\n peek(function () {\n var childScope = { ...globalHelpers, ...capturedComponentScope, ...(pick.capturedElementScope || {}) };\n // Components compiled inside any branch of an if/else-if/else\n // chain carry scoped setup scripts with them. Branch nodes are\n // detached before those scripts can execute, so simply\n // re-inserting the selected branch leaves component props,\n // events, directives, and projected slot expressions inert.\n // Hydrate those scopes before the normal subtree walk, matching\n // the single-template :if and :for insertion paths.\n var previouslyTrackedNodes = new Set();\n pick.nodes.forEach(function (n) {\n if (n && n.__stx_disposers) previouslyTrackedNodes.add(n);\n });\n hydrateComponentScopes(pick.nodes, childScope);\n pick.nodes.forEach(function (n) {\n if (n.nodeType !== 1) return; // whitespace/text between template children\n // A scoped component receives its disposer in the outer scope\n // walk immediately after processElement returns from binding\n // this conditional. That first pass intentionally stops at\n // :if, so a disposer does not mean its children were hydrated.\n if (previouslyTrackedNodes.has(n) || !n.__stx_disposers)\n processElement(n, childScope);\n n.removeAttribute('x-cloak');\n n.querySelectorAll('[x-cloak]').forEach(function (c) { c.removeAttribute('x-cloak'); });\n });\n resumeDetachedBranches();\n });\n });\n }\n }\n\n currentIdx = pickedIdx;\n });\n }\n\n // Shown branches whose deferred bind found them off the page: an enclosing\n // :if, bound later in the same pass, hid them between the queue and the run.\n // Their own condition has not changed, so their effect never runs again to\n // retry; each resumes here when an enclosing branch puts it back.";
@@ -0,0 +1,283 @@
1
+ export const SIGNALS_IF_CHAIN_RUNTIME = ` // Reactive if/else-if/else chain. A single effect drives mutual exclusion:
2
+ // on each run it picks the first branch whose condition is truthy (the
3
+ // trailing x-else always matches), inserts that branch, and removes
4
+ // whichever branch was previously shown. One effect for the whole chain
5
+ // means branches can't transiently both render or both vanish in a tick,
6
+ // and a single source signal isn't subscribed N times. See #1734.
7
+ function bindIfChain(chain, passedScope = componentScope) {
8
+ var head = chain[0].el;
9
+ if (head.__stx_if_bound) { console.log('[stx] bindIfChain SKIPPED (head already bound):', head.tagName, chain.map(function(c) { return c.attr; }).join(',')); return; }
10
+ console.log('[stx] bindIfChain entry:', head.tagName, 'branches:', chain.map(function(c) { return c.attr; }).join(','));
11
+
12
+ var parent = head.parentNode;
13
+ if (!parent) { console.warn('[STX] bindIfChain: head element has no parent, skipping'); return; }
14
+
15
+ var capturedComponentScope = { ...passedScope };
16
+
17
+ // Detach every branch up-front, leaving a positional placeholder comment
18
+ // so reinsertion preserves source order. Mark each as a chain member so
19
+ // the parent's snapshot child-iteration skips the detached (non-active)
20
+ // branches instead of bringing their content to life. The active branch
21
+ // is re-inserted below and IS connected, so it processes normally.
22
+ chain.forEach(function(b) {
23
+ preserveConditionalComponentScopes(b.el, capturedComponentScope);
24
+ b.el.__stx_if_bound = true;
25
+ b.el.__stx_chain_member = true;
26
+ b.el.__stx_chain_active = false;
27
+ b.el.__stx_if_visible = state(false);
28
+ b.capturedElementScope = findElementScope(b.el);
29
+ b.placeholder = stxHost.anchor('stx-if-chain');
30
+ stxHost.insert(parent, b.placeholder, b.el);
31
+ b.el.removeAttribute(b.attr);
32
+ // A <template> branch (the wrapper convertSignalDirectivesToAttributes
33
+ // emits for a multi-child / text branch) is INERT \u2014 inserting the element
34
+ // renders nothing, its content lives in a document fragment. Clone that
35
+ // content ONCE into a stable node set we toggle in and out, exactly as
36
+ // bindIf/bindFor already do for template elements. An element branch is
37
+ // its own single node. Without this, a multi-element @else / @else-if
38
+ // branch rendered blank the moment the markup was well-formed enough to
39
+ // survive as a real <template> (the #1784 markup fix). See #1784.
40
+ b.isTemplate = b.el.tagName === 'TEMPLATE';
41
+ // A template branch renders CLONES, re-cloned on every show, and marks
42
+ // where they end -- the same contract the single-template :if got in
43
+ // #1955. Its content was cloned once here and that one node set was
44
+ // toggled in and out, which broke two ways as soon as the branch held a
45
+ // structural directive: a :for inside it replaces its own source element
46
+ // with a placeholder comment and renders rows as SIBLINGS, so hiding
47
+ // removed neither (the rows were never in this list, and the source node
48
+ // it did hold was already detached, so the parentNode guard skipped it)
49
+ // and both branches stayed on screen at once. Re-showing then re-inserted
50
+ // that source element, painting the literal text of its interpolations.
51
+ // An element branch still owns exactly the node it was bound to: whatever
52
+ // a directive inside it renders is inside that element.
53
+ // Snapshot the content BEFORE anything processes it, and clone each show
54
+ // from the snapshot rather than from the live template. A nested :for
55
+ // does not leave content pristine -- processing moves its row source out
56
+ // and the attributes it consumed (x-model, :id) do not come back -- so a
57
+ // second clone taken from the element would arrive already stripped, with
58
+ // no binding and no way to acquire one.
59
+ b.pristine = b.isTemplate ? stxHost.clone(b.el.content) : null;
60
+ b.nodes = b.isTemplate ? [] : [b.el];
61
+ b.endMarker = null;
62
+ stxHost.remove(b.el);
63
+ b.childrenProcessed = false;
64
+ });
65
+
66
+ // Per-branch evaluator. Evaluated inside the chain effect via with()
67
+ // (like evalLazy) so ONLY the signals the expression actually references
68
+ // register as dependencies \u2014 not every signal in scope. The old form
69
+ // (new Function(...Object.keys(scope)) called with ...Object.values of
70
+ // the unwrap proxy) read every scope value through the proxy to build the
71
+ // positional args, subscribing the effect to ALL scope signals, so it
72
+ // re-ran on every unrelated mutation (#1738). with() only triggers the
73
+ // proxy's get-trap for identifiers the expression names.
74
+ //
75
+ // Two passes, same as bindIf (#1733): proxy pass first (so bare-ref
76
+ // comparisons like count === 0 read the signal as a value), raw-scope
77
+ // retry second (so call-syntax like count() === 0 works \u2014 the proxy
78
+ // would have unwrapped count to a value, making count() throw).
79
+ function evalBranch(b) {
80
+ var expression = b.expr;
81
+ if (/^__[A-Z_]+__$/.test(expression.trim())) return expression;
82
+ var scope = { ...globalHelpers, ...capturedComponentScope, ...(b.capturedElementScope || {}) };
83
+ try {
84
+ var unwrapScope = createExpressionAutoUnwrapProxy(scope, expression);
85
+ // Compiled over the names the expression mentions (see __stxCompileScoped).
86
+ var fn = __stxCompileScoped(unwrapScope, [], 'return ' + expression + '');
87
+ return fn(...__stxArgs(fn, unwrapScope));
88
+ }
89
+ catch (e1) {
90
+ try {
91
+ var fn2 = __stxCompileScoped(scope, [], 'return ' + expression + '');
92
+ return fn2(...__stxArgs(fn2, scope));
93
+ }
94
+ catch (e2) {
95
+ if (!(e2 instanceof ReferenceError) && !(e2 instanceof TypeError)) console.warn('[STX] Expression error:', expression, e2);
96
+ return '';
97
+ }
98
+ }
99
+ }
100
+
101
+ var currentIdx = -1;
102
+
103
+ effect(function() {
104
+ // Evaluate EVERY branch's condition each run (not for-break) so the
105
+ // reactive tracker registers dependencies on exactly the signals the
106
+ // branch expressions reference \u2014 and on ALL of them, so a transition
107
+ // from a later branch back to an earlier one still re-fires. Then pick
108
+ // the first truthy branch (terminal x-else always matches).
109
+ //
110
+ // Pre-fix (#1738) this used a for-break picker, which only subscribed
111
+ // to signals up to the first truthy branch; to stay correct it then
112
+ // eagerly read EVERY signal in scope \u2014 a sledgehammer that re-ran this
113
+ // effect on every unrelated signal mutation in the scope (50+ no-op
114
+ // runs per page load on real apps). Evaluating all branches subscribes
115
+ // narrowly to just the branch signals instead.
116
+ var pickedIdx = -1;
117
+ for (var i = 0; i < chain.length; i++) {
118
+ var b = chain[i];
119
+ var matched = b.terminal ? true : !!evalBranch(b);
120
+ if (matched && pickedIdx === -1) pickedIdx = i;
121
+ }
122
+
123
+ console.log('[stx] bindIfChain pick:', pickedIdx, 'of', chain.length, '(', pickedIdx >= 0 ? chain[pickedIdx].attr : 'none', ') prev:', currentIdx);
124
+ if (__stxDevtoolsTracking) {
125
+ var __ifScope = null;
126
+ try { __ifScope = stxHost.scopeOf(head); } catch (e) { __ifScope = null; }
127
+ __stxDevtoolsRecordIf({
128
+ scopeId: __ifScope ? __ifScope.getAttribute('data-stx-scope') : null,
129
+ branches: chain.map(function(c) { return c.attr; }),
130
+ picked: pickedIdx,
131
+ pickedAttr: pickedIdx >= 0 ? chain[pickedIdx].attr : null,
132
+ prev: currentIdx
133
+ });
134
+ }
135
+ if (pickedIdx === currentIdx) return;
136
+
137
+ // Remove the previously-shown branch. Do NOT disposeSubtreeScopes here:
138
+ // a chain branch is a TOGGLE (re-shown when its condition matches again),
139
+ // not a permanent unmount, and a nested data-stx-scope inside it can't be
140
+ // recreated once deleted from window.stx._scopes (its setup IIFE ran
141
+ // once at page load). Deleting it broke re-show of nested scoped
142
+ // components under reactive conditionals (#1737). Permanent disposal is
143
+ // still handled by bindFor (item removal) and cleanupContainer (SPA nav).
144
+ if (currentIdx !== -1) {
145
+ var gone = chain[currentIdx];
146
+ gone.el.__stx_chain_active = false;
147
+ gone.el.__stx_if_visible.set(false);
148
+ // Unmount what the branch held, as a single :if does, before any of
149
+ // it leaves the page.
150
+ var leavingNodes = gone.nodes.filter(function (n) { return n.parentNode; });
151
+ if (gone.isTemplate && gone.endMarker && gone.endMarker.parentNode) {
152
+ leavingNodes = [];
153
+ for (var walk = gone.placeholder.nextSibling; walk && walk !== gone.endMarker; walk = walk.nextSibling) leavingNodes.push(walk);
154
+ }
155
+ suspendSubtreeScopes(leavingNodes);
156
+
157
+ if (gone.isTemplate) {
158
+ // Everything this branch rendered goes, not just the clones it owns:
159
+ // a nested :for or :if renders siblings of its own that no clone list
160
+ // contains. The marker bounds the range, so a sibling that belongs to
161
+ // a later branch or to ordinary markup is never touched.
162
+ if (gone.endMarker && gone.endMarker.parentNode) {
163
+ var doomed = gone.placeholder.nextSibling;
164
+ while (doomed && doomed !== gone.endMarker) {
165
+ var nextDoomed = doomed.nextSibling;
166
+ disposeSubtreeEffects(doomed);
167
+ stxHost.remove(doomed);
168
+ doomed = nextDoomed;
169
+ }
170
+ stxHost.remove(gone.endMarker);
171
+ gone.endMarker = null;
172
+ }
173
+ gone.nodes.forEach(function (n) {
174
+ if (!n.parentNode) return;
175
+ disposeSubtreeEffects(n);
176
+ stxHost.remove(n);
177
+ });
178
+ // The next show clones afresh and processes again, so these effects
179
+ // are finished with; leaving them bound only accumulates work (#1954).
180
+ if (typeof gone.el.__stx_chain_disposers === 'function') {
181
+ try { gone.el.__stx_chain_disposers(); }
182
+ catch (e) { /* a disposer of its own is not this branch's problem */ }
183
+ gone.el.__stx_chain_disposers = null;
184
+ }
185
+ gone.nodes = [];
186
+ gone.childrenProcessed = false;
187
+ }
188
+ else {
189
+ gone.nodes.forEach(function (n) {
190
+ if (!n.parentNode) return;
191
+ // Detached nodes are out of reach of a DOM walk, so a row removed
192
+ // while this branch is hidden could not dispose the effects it was
193
+ // processed with (#1954). Same registry the single-element :if uses.
194
+ var parentEl = n.parentNode;
195
+ if (!parentEl.__stx_detached_if) parentEl.__stx_detached_if = new Set();
196
+ parentEl.__stx_detached_if.add(n);
197
+ stxHost.remove(n);
198
+ });
199
+ }
200
+ }
201
+
202
+ // Insert + process the newly-picked branch.
203
+ if (pickedIdx !== -1) {
204
+ var pick = chain[pickedIdx];
205
+ pick.el.__stx_chain_active = true;
206
+ // Insert this branch's node(s) before the placeholder's next sibling.
207
+ // The anchor is captured once so the nodes stack in source order.
208
+ var anchor = pick.placeholder.nextSibling;
209
+ var pickHost = pick.placeholder.parentNode;
210
+ if (pick.isTemplate && pick.nodes.length === 0)
211
+ pick.nodes = Array.prototype.slice.call(stxHost.clone(pick.pristine).childNodes);
212
+ pick.nodes.forEach(function (n) {
213
+ if (pickHost.__stx_detached_if) pickHost.__stx_detached_if.delete(n);
214
+ stxHost.insert(pickHost, n, anchor);
215
+ });
216
+ pick.el.__stx_if_visible.set(true);
217
+ // Bound AFTER the clones, so hiding can remove whatever a structural
218
+ // directive inside the branch renders as their sibling.
219
+ if (pick.isTemplate) {
220
+ if (!pick.endMarker) pick.endMarker = stxHost.anchor('stx-if-chain-end');
221
+ stxHost.insert(pickHost, pick.endMarker, anchor);
222
+ }
223
+ pick.el.__stx_shown_at = performance.now();
224
+ // An element branch shown before keeps its bindings and its scopes;
225
+ // the components in it mount again (a template branch is cloned afresh
226
+ // and mounts through hydrateComponentScopes below).
227
+ if (pick.childrenProcessed) {
228
+ var shownNodes = pick.nodes;
229
+ queueMicrotask(function () {
230
+ if (pick.el.__stx_chain_active) peek(function () { resumeSubtreeScopes(shownNodes); });
231
+ });
232
+ }
233
+ if (!pick.childrenProcessed) {
234
+ pick.childrenProcessed = true;
235
+ // Hydrate before the outer scope walk can see the inserted branch.
236
+ // Chromium executes scripts cloned from template.content as soon as
237
+ // they are connected, so deferring this pass allowed the global walk
238
+ // to process projected slot expressions without the loop caller
239
+ // scope. peek() keeps this synchronous pass from subscribing child
240
+ // reads to the current chain effect.
241
+ // Tracked on the branch element: this runs inside the chain effect,
242
+ // where no tracker is active, so without a handle the effects of a
243
+ // branch picked after render survive their row's removal (#1954).
244
+ pick.el.__stx_chain_disposers = trackEffects(function () {
245
+ peek(function () {
246
+ var childScope = { ...globalHelpers, ...capturedComponentScope, ...(pick.capturedElementScope || {}) };
247
+ // Components compiled inside any branch of an if/else-if/else
248
+ // chain carry scoped setup scripts with them. Branch nodes are
249
+ // detached before those scripts can execute, so simply
250
+ // re-inserting the selected branch leaves component props,
251
+ // events, directives, and projected slot expressions inert.
252
+ // Hydrate those scopes before the normal subtree walk, matching
253
+ // the single-template :if and :for insertion paths.
254
+ var previouslyTrackedNodes = new Set();
255
+ pick.nodes.forEach(function (n) {
256
+ if (n && n.__stx_disposers) previouslyTrackedNodes.add(n);
257
+ });
258
+ hydrateComponentScopes(pick.nodes, childScope);
259
+ pick.nodes.forEach(function (n) {
260
+ if (n.nodeType !== 1) return; // whitespace/text between template children
261
+ // A scoped component receives its disposer in the outer scope
262
+ // walk immediately after processElement returns from binding
263
+ // this conditional. That first pass intentionally stops at
264
+ // :if, so a disposer does not mean its children were hydrated.
265
+ if (previouslyTrackedNodes.has(n) || !n.__stx_disposers)
266
+ processElement(n, childScope);
267
+ n.removeAttribute('x-cloak');
268
+ n.querySelectorAll('[x-cloak]').forEach(function (c) { c.removeAttribute('x-cloak'); });
269
+ });
270
+ resumeDetachedBranches();
271
+ });
272
+ });
273
+ }
274
+ }
275
+
276
+ currentIdx = pickedIdx;
277
+ });
278
+ }
279
+
280
+ // Shown branches whose deferred bind found them off the page: an enclosing
281
+ // :if, bound later in the same pass, hid them between the queue and the run.
282
+ // Their own condition has not changed, so their effect never runs again to
283
+ // retry; each resumes here when an enclosing branch puts it back.`;
@@ -0,0 +1,2 @@
1
+ /** Single-branch conditional binding for the generated client runtime. */
2
+ export declare const SIGNALS_IF_RUNTIME = " const detachedBranches = new Set();\n function resumeDetachedBranches() {\n if (!detachedBranches.size) return;\n Array.from(detachedBranches).forEach(function(resume) {\n if (!resume.el.isConnected) return;\n detachedBranches.delete(resume);\n resume();\n });\n }\n\n function bindIf(el, passedScope = componentScope, attrName = '@if') {\n // Guard: prevent double-binding on the same element\n if (el.__stx_if_bound) { console.log('[stx] bindIf SKIPPED (already bound):', el.getAttribute(attrName) || '(attr removed)', 'on', el.tagName); return; }\n el.__stx_if_bound = true;\n\n const expr = el.getAttribute(attrName);\n let parent = el.parentNode;\n\n // Guard: if element has no parent, it's detached - skip processing\n if (!parent) {\n console.warn('[STX] bindIf: element has no parent, skipping');\n return;\n }\n\n const placeholder = stxHost.anchor('stx-if');\n // Marks where this branch's rendered content ENDS (stacksjs/stx#1955).\n // Hiding used to remove only the cloned nodes, but a structural directive\n // directly inside the template renders its own output as siblings that are\n // not among those clones -- a <template :for> at the top level of a\n // <template :if> left every row on screen after the branch went false.\n // Only the template branch needs it; the single-element branch owns exactly\n // the node it was bound to.\n let endMarker = null;\n let isInserted = true;\n\n // Handle <template> elements specially - clone their content\n const isTemplate = el.tagName === 'TEMPLATE';\n if (!isTemplate) el.__stx_if_visible = state(true);\n const componentSetupSiblings = isTemplate ? [] : findConditionalComponentSetupSiblings(el);\n let currentNodes = isTemplate ? [] : [el, ...componentSetupSiblings];\n\n // Capture BOTH element scope AND passedScope NOW before anything changes\n // passedScope may contain @for iteration variables or parent component signals\n const capturedElementScope = findElementScope(el);\n const capturedComponentScope = { ...passedScope };\n\n preserveConditionalComponentScopes(el, capturedComponentScope);\n stxHost.insert(parent, placeholder, el);\n el.removeAttribute(attrName);\n\n if (isTemplate) {\n // Nothing is cloned until the condition holds: the effect below clones\n // template.content on the first true and binds it then. Every branch\n // used to be cloned and inserted up front and the false ones removed, so\n // a false branch still built its elements - in WebKit a <video> or\n // <audio> sets up a media player as it is created.\n isInserted = false;\n stxHost.remove(el); // Remove the template element itself\n }\n\n // Helper to evaluate with captured scope (auto-unwraps signals).\n // A with-scope resolves only identifiers the expression actually references,\n // so the conditional subscribes narrowly instead of reading every signal\n // in a component scope. That broad subscription made an unrelated ref\n // update re-enter structural removal while the real condition was already\n // removing the same subtree. First try the auto-unwrap proxy (so a bare\n // comparison like count > 5 reads the signal value), then retry with the\n // raw scope so call syntax like count() === 0 still works (#1733).\n const evalExpr = (expression) => {\n // Skip placeholder expressions like __TITLE__ (build-time placeholders)\n if (/^__[A-Z_]+__$/.test(expression.trim())) {\n return expression;\n }\n try {\n const scope = { ...globalHelpers, ...capturedComponentScope, ...(capturedElementScope || {}) };\n const unwrapScope = createExpressionAutoUnwrapProxy(scope, expression);\n const fn = __stxCompileScoped(unwrapScope, [], 'return ' + expression + '');\n return fn(...__stxArgs(fn, unwrapScope));\n }\ncatch (e1) {\n try {\n // Retry without the unwrap proxy so call-syntax (signal()) works.\n const scope2 = { ...globalHelpers, ...capturedComponentScope, ...(capturedElementScope || {}) };\n const fn2 = __stxCompileScoped(scope2, [], 'return ' + expression + '');\n return fn2(...__stxArgs(fn2, scope2));\n }\ncatch (e2) {\n if (!(e2 instanceof ReferenceError) && !(e2 instanceof TypeError)) console.warn('[STX] Expression error:', expression, e2);\n return '';\n }\n }\n };\n\n // Track if children have been processed\n let childrenProcessed = false;\n\n // Helper to process children with captured scope\n const processChildrenWithScope = () => {\n // Build the combined scope for children - no need to modify global componentScope\n // Just pass the scope explicitly to processElement\n const childScope = { ...globalHelpers, ...capturedComponentScope, ...(capturedElementScope || {}) };\n\n\n Array.from(el.childNodes).forEach(child => processElement(child, childScope));\n\n childrenProcessed = true;\n };\n\n // A <template :if> inserts clones of template.content rather than the\n // template element itself. Those clones still need the normal directive\n // and interpolation pass. Previously the initially-visible branch was\n // inserted and left inert, so bindings such as :text and {{ expression }}\n // leaked into the rendered UI until the condition toggled.\n const processTemplateNodes = (nodes) => {\n const childScope = { ...globalHelpers, ...capturedComponentScope, ...(capturedElementScope || {}) };\n // Components compiled inside a <template :if> carry setup scripts in the\n // template content. Browser-cloned scripts are inert, so register their\n // scopes and forwarded props before walking the inserted branch. This is\n // the same component hydration path used by <template :for>.\n hydrateComponentScopes(nodes, childScope);\n nodes.forEach(node => {\n if (!node.__stx_disposers && node.tagName !== 'SCRIPT')\n node.__stx_effect_disposers = trackEffects(function() { processElement(node, childScope); });\n if (node.nodeType === 1) {\n node.removeAttribute('x-cloak');\n node.querySelectorAll('[x-cloak]').forEach(c => c.removeAttribute('x-cloak'));\n }\n });\n resumeDetachedBranches();\n };\n\n // Evaluate the :if expression \u2014 use direct signal read for simple refs,\n // falling back to evalExpr for complex expressions\n const fullScope = { ...globalHelpers, ...capturedComponentScope, ...(capturedElementScope || {}) };\n const directSignal = fullScope[expr];\n\n effect(() => {\n parent = followPlaceholder(placeholder, parent, currentNodes);\n var value;\n if (directSignal && (directSignal._isSignal || directSignal._isDerived)) {\n value = directSignal();\n console.log('[stx] bindIf effect (direct):', expr, '\u2192', value, 'isInserted:', isInserted);\n } else {\n value = evalExpr(expr);\n }\n\n if (isTemplate) {\n if (value && !isInserted) {\n // Re-insert cloned content\n currentNodes = Array.from(el.content.childNodes).map(n => stxHost.clone(n));\n const insertionAnchor = placeholder.nextSibling;\n currentNodes.forEach(node => stxHost.insert(parent, node, insertionAnchor));\n // Bound AFTER the clones, so hiding can remove whatever a nested\n // structural directive rendered as their sibling (#1955).\n if (!endMarker) endMarker = stxHost.anchor('stx-if-end');\n stxHost.insert(parent, endMarker, insertionAnchor);\n processTemplateNodes(currentNodes);\n childrenProcessed = true;\n // Stamp insertion time for click propagation guard\n currentNodes.forEach(function(n) { if (n.nodeType === 1) n.__stx_shown_at = performance.now(); });\n isInserted = true;\n }\nelse if (!value && isInserted) {\n // Remove all current nodes. Do NOT disposeSubtreeScopes \u2014 :if is a\n // toggle, not a permanent unmount; see the single-element branch\n // below and #1737. Effects are disposed, though: these clones are never\n // reused, and a re-show clones afresh, so leaving them bound only\n // accumulates work (#1954).\n //\n // Everything between the placeholder and the end marker goes, not\n // just the clones: a nested :for or :if renders siblings of its own\n // that no clone list contains (#1955).\n // Only walk the range when THIS binding inserted the content and\n // left its marker. Without that guard the walk ran to the end of the\n // parent and took a sibling <template :if> with it -- the initial\n // server-rendered state has no marker to stop at.\n if (endMarker && endMarker.parentNode === parent) {\n var leaving = [];\n for (var cursor = placeholder.nextSibling; cursor && cursor !== endMarker; cursor = cursor.nextSibling) leaving.push(cursor);\n suspendSubtreeScopes(leaving);\n var doomed = placeholder.nextSibling;\n while (doomed && doomed !== endMarker) {\n var nextDoomed = doomed.nextSibling;\n disposeSubtreeEffects(doomed);\n stxHost.remove(doomed);\n doomed = nextDoomed;\n }\n stxHost.remove(endMarker);\n }\n suspendSubtreeScopes(currentNodes.filter(node => node.parentNode));\n currentNodes.forEach(node => { disposeSubtreeEffects(node); stxHost.remove(node); });\n currentNodes = [];\n isInserted = false;\n childrenProcessed = false;\n }\n else if (value && isInserted && !childrenProcessed) {\n // Initial template content is cloned before the effect runs. Process\n // it after the condition is confirmed so hidden branches stay inert.\n // Keep hydration synchronous so the outer scope walk cannot bind\n // caller-owned slot expressions first, while peek() prevents child\n // reads from subscribing to this conditional effect.\n childrenProcessed = true;\n peek(function() {\n if (isInserted) processTemplateNodes(currentNodes);\n });\n }\n }\nelse {\n // Native hosts keep a view hierarchy rather than a DOM subtree. Route\n // the conditional through the same visibility contract as :show so a\n // false branch is hidden in the first render and in every loop row;\n // the structural remove/insert below still preserves browser and\n // native lifecycle behaviour when the branch changes.\n if (stxHost.isNative) stxHost.setVisible(el, !!value);\n if (value && !isInserted) {\n console.log('[stx] bindIf INSERTING element for :if=' + expr);\n const insertionAnchor = placeholder.nextSibling;\n currentNodes.forEach(node => stxHost.insert(parent, node, insertionAnchor));\n if (parent && parent.__stx_detached_if) currentNodes.forEach(node => parent.__stx_detached_if.delete(node));\n el.__stx_if_visible.set(true);\n el.__stx_shown_at = performance.now();\n isInserted = true;\n // A previously hydrated parent skips hydrateShownBranch on re-show.\n // Its children may have become visible while it was detached, so\n // resume their pending bindings now that the subtree is connected.\n peek(resumeDetachedBranches);\n // Shown before, so the components in it mounted and were suspended\n // when it hid. They mount again now -- in a microtask, the same\n // moment their first mount ran, and only if still shown by then.\n if (childrenProcessed) {\n queueMicrotask(function() {\n if (isInserted) peek(function() { resumeSubtreeScopes(currentNodes); });\n });\n }\n }\nelse if (!value && isInserted) {\n console.log('[stx] bindIf REMOVING element for :if=' + expr, 'el.isConnected:', el.isConnected, 'parent:', parent.tagName);\n el.__stx_if_visible.set(false);\n // Unmounted, not disposed: the components in it release what they\n // hold while their markup is still on the page, and keep their scopes.\n suspendSubtreeScopes(currentNodes);\n // Do NOT disposeSubtreeScopes here. :if is a TOGGLE \u2014 the element is\n // re-shown when the condition flips back \u2014 not a permanent unmount.\n // A nested data-stx-scope inside this subtree is created once by its\n // setup IIFE at page load and stored in window.stx._scopes; deleting\n // it on hide left re-show unable to recreate it, so nested scoped\n // components under reactive conditionals rendered all branches at\n // once (#1737). Permanent disposal stays in bindFor (item removal)\n // and cleanupContainer (SPA navigation). The double-bind guards make\n // re-show idempotent, so toggling doesn't leak.\n currentNodes.forEach(node => stxHost.remove(node));\n // Detached nodes are out of reach of a DOM walk, so an ancestor row or\n // branch removed while this is hidden could not dispose their effects\n // (#1954). Record them on the parent that keeps the placeholder.\n if (parent) {\n if (!parent.__stx_detached_if) parent.__stx_detached_if = new Set();\n currentNodes.forEach(node => parent.__stx_detached_if.add(node));\n }\n isInserted = false;\n console.log('[stx] bindIf REMOVED, el.isConnected:', el.isConnected);\n }\n // Process the entire subtree when element is visible and not yet processed.\n // peek() keeps child effects from subscribing to this bindIf's tracked\n // signals. Use capturedComponentScope (not global componentScope) so\n // iteration variables from an enclosing for-loop remain in scope.\n // Process the element itself, not just children, so sibling directives\n // on the same element (e.g. text binding alongside if) fire too. The if\n // attribute was already removed, so no recursion.\n //\n // Synchronously when the branch is on the page, as the template and\n // if/else-chain branches already are. This pass used to wait for a\n // timer, so every :if (and each :for inside one) filled in a frame\n // after the rest of the page was bound: a screen opened from a tab bar\n // showed its sections arriving one after another.\n if (value && isInserted && !childrenProcessed) {\n childrenProcessed = true;\n // Until this pass runs, the shown subtree still holds literal {{ }}.\n // Flag it so the hydration audit doesn't report those as a binding\n // miss when the pass is deferred (#1773).\n el.__stx_if_pending = true;\n var hydrateShownBranch = function() {\n // Removed with its row, or hidden again, before this ran. Hydrating\n // a detached element now creates effects nothing will dispose\n // (#1954). Leave it unprocessed so the next show schedules the pass.\n if (!el.isConnected) {\n childrenProcessed = false;\n el.__stx_if_pending = false;\n // Hidden by an ancestor rather than by this condition (a page :if\n // around a component whose own :if queued this pass), the branch\n // comes back without this effect running, and a component shown\n // again kept its :for rows as raw markup.\n var resume = function() {\n if (!isInserted || childrenProcessed) return;\n childrenProcessed = true;\n el.__stx_if_pending = true;\n peek(hydrateShownBranch);\n };\n resume.el = el;\n detachedBranches.add(resume);\n return;\n }\n var childScope = { ...globalHelpers, ...capturedComponentScope, ...(capturedElementScope || {}) };\n // A false single-element conditional is detached before the\n // DOMContentLoaded component-scope pass. When it becomes visible,\n // hydrate any component roots in the restored subtree first so\n // projected slot bindings and component-local directives receive\n // the same lifecycle as components inserted by template :if.\n var wasTrackedBeforeConditionalHydration = !!el.__stx_disposers;\n hydrateComponentScopes(currentNodes, childScope);\n // Tracked on its own property so an ancestor row or branch removal\n // reaches these effects too (#1954). This runs after the enclosing\n // tracker has closed, so nothing else would collect them.\n if (wasTrackedBeforeConditionalHydration || !el.__stx_disposers)\n el.__stx_if_disposers = trackEffects(function() { processElement(el, childScope); });\n // Remove x-cloak from the inserted subtree \u2014 the initial\n // cloak removal (after processElement on the root) already\n // ran before this deferred processing, so newly-inserted\n // :if children still have x-cloak and stay hidden.\n el.removeAttribute('x-cloak');\n el.querySelectorAll('[x-cloak]').forEach(function(c) { c.removeAttribute('x-cloak'); });\n // Deferred bind complete \u2014 the audit may inspect this subtree now.\n el.__stx_if_pending = false;\n // Branches inside this one that were hidden with it can bind now.\n resumeDetachedBranches();\n };\n // In a microtask, not inside this effect's own run: child effects\n // created while it is running saw the data mid-change (a screen\n // swapping workouts) and recorded expressions that had never\n // evaluated. A microtask still runs before the browser paints, so\n // the branch is bound in the first frame all the same. A branch\n // shown while detached (inside content not on the page yet) waits a\n // macrotask, when it has been placed.\n if (el.isConnected) {\n // A native host sends the insertion as soon as its current\n // mutation turn ends. Hydrating in a later microtask would put the\n // handler registration in a second batch, leaving a same-turn tap\n // with the source expression instead of a native handler id.\n if (stxHost.isNative) peek(hydrateShownBranch);\n else queueMicrotask(function() { peek(hydrateShownBranch); });\n }\n else setTimeout(hydrateShownBranch, 0);\n }\n }\n });\n }\n";