mirror of https://github.com/sveltejs/svelte
[fix]destroy empty component (#7492)
* fix: destroy non-fragment element such as empty components * fix: fragment property of Empty Component is set as true in dev mode, inconsistent with production mode * chore: revert 'removal' of component.compile_options.dev * feat: add test for destroying empty component * chore: update typechecking callback * chore: revert fragment dev checks * chore: remove unnecessary comment * chore: update test for empty-component-destroy * fix: revert back the patching of console.log * use before_test and after_test Co-authored-by: qinmu <magenta2127@mail.com> Co-authored-by: tanhauhau <lhtan93@gmail.com>pull/7658/head
parent
31e5f8b5de
commit
02f60fbebf
@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
<script>
|
||||||
|
import { onDestroy } from 'svelte';
|
||||||
|
|
||||||
|
onDestroy(() => {
|
||||||
|
console.log('destroy');
|
||||||
|
});
|
||||||
|
</script>
|
@ -0,0 +1,25 @@
|
|||||||
|
let log;
|
||||||
|
export default {
|
||||||
|
html: `
|
||||||
|
<button>destroy component</button>
|
||||||
|
`,
|
||||||
|
|
||||||
|
before_test() {
|
||||||
|
log = console.log;
|
||||||
|
},
|
||||||
|
after_test() {
|
||||||
|
console.log = log;
|
||||||
|
},
|
||||||
|
|
||||||
|
async test({ assert, target, window }) {
|
||||||
|
const button = target.querySelector('button');
|
||||||
|
const event = new window.MouseEvent('click');
|
||||||
|
const messages = [];
|
||||||
|
console.log = msg => messages.push(msg);
|
||||||
|
await button.dispatchEvent(event);
|
||||||
|
assert.htmlEqual(target.innerHTML, `
|
||||||
|
<button>destroy component</button>
|
||||||
|
`);
|
||||||
|
assert.deepEqual(messages, ['destroy']);
|
||||||
|
}
|
||||||
|
};
|
@ -0,0 +1,8 @@
|
|||||||
|
<script>
|
||||||
|
import Empty from './Empty.svelte';
|
||||||
|
let active = true;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button on:click='{() => active = false }'>destroy component</button>
|
||||||
|
|
||||||
|
<svelte:component this={active ? Empty : null} />
|
Loading…
Reference in new issue