@percy/dom 1.30.7-beta.1 → 1.30.7-beta.3

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 +18 -9
  2. package/package.json +2 -2
package/dist/bundle.js CHANGED
@@ -441,7 +441,7 @@
441
441
  base64Index += ';base64,'.length;
442
442
  return src.substring(base64Index);
443
443
  }
444
- function serializeBase64(node, resources) {
444
+ function serializeBase64(node, resources, cache) {
445
445
  let src = node.src;
446
446
  let isHrefUsed = false;
447
447
 
@@ -455,14 +455,22 @@
455
455
  let base64String = getBase64Substring(src.toString());
456
456
  // skip if src is not base64
457
457
  if (base64String == null) return;
458
-
459
- // create a resource from the serialized data url
460
- let resource = resourceFromText(uid(), mimetype, base64String);
461
- resources.add(resource);
458
+ if (!cache.has(base64String)) {
459
+ // create a resource from the serialized data url
460
+ let resource = resourceFromText(uid(), mimetype, base64String);
461
+ resources.add(resource);
462
+ cache.set(base64String, resource.url);
463
+ }
462
464
  if (isHrefUsed === true) {
463
- node.href.baseVal = resource.url;
465
+ node.href.baseVal = cache.get(base64String);
464
466
  } else {
465
- node.src = resource.url;
467
+ // we use data-percy-serialized-attribute-src here instead of `src`.
468
+ // As soon as src is used the browser will try to load the resource,
469
+ // thus making a network call which would fail as this is a
470
+ // dynamic cached resource and not a resource that backend can serve.
471
+ // we later post converting domtree to html replace this with src
472
+ node.removeAttribute('src');
473
+ node.setAttribute('data-percy-serialized-attribute-src', cache.get(base64String));
466
474
  }
467
475
  }
468
476
 
@@ -482,7 +490,8 @@
482
490
  let {
483
491
  dom,
484
492
  disableShadowDOM,
485
- resources
493
+ resources,
494
+ cache
486
495
  } = ctx;
487
496
  // clones shadow DOM and light DOM for a given node
488
497
  let cloneNode = (node, parent) => {
@@ -502,7 +511,7 @@
502
511
 
503
512
  // We apply any element transformations here to avoid another treeWalk
504
513
  applyElementTransformations(clone);
505
- serializeBase64(clone, resources);
514
+ serializeBase64(clone, resources, cache);
506
515
  parent.appendChild(clone);
507
516
 
508
517
  // shallow clone should not contain children
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@percy/dom",
3
- "version": "1.30.7-beta.1",
3
+ "version": "1.30.7-beta.3",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -35,5 +35,5 @@
35
35
  "devDependencies": {
36
36
  "interactor.js": "^2.0.0-beta.10"
37
37
  },
38
- "gitHead": "b9a15ba7853ff350b7d7b7c3364700e70ca66643"
38
+ "gitHead": "06141a5d15278e9cb14550a96c745336acf8bafd"
39
39
  }