File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed
Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -86,6 +86,7 @@ import { isAsyncWrapper } from './apiAsyncComponent'
8686import { isCompatEnabled } from './compat/compatConfig'
8787import { DeprecationTypes } from './compat/compatConfig'
8888import type { TransitionHooks } from './components/BaseTransition'
89+ import type { VueElement } from '@vue/runtime-dom'
8990
9091export interface Renderer < HostElement = RendererElement > {
9192 render : RootRenderFunction < HostElement >
@@ -1348,7 +1349,11 @@ function baseCreateRenderer(
13481349 }
13491350 } else {
13501351 // custom element style injection
1351- if ( root . ce ) {
1352+ if (
1353+ root . ce &&
1354+ // @ts -expect-error _def is private
1355+ ( root . ce as VueElement ) . _def . shadowRoot !== false
1356+ ) {
13521357 root . ce . _injectChildStyle ( type )
13531358 }
13541359
Original file line number Diff line number Diff line change @@ -916,6 +916,30 @@ describe('defineCustomElement', () => {
916916 assertStyles ( el , [ `div { color: blue; }` , `div { color: red; }` ] )
917917 } )
918918
919+ test ( "child components should not inject styles to root element's shadow root w/ shadowRoot false" , async ( ) => {
920+ const Bar = defineComponent ( {
921+ styles : [ `div { color: green; }` ] ,
922+ render ( ) {
923+ return 'bar'
924+ } ,
925+ } )
926+ const Baz = ( ) => h ( Bar )
927+ const Foo = defineCustomElement (
928+ {
929+ render ( ) {
930+ return [ h ( Baz ) ]
931+ } ,
932+ } ,
933+ { shadowRoot : false } ,
934+ )
935+
936+ customElements . define ( 'my-foo-with-shadowroot-false' , Foo )
937+ container . innerHTML = `<my-foo-with-shadowroot-false></my-foo-with-shadowroot-false>`
938+ const el = container . childNodes [ 0 ] as VueElement
939+ const style = el . shadowRoot ?. querySelector ( 'style' )
940+ expect ( style ) . toBeUndefined ( )
941+ } )
942+
919943 test ( 'with nonce' , ( ) => {
920944 const Foo = defineCustomElement (
921945 {
You can’t perform that action at this time.
0 commit comments