File tree Expand file tree Collapse file tree 5 files changed +43
-20
lines changed Expand file tree Collapse file tree 5 files changed +43
-20
lines changed Original file line number Diff line number Diff line change @@ -20,11 +20,6 @@ if (process.env.NODE_ENV === `production`) {
20
20
}
21
21
}
22
22
23
- const JS_NPM_URLS = [
24
- '//unpkg.com/docsearch.js@2.4.1/dist/cdn/docsearch.min.js' ,
25
- '//unpkg.com/babel-standalone@6.26.0/babel.min.js' ,
26
- ] ;
27
-
28
23
export default class HTML extends Component {
29
24
render ( ) {
30
25
let css ;
@@ -37,8 +32,6 @@ export default class HTML extends Component {
37
32
) ;
38
33
}
39
34
40
- const js = JS_NPM_URLS . map ( url => < script key = { url } src = { url } /> ) ;
41
-
42
35
return (
43
36
< html lang = "en" >
44
37
< head >
@@ -50,7 +43,6 @@ export default class HTML extends Component {
50
43
/>
51
44
< link rel = "icon" href = "/favicon.ico" />
52
45
{ this . props . headComponents }
53
- { js }
54
46
{ css }
55
47
</ head >
56
48
< body >
Original file line number Diff line number Diff line change @@ -19,6 +19,8 @@ import Flex from 'components/Flex';
19
19
import Footer from 'components/LayoutFooter' ;
20
20
import Header from 'components/LayoutHeader' ;
21
21
import { media } from 'theme' ;
22
+ import loadScript from 'utils/loadScript' ;
23
+ import { docsearchURL } from 'site-constants' ;
22
24
23
25
// Import global styles
24
26
import '../prism-styles' ;
@@ -28,13 +30,15 @@ import 'css/algolia.css';
28
30
29
31
class Template extends Component {
30
32
componentDidMount ( ) {
31
- // Initialize Algolia search.
32
- // TODO Is this expensive? Should it be deferred until a user is about to search?
33
- // eslint-disable-next-line no-undef
34
- docsearch ( {
35
- apiKey : '36221914cce388c46d0420343e0bb32e' ,
36
- indexName : 'react' ,
37
- inputSelector : '#algolia-doc-search' ,
33
+ loadScript ( docsearchURL ) . then ( ( ) => {
34
+ // Initialize Algolia search.
35
+ // TODO Is this expensive? Should it be deferred until a user is about to search?
36
+ // eslint-disable-next-line no-undef
37
+ docsearch ( {
38
+ apiKey : '36221914cce388c46d0420343e0bb32e' ,
39
+ indexName : 'react' ,
40
+ inputSelector : '#algolia-doc-search' ,
41
+ } ) ;
38
42
} ) ;
39
43
}
40
44
Original file line number Diff line number Diff line change 14
14
// the SSR part in node.js we won't have a proper location.
15
15
const urlRoot = 'https://reactjs.org' ;
16
16
const version = '16.0.0' ;
17
+ const babelURL = '//unpkg.com/babel-standalone@6.26.0/babel.min.js' ;
18
+ const docsearchURL = '//unpkg.com/docsearch.js@2.4.1/dist/cdn/docsearch.min.js' ;
17
19
18
- export { urlRoot , version } ;
20
+ export { urlRoot , version , babelURL , docsearchURL } ;
Original file line number Diff line number Diff line change @@ -18,13 +18,17 @@ import React, {Component} from 'react';
18
18
import TitleAndMetaTags from 'components/TitleAndMetaTags' ;
19
19
import { colors , media , sharedStyles } from 'theme' ;
20
20
import createOgUrl from 'utils/createOgUrl' ;
21
+ import loadScript from 'utils/loadScript' ;
22
+ import { babelURL } from 'site-constants' ;
21
23
22
24
class Home extends Component {
23
25
componentDidMount ( ) {
24
- mountCodeExample ( 'helloExample' , HELLO_COMPONENT ) ;
25
- mountCodeExample ( 'timerExample' , TIMER_COMPONENT ) ;
26
- mountCodeExample ( 'todoExample' , TODO_COMPONENT ) ;
27
- mountCodeExample ( 'markdownExample' , MARKDOWN_COMPONENT ) ;
26
+ loadScript ( babelURL ) . then ( ( ) => {
27
+ mountCodeExample ( 'helloExample' , HELLO_COMPONENT ) ;
28
+ mountCodeExample ( 'timerExample' , TIMER_COMPONENT ) ;
29
+ mountCodeExample ( 'todoExample' , TODO_COMPONENT ) ;
30
+ mountCodeExample ( 'markdownExample' , MARKDOWN_COMPONENT ) ;
31
+ } )
28
32
}
29
33
30
34
render ( ) {
Original file line number Diff line number Diff line change
1
+ /**
2
+ * Copyright (c) 2013-present, Facebook, Inc.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @emails react-core
8
+ */
9
+
10
+ 'use strict' ;
11
+
12
+ export default url => new Promise ( ( resolve , reject ) =>
13
+ document . head . appendChild (
14
+ Object . assign ( document . createElement ( 'script' ) , {
15
+ async : true ,
16
+ src : url ,
17
+ onload : resolve ,
18
+ onerror : reject
19
+ } )
20
+ )
21
+ ) ;
You can’t perform that action at this time.
0 commit comments