Skip to content

Commit

Permalink
Element: Fix Fragment render error on empty children (#6711)
Browse files Browse the repository at this point in the history
  • Loading branch information
aduth committed May 14, 2018
1 parent be88c3c commit 73f2331
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 4 additions & 2 deletions element/serialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,14 +406,14 @@ export function renderNativeComponent( type, props, context = {} ) {
// Textarea children can be assigned as value prop. If it is, render in
// place of children. Ensure to omit so it is not assigned as attribute
// as well.
content = renderChildren( [ props.value ], context );
content = renderChildren( props.value, context );
props = omit( props, 'value' );
} else if ( props.dangerouslySetInnerHTML &&
typeof props.dangerouslySetInnerHTML.__html === 'string' ) {
// Dangerous content is left unescaped.
content = props.dangerouslySetInnerHTML.__html;
} else if ( typeof props.children !== 'undefined' ) {
content = renderChildren( castArray( props.children ), context );
content = renderChildren( props.children, context );
}

if ( ! type ) {
Expand Down Expand Up @@ -465,6 +465,8 @@ export function renderComponent( Component, props, context = {} ) {
function renderChildren( children, context = {} ) {
let result = '';

children = castArray( children );

for ( let i = 0; i < children.length; i++ ) {
const child = children[ i ];

Expand Down
6 changes: 6 additions & 0 deletions element/test/serialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,12 @@ describe( 'renderElement()', () => {
expect( result ).toBe( 'Hello' );
} );

it( 'renders Fragment with undefined children', () => {
const result = renderElement( <Fragment /> );

expect( result ).toBe( '' );
} );

it( 'renders RawHTML as its unescaped children', () => {
const result = renderElement( <RawHTML>{ '<img/>' }</RawHTML> );

Expand Down

0 comments on commit 73f2331

Please sign in to comment.