File tree 1 file changed +12
-3
lines changed
1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change 4
4
* SPDX-License-Identifier: BSD-3-Clause
5
5
*/
6
6
7
+ // lib.dom.ts is out of date, so declare our own parseFromString here.
8
+ interface DOMParser {
9
+ parseFromString ( string : string , type : DOMParserSupportedType , options ?: {
10
+ includeShadowRoots : boolean ;
11
+ } ) : Document ;
12
+ }
13
+
7
14
// This isn't ideal. Setting .innerHTML is not compatible with some
8
15
// TrustedTypes CSP policies. Discussion at:
9
16
// https://github.com/mfreed7/declarative-shadow-dom/issues/3
10
17
let hasNative : boolean | undefined ;
11
18
export function hasNativeDeclarativeShadowRoots ( ) : boolean {
12
19
if ( hasNative === undefined ) {
13
- const div = document . createElement ( 'div' ) ;
14
- div . innerHTML = `<div><template shadowroot="open"></template></div>` ;
15
- hasNative = ! ! div . firstElementChild ! . shadowRoot ;
20
+ const html = `<div><template shadowroot="open"></template></div>` ;
21
+ const fragment = ( new DOMParser ( ) as DOMParser ) . parseFromString ( html , 'text/html' , {
22
+ includeShadowRoots : true
23
+ } ) ;
24
+ hasNative = ! ! fragment . querySelector ( 'div' ) ?. shadowRoot ;
16
25
}
17
26
return hasNative ;
18
27
}
You can’t perform that action at this time.
0 commit comments