Skip to content

Commit

Permalink
[fix] add key dependencies into block dependencies (#7422)
Browse files Browse the repository at this point in the history
* add key dependencies into block dependencies

* fix lint
  • Loading branch information
tanhauhau authored Apr 8, 2022
1 parent 6ef0aa2 commit 89fda7e
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/compiler/compile/render_dom/wrappers/KeyBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export default class KeyBlockWrapper extends Wrapper {
name: renderer.component.get_unique_name('create_key_block'),
type: 'key'
});
block.add_dependencies(node.expression.dependencies);
renderer.blocks.push(block);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<slot/>
12 changes: 12 additions & 0 deletions test/runtime/samples/key-block-component-slot/Component2.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<script>
import { onMount } from "svelte";
export let logs;
onMount(() => {
logs.push("mount");
return () => {
logs.push("unmount");
};
});
</script>
18 changes: 18 additions & 0 deletions test/runtime/samples/key-block-component-slot/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const logs = [];

export default {
html: '<button>Reset!</button>',
props: {
logs
},
async test({ assert, component, target, raf }) {
assert.deepEqual(logs, ['mount']);

const button = target.querySelector('button');

const click = new window.MouseEvent('click');
await button.dispatchEvent(click);

assert.deepEqual(logs, ['mount', 'unmount', 'mount']);
}
};
17 changes: 17 additions & 0 deletions test/runtime/samples/key-block-component-slot/main.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<script>
import Component1 from './Component1.svelte'
import Component2 from './Component2.svelte'
let reset = false
export let logs;
</script>

<Component1>
{#key reset}
<Component2 {logs} />
{/key}
</Component1>

<button on:click={() => reset = !reset}>
Reset!
</button>

0 comments on commit 89fda7e

Please sign in to comment.