diff --git a/packages/dom/src/prepare-dom.js b/packages/dom/src/prepare-dom.js index 25a093219..52d1a0011 100644 --- a/packages/dom/src/prepare-dom.js +++ b/packages/dom/src/prepare-dom.js @@ -6,18 +6,13 @@ export function uid() { export function markElement(domElement, disableShadowDOM) { // Mark elements that are to be serialized later with a data attribute. if (['input', 'textarea', 'select', 'iframe', 'canvas', 'video', 'style'].includes(domElement.tagName?.toLowerCase())) { - if (!domElement.getAttribute('data-percy-element-id')) { - domElement.setAttribute('data-percy-element-id', uid()); - } + domElement.setAttribute('data-percy-element-id', uid()); } // add special marker for shadow host if (!disableShadowDOM && domElement.shadowRoot) { domElement.setAttribute('data-percy-shadow-host', ''); - - if (!domElement.getAttribute('data-percy-element-id')) { - domElement.setAttribute('data-percy-element-id', uid()); - } + domElement.setAttribute('data-percy-element-id', uid()); } } diff --git a/packages/dom/test/serialize-inputs.test.js b/packages/dom/test/serialize-inputs.test.js index da37f106a..156e0c10d 100644 --- a/packages/dom/test/serialize-inputs.test.js +++ b/packages/dom/test/serialize-inputs.test.js @@ -62,8 +62,10 @@ describe('serializeInputs', () => { option.selected = false; } }); - cache[platform].dom = dom; cache[platform].$ = parseDOM(serializeDOM(), platform); + // save DOM, only after serializing it + // clone DOM, so that during next platform iteration, serializeDOM doesn't change current original DOM + cache[platform].dom = platform === 'shadow' ? dom : dom.cloneNode(true); }); // interact with the inputs to update properties (does not update attributes) }); @@ -132,14 +134,6 @@ describe('serializeInputs', () => { expect(og).toEqual($('[data-percy-element-id]')[0].getAttribute('data-percy-element-id')); }); - it(`${platform}: does not override previous guids when reserializing`, () => { - let getUid = () => dom.querySelector('[data-percy-element-id]').getAttribute('data-percy-element-id'); - let first = getUid(); - - serializeDOM(); - expect(getUid()).toEqual(first); - }); - it(`${platform}: does not mutate values in origial DOM`, () => { expect($('#name')[0].getAttribute('value')).toBe('Bob Boberson'); expect(dom.querySelector('#name').getAttribute('value')).toBeNull();