File tree Expand file tree Collapse file tree 3 files changed +8
-8
lines changed Expand file tree Collapse file tree 3 files changed +8
-8
lines changed Original file line number Diff line number Diff line change 1
1
import { PropTypes } from 'react'
2
2
3
3
// Works around issues with context updates failing to propagate.
4
+ // Caveat: the context value is expected to never change its identity.
4
5
// https://github.com/facebook/react/issues/2517
5
6
// https://github.com/reactjs/react-router/issues/470
6
7
@@ -43,9 +44,8 @@ export function ContextProvider(name) {
43
44
} ,
44
45
45
46
componentDidUpdate ( ) {
46
- const nextValue = this . getChildContext ( ) [ name ]
47
47
this [ listenersKey ] . forEach ( listener =>
48
- listener ( this [ eventIndexKey ] , nextValue )
48
+ listener ( this [ eventIndexKey ] )
49
49
)
50
50
} ,
51
51
@@ -112,12 +112,8 @@ export function ContextSubscriber(name) {
112
112
this [ unsubscribeKey ] = null
113
113
} ,
114
114
115
- [ handleContextUpdateKey ] ( eventIndex , nextValue ) {
115
+ [ handleContextUpdateKey ] ( eventIndex ) {
116
116
if ( eventIndex !== this . state [ lastRenderedEventIndexKey ] ) {
117
- if ( this . context [ name ] !== nextValue ) {
118
- // React uses a stale value so we update it manually.
119
- this . context [ name ] = nextValue
120
- }
121
117
this . setState ( { [ lastRenderedEventIndexKey ] : eventIndex } )
122
118
}
123
119
}
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import RouterContext from './RouterContext'
6
6
import { createRoutes } from './RouteUtils'
7
7
import { createRouterObject } from './RouterUtils'
8
8
import warning from './routerWarning'
9
+ import assign from 'object-assign'
9
10
10
11
const { func, object } = React . PropTypes
11
12
@@ -88,7 +89,9 @@ const Router = React.createClass({
88
89
if ( error ) {
89
90
this . handleError ( error )
90
91
} else {
91
- this . router = this . createRouterObject ( state )
92
+ // Keep the identity of this.router because of a caveat in ContextUtils:
93
+ // they only work if the object identity is preserved.
94
+ assign ( this . router , this . createRouterObject ( state ) )
92
95
this . setState ( state , this . props . onUpdate )
93
96
}
94
97
} )
Original file line number Diff line number Diff line change 35
35
"history" : " ^2.0.1" ,
36
36
"hoist-non-react-statics" : " ^1.0.5" ,
37
37
"invariant" : " ^2.2.1" ,
38
+ "object-assign" : " ^4.1.0" ,
38
39
"warning" : " ^2.1.0"
39
40
},
40
41
"peerDependencies" : {
You can’t perform that action at this time.
0 commit comments