@@ -160,10 +160,14 @@ function keepSized(el: HTMLMediaElement, scale: number): void {
160160 const needed = shown && lowered ? scalePreviewProxyBox ( shown , previewQuality ) : shown ;
161161 if ( lowered && ! needed ) return ;
162162 if ( needed && lowered && copy . light && lightCopyNoLongerNeeded ( el , needed ) ) {
163+ // One waiter per clip: a drag of the panel asks this again and again while the clip plays.
164+ if ( restoreWaiting . has ( el ) ) return ;
165+ restoreWaiting . add ( el ) ;
163166 return whenNotPlayingHere (
164167 el ,
165168 ( ) => boxedElements . get ( el ) === copy ,
166169 ( ) => restoreOriginal ( el ) ,
170+ ( ) => restoreWaiting . delete ( el ) ,
167171 ) ;
168172 }
169173 if ( boxCovers ( copy . box , needed , lowered ) ) return dropUnneededCopy ( el ) ;
@@ -176,11 +180,18 @@ function playingHere(el: HTMLMediaElement): boolean {
176180}
177181
178182const SETTLE_POLL_MS = 250 ;
183+ const restoreWaiting = new WeakSet < HTMLMediaElement > ( ) ;
179184
180185/** Runs `apply` once `el` is not a clip playing at the playhead: now when it is not, else when it pauses, seeks, ends
181- * or leaves its window. Nothing runs when `wanted` has turned false by then. */
182- function whenNotPlayingHere ( el : HTMLMediaElement , wanted : ( ) => boolean , apply : ( ) => void ) : void {
186+ * or leaves its window. Nothing runs when `wanted` has turned false by then. `settled` runs first either way. */
187+ function whenNotPlayingHere (
188+ el : HTMLMediaElement ,
189+ wanted : ( ) => boolean ,
190+ apply : ( ) => void ,
191+ settled ?: ( ) => void ,
192+ ) : void {
183193 if ( ! playingHere ( el ) ) {
194+ settled ?.( ) ;
184195 if ( wanted ( ) ) apply ( ) ;
185196 return ;
186197 }
@@ -190,6 +201,7 @@ function whenNotPlayingHere(el: HTMLMediaElement, wanted: () => boolean, apply:
190201 if ( wanted ( ) && playingHere ( el ) ) return ;
191202 events . forEach ( ( type ) => el . removeEventListener ( type , check ) ) ;
192203 clearInterval ( poll ) ;
204+ settled ?.( ) ;
193205 if ( wanted ( ) ) apply ( ) ;
194206 } ;
195207 events . forEach ( ( type ) => el . addEventListener ( type , check ) ) ;
0 commit comments