Skip to content

Commit

Permalink
fix: condition render in Fragments #942 (#943)
Browse files Browse the repository at this point in the history
  • Loading branch information
theKashey authored and gregberge committed Apr 24, 2018
1 parent acb6bf1 commit 2549a18
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/reconciler/hotReplacementRender.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ const mergeInject = (a, b, instance) => {
const transformFlowNode = flow =>
flow.reduce((acc, node) => {
if (isFragmentNode(node) && node.props && node.props.children) {
return [...acc, ...node.props.children]
return [...acc, ...filterNullArray(node.props.children)]
}
return [...acc, node]
}, [])
Expand Down
14 changes: 12 additions & 2 deletions test/AppContainer.dev.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1889,7 +1889,10 @@ describe(`AppContainer (dev)`, () => {

const InnerItem = () => (
<React.Fragment>
{false && <div>hole</div>}
-1-<InnerComponent />
{false && <div>hole</div>}
-3-<InnerComponent />
</React.Fragment>
)
RHL.register(InnerItem, 'InnerItem', 'test.js')
Expand All @@ -1916,7 +1919,9 @@ describe(`AppContainer (dev)`, () => {
</AppContainer>,
)

expect(wrapper.update().text()).toBe('1-1-OldInnerComponent3')
expect(wrapper.update().text()).toBe(
'1-1-OldInnerComponent-3-OldInnerComponent3',
)
{
class InnerComponent extends Component {
componentWillUnmount() {
Expand All @@ -1932,15 +1937,20 @@ describe(`AppContainer (dev)`, () => {

const InnerItem = () => (
<React.Fragment>
{false && <div>hole</div>}
-2-<InnerComponent />
{false && <div>hole</div>}
-3-<InnerComponent />
</React.Fragment>
)
RHL.register(InnerItem, 'InnerItem', 'test.js')

wrapper.setProps({ children: <App /> })
}
expect(unmount).toHaveBeenCalledTimes(0)
expect(wrapper.update().text()).toBe('1-2-NewInnerComponent3')
expect(wrapper.update().text()).toBe(
'1-2-NewInnerComponent-3-NewInnerComponent3',
)
} else {
// React 15 is always ok
expect(true).toBe(true)
Expand Down

0 comments on commit 2549a18

Please sign in to comment.