-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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>
- Loading branch information
1 parent
31e5f8b
commit 02f60fb
Showing
5 changed files
with
45 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
<script> | ||
import { onDestroy } from 'svelte'; | ||
onDestroy(() => { | ||
console.log('destroy'); | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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']); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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} /> |