@@ -341,6 +341,29 @@ export interface AggregatedRender {
341341 computedKey : OutlineKey | null ;
342342}
343343
344+ export let areFibersEqual = ( fiberA : Fiber , fiberB : Fiber ) => {
345+ if ( fiberA === fiberB ) {
346+ return true ;
347+ }
348+
349+ if ( fiberA . alternate === fiberB ) {
350+ return true ;
351+ }
352+
353+ if ( fiberA === fiberB . alternate ) {
354+ return true ;
355+ }
356+
357+ if (
358+ fiberA . alternate &&
359+ fiberB . alternate &&
360+ fiberA . alternate === fiberB . alternate
361+ ) {
362+ return true ;
363+ }
364+ return false ;
365+ } ;
366+
344367const activateOutlines = async ( ) => {
345368 const domNodes : Array < HTMLElement > = [ ] ;
346369 const scheduledOutlines = ReactScanInternals . scheduledOutlines ;
@@ -411,7 +434,6 @@ const activateOutlines = async () => {
411434 rect . right < 0 ||
412435 rect . top > viewportHeight ||
413436 rect . left > viewportWidth ;
414- // it is ~8x faster to delete map items in the loop vs accumulating them in an array then deleting after on node v23.4.0
415437 if ( isOffScreen ) {
416438 // if its offscreen there is no reason to waste computation to aggregate + draw it
417439 continue ;
@@ -437,8 +459,17 @@ const activateOutlines = async () => {
437459
438460 existingOutline . aggregatedRender . computedKey = key ;
439461
462+
463+ // handles canceling the animation of the associated render that was painted at a different location
440464 if ( prevAggregatedRender ?. computedKey ) {
441- activeOutlines . delete ( prevAggregatedRender . computedKey ) ;
465+ const groupOnKey = activeOutlines . get ( prevAggregatedRender . computedKey ) ;
466+ groupOnKey ?. groupedAggregatedRender ?. forEach (
467+ ( value , prevStoredFiber ) => {
468+ if ( areFibersEqual ( prevStoredFiber , fiber ) ) {
469+ value . frame = 45 ;
470+ }
471+ } ,
472+ ) ;
442473 }
443474 activeOutlines . set ( key , existingOutline ) ;
444475 }
0 commit comments