Skip to content

Commit 876a75b

Browse files
committed
clever hack
1 parent 674615e commit 876a75b

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

packages/svelte/src/internal/client/each.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,6 @@ export function destroy_each_item_block(
735735
controlled = false
736736
) {
737737
const transitions = block.s;
738-
const dom = block.d;
739738

740739
if (apply_transitions && transitions !== null) {
741740
// We might have pending key transitions, if so remove them first
@@ -751,13 +750,10 @@ export function destroy_each_item_block(
751750
if (transition_block !== null) {
752751
transition_block.push(block);
753752
}
754-
if (dom !== null) {
755-
// @ts-ignore
756-
dom.__animate = false;
757-
}
758753
return;
759754
}
760755
}
756+
const dom = block.d;
761757
if (!controlled && dom !== null) {
762758
remove(dom);
763759
}

packages/svelte/src/internal/client/transitions.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ function create_transition(dom, init, direction, effect) {
370370
// out
371371
o() {
372372
// @ts-ignore
373-
const has_keyed_transition = dom.__animate === true;
373+
const has_keyed_transition = dom.__animate;
374374
const needs_reverse = direction === 'both' && curr_direction !== 'out';
375375
curr_direction = 'out';
376376
if (animation === null || cancelled) {
@@ -402,11 +402,17 @@ function create_transition(dom, init, direction, effect) {
402402
dom.style.height = height;
403403
const b = dom.getBoundingClientRect();
404404
if (a.left !== b.left || a.top !== b.top) {
405+
// Previously, in the Svelte 4, we'd just apply the transform the the DOM element. However,
406+
// because we're now using Web Animations, we can't do that as it won't work properly if the
407+
// animation is also making use of the same transformations. So instead, we apply an instantaneous
408+
// animation and pause it on the first frame, just applying the same behavior.
405409
const style = getComputedStyle(dom);
406410
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)`;
411+
const frame = {
412+
transform: `${transform} translate(${a.left - b.left}px, ${a.top - b.top}px)`
413+
};
414+
const animation = dom.animate([frame, frame], { duration: 1 });
415+
animation.pause();
410416
}
411417
}
412418
}

0 commit comments

Comments
 (0)