-
-
Notifications
You must be signed in to change notification settings - Fork 528
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lucide won't render data-lucide
if inside <template>
#2635
Comments
I had a quick look at the code. I am not experienced with JS, but I'll try to help: It seems that lucide searches for elements using lucide/packages/lucide/src/lucide.ts Lines 19 to 22 in 49070b4
// Test to see if the browser supports the HTML template element by checking
// for the presence of the template element's content attribute.
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/template#examples
if ("content" in document.createElement("template")) {
document.querySelectorAll('template').forEach((template) =>
template.content.querySelectorAll('[data-lucide]').forEach((element) =>
console.log(element)
)
);
} |
As I said, I'm not experienced enough to contribute with a PR. For anyone who encounters this, you might be able to solve it like it did: Use pnpm patch and edit the code as below: diff --git a/dist/esm/lucide.js b/dist/esm/lucide.js
index xxx..xxx 100644
--- a/dist/esm/lucide.js
+++ b/dist/esm/lucide.js
@@ -1562,6 +1562,15 @@ const createIcons = ({ icons = {}, nameAttr = "data-lucide", attrs = {} } = {})
Array.from(elementsToReplace).forEach(
(element) => replaceElement(element, { nameAttr, icons, attrs })
);
+ if ("content" in document.createElement("template")) {
+ const templateElements = document.querySelectorAll('template');
+ templateElements.forEach((template) => {
+ const templateContentElementsToReplace = template.content.querySelectorAll(`[${nameAttr}]`);
+ Array.from(templateContentElementsToReplace).forEach(
+ (element) => replaceElement(element, { nameAttr, icons, attrs })
+ );
+ })
+ }
if (nameAttr === "data-lucide") {
const deprecatedElements = document.querySelectorAll("[icon-name]");
if (deprecatedElements.length > 0) { If you are using Node with npm, there's patch-package. If you are using bun, there's bun patch, if you are using Deno I have no idea, sorry. |
Package
Version
0.460.0
Can you reproduce this in the latest version?
Browser
Operating system
Description
I'm using the Content Template element (
<template>
) to render parts of an HTML form that I use as a template (duh) within JavaScript. Elements withdata-lucide
inside thetemplate
tag do not render.Steps to reproduce
Checklist
The text was updated successfully, but these errors were encountered: