diff --git a/.changeset/olive-garlics-marry.md b/.changeset/olive-garlics-marry.md new file mode 100644 index 000000000000..342db3a6f691 --- /dev/null +++ b/.changeset/olive-garlics-marry.md @@ -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. diff --git a/packages/astro/src/runtime/server/render/server-islands.ts b/packages/astro/src/runtime/server/render/server-islands.ts index 6dd06b8d7b1a..b8ac34024ae2 100644 --- a/packages/astro/src/runtime/server/render/server-islands.ts +++ b/packages/astro/src/runtime/server/render/server-islands.ts @@ -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! @@ -97,6 +97,7 @@ if(response.status === 200 && response.headers.get('content-type') === 'text/htm script.before(frag); } script.remove(); +} `); }, };