-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Lightdom slots #4348
Lightdom slots #4348
Conversation
@crisward do you need help with the merge conflicts? This and your other light dom PR enable custom element support without shadow dom I’m personally interested in seeing it land and been watching this (and typescript support which just landed) for some time |
To be honest, I'd given up on this. The problem I was trying to solve was to be able create a svelte app, then wrap it in an outer shadow dom to give me css isolation. Svelte at the moment only allows you to either use web-components all the way down, or mount a standard svelte app into the light dom. I got around this by creating a web-component wrapper, that takes a normal svelte component as an argument. It even has support for named and default slots, also enabling the choice between shadow and light dom. The slot support relies on some non-public svelte apis, which may be a problem going forward. I've very quickly uploaded this to github & npm I've extracted this for an internal app I've been working on. I still need to finish the readme and extract the tests. But hopefully it'll negate the need to modify svelte. |
@crisward if you want to use a svelte app inside an shadow dom for style encapsultion, you should checkout this PR: #5639.
|
If I understand your problem @crisward, You could always combine the // rollup.config.js
...
plugins: [
...
// Regular Svelte components fed here
svelte({
exclude: "**/*.wc.svelte",
}),
// Web Components will be fed here
svelte({
customElement: true,
include: "**/*.wc.svelte",
}),
...
]
... You may also need to do something similar in your |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This pull request also includes changes from #4330. This pull request simulates slots and named slots for web components without shadowdom. This works even if the slot has been inserted conditionally, ie it's surrounded by an
{#if} ... {/if}
though I will add tests to verify this later.I'm using a mutation observer to update the slots, and grabbing the content just before the component is rendered. The functionality is added in the compiler so is only included if shadowdom is set to none. I'd like to omit it if slots are not present in the component, but I'm not clear how to detect this (appreciate any hints on this).
This feature helps svelte encapsulate some of the benefit of custom elements (ie just inserting a tag into a page) but without the downsides of shadowdom (auto complete issues, custom form element issues, etc).
Relates to issue #1748
Before submitting the PR, please make sure you do the following
npm run lint
!)Tests
npm test
oryarn test
)