Skip to content

Commit

Permalink
fix: prevent duplicate child cloning of iframe content
Browse files Browse the repository at this point in the history
  • Loading branch information
joshualoehr-smar committed Sep 20, 2023
1 parent 05a2712 commit b025b5e
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/clone-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,6 @@ async function cloneChildren<T extends HTMLElement>(

if (isSlotElement(nativeNode) && nativeNode.assignedNodes) {
children = toArray<T>(nativeNode.assignedNodes())
} else if (
isInstanceOfElement(nativeNode, HTMLIFrameElement) &&
nativeNode.contentDocument?.body
) {
children = toArray<T>(nativeNode.contentDocument.body.childNodes)
} else {
children = toArray<T>((nativeNode.shadowRoot ?? nativeNode).childNodes)
}
Expand Down Expand Up @@ -133,11 +128,11 @@ function cloneCSSStyle<T extends HTMLElement>(nativeNode: T, clonedNode: T) {
) {
value = 'block'
}

if (name === 'd' && clonedNode.getAttribute('d')) {
value = `path(${clonedNode.getAttribute('d')})`
}

targetStyle.setProperty(
name,
value,
Expand Down Expand Up @@ -171,7 +166,10 @@ function cloneSelectValue<T extends HTMLElement>(nativeNode: T, clonedNode: T) {
}

function decorate<T extends HTMLElement>(nativeNode: T, clonedNode: T): T {
if (isInstanceOfElement(clonedNode, Element)) {
if (
isInstanceOfElement(clonedNode, Element) &&
!isInstanceOfElement(nativeNode, HTMLIFrameElement)
) {
cloneCSSStyle(nativeNode, clonedNode)
clonePseudoElements(nativeNode, clonedNode)
cloneInputValue(nativeNode, clonedNode)
Expand Down
5 changes: 5 additions & 0 deletions test/resources/iframe/embed.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html>
<body>
<div>Embeddable content</div>
</body>
</html>
1 change: 1 addition & 0 deletions test/resources/iframe/image
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAAAXNSR0IArs4c6QAACMlJREF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SdhJdWm1lEjYHhdyHK51420DvsTKoVuyzayRGk9SwQhtkzVQLV39FagpW7dk3PXB4i6DzOm1srtQ4gtV8v8du0+DtinHnebsS8h9k66lduFUPY5vbOPhejrbRDZGfSmhqP1yXVLH4vgrP93tO5acyt9CGkW4m0Nnzdw29xqQ6LsQfj/Jd5CGki2Im0e2SUzaHqzxNjgbQ9BsmXpMGDvHIHWhpPzZl36e4euxVshZlIOO3S6H/czPhkTHLo8Y5Yu0HkvEbSszGBu7LLN640Pb1V6ncfrQyYTKoXK5rr5ujc8J40fuqiPhbinvt3Wq3m+mZVXdQyiDu9cGWDtttnsMe0UOIO5xLWuoXsY1FvHr8UY44W/mxR4B9f0+tR4l/sbp+zKPSbeI9gqgMTr3oxvtnlVCGNZ62iqFLae/6dGX0L8KO/N2rY0VoxqnXNecvNscdUctNK+u0S3fd3P/rbv0sqGDOOH67tXcoasX9BnhxCyoIIuKS8vQpIxXYQUIckQSCZOWUgRkgyBZOKUhRQhyRBIJk5ZSBGSDIFk4pSFFCHJEEgmTllIEZIMgWTilIUUIckQSCZOWUgRkgyBZOKUhRQhyRBIJk5ZSBGSDIFk4pSFFCHJEEgmTllIEZIMgWTilIUUIckQSCZOWUgRkgyBZOKUhRQhyRBIJk5ZSBGSDIFk4pSFFCHJEEgmTllIEZIMgWTilIUUIckQSCZOWUgRkgyBZOKUhRQhyRBIJk5ZSBGSDIFk4pSFFCHJEEgmTllIEZIMgWTilIUUIckQSCZOWUgRkgyBZOKUhRQhyRBIJk5ZSBGSDIFk4pSFJCPkP7EF8XTxUTHdAAAAAElFTkSuQmCC
6 changes: 6 additions & 0 deletions test/resources/iframe/node.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<iframe
id="iframe"
src="/base/test/resources/iframe/embed.html"
width="100"
height="100"
></iframe>
21 changes: 21 additions & 0 deletions test/spec/iframe.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* eslint-disable promise/no-callback-in-promise */

import './setup'
import { bootstrap, renderAndCheck } from './helper'
import { delay } from '../../src/util'

describe('work with iframe element', () => {
it('should render iframe element', (done) => {
bootstrap('iframe/node.html', undefined, 'iframe/image')
.then(delay(100))
.then((node) => {
const iframe = node.querySelector('#iframe') as HTMLIFrameElement
return renderAndCheck(node, {
width: parseInt(iframe.width, 10),
height: parseInt(iframe.height, 10),
})
})
.then(done)
.catch(done)
})
})

0 comments on commit b025b5e

Please sign in to comment.