Skip to content

Commit

Permalink
fix to apply class directive for svelte:element (#7531)
Browse files Browse the repository at this point in the history
  • Loading branch information
baseballyama committed May 18, 2022
1 parent 5242ab9 commit 6776fe0
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/compiler/compile/render_dom/wrappers/Element/index.ts
Expand Up @@ -1048,7 +1048,7 @@ export default class ElementWrapper extends Wrapper {

block.chunks.hydrate.push(updater);

if (has_spread) {
if (has_spread || this.node.is_dynamic_element) {
block.chunks.update.push(updater);
} else if ((dependencies && dependencies.size > 0) || this.class_dependencies.length) {
const all_dependencies = this.class_dependencies.concat(...dependencies);
Expand Down
13 changes: 13 additions & 0 deletions test/runtime/samples/dynamic-element-class-directive/Link.svelte
@@ -0,0 +1,13 @@
<script>
export let item;
</script>

<svelte:element this="div" class:active={true}>
{item.text}
</svelte:element>

<style>
.active {
color: red;
}
</style>
11 changes: 11 additions & 0 deletions test/runtime/samples/dynamic-element-class-directive/_config.js
@@ -0,0 +1,11 @@
export default {
html: `
<div class="svelte-1vsuzn0 active">foo</div>
<div class="svelte-1vsuzn0 active">foo0</div>
<div class="svelte-1vsuzn0 active">foo0</div>
<div class="svelte-1vsuzn0 active">foo0</div>
<div class="svelte-1vsuzn0 active">foo1</div>
<div class="svelte-1vsuzn0 active">foo2</div>
<div class="svelte-1vsuzn0 active">foo3</div>
`
};
16 changes: 16 additions & 0 deletions test/runtime/samples/dynamic-element-class-directive/main.svelte
@@ -0,0 +1,16 @@
<script>
import Link from "./Link.svelte";
let foo = [
{ text: "foo0" },
{ text: "foo1" },
{ text: "foo2" },
{ text: "foo3" },
];
</script>

<Link item={{ text: "foo" }} />
<Link item={foo[0]} />
<Link bind:item={foo[0]} />
{#each foo as item}
<Link bind:item />
{/each}

0 comments on commit 6776fe0

Please sign in to comment.