Skip to content

Commit 1edb697

Browse files
committed
Merge pull request #50 from istarkov/master
Fix undefined children does not update children in state
2 parents b695023 + a1667b8 commit 1edb697

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

src/components/createConnect.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,13 @@ export default function createConnect(React) {
131131
recomputeState(props = this.props) {
132132
const nextState = this.computeNextState(props);
133133
if (!shallowEqual(nextState, this.state)) {
134-
this.setState(nextState);
134+
this.setState({
135+
...Object.keys(this.state)
136+
.reduce((r, k) => ({
137+
[k]: undefined
138+
}), {}),
139+
...nextState,
140+
});
135141
}
136142
}
137143

test/components/connect.spec.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,51 @@ describe('React', () => {
180180
expect(div.props.pass).toEqual('through');
181181
});
182182

183+
it('should remove undefined props', () => {
184+
const store = createStore(() => ({}));
185+
let props = {x: true};
186+
let container;
187+
188+
@connect(()=>({}), ()=>({}))
189+
class ConnectContainer extends Component {
190+
render() {
191+
return (
192+
<div {...this.props} />
193+
);
194+
}
195+
}
196+
197+
class HolderContainer extends Component {
198+
render() {
199+
return (
200+
<ConnectContainer {...props} />
201+
);
202+
}
203+
}
204+
205+
TestUtils.renderIntoDocument(
206+
<Provider store={store}>
207+
{() => (
208+
<HolderContainer ref={instance => container = instance} />
209+
)}
210+
</Provider>
211+
);
212+
213+
const propsBefore = {
214+
...TestUtils.findRenderedDOMComponentWithTag(container, 'div').props
215+
};
216+
217+
props = {};
218+
container.forceUpdate();
219+
220+
const propsAfter = {
221+
...TestUtils.findRenderedDOMComponentWithTag(container, 'div').props
222+
};
223+
224+
expect(propsBefore.x).toEqual(true);
225+
expect(propsAfter.x).toNotEqual(true);
226+
});
227+
183228
it('should ignore deep mutations in props', () => {
184229
const store = createStore(() => ({
185230
foo: 'bar'

0 commit comments

Comments
 (0)