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'
86
86
import { isCompatEnabled } from './compat/compatConfig'
87
87
import { DeprecationTypes } from './compat/compatConfig'
88
88
import type { TransitionHooks } from './components/BaseTransition'
89
+ import type { VueElement } from '@vue/runtime-dom'
89
90
90
91
export interface Renderer < HostElement = RendererElement > {
91
92
render : RootRenderFunction < HostElement >
@@ -1348,7 +1349,11 @@ function baseCreateRenderer(
1348
1349
}
1349
1350
} else {
1350
1351
// 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
+ ) {
1352
1357
root . ce . _injectChildStyle ( type )
1353
1358
}
1354
1359
Original file line number Diff line number Diff line change @@ -916,6 +916,30 @@ describe('defineCustomElement', () => {
916
916
assertStyles ( el , [ `div { color: blue; }` , `div { color: red; }` ] )
917
917
} )
918
918
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
+
919
943
test ( 'with nonce' , ( ) => {
920
944
const Foo = defineCustomElement (
921
945
{
You can’t perform that action at this time.
0 commit comments