main
js 51 lines 1.4 KB
Raw
1 import './polyfills';
2 import loadReact, {isLocal} from './react-loader';
3
4 if (isLocal()) {
5 Promise.all([
6 import('react'),
7 import('react-dom'),
8 import('react-dom/client'),
9 ])
10 .then(([React, ReactDOM, ReactDOMClient]) => {
11 if (
12 React === undefined ||
13 ReactDOM === undefined ||
14 ReactDOMClient === undefined
15 ) {
16 throw new Error(
17 'Unable to load React. Build experimental and then run `yarn dev` again'
18 );
19 }
20 window.React = React;
21 window.ReactDOM = ReactDOM;
22 window.ReactDOMClient = ReactDOMClient;
23 })
24 .then(() => import('./components/App'))
25 .then(App => {
26 window.ReactDOMClient.createRoot(document.getElementById('root')).render(
27 window.React.createElement(App.default)
28 );
29 });
30 } else {
31 loadReact()
32 .then(() => import('./components/App'))
33 .then(App => {
34 const {React, ReactDOM} = window;
35 if (
36 typeof window.ReactDOMClient !== 'undefined' &&
37 typeof window.ReactDOMClient.createRoot !== 'undefined'
38 ) {
39 // we are in a React that only supports modern roots
40
41 window.ReactDOMClient.createRoot(
42 document.getElementById('root')
43 ).render(React.createElement(App.default));
44 } else {
45 ReactDOM.render(
46 React.createElement(App.default),
47 document.getElementById('root')
48 );
49 }
50 });
51 }