Skip to content

Commit

Permalink
Fix Issues with passing void elements to React with `experimentalReac…
Browse files Browse the repository at this point in the history
…tChildren` flag set (#9849)

* Create simple react element if element has no children

* Fix for when element has text

* add changeset

* minor -> patch

---------

Co-authored-by: Arsh <[email protected]>
Co-authored-by: Nate Moore <[email protected]>
  • Loading branch information
3 people authored Feb 7, 2024
1 parent 9836ddd commit 20ca315
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/metal-penguins-drum.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@astrojs/react": patch
---

Fixes an issue where passing void elements (img, etc..) did not work with the `experimentalReactChildren` option enabled
4 changes: 4 additions & 0 deletions packages/integrations/react/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ 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.firstChild === null) {
return createElement(element.localName, attrs);
}

return createElement(
element.localName,
Expand Down

0 comments on commit 20ca315

Please sign in to comment.