@@ -998,6 +998,10 @@ <h2>Available Animated Pixel Companions for Codex:</h2>
998998 tile . _anim = null ;
999999 }
10001000
1001+ // Increment hover session ID to invalidate any stale asynchronous callbacks from previous hovers
1002+ tile . _hoverSession = ( tile . _hoverSession || 0 ) + 1 ;
1003+ const currentSession = tile . _hoverSession ;
1004+
10011005 const el = tile . _spritePlayer ;
10021006 const pet = getPet ( tile . dataset . slug ) ;
10031007 if ( ! el || ! pet ) return ;
@@ -1010,7 +1014,7 @@ <h2>Available Animated Pixel Companions for Codex:</h2>
10101014 let t0 = null ;
10111015
10121016 function tick ( now ) {
1013- if ( ! tile . _isHovered ) {
1017+ if ( tile . _hoverSession !== currentSession || ! tile . _isHovered ) {
10141018 stopHover ( tile ) ;
10151019 return ;
10161020 }
@@ -1050,6 +1054,9 @@ <h2>Available Animated Pixel Companions for Codex:</h2>
10501054 loadSprite (
10511055 el ,
10521056 ( pct ) => {
1057+ // Cancel progress if hover session has changed
1058+ if ( tile . _hoverSession !== currentSession ) return ;
1059+
10531060 // If the network is slow, override the CSS transition and follow actual stream progress
10541061 const timeElapsed = Date . now ( ) - hoverStartTime ;
10551062 if ( timeElapsed > minDefrostDuration ) {
@@ -1067,6 +1074,9 @@ <h2>Available Animated Pixel Companions for Codex:</h2>
10671074 const remainingTime = Math . max ( 0 , minDefrostDuration - timeElapsed ) ;
10681075 await new Promise ( r => setTimeout ( r , remainingTime ) ) ;
10691076
1077+ // Cancel completion if hover session has changed
1078+ if ( tile . _hoverSession !== currentSession ) return ;
1079+
10701080 // Hide the steam container and update active rendering states
10711081 tile . classList . remove ( "loading" ) ;
10721082
@@ -1091,6 +1101,7 @@ <h2>Available Animated Pixel Companions for Codex:</h2>
10911101 }
10921102
10931103 function stopHover ( tile ) {
1104+ tile . _hoverSession = 0 ; // Invalidate any running session instantly
10941105 tile . classList . remove ( "loading" ) ;
10951106 tile . classList . remove ( "playing" ) ;
10961107 if ( tile . _anim ) {
0 commit comments