Skip to content

Commit 485d06d

Browse files
committed
use EACH_IS_ANIMATED flag
1 parent 0631011 commit 485d06d

File tree

2 files changed

+14
-13
lines changed
  • packages/svelte/src

2 files changed

+14
-13
lines changed

packages/svelte/src/compiler/phases/3-transform/client/visitors/EachBlock.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,7 @@ export function EachBlock(node, context) {
8080
flags |= EACH_ITEM_IMMUTABLE;
8181
}
8282

83-
// Since `animate:` can only appear on elements that are the sole child of a keyed each block,
84-
// we can determine at compile time whether the each block is animated or not (in which
85-
// case it should measure animated elements before and after reconciliation).
86-
if (
87-
node.key &&
88-
node.body.nodes.some((child) => {
89-
if (child.type !== 'RegularElement' && child.type !== 'SvelteElement') return false;
90-
return child.attributes.some((attr) => attr.type === 'AnimateDirective');
91-
})
92-
) {
83+
if (node.key && node.body.nodes.some(is_animate_directive)) {
9384
flags |= EACH_IS_ANIMATED;
9485
}
9586

@@ -348,3 +339,14 @@ function collect_transitive_dependencies(binding, seen = new Set()) {
348339

349340
return [...seen];
350341
}
342+
343+
/** @param {AST.Text | AST.Tag | AST.ElementLike | AST.Comment | AST.Block} child */
344+
function is_animate_directive(child) {
345+
if (child.type === 'RenderTag') {
346+
for (const snippetBlock of child.metadata.snippets) {
347+
return snippetBlock.body.nodes.some(is_animate_directive);
348+
}
349+
}
350+
if (child.type !== 'RegularElement' && child.type !== 'SvelteElement') return false;
351+
return child.attributes.some((attr) => attr.type === 'AnimateDirective');
352+
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,15 +276,14 @@ export function each(node, flags, get_collection, get_key, render_fn, fallback_f
276276
* @returns {void}
277277
*/
278278
function reconcile(array, state, anchor, render_fn, flags, is_inert, get_key, get_collection) {
279+
var is_animated = (flags & EACH_IS_ANIMATED) !== 0;
279280
var should_update = (flags & (EACH_ITEM_REACTIVE | EACH_INDEX_REACTIVE)) !== 0;
280281

281282
var length = array.length;
282283
var items = state.items;
283284
var first = state.first;
284285
var current = first;
285-
286-
var is_animated = items.get(get_key(array[0], 0))?.a !== null;
287-
286+
288287
/** @type {undefined | Set<EachItem>} */
289288
var seen;
290289

0 commit comments

Comments
 (0)