Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/runtime-core/src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ import { isAsyncWrapper } from './apiAsyncComponent'
import { isCompatEnabled } from './compat/compatConfig'
import { DeprecationTypes } from './compat/compatConfig'
import type { TransitionHooks } from './components/BaseTransition'
import type { VueElement } from '@vue/runtime-dom'

export interface Renderer<HostElement = RendererElement> {
render: RootRenderFunction<HostElement>
Expand Down Expand Up @@ -1348,7 +1349,11 @@ function baseCreateRenderer(
}
} else {
// custom element style injection
if (root.ce) {
if (
root.ce &&
// @ts-expect-error _def is private
(root.ce as VueElement)._def.shadowRoot !== false
) {
root.ce._injectChildStyle(type)
}

Expand Down
24 changes: 24 additions & 0 deletions packages/runtime-dom/__tests__/customElement.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,30 @@ describe('defineCustomElement', () => {
assertStyles(el, [`div { color: blue; }`, `div { color: red; }`])
})

test("child components should not inject styles to root element's shadow root w/ shadowRoot false", async () => {
const Bar = defineComponent({
styles: [`div { color: green; }`],
render() {
return 'bar'
},
})
const Baz = () => h(Bar)
const Foo = defineCustomElement(
{
render() {
return [h(Baz)]
},
},
{ shadowRoot: false },
)

customElements.define('my-foo-with-shadowroot-false', Foo)
container.innerHTML = `<my-foo-with-shadowroot-false></my-foo-with-shadowroot-false>`
const el = container.childNodes[0] as VueElement
const style = el.shadowRoot?.querySelector('style')
expect(style).toBeUndefined()
})

test('with nonce', () => {
const Foo = defineCustomElement(
{
Expand Down