summaryrefslogtreecommitdiff
path: root/packages/integrations/react/server.js
diff options
context:
space:
mode:
authorGravatar Matthew Phillips <matthew@skypack.dev> 2023-05-17 10:18:04 -0400
committerGravatar GitHub <noreply@github.com> 2023-05-17 10:18:04 -0400
commit3d525efc95cfb2deb5d9e04856d02965d66901c9 (patch)
treeaf1973aede0d2950d94b7ebfc957770be214446c /packages/integrations/react/server.js
parente9fc2c2213036d47cd30a47a6cdad5633481a0f8 (diff)
downloadastro-3d525efc95cfb2deb5d9e04856d02965d66901c9.tar.gz
astro-3d525efc95cfb2deb5d9e04856d02965d66901c9.tar.zst
astro-3d525efc95cfb2deb5d9e04856d02965d66901c9.zip
Prevent removal of nested slots within islands (#7093)
* Prevent removal of nested slots within islands * Fix build errors
Diffstat (limited to 'packages/integrations/react/server.js')
-rw-r--r--packages/integrations/react/server.js17
1 files changed, 15 insertions, 2 deletions
diff --git a/packages/integrations/react/server.js b/packages/integrations/react/server.js
index 3f7e786ac..e84b8bf27 100644
--- a/packages/integrations/react/server.js
+++ b/packages/integrations/react/server.js
@@ -58,6 +58,11 @@ async function getNodeWritable() {
return Writable;
}
+function needsHydration(metadata) {
+ // Adjust how this is hydrated only when the version of Astro supports `astroStaticSlot`
+ return metadata.astroStaticSlot ? !!metadata.hydrate : true;
+}
+
async function renderToStaticMarkup(Component, props, { default: children, ...slotted }, metadata) {
let prefix;
if (this && this.result) {
@@ -69,7 +74,11 @@ async function renderToStaticMarkup(Component, props, { default: children, ...sl
const slots = {};
for (const [key, value] of Object.entries(slotted)) {
const name = slotName(key);
- slots[name] = React.createElement(StaticHtml, { value, name });
+ slots[name] = React.createElement(StaticHtml, {
+ hydrate: needsHydration(metadata),
+ value,
+ name
+ });
}
// Note: create newProps to avoid mutating `props` before they are serialized
const newProps = {
@@ -78,7 +87,10 @@ async function renderToStaticMarkup(Component, props, { default: children, ...sl
};
const newChildren = children ?? props.children;
if (newChildren != null) {
- newProps.children = React.createElement(StaticHtml, { value: newChildren });
+ newProps.children = React.createElement(StaticHtml, {
+ hydrate: needsHydration(metadata),
+ value: newChildren
+ });
}
const vnode = React.createElement(Component, newProps);
const renderOptions = {
@@ -182,4 +194,5 @@ async function renderToReadableStreamAsync(vnode, options) {
export default {
check,
renderToStaticMarkup,
+ supportsAstroStaticSlot: true,
};