Only define MyElement when needed (#11069)
Brandon Dail committed
Oct 3, 2017 at 10:23 UTC
f6a79d1f1607fb5e50904b143edcf3801144d2ce
1 file changed
+16
-17
fixtures/dom/src/components/fixtures/custom-elements/index.js
+16
-17
@@ -12,24 +12,23 @@ class HelloWorld extends React.Component {
12
}
13
}
14
15
-// Babel breaks web components.
16
-// https://github.com/w3c/webcomponents/issues/587
17
-// eslint-disable-next-line no-new-func
18
-const MyElement = new Function(
19
- 'React',
20
- 'ReactDOM',
21
- 'HelloWorld',
22
- `
23
-return class MyElement extends HTMLElement {
24
- constructor() {
25
- super();
26
- const shadowRoot = this.attachShadow({ mode:'open' });
27
- ReactDOM.render(React.createElement(HelloWorld), shadowRoot);
28
- }
29
-}`
30
-)(React, ReactDOM, HelloWorld);
31
-
15
if (supportsCustomElements) {
16
+ // Babel breaks web components.
17
+ // https://github.com/w3c/webcomponents/issues/587
18
+ // eslint-disable-next-line no-new-func
19
+ const MyElement = new Function(
20
+ 'React',
21
+ 'ReactDOM',
22
+ 'HelloWorld',
23
+ `
24
+ return class MyElement extends HTMLElement {
25
+ constructor() {
26
+ super();
27
+ const shadowRoot = this.attachShadow({ mode:'open' });
28
+ ReactDOM.render(React.createElement(HelloWorld), shadowRoot);
29
+ }
30
+ }`
31
+ )(React, ReactDOM, HelloWorld);
32
customElements.define('my-element', MyElement);
33
}
34