-
-
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
fix: component filling a named slot does not honor let: directives #10395
fix: component filling a named slot does not honor let: directives #10395
Conversation
🦋 Changeset detectedLatest commit: 345973e The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
f6233c8
to
0b67bd6
Compare
0b67bd6
to
98efc2b
Compare
…n it fills a named slot
98efc2b
to
a3d3270
Compare
Could you clarify with examples what you mean by the second-last bullet points (multiple fill the same)? It sounds like you found a related bug while trying to fix this? |
Thanks for the assistance here!
Actually this turns out to be simpler than I thought, since the code that causes the error shouldn't be allowed in the first place. If I use 2 divs instead, I get a "duplicate slot" error on both Svelte 4 and 5, so I think the issue here is actually just that slot attributes on components aren't participating in that part of the analysis. |
Yeah this throws a validation error in Svelte 4 but currently doesn't in Svelte 5. You can add it to the PR if you want or create a separate one. |
Sounds good, I'll just add it into this current PR. Should have more time to work on this tonight I think. Thanks! |
Turned out to be a small change to get that working. Thanks again for your help here! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
Fixes #9797, a regression in Svelte 5 in which let: directives on a component filling a named slot do not work.
This fix mostly works but is not complete yet. I'm hoping someone more knowledgable can help fill in the exact details on how to do things.
Some problems:
On the client side, the value passed to the inner component is an object instead of the actual value. It looks like this is becauseSimon fixed this one :)attribute.metadata.dynamic === false
when it should probably be true. I haven't yet figured out the right way to accomplish this.When multiple elements fill the same named slot, it rendersupdate: as described below, the code that rendered to this wasn't supposed to be allowed in the first place.const thing = $$slotProps.thing
twice, although I think that's an issue with the existing implementation as well. Might just need some kind of deduplication when rendering the elements in context.state.init, but maybe there's a better way?It's a bit ambiguous as to whether aEDIT: I tested on Svelte 4 and it removes the bindings to the default slot in this case, so I've done the same here.let:
directive in this case applies to the parent's named slot being filled, or the current component's default slot. This change is only additive, pulling in values from the parent's named slot, and never cancelling the rendering of the current component's default slot. I think that ends up ok, worst case it's a bit of wasted code.Svelte 5 rewrite
Please note that the Svelte codebase is currently being rewritten for Svelte 5. Changes should target Svelte 5, which lives on the default branch (
main
).If your PR concerns Svelte 4 (including updates to svelte.dev.docs), please ensure the base branch is
svelte-4
and notmain
.Before submitting the PR, please make sure you do the following
feat:
,fix:
,chore:
, ordocs:
.Tests and linting
pnpm test
and lint the project withpnpm lint