File tree Expand file tree Collapse file tree 2 files changed +52
-1
lines changed Expand file tree Collapse file tree 2 files changed +52
-1
lines changed Original file line number Diff line number Diff line change @@ -131,7 +131,13 @@ export default function createConnect(React) {
131
131
recomputeState ( props = this . props ) {
132
132
const nextState = this . computeNextState ( props ) ;
133
133
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
+ } ) ;
135
141
}
136
142
}
137
143
Original file line number Diff line number Diff line change @@ -180,6 +180,51 @@ describe('React', () => {
180
180
expect ( div . props . pass ) . toEqual ( 'through' ) ;
181
181
} ) ;
182
182
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
+
183
228
it ( 'should ignore deep mutations in props' , ( ) => {
184
229
const store = createStore ( ( ) => ( {
185
230
foo : 'bar'
You can’t perform that action at this time.
0 commit comments