diff --git a/packages/integrations/react/vnode-children.js b/packages/integrations/react/vnode-children.js index 0b5738c2cce6..5fd421e67f71 100644 --- a/packages/integrations/react/vnode-children.js +++ b/packages/integrations/react/vnode-children.js @@ -1,9 +1,6 @@ import { parse, DOCUMENT_NODE, ELEMENT_NODE, TEXT_NODE } from 'ultrahtml'; import { createElement, Fragment } from 'react'; -// https://github.com/facebook/react/blob/bbb9cb116dbf7b6247721aa0c4bcb6ec249aa8af/packages/react-dom-bindings/src/server/ReactFizzConfigDOM.js#L3593-L3617 -const selfClosingTags = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'keygen', 'meta', 'param', 'source', 'track', 'wbr'] - let ids = 0; export default function convert(children) { let doc = parse(children.toString().trim()); @@ -11,21 +8,10 @@ export default function convert(children) { let key = 0; function createReactElementFromNode(node) { - if (node.isSelfClosingTag === true && Array.isArray(node.children) && node.children.length === 0) { - node.children = undefined; - } - - const childVnodes = Array.isArray(node.children) + const childVnodes = Array.isArray(node.children) && node.children.length ? node.children - .map((child) => { - if (child.type === ELEMENT_NODE) { - return createReactElementFromNode(child); - } else if (child.type === TEXT_NODE) { - // 0-length text gets omitted in JSX - return child.value.trim() ? child.value : undefined; - } - }) - .filter((n) => !!n) + .map((child) => createReactElementFromNode(child)) + .filter(Boolean) : undefined; if (node.type === DOCUMENT_NODE) { @@ -33,6 +19,9 @@ export default function convert(children) { } else if (node.type === ELEMENT_NODE) { const { class: className, ...props } = node.attributes; return createElement(node.name, { ...props, className, key: `${id}-${key++}` }, childVnodes); + } else if (node.type === TEXT_NODE) { + // 0-length text gets omitted in JSX + return node.value.trim() ? node.value : undefined; } }