11ty / webc

Single File Web Components
MIT License
1.3k stars 36 forks source link

Can't seem to get `:attribute` working with `webc:root` #194

Open hojberg opened 9 months ago

hojberg commented 9 months ago

Here's a simple example of a component where I don't want a wrapping element:

<script webc:setup>
  function featureSize(size) {
    return `feature_${size.replace("/", "-")}`;
  }
</script>
<section webc:root :class="featureSize(size)">
  <!-- ... -->
</section>

This fails with:

[11ty] 1. Having trouble rendering webc template ./src/index.webc (via TemplateContentRenderError)
[11ty] 2. Evaluating a dynamic attribute failed: `:class="featureSize(size)"`.
[11ty] Original error message: featureSize is not a function (via Error)

I'm not sure how to best deal with this. Seems like js isn't accessible on the root element or something like that?