@@ -5,6 +5,8 @@ import { Component, PropTypes, createElement } from 'react'
55import Subscription from '../utils/Subscription'
66import storeShape from '../utils/storeShape'
77
8+
9+ let defaultReact15CompatibilityMode = true
810let hotReloadingVersion = 0
911export default function connectAdvanced (
1012 /*
@@ -18,7 +20,7 @@ export default function connectAdvanced(
1820
1921 Access to dispatch is provided to the factory so selectorFactories can bind actionCreators
2022 outside of their selector as an optimization. Options passed to connectAdvanced are passed to
21- the selectorFactory, along with displayName and WrappedComponent, as the second argument.
23+ the selectorFactory, along with displayName and WrappedComponent, as the second argument.
2224
2325 Note that selectorFactory is responsible for all caching/memoization of inbound and outbound
2426 props. Do not use connectAdvanced directly without memoizing results between calls to your
@@ -35,6 +37,9 @@ export default function connectAdvanced(
3537 // probably overridden by wrapper functions such as connect()
3638 methodName = 'connectAdvanced' ,
3739
40+ // temporary compatibility setting for React 15. See Connect constructor for details
41+ react15CompatibilityMode = undefined ,
42+
3843 // if defined, the name of the property passed to the wrapped element indicating the number of
3944 // calls to render. useful for watching in react devtools for unnecessary re-renders.
4045 renderCountProp = undefined ,
@@ -57,11 +62,12 @@ export default function connectAdvanced(
5762
5863 const contextTypes = {
5964 [ storeKey ] : storeShape ,
60- [ subscriptionKey ] : PropTypes . instanceOf ( Subscription )
65+ [ subscriptionKey ] : PropTypes . instanceOf ( Subscription ) ,
66+ react15CompatibilityMode : PropTypes . bool ,
6167 }
6268 const childContextTypes = {
6369 [ subscriptionKey ] : PropTypes . instanceOf ( Subscription )
64- }
70+ }
6571
6672 return function wrapWithConnect ( WrappedComponent ) {
6773 invariant (
@@ -97,7 +103,19 @@ export default function connectAdvanced(
97103 this . state = { }
98104 this . renderCount = 0
99105 this . store = this . props [ storeKey ] || this . context [ storeKey ]
100- this . parentSub = this . props [ subscriptionKey ] || this . context [ subscriptionKey ]
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 ]
118+
101119 this . setWrappedInstance = this . setWrappedInstance . bind ( this )
102120
103121 invariant ( this . store ,
@@ -257,3 +275,9 @@ export default function connectAdvanced(
257275 return hoistStatics ( Connect , WrappedComponent )
258276 }
259277}
278+
279+ connectAdvanced . setDefaultReact15CompatibilityMode =
280+ function setDefaultReact15CompatibilityMode ( compat ) {
281+ defaultReact15CompatibilityMode = compat
282+ }
283+
0 commit comments