Skip to content

Commit

Permalink
fix: server island hydration (#12444)
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico authored Nov 20, 2024
1 parent ab0580b commit 28dd3ce
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/olive-garlics-marry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fixes an issue where a server island hydration script might fail case the island ID misses from the DOM.
5 changes: 3 additions & 2 deletions packages/astro/src/runtime/server/render/server-islands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ let response = await fetch('${serverIslandUrl}', {
method: 'POST',
body: JSON.stringify(data),
});
if(response.status === 200 && response.headers.get('content-type') === 'text/html') {
if (script) {
if(response.status === 200 && response.headers.get('content-type') === 'text/html') {
let html = await response.text();
// Swap!
Expand All @@ -97,6 +97,7 @@ if(response.status === 200 && response.headers.get('content-type') === 'text/htm
script.before(frag);
}
script.remove();
}
</script>`);
},
};
Expand Down

0 comments on commit 28dd3ce

Please sign in to comment.