Skip to content
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

[Bug] Build error when slotting a component into another with webc:setup script #205

Open
hasanhaja opened this issue Apr 6, 2024 · 0 comments

Comments

@hasanhaja
Copy link

I was trying to create a reusable <select> component, and my naive approach was to use slots, but that didn't work. I've resorted to using a render function within my custom select WebC component and it works now. However, to be generic, I'm trying to pass data in as an object and dynamically render it on the other side. The reproduction and the workaround I've found are at the bottom of this issue.

Bug

<!-- Main component -->
<script webc:setup>
  function options() {
    return [
      "1",
      "2",
      "3",
      "4",
    ];
  }
</script>

<cr-fieldset>
  <cr-select
    name="motivation" 
    :@options="options()"
  ></cr-select>
</cr-fieldset>
<!-- cr-fieldset -->
<fieldset :data-required="required">
  <legend>
    <h2 @text="title"></h2>
    <p @text="label"></p> 
  </legend>
  <slot></slot>
</fieldset>
<!-- cr-select -->
<select
  :name="name"
>
  <option value="">Please select</option>
  <script webc:type="js" webc:root>
    options
      .map((value) => `<option value="${value}">${value}</option>`)
      .join("\n");
  </script>
</select>

This results in the follow error:

11ty-build-error

Reproduction

Reproduction commit: darthmall/webc-select-options-setup-func-repro@247df02

I managed to get around the issue by pulling the setup script and <cr-select> to a separate file.

Workaround commit: darthmall/webc-select-options-setup-func-repro@df8ef9b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant