-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: enable animate:
directive for snippets
#14796
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 10c01bc The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
preview: https://svelte-dev-git-preview-svelte-14796-svelte.vercel.app/ this is an automated message |
|
||
mark_subtree_dynamic(context.path); | ||
|
||
context.next({ ...context.state, render_tag: node }); | ||
} | ||
|
||
/** @param {AST.Text | AST.Tag | AST.ElementLike | AST.Comment | AST.Block} child */ | ||
function is_animate_directive(child) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is used twice as it is also in phases/3-transform/client/visitors/EachBlock.js#L347. Do I put it anywhere to re-use it across the two phases?
} | ||
else if (!parent.key) { | ||
e.animation_missing_key(parent); | ||
} else if (parent.body.nodes.filter((n) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same logic as in phases/2-analyze/visitors/shared/element.js#L92. Maybe re-use logic for consistent maintainence for future updates to this logic?
For this PR, if an each loop snippet gets exported from a file, and then imported into another file, animations won't work. I'll try looking into it🦒 For instance, if you have a file, e.g. <script module lang='ts'>
export { renderArray }
</script>
{#snippet renderArray(array, snippet)}
{#each array as item, i (item)}
{@render snippet(item)}
{/each}
{/snippet} And then render this each-loop in <script>
import { renderArray } from './ArraySnippet.svelte'
let array = $state([ 'a', 'b', 'c', 'd', 'e', 'f', 'g' ])
function randomOrder() {
array.sort((a,b) => Math.random() > 0.5)
}
</script>
<button onclick={randomOrder}> Randomize order </button>
<#snippet itemSnippet(value)>
<div animate:flip> {value} </div>
</snippet
{@render renderArray(array, itemSnippet)} |
This would solve #14792 which still needs to be discussed. I'm opening this PR as an initiative.
This feature allows the use of the
animate:
directive within snippets:I've added error feedback:
animate:
directive andeach
-blockeach
-block isn't keyedeach
-block have multiple children, with an animated snippet.Svelte Playground for #14796
feat:
,fix:
,chore:
, ordocs:
.packages/svelte/src
, add a changeset (npx changeset
).Tests and linting
pnpm test
and lint the project withpnpm lint