8
8
*/
9
9
10
10
import type {
11
- Wakeable ,
12
11
Thenable ,
13
12
PendingThenable ,
14
13
FulfilledThenable ,
@@ -18,14 +17,8 @@ import type {
18
17
import ReactSharedInternals from 'shared/ReactSharedInternals' ;
19
18
const { ReactCurrentActQueue} = ReactSharedInternals ;
20
19
21
- let suspendedThenable : Thenable < mixed > | null = null ;
22
- let adHocSuspendCount : number = 0 ;
23
-
24
- // TODO: Sparse arrays are bad for performance.
20
+ let suspendedThenable : Thenable < any > | null = null ;
25
21
let usedThenables : Array < Thenable < any > | void > | null = null ;
26
- let lastUsedThenable : Thenable < any > | null = null ;
27
-
28
- const MAX_AD_HOC_SUSPEND_COUNT = 50 ;
29
22
30
23
export function isTrackingSuspendedThenable ( ) : boolean {
31
24
return suspendedThenable !== null ;
@@ -39,22 +32,17 @@ export function suspendedThenableDidResolve(): boolean {
39
32
return false ;
40
33
}
41
34
42
- export function trackSuspendedWakeable ( wakeable : Wakeable ) {
43
- // If this wakeable isn't already a thenable, turn it into one now. Then,
44
- // when we resume the work loop, we can check if its status is
45
- // still pending.
46
- // TODO: Get rid of the Wakeable type? It's superseded by UntrackedThenable.
47
- const thenable : Thenable < mixed > = (wakeable: any);
35
+ export function trackUsedThenable < T > ( thenable : Thenable < T > , index : number ) {
36
+ if ( __DEV__ && ReactCurrentActQueue . current !== null ) {
37
+ ReactCurrentActQueue . didUsePromise = true ;
38
+ }
48
39
49
- if (thenable !== lastUsedThenable) {
50
- // If this wakeable was not just `use`-d, it must be an ad hoc wakeable
51
- // that was thrown by an older Suspense implementation. Keep a count of
52
- // these so that we can detect an infinite ping loop.
53
- // TODO: Once `use` throws an opaque signal instead of the actual thenable,
54
- // a better way to count ad hoc suspends is whether an actual thenable
55
- // is caught by the work loop.
56
- adHocSuspendCount ++ ;
40
+ if ( usedThenables === null ) {
41
+ usedThenables = [ thenable ] ;
42
+ } else {
43
+ usedThenables [ index ] = thenable ;
57
44
}
45
+
58
46
suspendedThenable = thenable ;
59
47
60
48
// We use an expando to track the status and result of a thenable so that we
@@ -105,34 +93,12 @@ export function trackSuspendedWakeable(wakeable: Wakeable) {
105
93
106
94
export function resetWakeableStateAfterEachAttempt ( ) {
107
95
suspendedThenable = null ;
108
- adHocSuspendCount = 0 ;
109
- lastUsedThenable = null ;
110
96
}
111
97
112
98
export function resetThenableStateOnCompletion() {
113
99
usedThenables = null ;
114
100
}
115
101
116
- export function throwIfInfinitePingLoopDetected() {
117
- if ( adHocSuspendCount > MAX_AD_HOC_SUSPEND_COUNT ) {
118
- // TODO: Guard against an infinite loop by throwing an error if the same
119
- // component suspends too many times in a row. This should be thrown from
120
- // the render phase so that it gets the component stack.
121
- }
122
- }
123
-
124
- export function trackUsedThenable< T > (thenable: Thenable< T > , index: number) {
125
- if ( usedThenables === null ) {
126
- usedThenables = [ ] ;
127
- }
128
- usedThenables[index] = thenable;
129
- lastUsedThenable = thenable;
130
-
131
- if (__DEV__ && ReactCurrentActQueue . current !== null ) {
132
- ReactCurrentActQueue . didUsePromise = true ;
133
- }
134
- }
135
-
136
102
export function getPreviouslyUsedThenableAtIndex< T > (
137
103
index: number,
138
104
): Thenable< T > | null {
0 commit comments