11ty / 11ty/webc

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

Open
#205 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
1.4k
Forks
46
Avg merge
10m
Merged PRs (30d)
2

Description

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: https://github.com/darthmall/webc-select-options-setup-func-repro/pull/1/commits/247df02bac1e017f935bdbde5f94cc61d7b66cee

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

Workaround commit: https://github.com/darthmall/webc-select-options-setup-func-repro/pull/1/commits/df8ef9be1dcc2e94d8a84abcf89713e1b77b538a

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproduction commit linked in the issue and run its build to observe the error involving webc:setup, slots, and cr-select. Compare it with the workaround commit to identify the relevant compiler path; done means the original inline setup and slotted component build successfully without requiring separate files.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
build-system, frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.