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(runtime-dom): Ensure custom Elements can inherit provides from ancestors (fix: #5096) #5098

Merged
merged 1 commit into from Nov 11, 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
46 changes: 46 additions & 0 deletions packages/runtime-dom/__tests__/customElement.spec.ts
Expand Up @@ -323,6 +323,52 @@ describe('defineCustomElement', () => {
await nextTick()
expect(consumer.shadowRoot!.innerHTML).toBe(`<div>changed!</div>`)
})

test('inherited from ancestors', async () => {
const fooA = ref('FooA!')
const fooB = ref('FooB!')
const ProviderA = defineCustomElement({
provide: {
fooA
},
render() {
return h('provider-b')
}
})
const ProviderB = defineCustomElement({
provide: {
fooB
},
render() {
return h('my-multi-consumer')
}
})

const Consumer = defineCustomElement({
setup() {
const fooA = inject<Ref>('fooA')!
const fooB = inject<Ref>('fooB')!
return () => h('div', `${fooA.value} ${fooB.value}`)
}
})

customElements.define('provider-a', ProviderA)
customElements.define('provider-b', ProviderB)
customElements.define('my-multi-consumer', Consumer)
container.innerHTML = `<provider-a><provider-a>`
const providerA = container.childNodes[0] as VueElement
const providerB = providerA.shadowRoot!.childNodes[0] as VueElement
const consumer = providerB.shadowRoot!.childNodes[0] as VueElement

expect(consumer.shadowRoot!.innerHTML).toBe(`<div>FooA! FooB!</div>`)

fooA.value = 'changedA!'
fooB.value = 'changedB!'
await nextTick()
expect(consumer.shadowRoot!.innerHTML).toBe(
`<div>changedA! changedB!</div>`
)
})
})

describe('styles', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/runtime-dom/src/apiCustomElement.ts
Expand Up @@ -354,6 +354,7 @@ export class VueElement extends BaseClass {
) {
if (parent instanceof VueElement) {
instance.parent = parent._instance
instance.provides = parent._instance!.provides
break
}
}
Expand Down