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

Slots in Svelte customElements not working #9906

Closed
vekunz opened this issue Dec 13, 2023 · 3 comments
Closed

Slots in Svelte customElements not working #9906

vekunz opened this issue Dec 13, 2023 · 3 comments

Comments

@vekunz
Copy link

vekunz commented Dec 13, 2023

Describe the bug

In our company, we want to build a UI component library for use with several frontend frameworks. Therefore we have to build them as Web Components (aka custom elements). We are trying to build them with Svelte because Svelte is just cool.
We are using Rollup for this because we couldn't get it to work with Vite (maybe someone has a guide for Vite for custom elements as build output from Svelte files).

Our problem now is that everything seems to work, except Slots. We have a <slot /> in our Svelte component, but after compiling the Svelte component to a Web component, the slot does not work at all.

Reproduction

I created a reproduction repository with our Rollup setup https://github.com/vekunz/svelte-rollup-webcomponents-slot.

  1. npm install
  2. npm run package
  3. Open demo.html in browser.

-> Slot content from <my-button> in demo.html is not shown in the browser

Logs

---

System Info

System:
    OS: macOS 14.1.2
    CPU: (10) arm64 Apple M2 Pro
    Memory: 537.33 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.18.0 - ~/.nvm/versions/node/v18.18.0/bin/node
    Yarn: 1.22.21 - ~/.nvm/versions/node/v18.18.0/bin/yarn
    npm: 9.8.1 - ~/.nvm/versions/node/v18.18.0/bin/npm
    pnpm: 8.11.0 - ~/.nvm/versions/node/v18.18.0/bin/pnpm
  Browsers:
    Chrome: 120.0.6099.109
    Safari: 17.1.2
  npmPackages:
    rollup: 4.9.0 => 4.9.0 
    svelte: 4.2.8 => 4.2.8

Severity

blocking all usage of svelte

@dummdidumm
Copy link
Member

I tried the reproduction repository. It fails the install for me, something in the package.lock.json seems to be broken. If I remove it or use pnpm, it installs correctly and the slot feature works as expected.
Please provide a reproduction that does reproduce this.

@vekunz
Copy link
Author

vekunz commented Dec 15, 2023

Oh, sorry. I forgot this again. We have a company internal NPM registry, which mirrors the public one. I recreated the package-lock.json with the correct entries.

When I try this out, the first button just says "Hello", but it should say "Hello world!". The "Hello" comes from an attribute, the "world!" from the slot.

@dummdidumm
Copy link
Member

Thanks, can reproduce it now - closing as duplicate of #8997, the workaround mentioned there should work here, too.

@dummdidumm dummdidumm closed this as not planned Won't fix, can't repro, duplicate, stale Dec 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants