@@ -35,10 +35,12 @@ import {
35
35
ContextConsumer ,
36
36
} from 'shared/ReactTypeOfWork' ;
37
37
import {
38
+ NoEffect ,
38
39
PerformedWork ,
39
40
Placement ,
40
41
ContentReset ,
41
42
Ref ,
43
+ DidCapture ,
42
44
} from 'shared/ReactTypeOfSideEffect' ;
43
45
import { ReactCurrentOwner } from 'shared/ReactGlobalSharedState' ;
44
46
import {
@@ -58,7 +60,12 @@ import {
58
60
reconcileChildFibers ,
59
61
cloneChildFibers ,
60
62
} from './ReactChildFiber' ;
61
- import { processUpdateQueue } from './ReactFiberUpdateQueue' ;
63
+ import { processUpdateQueue as processLegacyUpdateQueue } from './ReactFiberUpdateQueue' ;
64
+ import {
65
+ createDeriveStateFromPropsUpdate ,
66
+ enqueueRenderPhaseUpdate ,
67
+ processUpdateQueue ,
68
+ } from './ReactUpdateQueue' ;
62
69
import { NoWork , Never } from './ReactFiberExpirationTime' ;
63
70
import { AsyncMode , StrictMode } from './ReactTypeOfMode' ;
64
71
import MAX_SIGNED_31_BIT_INT from './maxSigned31BitInt' ;
@@ -260,7 +267,11 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
260
267
if ( current === null ) {
261
268
if ( workInProgress . stateNode === null ) {
262
269
// In the initial pass we might need to construct the instance.
263
- constructClassInstance ( workInProgress , workInProgress . pendingProps ) ;
270
+ constructClassInstance (
271
+ workInProgress ,
272
+ workInProgress . pendingProps ,
273
+ renderExpirationTime ,
274
+ ) ;
264
275
mountClassInstance ( workInProgress , renderExpirationTime ) ;
265
276
266
277
shouldUpdate = true ;
@@ -278,22 +289,11 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
278
289
renderExpirationTime ,
279
290
) ;
280
291
}
281
-
282
- // We processed the update queue inside updateClassInstance. It may have
283
- // included some errors that were dispatched during the commit phase.
284
- // TODO: Refactor class components so this is less awkward.
285
- let didCaptureError = false ;
286
- const updateQueue = workInProgress . updateQueue ;
287
- if ( updateQueue !== null && updateQueue . capturedValues !== null ) {
288
- shouldUpdate = true ;
289
- didCaptureError = true ;
290
- }
291
292
return finishClassComponent (
292
293
current ,
293
294
workInProgress ,
294
295
shouldUpdate ,
295
296
hasContext ,
296
- didCaptureError ,
297
297
renderExpirationTime ,
298
298
) ;
299
299
}
@@ -303,12 +303,14 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
303
303
workInProgress : Fiber ,
304
304
shouldUpdate : boolean ,
305
305
hasContext : boolean ,
306
- didCaptureError : boolean ,
307
306
renderExpirationTime : ExpirationTime ,
308
307
) {
309
308
// Refs should update even if shouldComponentUpdate returns false
310
309
markRef ( current , workInProgress ) ;
311
310
311
+ const didCaptureError =
312
+ ( workInProgress . effectTag & DidCapture ) !== NoEffect ;
313
+
312
314
if ( ! shouldUpdate && ! didCaptureError ) {
313
315
// Context providers should defer to sCU for rendering
314
316
if ( hasContext ) {
@@ -414,7 +416,7 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
414
416
let updateQueue = workInProgress . updateQueue ;
415
417
if ( updateQueue !== null ) {
416
418
const prevState = workInProgress . memoizedState ;
417
- const state = processUpdateQueue (
419
+ const state = processLegacyUpdateQueue (
418
420
current ,
419
421
workInProgress ,
420
422
updateQueue ,
@@ -607,20 +609,13 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
607
609
workInProgress . memoizedState =
608
610
value . state !== null && value . state !== undefined ? value . state : null ;
609
611
610
- if ( typeof Component . getDerivedStateFromProps === 'function' ) {
611
- const partialState = callGetDerivedStateFromProps (
612
- workInProgress ,
613
- value ,
614
- props ,
615
- workInProgress . memoizedState ,
616
- ) ;
617
-
618
- if ( partialState !== null && partialState !== undefined ) {
619
- workInProgress . memoizedState = Object . assign (
620
- { } ,
621
- workInProgress . memoizedState ,
622
- partialState ,
623
- ) ;
612
+ const getDerivedStateFromProps = Component . getDerivedStateFromProps ;
613
+ if ( typeof getDerivedStateFromProps === 'function' ) {
614
+ const update = createDeriveStateFromPropsUpdate ( renderExpirationTime ) ;
615
+ enqueueRenderPhaseUpdate ( workInProgress , update , renderExpirationTime ) ;
616
+ const updateQueue = workInProgress . updateQueue ;
617
+ if ( updateQueue !== null ) {
618
+ processUpdateQueue ( workInProgress , updateQueue , renderExpirationTime ) ;
624
619
}
625
620
}
626
621
@@ -635,7 +630,6 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
635
630
workInProgress ,
636
631
true ,
637
632
hasContext ,
638
- false ,
639
633
renderExpirationTime ,
640
634
) ;
641
635
} else {
0 commit comments