-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Nested Custom Element slots are never rendered #3128
Comments
Some further observations. It seems that I think that the output should include this if there are slots, however my component has a slot with no props, so this is not being generated. Will continue investigating. |
I have further evidence of this problem at this example repository. https://github.com/cam-stitt/svelte-nested-ce |
After even more investigation (as well as some silly things missed) I realised the following. A nested component of a custom element does not get used as a custom element. However, the code is generated as a custom element. Therefore, the custom element lifecycle is never called and the slot disappears into oblivion. We either need to make the parent use the custom element through it's appropriate tag, or have the generated custom element include the Slot wrapper related methods. |
Ah, thank you, I pretty sure I'm running into the issue you uncovered as I posted on StackOverflow. Adding the link here in case the marginally additional context is helpful. |
Also styles from |
This is still a fairly significant issue (although it may be edge-case) for us. We have a production component library that makes heavy use of nested custom elements, and we cannot fully migrate to Svelte 3 until this is resolved. I have tried a number of times to investigate a fix, but I have failed to get a full grasp of a potential fix. |
I have what I believe to be a fix in #3136. |
just tried in svelte 3.9.2 and this is not resolved. Getting an empty container for a nested component. |
Any updates on this @Rich-Harris @Conduitry? It's a pretty significant issue to still have around. I validated that it is still a problem on the latest release. |
Any progress on this? Happy to provide my example of this break, but in summary it involves making https://svelte.dev/examples#slot-props a customElement (
This is a major break that's keeping me from migrating to Svelte :( |
I've updated the most recent version of Svelte with the changes per 0c397ae (sans the /examples/ changes as those file don't seem to be present any longer) here: https://github.com/campbeln/svelte Unfortunately... these changes don't seem to fix the issues any longer. |
We dropped svelte because of this. |
@matt-shine A fix for current build is contained in master...campbeln:master and an example of working code is included in #4402. NOTE: Not certain if change to line 23 of src/compiler/compile/render_dom/index.ts is necessary. Also not certain if this also breaks sveltestrap as noted here - #3136 (comment) . |
Is there any update on this? Trying to get my team to move to using Svelte for custom elements but it's an absolute no-go whilst this is still open |
This issue 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 is an overhaul of custom elements in Svelte. Instead of compiling to a custom element class, the Svelte component class is mostly preserved as-is. Instead a wrapper is introduced which wraps a Svelte component constructor and returns a HTML element constructor. This has a couple of advantages: - component can be used both as a custom element as well as a regular component. This allows creating one wrapper custom element and using regular Svelte components inside. Fixes #3594, fixes #3128, fixes #4274, fixes #5486, fixes #3422, fixes #2969, helps with sveltejs/kit#4502 - all components are compiled with injected styles (inlined through Javascript), fixes #4274 - the wrapper instantiates the component in `connectedCallback` and disconnects it in `disconnectedCallback` (but only after one tick, because this could be a element move). Mount/destroy works as expected inside, fixes #5989, fixes #8191 - the wrapper forwards `addEventListener` calls to `component.$on`, which allows to listen to custom events, fixes #3119, closes #4142 - some things are hard to auto-configure, like attribute hyphen preferences or whether or not setting a property should reflect back to the attribute. This is why `<svelte:options customElement={..}>` can also take an object to modify such aspects. This option allows to specify whether setting a prop should be reflected back to the attribute (default `false`), what to use when converting the property to the attribute value and vice versa (through `type`, default `String`, or when `export let prop = false` then `Boolean`), and what the corresponding attribute for the property is (`attribute`, default lowercased prop name). These options are heavily inspired by lit: https://lit.dev/docs/components/properties. Closes #7638, fixes #5705 - adds a `shadowdom` option to control whether or not encapsulate the custom element. Closes #4330, closes #1748 Breaking changes: - Wrapped Svelte component now stays as a regular Svelte component (invokeing it like before with `new Component({ target: ..})` won't create a custom element). Its custom element constructor is now a static property named `element` on the class (`Component.element`) and should be regularly invoked through setting it in the html. - The timing of mount/destroy/update is different. Mount/destroy/updating a prop all happen after a tick, so `shadowRoot.innerHTML` won't immediately reflect the change (Lit does this too). If you rely on it, you need to await a promise
Closed via #8457, to be released in Svelte 4 |
This is more of an observation that anything at this point. I have been doing some digging into some CustomElement issues that have surface through a Svelte 2 -> 3 migration. One thing I noticed is that
this.$$.slotted
found here doesn't ever seem to be set. Is there something obvious I am missing?The text was updated successfully, but these errors were encountered: