diff --git a/.changeset/dirty-boats-suffer.md b/.changeset/dirty-boats-suffer.md
new file mode 100644
index 0000000000..9ca1d994a6
--- /dev/null
+++ b/.changeset/dirty-boats-suffer.md
@@ -0,0 +1,5 @@
+---
+"astro": patch
+---
+
+Fix dynamic slots missing hydration scripts
diff --git a/packages/astro/src/core/render/result.ts b/packages/astro/src/core/render/result.ts
index cc7fa219e9..1e6f6f35a1 100644
--- a/packages/astro/src/core/render/result.ts
+++ b/packages/astro/src/core/render/result.ts
@@ -114,7 +114,7 @@ class Slots {
const slot = async () =>
typeof expression === 'function' ? expression(...args) : expression;
return await renderSlotToString(result, slot).then((res) => {
- return res != null ? String(res) : res;
+ return res;
});
}
// JSX
diff --git a/packages/astro/src/runtime/server/escape.ts b/packages/astro/src/runtime/server/escape.ts
index 879f1e75bf..b7bf60c3c8 100644
--- a/packages/astro/src/runtime/server/escape.ts
+++ b/packages/astro/src/runtime/server/escape.ts
@@ -101,6 +101,8 @@ export function unescapeHTML(
return Promise.resolve(str).then((value) => {
return unescapeHTML(value);
});
+ } else if(str[Symbol.for('astro:slot-string')]) {
+ return str;
} else if (Symbol.iterator in str) {
return unescapeChunks(str);
} else if (Symbol.asyncIterator in str || hasGetReader(str)) {
diff --git a/packages/astro/test/fixtures/hydration-race/src/components/WithSlot.astro b/packages/astro/test/fixtures/hydration-race/src/components/WithSlot.astro
new file mode 100644
index 0000000000..f6edb24ebb
--- /dev/null
+++ b/packages/astro/test/fixtures/hydration-race/src/components/WithSlot.astro
@@ -0,0 +1,16 @@
+---
+const getHtml = async () => {
+ if(Astro.slots.has("default")) {
+ let output = await Astro.slots.render("default", [{
+ foo: "bar"
+ }]);
+ return output;
+ } else {
+ return "";
+ }
+};
+
+---
+
+
+