Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] add key dependencies into block dependencies #7422

Merged
merged 2 commits into from Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/compiler/compile/render_dom/wrappers/KeyBlock.ts
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
@@ -0,0 +1 @@
<slot/>
12 changes: 12 additions & 0 deletions test/runtime/samples/key-block-component-slot/Component2.svelte
@@ -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
@@ -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
@@ -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>