Skip to content

Commit 0c78d46

Browse files
committed
Merge pull request #338 from tgriesser/fix-337
Fix #337, update impure component with custom mergeProps
2 parents 2d5ee79 + 1d89974 commit 0c78d46

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/components/connect.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ export default function connect(mapStateToProps, mapDispatchToProps, mergeProps,
3939
mapDispatchToProps || defaultMapDispatchToProps
4040

4141
const finalMergeProps = mergeProps || defaultMergeProps
42-
const checkMergedEquals = finalMergeProps !== defaultMergeProps
4342
const { pure = true, withRef = false } = options
43+
const checkMergedEquals = pure && finalMergeProps !== defaultMergeProps
4444

4545
// Helps track hot reloading.
4646
const version = nextVersion++

test/components/connect.spec.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,5 +1639,38 @@ describe('React', () => {
16391639
expect(mapStateCalls).toBe(2)
16401640
expect(renderCalls).toBe(1)
16411641
})
1642+
1643+
it('should update impure components with custom mergeProps', () => {
1644+
let store = createStore(() => ({}))
1645+
let renderCount = 0
1646+
1647+
@connect(null, null, () => ({ a: 1 }), { pure: false })
1648+
class Container extends React.Component {
1649+
render() {
1650+
++renderCount
1651+
return <div />
1652+
}
1653+
}
1654+
1655+
class Parent extends React.Component {
1656+
componentDidMount() {
1657+
this.forceUpdate()
1658+
}
1659+
render() {
1660+
return <Container />
1661+
}
1662+
}
1663+
1664+
TestUtils.renderIntoDocument(
1665+
<ProviderMock store={store}>
1666+
<Parent>
1667+
<Container />
1668+
</Parent>
1669+
</ProviderMock>
1670+
)
1671+
1672+
expect(renderCount).toBe(2)
1673+
})
1674+
16421675
})
16431676
})

0 commit comments

Comments
 (0)