11ty / webc

Single File Web Components
MIT License
1.32k stars 38 forks source link

when using `webc:type="js"` i get output twice #156

Open niklasgrewe opened 1 year ago

niklasgrewe commented 1 year ago

i created a link.webc component like this:

<script webc:type="js" webc:root>
   `<link @attributes>`;
</script>

my <head> inside my base.webc layout looks like this:

<head>
   <link rel="icon" type="image/svg+xml" href="/images/favicon.svg" />
   <link rel="mask-icon" href="/images/safari-mask-icon.svg" color="#888888" />
   <link rel="apple-touch-icon" href="/images/apple-touch-icon.png" />
</head>

but now i get the <link> tags twice:

<!-- generated content -->
<head>
   <link rel="icon" type="image/svg+xml" href="/images/favicon.svg" />
   <link rel="icon" type="image/svg+xml" href="/images/favicon.svg" />
   <link rel="mask-icon" href="/images/safari-mask-icon.svg" color="#888888" />
   <link rel="mask-icon" href="/images/safari-mask-icon.svg" color="#888888" />
   <link rel="apple-touch-icon" href="/images/apple-touch-icon.png" />
   <link rel="apple-touch-icon" href="/images/apple-touch-icon.png" />
</head>

is this a bug? I am using @11ty/eleventy: 2.0.1 and @11ty/eleventy-plugin-webc: 0.11.0

niklasgrewe commented 1 year ago

Note: it works when i am using webc:nokeep

<script webc:type="js" webc:root>
  `<link webc:nokeep @attributes>`;
</script>
zachleat commented 1 year ago

This seems like a bug to me, given #107 shipped in v0.10.0.

What happens if you remove webc:root?

niklasgrewe commented 1 year ago

What happens if you remove webc:root?

it works and i can access the attributes too...

<script webc:type="js">
  console.log(href); // /images/favicon.svg etc.
  `<link @attributes>`;
</script>

interesting, i always thought i had to set webc:root to get the attributes, has that changed?

zachleat commented 1 year ago

I’m not sure if it answers your question but I would not have expected webc:root to be required to use @attributes