-
Notifications
You must be signed in to change notification settings - Fork 10.3k
/
app.js
69 lines (59 loc) · 1.55 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const apiRunner = require(`./api-runner-browser`)
import React from "react"
import ReactDOM from "react-dom"
import { AppContainer as HotContainer } from "react-hot-loader"
import domReady from "domready"
import socketIo from "./socketIo"
window.___emitter = require(`./emitter`)
// Let the site/plugins run code very early.
apiRunner(`onClientEntry`)
// Hook up the client to socket.io on server
socketIo()
/**
* Service Workers are persistent by nature. They stick around,
* serving a cached version of the site if they aren't removed.
* This is especially frustrating when you need to test the
* production build on your local machine.
*
* Let's unregister the service workers in development, and tidy up a few errors.
*/
if (`serviceWorker` in navigator) {
navigator.serviceWorker.getRegistrations().then(registrations => {
for (let registration of registrations) {
registration.unregister()
}
})
}
const rootElement = document.getElementById(`___gatsby`)
let Root = require(`./root`)
if (Root.default) {
Root = Root.default
}
domReady(() =>
ReactDOM.render(
<HotContainer>
<Root />
</HotContainer>,
rootElement,
() => {
apiRunner(`onInitialClientRender`)
}
)
)
if (module.hot) {
module.hot.accept(`./root`, () => {
let NextRoot = require(`./root`)
if (NextRoot.default) {
NextRoot = NextRoot.default
}
ReactDOM.render(
<HotContainer>
<NextRoot />
</HotContainer>,
rootElement,
() => {
apiRunner(`onInitialClientRender`)
}
)
})
}