fix: ensure transitions are applied to nested elements (#14080)

pull/14081/head
Dominic Gannaway 5 days ago committed by GitHub
parent 0ed914b2e5
commit 58b1540ddc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: ensure transitions are applied to nested elements

@ -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';
@ -172,6 +173,7 @@ const visitors = {
SvelteWindow,
TaggedTemplateExpression,
Text,
TransitionDirective,
TitleElement,
UpdateExpression,
UseDirective,

@ -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();
}

@ -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>');
}
});

@ -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}
Loading…
Cancel
Save