@@ -898,23 +898,22 @@ suite('Static get styles', () => {
898
898
document . body . removeChild ( element ) ;
899
899
} ) ;
900
900
901
- // Test this in Shadow DOM without `adoptedStyleSheets` only since it's easily
902
- // detectable in that case. Look explicitly for no ShadyCSS.
903
901
const testAdoptedStyleSheets =
904
- ( typeof ShadowRoot === 'function' ) &&
905
- ( 'adoptedStyleSheets ' in window . ShadowRoot . prototype ) ;
902
+ ( window . ShadowRoot ) &&
903
+ ( 'replace ' in CSSStyleSheet . prototype ) ;
906
904
( testAdoptedStyleSheets ? test : test . skip ) (
907
905
'Can return CSSStyleSheet where adoptedStyleSheets are natively supported' ,
908
906
async ( ) => {
909
907
const sheet = new CSSStyleSheet ( ) ;
910
908
sheet . replaceSync ( 'div { border: 4px solid red; }' ) ;
909
+ const normal = css `span { border: 4px solid blue; }` ;
911
910
912
911
const base = generateElementName ( ) ;
913
912
customElements . define ( base , class extends LitElement {
914
- static styles = sheet ;
913
+ static styles = [ sheet , normal ] ;
915
914
916
915
render ( ) {
917
- return htmlWithStyles `< div > </ div > ` ;
916
+ return htmlWithStyles `< div > </ div > < span > </ span > ` ;
918
917
}
919
918
} ) ;
920
919
@@ -926,37 +925,42 @@ suite('Static get styles', () => {
926
925
getComputedStyle ( div ) . getPropertyValue ( 'border-top-width' ) . trim ( ) ,
927
926
'4px' ) ;
928
927
928
+ const span = el . shadowRoot ! . querySelector ( 'span' ) ! ;
929
+ assert . equal (
930
+ getComputedStyle ( span ) . getPropertyValue ( 'border-top-width' ) . trim ( ) ,
931
+ '4px' ) ;
932
+
929
933
// When the WC polyfills are included, calling .replaceSync is a noop to
930
934
// our styles as they're already flattened (so expect 4px). Otherwise,
931
935
// look for the updated value.
932
- const flattenDueToPolyfill = ( window . ShadyCSS !== undefined && ! window . ShadyCSS . nativeShadow ) ;
933
- const expectedValue = flattenDueToPolyfill ? '4px ' : '2px ' ;
936
+ const usesAdoptedStyleSheet = ( window . ShadyCSS === undefined || window . ShadyCSS . nativeShadow ) ;
937
+ const expectedValue = usesAdoptedStyleSheet ? '2px ' : '4px ' ;
934
938
sheet . replaceSync ( 'div { border: 2px solid red; }' ) ;
935
939
936
940
assert . equal (
937
941
getComputedStyle ( div ) . getPropertyValue ( 'border-top-width' ) . trim ( ) ,
938
942
expectedValue ) ;
939
943
} ) ;
940
944
941
- // Test that when ShadyCSS is enabled with native support for
942
- // adoptedStyleSheets, we can return a CSSStyleSheet that will be flattened
945
+ // Test that when ShadyCSS is enabled (while still having native support for
946
+ // adoptedStyleSheets) , we can return a CSSStyleSheet that will be flattened
943
947
// and play nice with others.
944
- const testShadyCSSWithAdoptedStyleSheetSupport = ( typeof ShadowRoot === 'function' ) &&
945
- ( 'adoptedStyleSheets' in window . ShadowRoot . prototype ) &&
948
+ const testShadyCSSWithAdoptedStyleSheetSupport =
949
+ ( window . ShadowRoot ) &&
950
+ ( 'replace' in CSSStyleSheet . prototype ) &&
946
951
( window . ShadyCSS !== undefined && ! window . ShadyCSS . nativeShadow ) ;
947
952
( testShadyCSSWithAdoptedStyleSheetSupport ? test : test . skip ) (
948
953
'CSSStyleSheet is flattened where ShadyCSS is enabled yet adoptedStyleSheets are supported' ,
949
954
async ( ) => {
950
955
const sheet = new CSSStyleSheet ( ) ;
951
956
sheet . replaceSync ( 'div { border: 4px solid red; }' ) ;
952
- const normal = css `span { border: 4px solid blue; }` ;
953
957
954
958
const base = generateElementName ( ) ;
955
959
customElements . define ( base , class extends LitElement {
956
- static styles = [ sheet , normal ] ;
960
+ static styles = sheet ;
957
961
958
962
render ( ) {
959
- return htmlWithStyles `< div > </ div > < span > </ span > ` ;
963
+ return htmlWithStyles `< div > </ div > ` ;
960
964
}
961
965
} ) ;
962
966
@@ -969,11 +973,6 @@ suite('Static get styles', () => {
969
973
getComputedStyle ( div ) . getPropertyValue ( 'border-top-width' ) . trim ( ) ,
970
974
'4px' ) ;
971
975
972
- const span = el . shadowRoot ! . querySelector ( 'span' ) ! ;
973
- assert . equal (
974
- getComputedStyle ( span ) . getPropertyValue ( 'border-top-width' ) . trim ( ) ,
975
- '4px' ) ;
976
-
977
976
// CSSStyleSheet update should fail, as the styles will be flattened.
978
977
sheet . replaceSync ( 'div { border: 2px solid red; }' ) ;
979
978
assert . equal (
0 commit comments