diff --git a/packages/@lwc/synthetic-shadow/src/faux-shadow/node.ts b/packages/@lwc/synthetic-shadow/src/faux-shadow/node.ts index b33d7f8cbd..629feed204 100644 --- a/packages/@lwc/synthetic-shadow/src/faux-shadow/node.ts +++ b/packages/@lwc/synthetic-shadow/src/faux-shadow/node.ts @@ -408,7 +408,6 @@ defineProperties(Node.prototype, { }, cloneNode: { value(this: Node, deep?: boolean): Node { - deep = isUndefined(deep) || deep; if (isNodeShadowed(this) || isHostElement(this)) { return cloneNodePatched.call(this, deep); } diff --git a/packages/integration-karma/test/shadow-dom/Node-properties/Node.cloneNode.spec.js b/packages/integration-karma/test/shadow-dom/Node-properties/Node.cloneNode.spec.js index 64e99281a4..e9156cae86 100644 --- a/packages/integration-karma/test/shadow-dom/Node-properties/Node.cloneNode.spec.js +++ b/packages/integration-karma/test/shadow-dom/Node-properties/Node.cloneNode.spec.js @@ -55,6 +55,35 @@ describe('Node.cloneNode', () => { }); }); + describe('deep=undefined', () => { + it('should not clone shadow tree', () => { + const elm = createElement('x-slotted', { is: Slotted }); + document.body.appendChild(elm); + + const clone = elm.cloneNode(); + expect(clone.childNodes.length).toBe(0); + expect(clone.outerHTML).toBe(''); + }); + + it('should not clone slotted content', () => { + const elm = createElement('x-slotted', { is: Slotted }); + document.body.appendChild(elm); + + const clone = elm.shadowRoot.querySelector('x-container').cloneNode(); + expect(clone.childNodes.length).toBe(0); + expect(clone.outerHTML).toBe(''); + }); + + it('should not clone children of parent node with vanilla html', () => { + const table = document.createElement('table'); + table.innerHTML = 'CatDog'; + document.body.appendChild(table); + const clone = table.cloneNode(); + expect(clone.childNodes.length).toBe(0); + expect(clone.outerHTML).toBe('
'); + }); + }); + describe('deep=true', () => { it('should not clone shadow tree', () => { const elm = createElement('x-slotted', { is: Slotted }); @@ -95,5 +124,16 @@ describe('Node.cloneNode', () => { expect(clone.childNodes.length).toBe(0); expect(clone.outerHTML).toBe(''); }); + + it('should clone children of parent node with vanilla html', () => { + const table = document.createElement('table'); + table.innerHTML = 'CatDog'; + document.body.appendChild(table); + const clone = table.cloneNode(true); + expect(clone.childNodes.length).toBe(1); + expect(clone.outerHTML).toBe( + '
Cat
Dog
' + ); + }); }); });