@@ -17,6 +17,7 @@ import type { PriorityLevel } from 'ReactPriorityLevel';
17
17
18
18
var {
19
19
getMaskedContext,
20
+ getUnmaskedContext,
20
21
} = require ( 'ReactFiberContext' ) ;
21
22
var {
22
23
addUpdate,
@@ -204,10 +205,17 @@ module.exports = function(
204
205
function constructClassInstance ( workInProgress : Fiber ) : any {
205
206
const ctor = workInProgress . type ;
206
207
const props = workInProgress . pendingProps ;
207
- const context = getMaskedContext ( workInProgress ) ;
208
+ const unmaskedContext = getUnmaskedContext ( workInProgress ) ;
209
+ const context = getMaskedContext ( workInProgress , unmaskedContext ) ;
208
210
const instance = new ctor ( props , context ) ;
209
211
adoptClassInstance ( workInProgress , instance ) ;
210
212
checkClassInstance ( workInProgress ) ;
213
+
214
+ // Cache unmasked context so we can avoid recreating masked context unless necessary.
215
+ // ReactFiberContext usually updates this cache but can't for newly-created instances.
216
+ instance . __reactInternalMemoizedUnmaskedChildContext = unmaskedContext ;
217
+ instance . __reactInternalMemoizedMaskedChildContext = context ;
218
+
211
219
return instance ;
212
220
}
213
221
@@ -221,9 +229,11 @@ module.exports = function(
221
229
throw new Error ( 'There must be pending props for an initial mount.' ) ;
222
230
}
223
231
232
+ const unmaskedContext = getUnmaskedContext ( workInProgress ) ;
233
+
224
234
instance . props = props ;
225
235
instance . state = state ;
226
- instance . context = getMaskedContext ( workInProgress ) ;
236
+ instance . context = getMaskedContext ( workInProgress , unmaskedContext ) ;
227
237
228
238
if ( typeof instance . componentWillMount === 'function' ) {
229
239
instance . componentWillMount ( ) ;
@@ -256,7 +266,8 @@ module.exports = function(
256
266
throw new Error ( 'There should always be pending or memoized props.' ) ;
257
267
}
258
268
}
259
- const newContext = getMaskedContext ( workInProgress ) ;
269
+ const newUnmaskedContext = getUnmaskedContext ( workInProgress ) ;
270
+ const newContext = getMaskedContext ( workInProgress , newUnmaskedContext ) ;
260
271
261
272
// TODO: Should we deal with a setState that happened after the last
262
273
// componentWillMount and before this componentWillMount? Probably
@@ -277,7 +288,7 @@ module.exports = function(
277
288
const newInstance = constructClassInstance ( workInProgress ) ;
278
289
newInstance . props = newProps ;
279
290
newInstance . state = newState = newInstance . state || null ;
280
- newInstance . context = getMaskedContext ( workInProgress ) ;
291
+ newInstance . context = newContext ;
281
292
282
293
if ( typeof newInstance . componentWillMount === 'function' ) {
283
294
newInstance . componentWillMount ( ) ;
@@ -314,7 +325,8 @@ module.exports = function(
314
325
}
315
326
}
316
327
const oldContext = instance . context ;
317
- const newContext = getMaskedContext ( workInProgress ) ;
328
+ const newUnmaskedContext = getUnmaskedContext ( workInProgress ) ;
329
+ const newContext = getMaskedContext ( workInProgress , newUnmaskedContext ) ;
318
330
319
331
// Note: During these life-cycles, instance.props/instance.state are what
320
332
// ever the previously attempted to render - not the "current". However,
0 commit comments