Skip to content

Commit 6bbcb53

Browse files
jimbollatimdorr
authored andcommitted
Fixes reduxjs#525 (cursor bug) by moving notify from setState callback to componentDidUpdate. (reduxjs#557)
* Fixes reduxjs#525 (cursor bug) by moving notify from setState callback to cDU. This also eliminates react15CompatibilityMode stopgap setting. See: reduxjs#525 (comment) for discussion. * Optimizes perf of previous commit.
1 parent 72e9517 commit 6bbcb53

File tree

4 files changed

+10
-31
lines changed

4 files changed

+10
-31
lines changed

src/components/connectAdvanced.js

+7-26
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import { Component, PropTypes, createElement } from 'react'
55
import Subscription from '../utils/Subscription'
66
import storeShape from '../utils/storeShape'
77

8-
9-
let defaultReact15CompatibilityMode = true
108
let hotReloadingVersion = 0
119
export default function connectAdvanced(
1210
/*
@@ -37,9 +35,6 @@ export default function connectAdvanced(
3735
// probably overridden by wrapper functions such as connect()
3836
methodName = 'connectAdvanced',
3937

40-
// temporary compatibility setting for React 15. See Connect constructor for details
41-
react15CompatibilityMode = undefined,
42-
4338
// if defined, the name of the property passed to the wrapped element indicating the number of
4439
// calls to render. useful for watching in react devtools for unnecessary re-renders.
4540
renderCountProp = undefined,
@@ -63,7 +58,6 @@ export default function connectAdvanced(
6358
const contextTypes = {
6459
[storeKey]: storeShape,
6560
[subscriptionKey]: PropTypes.instanceOf(Subscription),
66-
react15CompatibilityMode: PropTypes.bool,
6761
}
6862
const childContextTypes = {
6963
[subscriptionKey]: PropTypes.instanceOf(Subscription)
@@ -103,18 +97,7 @@ export default function connectAdvanced(
10397
this.state = {}
10498
this.renderCount = 0
10599
this.store = this.props[storeKey] || this.context[storeKey]
106-
107-
// react15CompatibilityMode controls whether the subscription system is used. This is for
108-
// https://github.com/reactjs/react-redux/issues/525 and should be removed completely when
109-
// react-redux's dependency on react is bumped to mimimum v16, which is expected to include
110-
// PR https://github.com/facebook/react/pull/8204 which fixes the issue.
111-
const compatMode = [
112-
react15CompatibilityMode,
113-
props.react15CompatibilityMode,
114-
context.react15CompatibilityMode,
115-
defaultReact15CompatibilityMode
116-
].find(cm => cm !== undefined && cm !== null)
117-
this.parentSub = compatMode ? null : props[subscriptionKey] || context[subscriptionKey]
100+
this.parentSub = props[subscriptionKey] || context[subscriptionKey]
118101

119102
this.setWrappedInstance = this.setWrappedInstance.bind(this)
120103

@@ -209,7 +192,6 @@ export default function connectAdvanced(
209192
initSubscription() {
210193
if (shouldHandleStateChanges) {
211194
const subscription = this.subscription = new Subscription(this.store, this.parentSub)
212-
const notifyNestedSubs = subscription.notifyNestedSubs.bind(subscription)
213195
const dummyState = {}
214196

215197
subscription.onStateChange = function onStateChange() {
@@ -218,7 +200,12 @@ export default function connectAdvanced(
218200
if (!this.selector.shouldComponentUpdate) {
219201
subscription.notifyNestedSubs()
220202
} else {
221-
this.setState(dummyState, notifyNestedSubs)
203+
this.componentDidUpdate = function componentDidUpdate() {
204+
this.componentDidUpdate = undefined
205+
subscription.notifyNestedSubs()
206+
}
207+
208+
this.setState(dummyState)
222209
}
223210
}.bind(this)
224211
}
@@ -275,9 +262,3 @@ export default function connectAdvanced(
275262
return hoistStatics(Connect, WrappedComponent)
276263
}
277264
}
278-
279-
connectAdvanced.setDefaultReact15CompatibilityMode =
280-
function setDefaultReact15CompatibilityMode(compat) {
281-
defaultReact15CompatibilityMode = compat
282-
}
283-

src/connect/connect.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,4 @@ export function createConnect({
8787
}
8888
}
8989

90-
const connect = createConnect()
91-
connect.setDefaultReact15CompatibilityMode = connectAdvanced.setDefaultReact15CompatibilityMode
92-
export default connect
90+
export default createConnect()

test/components/Provider.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ describe('React', () => {
144144
// The state from parent props should always be consistent with the current state
145145
expect(state).toEqual(parentProps.parentState)
146146
return {}
147-
}, null, null, { react15CompatibilityMode: false })
147+
})
148148
class ChildContainer extends Component {
149149
render() {
150150
return <div />

test/components/connect.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1697,7 +1697,7 @@ describe('React', () => {
16971697
// The state from parent props should always be consistent with the current state
16981698
expect(state).toEqual(parentProps.parentState)
16991699
return {}
1700-
}, null, null, { react15CompatibilityMode: false })
1700+
})
17011701
class ChildContainer extends Component {
17021702
render() {
17031703
return <Passthrough {...this.props}/>

0 commit comments

Comments
 (0)