Skip to content

Commit

Permalink
Account for cloned DOM trees
Browse files Browse the repository at this point in the history
  • Loading branch information
developit committed Oct 28, 2020
1 parent fa3b266 commit e60ca42
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,8 @@ function getPaintRuleForElement(element) {
let paintRule = element.$$paintRule,
paintId = ensurePaintId(element);
if (paintRule==null) {
if (!element.hasAttribute('data-css-paint')) {
// Fix cloned DOM trees which can have incorrect data-css-paint attributes:
if (Number(element.getAttribute('data-css-paint')) !== paintId) {
element.setAttribute('data-css-paint', paintId);
}
let index = overrideStyles.insertRule(`[data-css-paint="${paintId}"] {}`, overrideStyles.cssRules.length);
Expand Down Expand Up @@ -706,15 +707,15 @@ function updateElement(element, computedStyle) {
if (USE_CSS_CANVAS_CONTEXT===true) {
newValue += `-webkit-canvas(${cssContextId})`;
// new or replaced context (note: `canvas` is any PRIOR canvas)
if (token[4] == null || canvas.id !== cssContextId) {
if (token[4] == null || canvas && canvas.id !== cssContextId) {
hasChanged = true;
}
}
else if (USE_CSS_ELEMENT===true) {
newValue += `-moz-element(#${cssContextId})`;
if (token[4] == null) hasChanged = true;
// `canvas` here is the current canvas.
if (canvas.id !== cssContextId) {
if (canvas && canvas.id !== cssContextId) {
canvas.id = cssContextId;
hasChanged = true;
}
Expand Down

0 comments on commit e60ca42

Please sign in to comment.