Skip to content

Commit

Permalink
fix(custom-element): fix custom-element double render on immediate pr…
Browse files Browse the repository at this point in the history
…op change

fix #9885
close #11335
  • Loading branch information
yyx990803 committed Aug 7, 2024
1 parent 1058ce8 commit 978ff3c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/runtime-core/src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2352,13 +2352,13 @@ function baseCreateRenderer(
namespace,
)
}
container._vnode = vnode
if (!isFlushing) {
isFlushing = true
flushPreFlushCbs()
flushPostFlushCbs()
isFlushing = false
}
container._vnode = vnode
}

const internals: RendererInternals = {
Expand Down
30 changes: 30 additions & 0 deletions packages/runtime-dom/__tests__/customElement.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ describe('defineCustomElement', () => {
myInputEl.removeAttribute('value')
await nextTick()
expect(inputEl.value).toBe('')
app.unmount()
})

test('should not unmount on move', async () => {
Expand Down Expand Up @@ -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',
)
})
})

0 comments on commit 978ff3c

Please sign in to comment.