Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions svg-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ const renderBody = (elem, options, body) => {

const isSpriteIcon = !!spriteIconId;
const parser = new DOMParser();
const doc = parser.parseFromString(body, "text/html");
const fragment = isSpriteIcon ? doc.getElementById(spriteIconId) : doc.querySelector("svg");
const doc = parser.parseFromString(body, "image/svg+xml");
const fragment = isSpriteIcon ? doc.getElementById(spriteIconId) : doc.documentElement;

const eventNames = getAllEventNames();

Expand Down Expand Up @@ -152,7 +152,8 @@ const renderBody = (elem, options, body) => {
});

// For a sprite we want to include the whole DOM of sprite element
elem.innerHTML = spriteIconId ? fragment.outerHTML : fragment.innerHTML;
const replacedContent = spriteIconId ? [fragment] : fragment.children;
elem.replaceChildren(...replacedContent);

// This code block basically merges attributes of the original SVG
// the SVG element where it is called from. For eg,
Expand Down Expand Up @@ -407,4 +408,4 @@ globalThis.SVGLoader.destroyCache = async () => {
localStorage.removeItem(key);
}
});
}
}