Skip to content
Myr

fix(jsx): render a child or odd children with `Fragment` correctly (#1541)

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

* fix(jsx): render a child or odd children with `Fragment` correctly * denoify

authored by Yusuke Wada · committed by GitHub · parent 93fec33 · Browse files · 4 files+46 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

4 files+46 added−4 removed

  • tests:+36 added−0 removed
  • other:+10 added−4 removed

4 files+46 added−4 removed

modified:deno_dist/jsx/index.test.tsx+18 added
401 unmodified lines
402 )403 expect(template.toString()).toBe('<p>1</p><p>2</p>')404 })405406 it('Should render a child', () => {407 const template = (408 <>409 <p>1</p>410 </>411 )412 expect(template.toString()).toBe('<p>1</p>')413 })414415 it('Should render a child - with `Fragment`', () => {416 const template = (417 <Fragment>418 <p>1</p>419 </Fragment>420 )421 expect(template.toString()).toBe('<p>1</p>')422 })423424 it('Should render nothing for empty Fragment', () => {425 const template = <></>426 expect(template.toString()).toBe('')427 })
6 unmodified lines
modified:deno_dist/jsx/index.ts+5 added-2 removed
233 unmodified lines
234 return (computed ||= component(props))235 }) as FC<T>236}237238export const Fragment = (props: { key?: string; children?: Child[] }): HtmlEscapedString => {239 return new JSXFragmentNode('', {}, props.children || []) as never238export const Fragment = (props: {239 key?: string240 children?: Child | HtmlEscapedString241}): HtmlEscapedString => {242 return new JSXFragmentNode('', {}, props.children ? [props.children] : []) as never243}
modified:src/jsx/index.test.tsx+18 added
401 unmodified lines
402 )403 expect(template.toString()).toBe('<p>1</p><p>2</p>')404 })405406 it('Should render a child', () => {407 const template = (408 <>409 <p>1</p>410 </>411 )412 expect(template.toString()).toBe('<p>1</p>')413 })414415 it('Should render a child - with `Fragment`', () => {416 const template = (417 <Fragment>418 <p>1</p>419 </Fragment>420 )421 expect(template.toString()).toBe('<p>1</p>')422 })423424 it('Should render nothing for empty Fragment', () => {425 const template = <></>426 expect(template.toString()).toBe('')427 })
6 unmodified lines
modified:src/jsx/index.ts+5 added-2 removed
233 unmodified lines
234 return (computed ||= component(props))235 }) as FC<T>236}237238export const Fragment = (props: { key?: string; children?: Child[] }): HtmlEscapedString => {239 return new JSXFragmentNode('', {}, props.children || []) as never238export const Fragment = (props: {239 key?: string240 children?: Child | HtmlEscapedString241}): HtmlEscapedString => {242 return new JSXFragmentNode('', {}, props.children ? [props.children] : []) as never243}