File tree Expand file tree Collapse file tree 2 files changed +41
-3
lines changed Expand file tree Collapse file tree 2 files changed +41
-3
lines changed Original file line number Diff line number Diff line change @@ -69,8 +69,11 @@ export function diff(
6969 // If the previous diff bailed out, resume creating/hydrating.
7070 if ( oldVNode . _flags & MODE_SUSPENDED ) {
7171 isHydrating = ! ! ( oldVNode . _flags & MODE_HYDRATE ) ;
72- excessDomChildren = oldVNode . _component . _excess ;
73- oldDom = newVNode . _dom = oldVNode . _dom = excessDomChildren [ 0 ] ;
72+ if ( oldVNode . _component . _excess ) {
73+ excessDomChildren = oldVNode . _component . _excess ;
74+ oldDom = newVNode . _dom = oldVNode . _dom = excessDomChildren [ 0 ] ;
75+ oldVNode . _component . _excess = null ;
76+ }
7477 }
7578
7679 if ( ( tmp = options . _diff ) ) tmp ( newVNode ) ;
Original file line number Diff line number Diff line change @@ -129,7 +129,42 @@ describe('createContext', () => {
129129 expect ( renders ) . to . equal ( 1 ) ;
130130 } ) ;
131131
132- it ( 'should preserve provider context through nesting providers' , async ( ) => {
132+ it ( 'skips referentially equal children to Provider w/ dom-node in between' , ( ) => {
133+ const { Provider, Consumer } = createContext ( null ) ;
134+ let set ,
135+ renders = 0 ;
136+ const Layout = ( { children } ) => {
137+ renders ++ ;
138+ return children ;
139+ } ;
140+ class State extends Component {
141+ constructor ( props ) {
142+ super ( props ) ;
143+ this . state = { i : 0 } ;
144+ set = this . setState . bind ( this ) ;
145+ }
146+ render ( ) {
147+ const { children } = this . props ;
148+ return < Provider value = { this . state } > { children } </ Provider > ;
149+ }
150+ }
151+ const App = ( ) => (
152+ < State >
153+ < div >
154+ < Layout >
155+ < Consumer > { ( { i } ) => < p > { i } </ p > } </ Consumer >
156+ </ Layout >
157+ </ div >
158+ </ State >
159+ ) ;
160+ render ( < App /> , scratch ) ;
161+ expect ( renders ) . to . equal ( 1 ) ;
162+ set ( { i : 2 } ) ;
163+ rerender ( ) ;
164+ expect ( renders ) . to . equal ( 1 ) ;
165+ } ) ;
166+
167+ it ( 'should preserve provider context through nesting providers' , done => {
133168 const { Provider, Consumer } = createContext ( null ) ;
134169 const CONTEXT = { a : 'a' } ;
135170 const CHILD_CONTEXT = { b : 'b' } ;
You can’t perform that action at this time.
0 commit comments