@@ -5,6 +5,8 @@ import { Component, PropTypes, createElement } from 'react'
5
5
import Subscription from '../utils/Subscription'
6
6
import storeShape from '../utils/storeShape'
7
7
8
+
9
+ let defaultReact15CompatibilityMode = true
8
10
let hotReloadingVersion = 0
9
11
export default function connectAdvanced (
10
12
/*
@@ -18,7 +20,7 @@ export default function connectAdvanced(
18
20
19
21
Access to dispatch is provided to the factory so selectorFactories can bind actionCreators
20
22
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.
22
24
23
25
Note that selectorFactory is responsible for all caching/memoization of inbound and outbound
24
26
props. Do not use connectAdvanced directly without memoizing results between calls to your
@@ -35,6 +37,9 @@ export default function connectAdvanced(
35
37
// probably overridden by wrapper functions such as connect()
36
38
methodName = 'connectAdvanced' ,
37
39
40
+ // temporary compatibility setting for React 15. See Connect constructor for details
41
+ react15CompatibilityMode = undefined ,
42
+
38
43
// if defined, the name of the property passed to the wrapped element indicating the number of
39
44
// calls to render. useful for watching in react devtools for unnecessary re-renders.
40
45
renderCountProp = undefined ,
@@ -57,11 +62,12 @@ export default function connectAdvanced(
57
62
58
63
const contextTypes = {
59
64
[ storeKey ] : storeShape ,
60
- [ subscriptionKey ] : PropTypes . instanceOf ( Subscription )
65
+ [ subscriptionKey ] : PropTypes . instanceOf ( Subscription ) ,
66
+ react15CompatibilityMode : PropTypes . bool ,
61
67
}
62
68
const childContextTypes = {
63
69
[ subscriptionKey ] : PropTypes . instanceOf ( Subscription )
64
- }
70
+ }
65
71
66
72
return function wrapWithConnect ( WrappedComponent ) {
67
73
invariant (
@@ -97,7 +103,19 @@ export default function connectAdvanced(
97
103
this . state = { }
98
104
this . renderCount = 0
99
105
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
+
101
119
this . setWrappedInstance = this . setWrappedInstance . bind ( this )
102
120
103
121
invariant ( this . store ,
@@ -257,3 +275,9 @@ export default function connectAdvanced(
257
275
return hoistStatics ( Connect , WrappedComponent )
258
276
}
259
277
}
278
+
279
+ connectAdvanced . setDefaultReact15CompatibilityMode =
280
+ function setDefaultReact15CompatibilityMode ( compat ) {
281
+ defaultReact15CompatibilityMode = compat
282
+ }
283
+
0 commit comments