From e24c9ffa0be211b93918302be3cc9893c4004320 Mon Sep 17 00:00:00 2001 From: StandardGage <50509562+StandardGage@users.noreply.github.com> Date: Thu, 1 Feb 2024 20:25:31 -0500 Subject: [PATCH 1/4] Create simple react element if element has no children --- packages/integrations/react/client.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/integrations/react/client.js b/packages/integrations/react/client.js index cef488c83bc4..1b8d5be8337e 100644 --- a/packages/integrations/react/client.js +++ b/packages/integrations/react/client.js @@ -16,6 +16,11 @@ function createReactElementFromDOMElement(element) { attrs[attr.name] = attr.value; } + // If the element has no children, we can create a simple React element + if (element.children.length === 0) { + return createElement(element.localName, attrs); + } + return createElement( element.localName, attrs, From 51b8e95601cb8289cf385c296f1eeabee157a86d Mon Sep 17 00:00:00 2001 From: StandardGage <50509562+StandardGage@users.noreply.github.com> Date: Thu, 1 Feb 2024 20:38:15 -0500 Subject: [PATCH 2/4] Fix for when element has text --- packages/integrations/react/client.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/integrations/react/client.js b/packages/integrations/react/client.js index 1b8d5be8337e..90e4ceb837b5 100644 --- a/packages/integrations/react/client.js +++ b/packages/integrations/react/client.js @@ -15,9 +15,8 @@ function createReactElementFromDOMElement(element) { for (const attr of element.attributes) { attrs[attr.name] = attr.value; } - // If the element has no children, we can create a simple React element - if (element.children.length === 0) { + if (element.firstChild === null) { return createElement(element.localName, attrs); } From c0d456a747023b2640b6db2357447e61bf370b88 Mon Sep 17 00:00:00 2001 From: StandardGage <50509562+StandardGage@users.noreply.github.com> Date: Fri, 2 Feb 2024 21:00:56 -0500 Subject: [PATCH 3/4] add changeset --- .changeset/metal-penguins-drum.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/metal-penguins-drum.md diff --git a/.changeset/metal-penguins-drum.md b/.changeset/metal-penguins-drum.md new file mode 100644 index 000000000000..deb59d4a96b1 --- /dev/null +++ b/.changeset/metal-penguins-drum.md @@ -0,0 +1,5 @@ +--- +"@astrojs/react": minor +--- + +Fixes an issue where passing void elements (img, etc..) did not work with the `experimentalReactChildren` option enabled From ccc7a51a0c9f3849b6e56699e086ca994e939e82 Mon Sep 17 00:00:00 2001 From: Arsh <69170106+lilnasy@users.noreply.github.com> Date: Mon, 5 Feb 2024 18:50:32 +0530 Subject: [PATCH 4/4] minor -> patch --- .changeset/metal-penguins-drum.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/metal-penguins-drum.md b/.changeset/metal-penguins-drum.md index deb59d4a96b1..cd740f6e558c 100644 --- a/.changeset/metal-penguins-drum.md +++ b/.changeset/metal-penguins-drum.md @@ -1,5 +1,5 @@ --- -"@astrojs/react": minor +"@astrojs/react": patch --- Fixes an issue where passing void elements (img, etc..) did not work with the `experimentalReactChildren` option enabled