Support custom element with nested components without errors
See original GitHub issueI have only 1 customElement and inside it there are several internal components of the Svelte. These internal/nested components cannot be 1 web component.
By setting the customElement option in the rollup
, he forced me to put <svelte:options tag={null} />
on all internal components, but that seems to be wrong, as they should not be 1 customElement
.
After setting up, I’m getting the following errors for internal components marked as tag={null}
:
Issue Analytics
- State:
- Created 4 years ago
- Reactions:30
- Comments:18 (1 by maintainers)
Top Results From Across the Web
Custom Element Best Practices - web.dev
Custom elements let you construct your own HTML tags. This checklist covers best practices to help you build high quality elements.
Read more >How to create and style svelte 3 custom elements with nested ...
My goal is to create web component with svelte and then use it outside of svelte as native web-component. Here is REPL. Custom...
Read more >Custom elements - The Modern JavaScript Tutorial
We can create custom HTML elements, described by our class, with its own methods and properties, events and so on. Once a custom...
Read more >Using custom elements - Web Components | MDN
The controller of custom elements on a web document is the CustomElementRegistry object — this object allows you to register a custom element...
Read more >Development: Scoped Elements - Open Web Components
Version 2 of Scoped Elements only supports lit with lit-element 3.x . ... Scoped Custom Element Registries feature and, by the moment, there...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Same problem here. It seems that
tag={null}
does not work as documented in Svelte components imported into a parent component that has atag="parent-component"
.The below does not work
ParentComponent.svelte
ImportedComponent.svelte
However, if I give the imported component a tag name
tag="imported-component"
and then use the new custom element inside the parent component<imported-component></imported-component>
then everything works.This works, but it’s not what I want
ParentComponent.svelte
ImportedComponent.svelte
But, I don’t want to generate all my components as custom elements. I just want the top level element to be generated as a custom element and the rest of my Svelte components to be used within the app as normal Svelte components (not custom elements).
I solved this by using a combination of Rollup and file extensions.
Custom Element components get the extension .wc.svelte. Rollup then sets the customElement config depending on the file extension.
This works smoothly with local and NPM imported components.
Demo: https://jawish.github.io/svelte-customelement-rollup/