Skip to content
Myr

fix(jsx): self-close wrapped empty tags (#4511)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Fix `JSXFunctionNode.prototype.toStringToBuffer` to leave `children` prop unset if there are no children.

authored by Jacob Lee · committed by GitHub · parent fa8eef7 · Browse files · 2 files+12 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+12 added−4 removed

  • tests:+6 added−0 removed
  • other:+6 added−4 removed

2 files+12 added−4 removed

modified:src/jsx/base.test.tsx+6 added
modified:src/jsx/base.ts+6 added-4 removed
243 unmodified lines
244class JSXFunctionNode extends JSXNode {245 override toStringToBuffer(buffer: StringBufferWithCallbacks): void {246 const { children } = this247248 const res = (this.tag as Function).call(null, {249 ...this.props,250 children: children.length <= 1 ? children[0] : children,251 })248 const props = { ...this.props }249 if (children.length) {250 props.children = children.length === 1 ? children[0] : children251 }252253 const res = (this.tag as Function).call(null, props)254255 if (typeof res === 'boolean' || res == null) {256 // boolean or null or undefined257 return258 } else if (res instanceof Promise) {
184 unmodified lines