Comments (8)
Is this what was intended?
from svelte.
Not really.
For example, if my-custom-element
has a shadow root, it requires the <span slot="slot">Slotted</span>
to have the slot
attribute which is missing in you example.
from svelte.
The $$slots
fields of props isn't really designed to be public. Can't you do as the error mentions and remove usage of <slot>
? Is it just because you want to use the native <slot>
element, not Svelte's?
from svelte.
I could also not use <slot>
but I can't give up using the slot=""
attribute because it is needed for the shadow DOM.
IMHO, there appears to be a consistency issue with the deprecation of slots in favour of snippets:
- if a component uses snippets, each child of the component instance should be rendered by the children function, even if it has
slot=""
attribute (REPL) - otherwise, we should be able to combine both snippets and
<slot name="" />
on the component side (REPL) - or, at least, be able to render slots from the
$$slots
property
Now that the slots are deprecated, if they were to be removed in the next major iteration I'd assume the first behavior would be the preferred one.
from svelte.
You can create a wrapper in which you use snippets, and forward that to the custom element using slot syntax. Example REPL. Doesn't that solve your issue?
from svelte.
It can certainly work in most cases, but wrapping an element to be slotted with a span or a div cannot always lead to the desired behavior. It therefore seems to me (but I remain in the realm of personal opinion, make of that what you will 😄) that the current implementation partially conflicts anyway.
Is there any technical reason why nodes with the slot=""
attribute cannot flow into children
when the component uses runes, since we are not able to render those elements <slot />
or with @render
?
from svelte.
The problem is that slot=".."
syntax is used for Svelte components and there's no way to know that you mean "leave this untouched" when written like that. What we could do is to allow slot=".."
attributes inside snippets. Then you could write this:
<script>
import Component from './Component.svelte';
</script>
<Component>
{#snippet children()}
Hello world!
<span slot="slot">Slotted</span>
{/snippet}
</Component>
Once the Svelte 4 syntax is gone completely, you'll be able to use slot attributes like normal, but until then the more common use case is that someone accidentally uses of Svelte slot syntax.
from svelte.
Once the Svelte 4 syntax is gone completely, you'll be able to use slot attributes like normal, but until then the more common use case is that someone accidentally uses of Svelte slot syntax.
It wont work anyway because after #12207 it is impossibile to create a component with runes that supports slotted element. Right now, if "someone accidentally uses of Svelte slot syntax" the slotted element is never rendered without any warning.
IMHO, automatically finding slotted elements within the children property when the component uses runes offers a much clearer syntax and is more future ready (it requires no changes once the Svelte 4 syntax is removed).
from svelte.
Related Issues (20)
- HMR fails if a component has a style tag HOT 1
- Icon Packs for Svelte HOT 5
- Setting a store to `undefined` and then trying to use it in a rune throws `state_unsafe_mutation` error HOT 7
- Svelte 5: Passing Date objects through `$state.snapshot()` turns it into a string
- HMR fails on next.179 and above HOT 8
- 🪲 sveltekit PROD bug with [email protected] using ternary in template HOT 1
- Svelte 5: state_unsafe_mutation Updating state inside a derived is forbidden. If the value should not be reactive, declare it without `$state` HOT 2
- Svelte 5: Automatically implement toJSON so state and properties are serialized. HOT 3
- Ternary in html attributes doesn't compile for production HOT 2
- Svelte 5 bug when moving mouse HOT 4
- $state, $bindable without backup value become 'undefined' in $derived HOT 5
- Svelte 5: SSR breaks rendering of Select component when HMR is enabled HOT 19
- Data returned from load function is stateless HOT 2
- Svelte 5: Add `class:list` directive HOT 3
- Individual states seemingly working like a singleton? I don't even know how to caption this HOT 1
- Distinguish between properties and attributes on custom elements HOT 10
- [REPL] modifying file name to same value wipes contents HOT 1
- `$props` aliasing allows invalid names HOT 7
- Svelte5: unexpected `Component` type errors HOT 4
- Proposal: Include README as component documentation upon packaging HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from svelte.