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:
parent
9836dddf82
commit
20ca3154fb
2 changed files with 9 additions and 0 deletions
5
.changeset/metal-penguins-drum.md
Normal file
5
.changeset/metal-penguins-drum.md
Normal 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
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Reference in a new issue