Skip to content

Commit

Permalink
Fix crash when component returns nested array from render()
Browse files Browse the repository at this point in the history
  • Loading branch information
Vadim Demedes committed Jul 16, 2017
1 parent 1eeda02 commit 0db786e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/instance.js
@@ -1,6 +1,7 @@
'use strict';

const PropTypes = require('prop-types');
const flatten = require('lodash.flattendeep');
const arrify = require('arrify');
const Div = require('./components/div');
const Span = require('./components/span');
Expand Down Expand Up @@ -62,7 +63,7 @@ class Instance {
}

set children(nextChildren) {
this.vnode.children = arrify(nextChildren);
this.vnode.children = flatten(arrify(nextChildren));

return nextChildren;
}
Expand Down
15 changes: 15 additions & 0 deletions test/components.js
Expand Up @@ -142,6 +142,21 @@ test('rerender nested components', t => {
t.is(renderToString(finalTree), 'C');
});

// Regression test for crash caused by <div> returning an array
// of children and a newline, e.g. [[A, B], '\n']
test('render deeply nested components', t => {
const A = () => 'A';
const B = () => 'B';
const Test = () => (
<div>
<A/>
<B/>
</div>
);

t.is(renderToString(build(<Test/>)), 'AB\n');
});

test('render children', t => {
class World extends Component {
render() {
Expand Down

0 comments on commit 0db786e

Please sign in to comment.