Skip to content

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

@hasanhaja

Description

@hasanhaja

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions