@stacksjs/stx 0.2.122 → 0.2.124

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.
package/dist/signals.js CHANGED
@@ -1970,7 +1970,10 @@ catch (e) {
1970
1970
  }
1971
1971
  }
1972
1972
  if (el.nodeType === Node.TEXT_NODE) {
1973
- const text = el.textContent;
1973
+ // DOM textContent is specified as a string, but lightweight DOM
1974
+ // implementations and user-created nodes can retain a numeric value
1975
+ // assigned by a binding. Normalize before interpolation detection.
1976
+ const text = el.textContent == null ? '' : String(el.textContent);
1974
1977
  if (text && text.includes('{{')) {
1975
1978
  const parts = text.split(/(\\{\\{[\\s\\S]+?\\}\\})/g);
1976
1979
  if (parts.length > 1) {
@@ -2880,13 +2883,24 @@ else if (typeof value === 'string') {
2880
2883
  var __forComponentSetupFactories = new Map();
2881
2884
 
2882
2885
  function forEachGroupElement(nodes, callback) {
2883
- nodes.forEach(function(node) {
2886
+ function visit(node, insideTemplateContent) {
2884
2887
  if (!node || node.nodeType !== Node.ELEMENT_NODE) return;
2885
- callback(node);
2886
- if (node.querySelectorAll) {
2887
- node.querySelectorAll('*').forEach(function(child) { callback(child); });
2888
- }
2889
- });
2888
+ callback(node, insideTemplateContent);
2889
+
2890
+ // HTMLTemplateElement children live in template.content, outside the
2891
+ // element's ordinary descendant tree. Component roots and setup scripts
2892
+ // wrapped by caller-owned :if/:for directives must still be discoverable
2893
+ // for scope remapping before those templates are cloned.
2894
+ var entersTemplateContent = node.tagName === 'TEMPLATE' && node.content;
2895
+ var childRoot = entersTemplateContent
2896
+ ? node.content
2897
+ : node;
2898
+ Array.from(childRoot.childNodes || []).forEach(function(child) {
2899
+ visit(child, insideTemplateContent || entersTemplateContent);
2900
+ });
2901
+ }
2902
+
2903
+ nodes.forEach(function(node) { visit(node, false); });
2890
2904
  }
2891
2905
 
2892
2906
  // A signal component expanded inside <template :for> carries a compiled
@@ -2934,7 +2948,11 @@ else if (typeof value === 'string') {
2934
2948
  function hydrateComponentScopes(nodes, callerScope) {
2935
2949
  var roots = [];
2936
2950
  var scripts = [];
2937
- forEachGroupElement(nodes, function(node) {
2951
+ forEachGroupElement(nodes, function(node, insideTemplateContent) {
2952
+ // A template's content is inert source material. Remapping must traverse
2953
+ // it, but setup and event hydration belong to the live clones inserted by
2954
+ // bindIf/bindFor, where the correct iteration scope is available.
2955
+ if (insideTemplateContent) return;
2938
2956
  if (node.hasAttribute && node.hasAttribute('data-stx-scope')) roots.push(node);
2939
2957
  if (node.tagName === 'SCRIPT' && node.hasAttribute('data-stx-scoped')) scripts.push(node);
2940
2958
  });