Skip to content
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

Different behavior with slot vs Astro.slots.render #7068

Closed
1 task
ido-pluto opened this issue May 11, 2023 · 7 comments · Fixed by #8929
Closed
1 task

Different behavior with slot vs Astro.slots.render #7068

ido-pluto opened this issue May 11, 2023 · 7 comments · Fixed by #8929
Assignees
Labels
- P3: minor bug An edge case that only affects very specific usage (priority)

Comments

@ido-pluto
Copy link
Contributor

ido-pluto commented May 11, 2023

What version of astro are you using?

2.4.4

Are you using an SSR adapter? If so, which one?

node

What package manager are you using?

npm

What operating system are you using?

Mac

What browser are you using?

Firefox

Describe the Bug

When using the <slot/> syntax and rendering the same component twice, the slot content will be empty.
Not happening when doing with Astro.slots.render

Link to Minimal Reproducible Example

https://codesandbox.io/p/sandbox/priceless-solomon-sxv6r4?on=codesandbox&file=%2Fsrc%2Fcomponents%2FCardContainer.astro%3A1%2C1

Participation

  • I am willing to submit a pull request for this issue.
@ido-pluto ido-pluto changed the title Different behuver with slot vs Astro.slots.render Different behavior with slot vs Astro.slots.render May 11, 2023
@JerryWu1234
Copy link
Contributor

let me take a look

@JerryWu1234
Copy link
Contributor

@ido-pluto you should add a await for Astro.slots.render

@matthewp matthewp added the - P3: minor bug An edge case that only affects very specific usage (priority) label Jun 12, 2023
@lilnasy
Copy link
Contributor

lilnasy commented Oct 17, 2023

I don't see Astro.slots being used anywhere in the repro.

@ido-pluto
Copy link
Contributor Author

I created a new repo for this:
https://github.com/ido-pluto/astro-render-issue/tree/main

It seems like in Astro version 3, the issue changed form: instead of empty slots, all the slot renders are the same

@lilnasy
Copy link
Contributor

lilnasy commented Oct 25, 2023

It does render the same random number each time you call slots.render() but that's probably because the component in the slot has already run before it becomes a slot. To make it render uniquely each time, you can turn it into a function.

<RenderMulti count={10}>
	{() => <RandomCard/>}
</RenderMulti>

Does that work for you?

@ido-pluto
Copy link
Contributor Author

This is working, but it is not the expected behaviour when I want to rerender a slot.
I need to make a special agistment to every nested slot there is.

I need this functionality for a framework I built for Astro that uses this for input validation when I want to render the same thing twice and It will have 2 two different outputs.

I think it still is performant without cache, because if someone wants to render twice, he expects a different output, if not, why not just store the output yourself in a variable?

@lilnasy
Copy link
Contributor

lilnasy commented Oct 26, 2023

From looking at the compiler output, I would expect that behavior as well. This is probably a bug, I'll take a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P3: minor bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants