@stacksjs/stx 0.2.172 → 0.2.174

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.
@@ -20,7 +20,50 @@ const BOOLEAN_ATTRS = new Set([
20
20
  "playsinline",
21
21
  "reversed",
22
22
  "selected"
23
+ ]), VOID_TAGS = new Set([
24
+ "area",
25
+ "base",
26
+ "br",
27
+ "col",
28
+ "embed",
29
+ "hr",
30
+ "img",
31
+ "input",
32
+ "link",
33
+ "meta",
34
+ "param",
35
+ "source",
36
+ "track",
37
+ "wbr"
23
38
  ]);
39
+ function reactiveLoopRanges(template) {
40
+ const ranges = [], openingTag = /<([a-zA-Z][a-zA-Z0-9-]*)\b((?:[^>"']|"[^"]*"|'[^']*')*)\s*\/?>/g;
41
+ let match;
42
+ while ((match = openingTag.exec(template)) !== null) {
43
+ const attributes = match[2] || "";
44
+ if (!/(?:^|\s)(?::for|x-for|v-for|@for)\s*=/.test(attributes))
45
+ continue;
46
+ const start = match.index, openingEnd = start + match[0].length, tagName = match[1].toLowerCase();
47
+ if (match[0].endsWith("/>") || VOID_TAGS.has(tagName)) {
48
+ ranges.push([start, openingEnd]);
49
+ continue;
50
+ }
51
+ const escapedTag = tagName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), sameTag = new RegExp(`<\\/?${escapedTag}\\b(?:[^>"']|"[^"]*"|'[^']*')*>`, "gi");
52
+ sameTag.lastIndex = openingEnd;
53
+ let depth = 1, closingEnd = openingEnd, nested;
54
+ while ((nested = sameTag.exec(template)) !== null)
55
+ if (nested[0].startsWith("</")) {
56
+ depth--;
57
+ if (depth === 0) {
58
+ closingEnd = nested.index + nested[0].length;
59
+ break;
60
+ }
61
+ } else if (!nested[0].endsWith("/>"))
62
+ depth++;
63
+ ranges.push([start, closingEnd]);
64
+ }
65
+ return ranges;
66
+ }
24
67
  function resolveClassBinding(value) {
25
68
  if (typeof value === "string")
26
69
  return value;
@@ -38,10 +81,11 @@ export function processServerBindings(template, context) {
38
81
  let match;
39
82
  while ((match = scriptStyleRegex.exec(template)) !== null)
40
83
  protectedRanges.push([match.index, match.index + match[0].length]);
84
+ protectedRanges.push(...reactiveLoopRanges(template));
41
85
  function isProtected(pos) {
42
86
  return protectedRanges.some(([start, end]) => pos >= start && pos < end);
43
87
  }
44
- const tagRegex = /<([a-zA-Z][a-zA-Z0-9-]*)((?:\s+(?:[^>"']|"[^"]*"|'[^']*'))*)\s*\/?>/g, replacements = [];
88
+ const tagRegex = /<([a-zA-Z][a-zA-Z0-9-]*)\b((?:[^>"']|"[^"]*"|'[^']*')*)\s*\/?>/g, replacements = [];
45
89
  while ((match = tagRegex.exec(output)) !== null) {
46
90
  if (isProtected(match.index))
47
91
  continue;
package/dist/signals.js CHANGED
@@ -1175,9 +1175,15 @@ else if (immediate) {
1175
1175
  // ==========================================================================
1176
1176
 
1177
1177
  function useRef(name) {
1178
+ // A ref belongs to the component scope that created it. Capturing that
1179
+ // owner now is essential: componentScope is a mutable compatibility
1180
+ // fallback and changes while the rest of the page hydrates. Reading it
1181
+ // from the getter made an early component resolve refs from whichever
1182
+ // component happened to hydrate last.
1183
+ var ownerScope = currentLifecycleScope() || componentScope;
1178
1184
  return {
1179
1185
  get current() {
1180
- return componentScope.$refs ? componentScope.$refs[name] : null;
1186
+ return ownerScope.$refs ? ownerScope.$refs[name] : null;
1181
1187
  },
1182
1188
  get value() {
1183
1189
  return this.current;