-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(slots): consume eagerly rendered slot after one use (#8929)
* render slots lazily * add test * add changeset * refactor * reword changeset
- Loading branch information
Showing
6 changed files
with
59 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'astro': patch | ||
--- | ||
|
||
Fixes an issue where rendering the same slot multiple times invoked it only once. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
packages/astro/test/fixtures/astro-slots/src/components/Random.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
const randomNumber = Math.random(); | ||
--- | ||
<div> | ||
{randomNumber} | ||
</div> |
15 changes: 15 additions & 0 deletions
15
packages/astro/test/fixtures/astro-slots/src/components/RenderMultipleTimes.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
interface Props { | ||
count: number; | ||
} | ||
const {count} = Astro.props; | ||
const renders: string[] = []; | ||
for (let i = 0; i < count; i++) { | ||
renders.push(await Astro.slots.render('default')); | ||
} | ||
--- | ||
|
||
{renders.map( | ||
(render, i) => <Fragment key={i} set:html={render} /> | ||
)} |
7 changes: 7 additions & 0 deletions
7
packages/astro/test/fixtures/astro-slots/src/pages/rendered-multiple-times.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
import RandomCard from '../components/Random.astro'; | ||
import RenderMulti from '../components/RenderMultipleTimes.astro'; | ||
--- | ||
<RenderMulti count={10}> | ||
<RandomCard/> | ||
</RenderMulti> |