Skip to content

Commit

Permalink
fix: ensure transitions are applied to nested elements (#14080)
Browse files Browse the repository at this point in the history
  • Loading branch information
trueadm authored Oct 31, 2024
1 parent 0ed914b commit 58b1540
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/modern-adults-lay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: ensure transitions are applied to nested elements
2 changes: 2 additions & 0 deletions packages/svelte/src/compiler/phases/2-analyze/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import { SvelteWindow } from './visitors/SvelteWindow.js';
import { TaggedTemplateExpression } from './visitors/TaggedTemplateExpression.js';
import { Text } from './visitors/Text.js';
import { TitleElement } from './visitors/TitleElement.js';
import { TransitionDirective } from './visitors/TransitionDirective.js';
import { UpdateExpression } from './visitors/UpdateExpression.js';
import { UseDirective } from './visitors/UseDirective.js';
import { VariableDeclarator } from './visitors/VariableDeclarator.js';
Expand Down Expand Up @@ -172,6 +173,7 @@ const visitors = {
SvelteWindow,
TaggedTemplateExpression,
Text,
TransitionDirective,
TitleElement,
UpdateExpression,
UseDirective,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/** @import { AST } from '#compiler' */
/** @import { Context } from '../types' */

import { mark_subtree_dynamic } from './shared/fragment.js';

/**
* @param {AST.TransitionDirective} node
* @param {Context} context
*/
export function TransitionDirective(node, context) {
mark_subtree_dynamic(context.path);

context.next();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { flushSync } from '../../../../src/index-client.js';
import { test } from '../../test';

export default test({
async test({ assert, raf, target }) {
assert.htmlEqual(target.innerHTML, '<button>Toggle</button><div><span>123</span></div>');

const btn1 = target.querySelector('button');
btn1?.click();
flushSync();
raf.tick(250);

assert.htmlEqual(
target.innerHTML,
'<button>Toggle</button><div><span style="opacity: 0.5;">123</span></div>'
);

flushSync();
raf.tick(500);

assert.htmlEqual(target.innerHTML, '<button>Toggle</button>');
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<script>
function fade(_) {
return {
duration: 500,
css: t => `opacity: ${t}`,
}
}
let visible = $state(true);
</script>

<button onclick={() => visible = !visible}>Toggle</button>

{#if visible}
<div>
<span transition:fade>123</span>
</div>
{/if}

0 comments on commit 58b1540

Please sign in to comment.