@@ -372,19 +372,6 @@ function create_transition(dom, init, direction, effect) {
372372 // @ts -ignore
373373 const has_keyed_transition = dom . __animate ;
374374
375- // If we're outroing an element that has an animation, then we need to fix
376- // its position to ensure it behaves nicely without causing layout shift.
377- if ( has_keyed_transition ) {
378- const style = getComputedStyle ( dom ) ;
379- const position = style . position ;
380-
381- if ( position !== 'absolute' && position !== 'fixed' ) {
382- const { width, height } = style ;
383- dom . style . position = 'absolute' ;
384- dom . style . width = width ;
385- dom . style . height = height ;
386- }
387- }
388375 const needs_reverse = direction === 'both' && curr_direction !== 'out' ;
389376 curr_direction = 'out' ;
390377 if ( animation === null || cancelled ) {
@@ -401,6 +388,28 @@ function create_transition(dom, init, direction, effect) {
401388 /** @type {Animation | TickAnimation } */ ( animation ) . play ( ) ;
402389 }
403390 }
391+ // If we're outroing an element that has an animation, then we need to fix
392+ // its position to ensure it behaves nicely without causing layout shift.
393+ if ( has_keyed_transition ) {
394+ const style = getComputedStyle ( dom ) ;
395+ const position = style . position ;
396+
397+ if ( position !== 'absolute' && position !== 'fixed' ) {
398+ const { width, height } = style ;
399+ const a = dom . getBoundingClientRect ( ) ;
400+ dom . style . position = 'absolute' ;
401+ dom . style . width = width ;
402+ dom . style . height = height ;
403+ const b = dom . getBoundingClientRect ( ) ;
404+ if ( a . left !== b . left || a . top !== b . top ) {
405+ const style = getComputedStyle ( dom ) ;
406+ const transform = style . transform === 'none' ? '' : style . transform ;
407+ dom . style . transform = `${ transform } translate(${ a . left - b . left } px, ${
408+ a . top - b . top
409+ } px)`;
410+ }
411+ }
412+ }
404413 } ,
405414 // cancel
406415 c ( ) {
0 commit comments