Skip to content

Commit 9aac2fd

Browse files
authored
perf: svg cloning optimized using deep clone (#462)
1 parent 2b7011c commit 9aac2fd

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/clone-node.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,24 @@ async function cloneSingleNode<T extends HTMLElement>(
6161
return cloneIFrameElement(node)
6262
}
6363

64-
return node.cloneNode(false) as T
64+
return node.cloneNode(isSVGElement(node)) as T
6565
}
6666

6767
const isSlotElement = (node: HTMLElement): node is HTMLSlotElement =>
6868
node.tagName != null && node.tagName.toUpperCase() === 'SLOT'
6969

70+
const isSVGElement = (node: HTMLElement): node is HTMLSlotElement =>
71+
node.tagName != null && node.tagName.toUpperCase() === 'SVG'
72+
7073
async function cloneChildren<T extends HTMLElement>(
7174
nativeNode: T,
7275
clonedNode: T,
7376
options: Options,
7477
): Promise<T> {
78+
if (isSVGElement(clonedNode)) {
79+
return clonedNode
80+
}
81+
7582
let children: T[] = []
7683

7784
if (isSlotElement(nativeNode) && nativeNode.assignedNodes) {
@@ -133,11 +140,11 @@ function cloneCSSStyle<T extends HTMLElement>(nativeNode: T, clonedNode: T) {
133140
) {
134141
value = 'block'
135142
}
136-
143+
137144
if (name === 'd' && clonedNode.getAttribute('d')) {
138145
value = `path(${clonedNode.getAttribute('d')})`
139146
}
140-
147+
141148
targetStyle.setProperty(
142149
name,
143150
value,

0 commit comments

Comments
 (0)