@@ -60,6 +60,11 @@ type QueuedReplayableEvent = {
60
60
61
61
let hasScheduledReplayAttempt = false ;
62
62
63
+ // The queue of discrete events to be replayed.
64
+ const queuedDiscreteEvents : Array < QueuedReplayableEvent > = [];
65
+
66
+ // Indicates if any continuous event targets are non-null for early bailout.
67
+ const hasAnyQueuedContinuousEvents: boolean = false;
63
68
// The last of each continuous event type. We only need to replay the last one
64
69
// if the last target was dehydrated.
65
70
let queuedFocus: null | QueuedReplayableEvent = null;
@@ -77,6 +82,14 @@ type QueuedHydrationTarget = {
77
82
} ;
78
83
const queuedExplicitHydrationTargets: Array< QueuedHydrationTarget > = [];
79
84
85
+ export function hasQueuedDiscreteEvents(): boolean {
86
+ return queuedDiscreteEvents . length > 0 ;
87
+ }
88
+
89
+ export function hasQueuedContinuousEvents(): boolean {
90
+ return hasAnyQueuedContinuousEvents ;
91
+ }
92
+
80
93
const discreteReplayableEvents: Array< DOMEventName > = [
81
94
'mousedown',
82
95
'mouseup',
@@ -433,6 +446,21 @@ function scheduleCallbackIfUnblocked(
433
446
export function retryIfBlockedOn (
434
447
unblocked : Container | SuspenseInstance ,
435
448
) : void {
449
+ // Mark anything that was blocked on this as no longer blocked
450
+ // and eligible for a replay.
451
+ if ( queuedDiscreteEvents . length > 0 ) {
452
+ scheduleCallbackIfUnblocked ( queuedDiscreteEvents [ 0 ] , unblocked ) ;
453
+ // This is a exponential search for each boundary that commits. I think it's
454
+ // worth it because we expect very few discrete events to queue up and once
455
+ // we are actually fully unblocked it will be fast to replay them.
456
+ for ( let i = 1 ; i < queuedDiscreteEvents . length ; i ++ ) {
457
+ const queuedEvent = queuedDiscreteEvents [ i ] ;
458
+ if ( queuedEvent . blockedOn === unblocked ) {
459
+ queuedEvent . blockedOn = null ;
460
+ }
461
+ }
462
+ }
463
+
436
464
if ( queuedFocus !== null ) {
437
465
scheduleCallbackIfUnblocked ( queuedFocus , unblocked ) ;
438
466
}
0 commit comments