@@ -16,7 +16,8 @@ export function createSidebarListMotion(parent: HTMLUListElement) {
1616 let positions : Map < HTMLElement , RowPosition > | null = null ;
1717 let disposed = false ;
1818 const document = parent . ownerDocument ;
19- const reducedMotion = document . defaultView ?. matchMedia ( "(prefers-reduced-motion: reduce)" ) ;
19+ const window = document . defaultView ;
20+ const reducedMotion = window ?. matchMedia ( "(prefers-reduced-motion: reduce)" ) ;
2021 const running = new Map < HTMLElement , { animation : Animation ; offset : number } > ( ) ;
2122 const entering = new Map < HTMLElement , { animation : Animation ; travel : number } > ( ) ;
2223 const exiting = new Map < HTMLElement , Animation > ( ) ;
@@ -117,13 +118,13 @@ export function createSidebarListMotion(parent: HTMLUListElement) {
117118 } ;
118119
119120 // Hidden documents freeze the animation timeline, so motion queued while minimized or
120- // occluded would replay on return instead of having already played.
121+ // occluded would replay on return. Resizes move the bottom-anchored shelves, which
122+ // makes the cached positions stale.
121123 const onVisibilityChange = ( ) => {
122- if ( document . visibilityState !== "hidden" ) return ;
123- for ( const node of running . keys ( ) ) cancel ( node ) ;
124- clearFades ( ) ;
124+ if ( document . visibilityState === "hidden" ) suspend ( ) ;
125125 } ;
126126 document . addEventListener ( "visibilitychange" , onVisibilityChange ) ;
127+ window ?. addEventListener ( "resize" , suspend ) ;
127128
128129 return {
129130 update ( animate : boolean ) {
@@ -249,6 +250,7 @@ export function createSidebarListMotion(parent: HTMLUListElement) {
249250 suspend,
250251 dispose ( ) {
251252 document . removeEventListener ( "visibilitychange" , onVisibilityChange ) ;
253+ window ?. removeEventListener ( "resize" , suspend ) ;
252254 suspend ( ) ;
253255 disposed = true ;
254256 } ,
0 commit comments