@@ -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' ;
@@ -740,17 +735,12 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
740
735
const nextProps = workInProgress . pendingProps ;
741
736
const prevProps = workInProgress . memoizedProps ;
742
737
743
- // Unless we already captured a promise during this render, reset the
744
- // placeholder state back to false. We always attempt to render the real
745
- // children before falling back to the placeholder.
746
- if ( ( workInProgress . effectTag & DidCapture ) === NoEffect ) {
747
- const update = createUpdate ( renderExpirationTime ) ;
748
- update . tag = ReplaceState ;
749
- update . payload = false ;
750
- enqueueCapturedUpdate ( workInProgress , update , renderExpirationTime ) ;
751
- }
738
+ const prevDidTimeout = workInProgress . memoizedState ;
752
739
753
- const prevState = workInProgress . memoizedState ;
740
+ // The update queue is only used to store expired promises, and to
741
+ // schedule a re-render once an expired promise resolves. It does not
742
+ // determine whether we should show the placeholder state, because we
743
+ // always attempt to show the placeholder state on every render.
754
744
const updateQueue = workInProgress . updateQueue ;
755
745
if ( updateQueue !== null ) {
756
746
processUpdateQueue (
@@ -761,19 +751,24 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
761
751
renderExpirationTime ,
762
752
) ;
763
753
}
764
- const nextState = workInProgress . memoizedState ;
754
+
755
+ // Check if we already attempted to render the normal state. If we did,
756
+ // and we timed out, render the placeholder state.
757
+ const alreadyCaptured =
758
+ ( workInProgress . effectTag & DidCapture ) === NoEffect ;
759
+ const nextDidTimeout = ! alreadyCaptured ;
765
760
766
761
if ( hasLegacyContextChanged ( ) ) {
767
762
// Normally we can bail out on props equality but if context has changed
768
763
// we don't do the bailout and we have to reuse existing props instead.
769
- } else if ( nextProps === prevProps && nextState === prevState ) {
764
+ } else if ( nextProps === prevProps && nextDidTimeout === prevDidTimeout ) {
770
765
return bailoutOnAlreadyFinishedWork ( current , workInProgress ) ;
771
766
}
772
767
773
- const didTimeout = nextState ;
774
768
const render = nextProps . children ;
775
- const nextChildren = render ( didTimeout ) ;
769
+ const nextChildren = render ( nextDidTimeout ) ;
776
770
workInProgress . memoizedProps = nextProps ;
771
+ workInProgress . memoizedState = nextDidTimeout ;
777
772
reconcileChildren ( current , workInProgress , nextChildren ) ;
778
773
return workInProgress . child ;
779
774
} else {
0 commit comments