File tree Expand file tree Collapse file tree 2 files changed +44
-4
lines changed Expand file tree Collapse file tree 2 files changed +44
-4
lines changed Original file line number Diff line number Diff line change @@ -37,6 +37,41 @@ describe('renderPrepass', () => {
3737 } )
3838 } )
3939
40+ it ( 'preserves the correct context values across yields' , ( ) => {
41+ let called = false
42+ const Inner = ( _ , context ) => {
43+ expect ( context . test ) . toBe ( 123 )
44+ called = true
45+ return null
46+ }
47+
48+ const Wait = ( ) => {
49+ const start = Date . now ( )
50+ while ( Date . now ( ) - start < 21 ) { }
51+ return < Inner />
52+ }
53+
54+ class Outer extends Component {
55+ getChildContext ( ) {
56+ return { test : 123 }
57+ }
58+
59+ render ( ) {
60+ return < Wait />
61+ }
62+ }
63+
64+ Inner . contextTypes = { test : null }
65+ Outer . childContextTypes = { test : null }
66+
67+ const render$ = renderPrepass ( < Outer /> )
68+ expect ( called ) . toBe ( false )
69+
70+ return render$ . then ( ( ) => {
71+ expect ( called ) . toBe ( true )
72+ } )
73+ } )
74+
4075 it ( 'does not yields when work is below the threshold' , ( ) => {
4176 const Inner = jest . fn ( ( ) => null )
4277 const Outer = ( ) => < Inner />
Original file line number Diff line number Diff line change @@ -190,10 +190,15 @@ const visitLoop = (
190190 const element = currChildren [ currIndex ]
191191 const children = visitElement ( element , queue , visitor )
192192
193- traversalChildren . push ( children )
194- traversalIndex . push ( 0 )
195- traversalMap . push ( flushPrevContextMap ( ) )
196- traversalStore . push ( flushPrevContextStore ( ) )
193+ if ( children . length > 0 ) {
194+ traversalChildren . push ( children )
195+ traversalIndex . push ( 0 )
196+ traversalMap . push ( flushPrevContextMap ( ) )
197+ traversalStore . push ( flushPrevContextStore ( ) )
198+ } else {
199+ restoreContextMap ( flushPrevContextMap ( ) )
200+ restoreContextStore ( flushPrevContextStore ( ) )
201+ }
197202 } else {
198203 traversalChildren . pop ( )
199204 traversalIndex . pop ( )
You can’t perform that action at this time.
0 commit comments