@percy/dom 1.30.9 → 1.30.10-beta.0

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 (2) hide show
  1. package/dist/bundle.js +27 -1
  2. package/package.json +3 -3
package/dist/bundle.js CHANGED
@@ -498,6 +498,29 @@
498
498
  */
499
499
 
500
500
  const ignoreTags = ['NOSCRIPT'];
501
+
502
+ /**
503
+ * if a custom element has attribute callback then cloneNode calls a callback that can
504
+ * increase CPU load or some other change.
505
+ * So we want to make sure that it is not called when doing serialization.
506
+ */
507
+ function cloneElementWithoutLifecycle(element) {
508
+ if (!element.attributeChangedCallback || !element.tagName.includes('-')) {
509
+ return element.cloneNode(); // Standard clone for non-custom elements
510
+ }
511
+ const cloned = document.createElement('data-percy-custom-element-' + element.tagName);
512
+
513
+ // Clone attributes without triggering attributeChangedCallback
514
+ for (const attr of element.attributes) {
515
+ // handle src separately
516
+ if (attr.name.toLowerCase() === 'src') {
517
+ cloned.setAttribute('data-percy-serialized-attribute-src', attr.value);
518
+ } else {
519
+ cloned.setAttribute(attr.name, attr.value);
520
+ }
521
+ }
522
+ return cloned;
523
+ }
501
524
  function cloneNodeAndShadow(ctx) {
502
525
  let {
503
526
  dom,
@@ -520,7 +543,7 @@
520
543
 
521
544
  // mark the node before cloning
522
545
  markElement(node, disableShadowDOM);
523
- let clone = node.cloneNode();
546
+ let clone = cloneElementWithoutLifecycle(node);
524
547
 
525
548
  // Handle <style> tag specifically for media queries
526
549
  if (node.nodeName === 'STYLE' && !enableJavaScript) {
@@ -549,6 +572,7 @@
549
572
 
550
573
  // shallow clone should not contain children
551
574
  if (clone.children) {
575
+ /* istanbul ignore next */
552
576
  Array.from(clone.children).forEach(child => clone.removeChild(child));
553
577
  }
554
578
 
@@ -640,6 +664,8 @@
640
664
  let html = getOuterHTML(ctx.clone.documentElement, {
641
665
  shadowRootElements: ctx.shadowRootElements
642
666
  });
667
+ // this is replacing serialized data tag with real tag
668
+ html = html.replace(/(<\/?)data-percy-custom-element-/g, '$1');
643
669
  // replace serialized data attributes with real attributes
644
670
  html = html.replace(/ data-percy-serialized-attribute-(\w+?)=/ig, ' $1=');
645
671
  // include the doctype with the html string
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@percy/dom",
3
- "version": "1.30.9",
3
+ "version": "1.30.10-beta.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -9,7 +9,7 @@
9
9
  },
10
10
  "publishConfig": {
11
11
  "access": "public",
12
- "tag": "latest"
12
+ "tag": "beta"
13
13
  },
14
14
  "main": "dist/bundle.js",
15
15
  "browser": "dist/bundle.js",
@@ -35,5 +35,5 @@
35
35
  "devDependencies": {
36
36
  "interactor.js": "^2.0.0-beta.10"
37
37
  },
38
- "gitHead": "bb6e994542280596015cb57f884fe3359be01c22"
38
+ "gitHead": "90bd2a86423622348069b7029942dc37d7c15c50"
39
39
  }