Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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/tough-tires-kneel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Makes server island work with the client router again.
12 changes: 6 additions & 6 deletions packages/astro/src/runtime/server/render/server-islands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export function renderServerIsland(
);
}

destination.write(`<script async type="module" data-island-id="${hostId}">
destination.write(`<script async type="module" data-astro-rerun data-island-id="${hostId}">
let script = document.querySelector('script[data-island-id="${hostId}"]');

${
Expand All @@ -128,23 +128,23 @@ let response = await fetch('${serverIslandUrl}', {
}
if (script) {
if(
response.status === 200
&& response.headers.has('content-type')
response.status === 200
&& response.headers.has('content-type')
&& response.headers.get('content-type').split(";")[0].trim() === 'text/html') {
let html = await response.text();

// Swap!
while(script.previousSibling &&
script.previousSibling.nodeType !== 8 &&
script.previousSibling.data !== '[if astro]>server-island-start<![endif]') {
script.previousSibling.remove();
}
script.previousSibling?.remove();

let frag = document.createRange().createContextualFragment(html);
script.before(frag);
}
script.remove();
script.remove(); // Prior to v5.4.2, this was the trick to force rerun of scripts. Keeping it to minimize change to the existing behavior.
}
</script>`);
},
Expand Down
Loading