@@ -65,12 +65,7 @@ import {
65
65
reconcileChildFibers ,
66
66
cloneChildFibers ,
67
67
} from './ReactChildFiber' ;
68
- import {
69
- createUpdate ,
70
- enqueueCapturedUpdate ,
71
- processUpdateQueue ,
72
- ReplaceState ,
73
- } from './ReactUpdateQueue' ;
68
+ import { processUpdateQueue } from './ReactUpdateQueue' ;
74
69
import { NoWork , Never } from './ReactFiberExpirationTime' ;
75
70
import { AsyncMode , StrictMode } from './ReactTypeOfMode' ;
76
71
import MAX_SIGNED_31_BIT_INT from './maxSigned31BitInt' ;
@@ -750,17 +745,12 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
750
745
const nextProps = workInProgress . pendingProps ;
751
746
const prevProps = workInProgress . memoizedProps ;
752
747
753
- // Unless we already captured a promise during this render, reset the
754
- // placeholder state back to false. We always attempt to render the real
755
- // children before falling back to the placeholder.
756
- if ( ( workInProgress . effectTag & DidCapture ) === NoEffect ) {
757
- const update = createUpdate ( renderExpirationTime ) ;
758
- update . tag = ReplaceState ;
759
- update . payload = false ;
760
- enqueueCapturedUpdate ( workInProgress , update , renderExpirationTime ) ;
761
- }
748
+ const prevDidTimeout = workInProgress . memoizedState ;
762
749
763
- const prevState = workInProgress . memoizedState ;
750
+ // The update queue is only used to store expired promises, and to
751
+ // schedule a re-render once an expired promise resolves. It does not
752
+ // determine whether we should show the placeholder state, because we
753
+ // always attempt to show the placeholder state on every render.
764
754
const updateQueue = workInProgress . updateQueue ;
765
755
if ( updateQueue !== null ) {
766
756
processUpdateQueue (
@@ -771,19 +761,24 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
771
761
renderExpirationTime ,
772
762
) ;
773
763
}
774
- const nextState = workInProgress . memoizedState ;
764
+
765
+ // Check if we already attempted to render the normal state. If we did,
766
+ // and we timed out, render the placeholder state.
767
+ const alreadyCaptured =
768
+ ( workInProgress . effectTag & DidCapture ) === NoEffect ;
769
+ const nextDidTimeout = ! alreadyCaptured ;
775
770
776
771
if ( hasLegacyContextChanged ( ) ) {
777
772
// Normally we can bail out on props equality but if context has changed
778
773
// we don't do the bailout and we have to reuse existing props instead.
779
- } else if ( nextProps === prevProps && nextState === prevState ) {
774
+ } else if ( nextProps === prevProps && nextDidTimeout === prevDidTimeout ) {
780
775
return bailoutOnAlreadyFinishedWork ( current , workInProgress ) ;
781
776
}
782
777
783
- const didTimeout = nextState ;
784
778
const render = nextProps . children ;
785
- const nextChildren = render ( didTimeout ) ;
779
+ const nextChildren = render ( nextDidTimeout ) ;
786
780
workInProgress . memoizedProps = nextProps ;
781
+ workInProgress . memoizedState = nextDidTimeout ;
787
782
reconcileChildren ( current , workInProgress , nextChildren ) ;
788
783
return workInProgress . child ;
789
784
} else {
0 commit comments