@miaskiewicz/turbo-dom 0.1.47 → 0.1.48

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@miaskiewicz/turbo-dom",
3
- "version": "0.1.47",
3
+ "version": "0.1.48",
4
4
  "description": "Faster, more spec-correct DOM for test runners — native html5ever (Rust/WASM) parser + lazy copy-on-write DOM. A drop-in-style alternative to jsdom/happy-dom for vitest & jest.",
5
5
  "license": "MIT",
6
6
  "main": "index.js",
@@ -630,7 +630,15 @@ export class Element extends Node {
630
630
  get children() {
631
631
  if (this.__childrenList) return this.__childrenList;
632
632
  const self = this;
633
- return (this.__childrenList = liveHTMLCollection(() => self.__children().filter((n) => n.nodeType === ELEMENT_NODE)));
633
+ // version-cache the element-filtered array (like cachedQSA): re-filter only when
634
+ // the DOM version changes, not on every children[i]/length access. Live —
635
+ // every mutation bumps Document.__version, invalidating the cache.
636
+ return (this.__childrenList = liveHTMLCollection(() => {
637
+ const d = self.ownerDocument, v = d ? (d.__version || 0) : 0;
638
+ if (self.__childrenArr !== undefined && self.__childrenArrV === v) return self.__childrenArr;
639
+ self.__childrenArrV = v;
640
+ return (self.__childrenArr = self.__children().filter((n) => n.nodeType === ELEMENT_NODE));
641
+ }));
634
642
  }
635
643
  get childElementCount() { return this.__children().filter((n) => n.nodeType === ELEMENT_NODE).length; }
636
644
  get firstElementChild() { return this.__children().find((n) => n.nodeType === ELEMENT_NODE) ?? null; }