-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Props not being passed to some slots #7610
Comments
I was looking at this issue in // src/pages/index.astro
---
import Test from '../Test.astro';
---
<Test>
<div slot="B">
{v => console.log('\n', 'Render B', v)}
</div>
<div slot="C">
{v => console.log('\n', 'Render C', v)}
</div>
<div slot="A">
{/* 'v' is undefined */}
{v => console.log('\n', 'Render A', v)}
</div>
</Test> The |
That does fix that example, but there are also cases where the problem persists when adding a see this: https://stackblitz.com/edit/github-32w1iv?file=README.md |
Relevant proposal: |
Names slots can't be function. In these examples the This should work for default slots (the only valid way to define a function as a slot). |
This used to work in previous versions of Astro, is there a reason this is not supported anymore? I built a library of components that uses this principal of passing template functions to named slot to customize the rendering of a component https://github.com/BryceRussell/astro-headless-ui/wiki#named-slot-functions would this be considered a regression? |
Oh I didn't know that. What version worked? |
I am not too sure I will do some testing and see which version it got changed |
@matthewp I tested this a bunch, passing a function to a named slot does still work but there is a caveat with the name of the tag, if the tag includes a dash
But this is unrelated to the original issue I made a minimal reproduction for the original issue here: https://stackblitz.com/edit/github-s9fusc?file=src%2Fpages%2Findex.astro,src%2FTest.astro,.gitignore I have a limited knowledge of how the rendering works but the way I understand it is:
|
What version of
astro
are you using?2.8.0
Are you using an SSR adapter? If so, which one?
None
What package manager are you using?
yarn
What operating system are you using?
Mac
What browser are you using?
Chrome
Describe the Bug
I am attaching a stripped-down example of what I am experiencing.
Basically, at least one of the slots I'm trying to render does not receive props ( hence the error ), usually the one named after. I found out about this when trying to build a component that receives multiple slots, all were passed props, except the one named after (or anything starting with A, weirdly enough) .
If I remove the props destructuring from the slotted function the slot is rendered.
By debugging the code into node_modules/astro/dist/core/render/result.js, I found out that that slot's expressions sometimes has an Object [Generator] {} as its first member (therefore the getFunctionExpression returns undefined because the expressions length is greater than 1) and I don't know where it comes from. However, sometimes, by changing the slot's name from after to something else the Object [Generator] {} disappears
What's the expected result?
I would like the props to be passed to all slots. It seems like the issue has something to do with my example not having a tag and the
after
slot being the first in alphabetical order ( but I have seen it happening even if the tag is included in other examples )Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-927mjd?file=src%2Fpages%2Findex.astro
Participation
The text was updated successfully, but these errors were encountered: