@percy/dom 1.32.8-beta.3 → 1.32.8-beta.4

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 +21 -17
  2. package/package.json +2 -2
package/dist/bundle.js CHANGED
@@ -364,12 +364,7 @@
364
364
  // Custom elements with ElementInternals or closed shadow roots also get
365
365
  // stamped so the post-clone state-fallback can locate their clones.
366
366
  let tagName = (_domElement$tagName = domElement.tagName) === null || _domElement$tagName === void 0 ? void 0 : _domElement$tagName.toLowerCase();
367
- // Stylesheet <link>s are stamped so the pseudo-class serializer can locate
368
- // the sheet's clone element and anchor its rewritten interactive-state rules
369
- // immediately after it — preserving the sheet's original cascade position
370
- // instead of appending at the end of <head> (PER-10077).
371
- let isStylesheetLink = tagName === 'link' && /(^|\s)stylesheet(\s|$)/i.test(domElement.getAttribute('rel') || '');
372
- if (['input', 'textarea', 'select', 'iframe', 'canvas', 'video', 'style', 'dialog'].includes(tagName) || isStylesheetLink || isCustomElement(domElement)) {
367
+ if (['input', 'textarea', 'select', 'iframe', 'canvas', 'video', 'style', 'dialog'].includes(tagName) || isCustomElement(domElement)) {
373
368
  if (!domElement.getAttribute('data-percy-element-id')) {
374
369
  domElement.setAttribute('data-percy-element-id', uid());
375
370
  }
@@ -437,7 +432,8 @@
437
432
  resources,
438
433
  cache,
439
434
  warnings,
440
- ignoreStyleSheetSerializationErrors
435
+ ignoreStyleSheetSerializationErrors,
436
+ styleSheetClones
441
437
  } = ctx;
442
438
  // in-memory CSSOM into their respective DOM nodes.
443
439
  let styleSheets = null;
@@ -466,6 +462,7 @@
466
462
  style.textContent = Array.from(styleSheet.cssRules).map(cssRule => cssRule.cssText).join('\n');
467
463
  cloneOwnerNode.parentNode.insertBefore(style, cloneOwnerNode.nextSibling);
468
464
  cloneOwnerNode.remove();
465
+ styleSheetClones === null || styleSheetClones === void 0 || styleSheetClones.set(styleSheet.ownerNode, style);
469
466
  } catch (err) {
470
467
  handleErrors(err, 'Error serializing stylesheet: ', cloneOwnerNode, {
471
468
  styleId: styleId
@@ -1190,11 +1187,11 @@
1190
1187
  // nosemgrep: javascript.browser.security.insecure-document-method.insecure-document-method
1191
1188
  styleElement.textContent = rewrittenRules.join('\n');
1192
1189
  if (owner === null) {
1193
- injectAtSheetPosition(ctx.clone, sheet, styleElement, ctx.clone.head || ctx.clone.querySelector('head'));
1190
+ injectAtSheetPosition(ctx, ctx.clone, sheet, styleElement, ctx.clone.head || ctx.clone.querySelector('head'));
1194
1191
  } else {
1195
1192
  const cloneHost = cloneByPercyId.get(owner.getAttribute('data-percy-element-id'));
1196
1193
  if (cloneHost && cloneHost.shadowRoot) {
1197
- injectAtSheetPosition(cloneHost.shadowRoot, sheet, styleElement, cloneHost.shadowRoot);
1194
+ injectAtSheetPosition(ctx, cloneHost.shadowRoot, sheet, styleElement, cloneHost.shadowRoot);
1198
1195
  }
1199
1196
  }
1200
1197
  }
@@ -1203,13 +1200,15 @@
1203
1200
  // Insert an interactive-states <style> immediately AFTER its source sheet's
1204
1201
  // clone element so the copy keeps the sheet's original source-order rank —
1205
1202
  // later stylesheets still win equal-specificity ties, exactly as on the live
1206
- // page (PER-10077). The sheet's ownerNode (<style> / <link rel=stylesheet>) is
1207
- // stamped with a data-percy-element-id, which serialize-cssom preserves on any
1208
- // node it rebuilds in place. Falls back to appending at the scope's end when
1209
- // the sheet has no locatable clone anchor.
1210
- function injectAtSheetPosition(scopeRoot, sheet, styleElement, fallbackTarget) {
1211
- const anchorId = sheet.ownerNode.getAttribute('data-percy-element-id');
1212
- const anchor = anchorId ? scopeRoot.querySelector(`[data-percy-element-id="${anchorId}"]`) : null;
1203
+ // page (PER-10077).
1204
+ function injectAtSheetPosition(ctx, scopeRoot, sheet, styleElement, fallbackTarget) {
1205
+ var _ctx$styleSheetClones, _anchor;
1206
+ const ownerNode = sheet.ownerNode;
1207
+ let anchor = ownerNode ? (_ctx$styleSheetClones = ctx.styleSheetClones) === null || _ctx$styleSheetClones === void 0 ? void 0 : _ctx$styleSheetClones.get(ownerNode) : null;
1208
+ if (!((_anchor = anchor) !== null && _anchor !== void 0 && _anchor.parentNode) && ownerNode) {
1209
+ const anchorId = ownerNode.getAttribute('data-percy-element-id');
1210
+ anchor = anchorId ? scopeRoot.querySelector(`[data-percy-element-id="${anchorId}"]`) : null;
1211
+ }
1213
1212
  const anchorParent = anchor ? anchor.parentNode : null;
1214
1213
  if (anchorParent) {
1215
1214
  anchorParent.insertBefore(styleElement, anchor.nextSibling);
@@ -1419,7 +1418,8 @@
1419
1418
  forceShadowAsLightDOM,
1420
1419
  resources,
1421
1420
  cache,
1422
- enableJavaScript
1421
+ enableJavaScript,
1422
+ styleSheetClones
1423
1423
  } = ctx;
1424
1424
  // clones shadow DOM and light DOM for a given node
1425
1425
  let cloneNode = (node, parent) => {
@@ -1441,6 +1441,9 @@
1441
1441
  // mark the node before cloning
1442
1442
  markElement(node, disableShadowDOM, forceShadowAsLightDOM);
1443
1443
  let clone = cloneElementWithoutLifecycle(node);
1444
+ if (styleSheetClones && (node.nodeName === 'LINK' || node.nodeName === 'STYLE')) {
1445
+ styleSheetClones.set(node, clone);
1446
+ }
1444
1447
 
1445
1448
  // Custom-element :state() is captured by the fallback path in
1446
1449
  // serialize-custom-states.js (live el.matches against state names
@@ -1660,6 +1663,7 @@
1660
1663
  warnings: new Set(),
1661
1664
  hints: new Set(),
1662
1665
  cache: new Map(),
1666
+ styleSheetClones: new WeakMap(),
1663
1667
  shadowRootElements: [],
1664
1668
  enableJavaScript,
1665
1669
  disableShadowDOM,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@percy/dom",
3
- "version": "1.32.8-beta.3",
3
+ "version": "1.32.8-beta.4",
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": "719021a0565d18a6b47d9d494961eaccb6d63009"
38
+ "gitHead": "8cb91228f629119207fa169f8db8388d66e0c2e0"
39
39
  }