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

[WIP] Allow custom elements to be rendered to light dom or shadow dom (open, closed) #4073

Closed
wants to merge 1 commit into from

Conversation

fsodano
Copy link

@fsodano fsodano commented Dec 9, 2019

Hi peeps,

We're in the middle of choosing a JS component wrapper for our design system. Svelte looks really good, best developer experience so far. Custom elements are an important part of this process because it allows teams to consume individual components in their own projects, which may then use React (even though it has known issues with custom elements, this library sorts them out for us https://github.com/BBKolton/reactify-wc/), Vue, Angular, Svelte, etc.

However, there are a couple of issues with the way it handles custom elements (#1748)

It's important to be able to render elements directly on the lightdom due to accessibility issues.

These small changes solve that specific issue:

Screenshot 2019-12-09 21 02 26

Screenshot 2019-12-09 21 02 21

But before looking deeper into this issue, I have a question that's more around what's the philosophy for Svelte:

Safari does not support extending built-in elements (e.g. <p is="my-svelte-component">). There is a (small) polyfill for Safari which is used in the heresy project.

Libraries like Stencil have no intention of adding polyfills for it, so I'm wondering; what's Svelte's stance on this?

Similarly to the point above, it's really important because it allows us to be able to progressively enhance a small component (such as an anchor or a paragraph) while keeping all the default attributes (like the aria- attributes) without having to re-implement them on each component.

If I'm completely missing something that already exists, or what I'm saying makes no sense at all, I'm also happy to be corrected.

Thanks.

@kmmbvnr
Copy link

kmmbvnr commented Dec 24, 2019

I'm just a svelte user, but I could list two disadvantages in this pull request.

  1. no per-element configuration. I suppose it's better to have an option to render some element in a shadow dom and others as light dom. Like stencil does.
  2. This PR doesn't touch CSS related code. In a case of open DOM, CSS are still injected as inner styles, probably it's better to handle it as usual CSS

@fsodano
Copy link
Author

fsodano commented Dec 24, 2019 via email

@kmmbvnr
Copy link

kmmbvnr commented Dec 24, 2019

@fsodano thank you for the PR. It was really inspired. I'm thinking to propose a bit different approach, by allowing for a user to specify custom base class for web components.

@timonweb
Copy link

glad to see progress on this. @kmmbvnr when do you think you'll make your PR?

@kmmbvnr
Copy link

kmmbvnr commented Dec 26, 2019

@timonweb I've just opened the issue with implementation proposal - #4168

@TehShrike
Copy link
Member

Interesting, what are you thinking for embedding the <style> when compiled with css: true?

@fsodano
Copy link
Author

fsodano commented Jan 29, 2020

Thanks all, seems there's some traction on this so I'm closing this WIP.

@fsodano fsodano closed this Jan 29, 2020
@patricknelson
Copy link

patricknelson commented Jun 15, 2023

For anyone landing here looking for light DOM support with Svelte custom elements, check out svelte-retag. It includes the ability to mix/match your Svelte components and only define which ones you want to utilize as custom elements, supports slots, Vite HMR and even early (iife) execution for reduced content layout shift.

I'd be interested to know if anyone experiences any issues with it, too.

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

Successfully merging this pull request may close these issues.

5 participants