0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-01-20 22:12:38 -05:00

Fix Issues with passing void elements to React with experimentalReactChildren 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 <69170106+lilnasy@users.noreply.github.com>
Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com>
This commit is contained in:
StandardGage 2024-02-07 13:08:44 -05:00 committed by GitHub
parent 9836dddf82
commit 20ca3154fb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 0 deletions

View file

@ -0,0 +1,5 @@
---
"@astrojs/react": patch
---
Fixes an issue where passing void elements (img, etc..) did not work with the `experimentalReactChildren` option enabled

View file

@ -15,6 +15,10 @@ function createReactElementFromDOMElement(element) {
for (const attr of element.attributes) { for (const attr of element.attributes) {
attrs[attr.name] = attr.value; 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( return createElement(
element.localName, element.localName,