fix : $.component() break transition (#13646)

* $.component() must use EFFECT_TRANSPARENT

* changeset

* Update .changeset/eight-pans-worry.md

---------

Co-authored-by: Dominic Gannaway <trueadm@users.noreply.github.com>
pull/13648/head
adiGuba 2 months ago committed by GitHub
parent 139114bdcb
commit bb245445fc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: transitions within dynamic components now function correctly

@ -1,4 +1,5 @@
/** @import { TemplateNode, Dom, Effect } from '#client' */
import { EFFECT_TRANSPARENT } from '../../constants.js';
import { block, branch, pause_effect } from '../../reactivity/effects.js';
import { hydrate_next, hydrate_node, hydrating } from '../hydration.js';
@ -34,7 +35,7 @@ export function component(node, get_component, render_fn) {
if (component) {
effect = branch(() => render_fn(anchor, component));
}
});
}, EFFECT_TRANSPARENT);
if (hydrating) {
anchor = hydrate_node;

@ -0,0 +1,13 @@
<script>
function fade(_) {
return {
duration: 100,
css: (t) => `opacity: ${t}`
};
}
</script>
<p transition:fade>foo</p>

@ -0,0 +1,32 @@
import { flushSync } from '../../../../src/index-client.js';
import { test } from '../../test';
/**
* $.component() should not break transition
* https://github.com/sveltejs/svelte/issues/13645
*/
export default test({
test({ assert, raf, target }) {
const btn = target.querySelector('button');
// in
btn?.click();
flushSync();
assert.htmlEqual(
target.innerHTML,
'<button>toggle</button><p style="opacity: 0;">foo</p><p style="opacity: 0;">foo</p>'
);
raf.tick(50);
assert.htmlEqual(
target.innerHTML,
'<button>toggle</button><p style="opacity: 0.5;">foo</p><p style="opacity: 0.5;">foo</p>'
);
raf.tick(100);
assert.htmlEqual(
target.innerHTML,
'<button>toggle</button><p style="">foo</p><p style="">foo</p>'
);
}
});

@ -0,0 +1,13 @@
<script>
import Foo from './Foo.svelte';
const Comp = { Foo };
let visible = $state(false);
</script>
<button onclick={() => (visible = !visible)}>toggle</button>
{#if visible}
<Foo />
<Comp.Foo />
{/if}
Loading…
Cancel
Save