Skip to content

Commit bb24544

Browse files
adigubatrueadm
andauthored
fix : $.component() break transition (#13646)
* $.component() must use EFFECT_TRANSPARENT * changeset * Update .changeset/eight-pans-worry.md --------- Co-authored-by: Dominic Gannaway <[email protected]>
1 parent 139114b commit bb24544

File tree

5 files changed

+65
-1
lines changed

5 files changed

+65
-1
lines changed

.changeset/eight-pans-worry.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: transitions within dynamic components now function correctly

packages/svelte/src/internal/client/dom/blocks/svelte-component.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/** @import { TemplateNode, Dom, Effect } from '#client' */
2+
import { EFFECT_TRANSPARENT } from '../../constants.js';
23
import { block, branch, pause_effect } from '../../reactivity/effects.js';
34
import { hydrate_next, hydrate_node, hydrating } from '../hydration.js';
45

@@ -34,7 +35,7 @@ export function component(node, get_component, render_fn) {
3435
if (component) {
3536
effect = branch(() => render_fn(anchor, component));
3637
}
37-
});
38+
}, EFFECT_TRANSPARENT);
3839

3940
if (hydrating) {
4041
anchor = hydrate_node;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<script>
2+
function fade(_) {
3+
return {
4+
duration: 100,
5+
css: (t) => `opacity: ${t}`
6+
};
7+
}
8+
9+
10+
</script>
11+
12+
<p transition:fade>foo</p>
13+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { flushSync } from '../../../../src/index-client.js';
2+
import { test } from '../../test';
3+
4+
/**
5+
* $.component() should not break transition
6+
* https://github.com/sveltejs/svelte/issues/13645
7+
*/
8+
export default test({
9+
test({ assert, raf, target }) {
10+
const btn = target.querySelector('button');
11+
12+
// in
13+
btn?.click();
14+
flushSync();
15+
assert.htmlEqual(
16+
target.innerHTML,
17+
'<button>toggle</button><p style="opacity: 0;">foo</p><p style="opacity: 0;">foo</p>'
18+
);
19+
20+
raf.tick(50);
21+
assert.htmlEqual(
22+
target.innerHTML,
23+
'<button>toggle</button><p style="opacity: 0.5;">foo</p><p style="opacity: 0.5;">foo</p>'
24+
);
25+
26+
raf.tick(100);
27+
assert.htmlEqual(
28+
target.innerHTML,
29+
'<button>toggle</button><p style="">foo</p><p style="">foo</p>'
30+
);
31+
}
32+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<script>
2+
import Foo from './Foo.svelte';
3+
const Comp = { Foo };
4+
5+
let visible = $state(false);
6+
</script>
7+
8+
<button onclick={() => (visible = !visible)}>toggle</button>
9+
10+
{#if visible}
11+
<Foo />
12+
<Comp.Foo />
13+
{/if}

0 commit comments

Comments
 (0)