Skip to content

Commit 0bdb59c

Browse files
authored
fix: compute rect directly before crossfading (#8314)
closes #4344 fixes #4111
1 parent e5b0b62 commit 0bdb59c

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/runtime/transition/index.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ export interface CrossfadeParams {
211211
easing?: EasingFunction;
212212
}
213213

214-
type ClientRectMap = Map<any, { rect: ClientRect }>;
214+
type ClientRectMap = Map<any, Element>;
215215

216216
export function crossfade({ fallback, ...defaults }: CrossfadeParams & {
217217
fallback?: (node: Element, params: CrossfadeParams, intro: boolean) => TransitionConfig;
@@ -232,13 +232,14 @@ export function crossfade({ fallback, ...defaults }: CrossfadeParams & {
232232
const to_receive: ClientRectMap = new Map();
233233
const to_send: ClientRectMap = new Map();
234234

235-
function crossfade(from: ClientRect, node: Element, params: CrossfadeParams): TransitionConfig {
235+
function crossfade(from_node: Element, node: Element, params: CrossfadeParams): TransitionConfig {
236236
const {
237237
delay = 0,
238238
duration = d => Math.sqrt(d) * 30,
239239
easing = cubicOut
240240
} = assign(assign({}, defaults), params);
241241

242+
const from = from_node.getBoundingClientRect();
242243
const to = node.getBoundingClientRect();
243244
const dx = from.left - to.left;
244245
const dy = from.top - to.top;
@@ -264,16 +265,14 @@ export function crossfade({ fallback, ...defaults }: CrossfadeParams & {
264265

265266
function transition(items: ClientRectMap, counterparts: ClientRectMap, intro: boolean) {
266267
return (node: Element, params: CrossfadeParams & { key: any }) => {
267-
items.set(params.key, {
268-
rect: node.getBoundingClientRect()
269-
});
268+
items.set(params.key, node);
270269

271270
return () => {
272271
if (counterparts.has(params.key)) {
273-
const { rect } = counterparts.get(params.key);
272+
const other_node = counterparts.get(params.key);
274273
counterparts.delete(params.key);
275274

276-
return crossfade(rect, node, params);
275+
return crossfade(other_node, node, params);
277276
}
278277

279278
// if the node is disappearing altogether

0 commit comments

Comments
 (0)