fix(custom-element): fix custom-element double render on immediate prop change

fix #9885
close #11335
This commit is contained in:
Evan You 2024-08-07 17:43:29 +08:00
parent 1058ce8e74
commit 978ff3c1db
No known key found for this signature in database
GPG Key ID: 00E9AB7A6704CE0A
2 changed files with 31 additions and 1 deletions

View File

@ -2352,13 +2352,13 @@ function baseCreateRenderer(
namespace,
)
}
container._vnode = vnode
if (!isFlushing) {
isFlushing = true
flushPreFlushCbs()
flushPostFlushCbs()
isFlushing = false
}
container._vnode = vnode
}
const internals: RendererInternals = {

View File

@ -108,6 +108,7 @@ describe('defineCustomElement', () => {
myInputEl.removeAttribute('value')
await nextTick()
expect(inputEl.value).toBe('')
app.unmount()
})
test('should not unmount on move', async () => {
@ -772,4 +773,33 @@ describe('defineCustomElement', () => {
)
})
})
// #9885
test('avoid double mount when prop is set immediately after mount', () => {
customElements.define(
'my-input-dupe',
defineCustomElement({
props: {
value: String,
},
render() {
return 'hello'
},
}),
)
createApp({
render() {
return h('div', [
h('my-input-dupe', {
onVnodeMounted(vnode) {
vnode.el!.value = 'fesfes'
},
}),
])
},
}).mount(container)
expect(container.children[0].children[0].shadowRoot?.innerHTML).toBe(
'hello',
)
})
})