From 691d604624b3de64db006dfa46fce1695dc4c702 Mon Sep 17 00:00:00 2001 From: seyeong yun Date: Wed, 19 Feb 2025 10:22:05 +0900 Subject: [PATCH 1/3] fix: fix a bug cannot read href attribute in use tags --- src/clone-node.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/clone-node.ts b/src/clone-node.ts index 5dfcd117..cb6d6eab 100644 --- a/src/clone-node.ts +++ b/src/clone-node.ts @@ -213,14 +213,14 @@ async function ensureSVGSymbols( const processedDefs: { [key: string]: HTMLElement } = {} for (let i = 0; i < uses.length; i++) { const use = uses[i] - const id = use.getAttribute('xlink:href') - if (id) { - const exist = clone.querySelector(id) - const definition = document.querySelector(id) as HTMLElement - if (!exist && definition && !processedDefs[id]) { - // eslint-disable-next-line no-await-in-loop - processedDefs[id] = (await cloneNode(definition, options, true))! - } + const id = use.getAttribute('href') ?? use.getAttribute('xlink:href') + if (!id) return + + const exist = clone.querySelector(id) + const definition = document.querySelector(id) as HTMLElement + if (!exist && definition && !processedDefs[id]) { + // eslint-disable-next-line no-await-in-loop + processedDefs[id] = (await cloneNode(definition, options, true))! } } From f87dacd7ad3d08cdb84bc2a6db8ce5375423889f Mon Sep 17 00:00:00 2001 From: seyeong yun Date: Wed, 19 Feb 2025 10:32:44 +0900 Subject: [PATCH 2/3] fix break for --- src/clone-node.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/clone-node.ts b/src/clone-node.ts index cb6d6eab..5832a7d7 100644 --- a/src/clone-node.ts +++ b/src/clone-node.ts @@ -214,7 +214,7 @@ async function ensureSVGSymbols( for (let i = 0; i < uses.length; i++) { const use = uses[i] const id = use.getAttribute('href') ?? use.getAttribute('xlink:href') - if (!id) return + if (!id) continue const exist = clone.querySelector(id) const definition = document.querySelector(id) as HTMLElement From 3caf213e24d96f8e4e576e47352f66b0c53d8b7d Mon Sep 17 00:00:00 2001 From: seyeong yun Date: Wed, 19 Feb 2025 10:37:59 +0900 Subject: [PATCH 3/3] fix return state --- src/clone-node.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/clone-node.ts b/src/clone-node.ts index 5832a7d7..0ff98a0d 100644 --- a/src/clone-node.ts +++ b/src/clone-node.ts @@ -214,13 +214,13 @@ async function ensureSVGSymbols( for (let i = 0; i < uses.length; i++) { const use = uses[i] const id = use.getAttribute('href') ?? use.getAttribute('xlink:href') - if (!id) continue - - const exist = clone.querySelector(id) - const definition = document.querySelector(id) as HTMLElement - if (!exist && definition && !processedDefs[id]) { - // eslint-disable-next-line no-await-in-loop - processedDefs[id] = (await cloneNode(definition, options, true))! + if (id) { + const exist = clone.querySelector(id) + const definition = document.querySelector(id) as HTMLElement + if (!exist && definition && !processedDefs[id]) { + // eslint-disable-next-line no-await-in-loop + processedDefs[id] = (await cloneNode(definition, options, true))! + } } }