Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/server-island-slot-scripts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fix: include `<script>` tags from components passed as slots to `server:defer` components in the server island response
Comment thread
jwoyo marked this conversation as resolved.
Outdated
15 changes: 14 additions & 1 deletion packages/astro/src/runtime/server/render/server-islands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,20 @@ export class ServerIslandComponent {
for (const name in this.slots) {
if (name !== 'fallback') {
const content = await renderSlotToString(this.result, this.slots[name]);
renderedSlots[name] = content.toString();
let slotHtml = content.toString();
// Append script instructions so that components passed as slots
// to server:defer components retain their scripts in the island response.
// renderSlotToString returns a SlotString (typed as string) that carries
// render instructions stripped from the HTML content.
const slotContent = content as unknown as import('./slot.js').SlotString;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you use ar regular top-level type import here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, that should work. This was an oversight and there no particular reason for this kind of import.

if (Array.isArray(slotContent.instructions)) {
for (const instruction of slotContent.instructions) {
if (instruction.type === 'script') {
slotHtml += instruction.content;
}
}
}
renderedSlots[name] = slotHtml;
}
}

Expand Down
Loading