@miaskiewicz/turbo-dom 0.1.41 → 0.1.43

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.41",
3
+ "version": "0.1.43",
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",
@@ -1410,11 +1410,12 @@ export class Document extends Node {
1410
1410
  let node;
1411
1411
  switch (buf.nodeType(idx)) {
1412
1412
  case ELEMENT_NODE: {
1413
- node = new Element(this, buf.tagName(idx), buf.ns(idx));
1413
+ const tag = buf.tagName(idx); // read once (was read twice — ctor + template check)
1414
+ node = new Element(this, tag, buf.ns(idx));
1414
1415
  node.__idx = idx;
1415
1416
  node.__attrIdx = idx; // attrs lazy (constructor left __attrs undefined)
1416
1417
  // template content fragment: a child node typed 11 named "content"
1417
- if (buf.tagName(idx) === 'template') {
1418
+ if (tag === 'template') {
1418
1419
  for (let c = buf.firstChild(idx); c !== -1; c = buf.nextSib(c)) {
1419
1420
  if (buf.nodeType(c) === DOCUMENT_FRAGMENT_NODE && buf.tagName(c) === 'content') {
1420
1421
  node.content = this.__nodeAt(c);
@@ -238,8 +238,13 @@ export class EventTarget {
238
238
  event.target = retarget(target, node);
239
239
  if (relatedTarget != null) event.relatedTarget = retarget(relatedTarget, node);
240
240
  }
241
- // snapshot — listeners added during dispatch don't fire this round
242
- for (const l of list.slice()) {
241
+ // snapshot — listeners added during dispatch don't fire this round. Skip the
242
+ // slice alloc for the single-listener case (common React-delegated one): a
243
+ // 1-element, length-captured iteration can't be disturbed by an add/remove in
244
+ // that one call. Multi-listener keeps the slice (concurrent-mutation guard).
245
+ const snap = list.length === 1 ? list : list.slice();
246
+ for (let k = 0, len = snap.length; k < len; k++) {
247
+ const l = snap[k];
243
248
  if (phase === PHASE_CAPTURING && !l.capture) continue;
244
249
  if (phase === PHASE_BUBBLING && l.capture) continue;
245
250
  if (l.once) {