-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Async onClientEntry #1735
Async onClientEntry #1735
Changes from 5 commits
7ef3fe6
a907304
080c9ef
fdc5309
0e9235a
7a1dfc8
139ef3a
e9261c0
8618a81
e4a85ae
69e57fd
3b775f5
1ffb082
99e91f6
640258e
e738266
8e74607
5f08f9c
9cc6beb
ae60de4
46327e4
810be19
a78b35e
eaffa6b
4988319
81917e6
6ccb27b
61d11a5
42e3bb3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,3 +45,5 @@ node_modules/ | |
.vscode/ | ||
yarn.lock | ||
package-lock.json | ||
|
||
__tests__ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,70 @@ | ||
const apiRunner = require(`./api-runner-browser`) | ||
|
||
import React from "react" | ||
import ReactDOM from "react-dom" | ||
import { AppContainer as HotContainer } from "react-hot-loader" | ||
import socketIo from "./socketIo" | ||
import apiRunner from "./api-runner-browser" | ||
import emitter from "./emitter" | ||
|
||
|
||
window.___emitter = emitter | ||
|
||
Promise | ||
.all(apiRunner(`onClientEntry`)) | ||
.catch((error) => { throw error }) | ||
.then(() => { | ||
|
||
const rootElement = document.getElementById(`___gatsby`) | ||
|
||
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() | ||
// Troubles with this import in the past? | ||
let Root = require("./root") | ||
if (Root.default) { | ||
Root = Root.default | ||
} | ||
}) | ||
} | ||
|
||
const rootElement = document.getElementById(`___gatsby`) | ||
|
||
let Root = require(`./root`) | ||
if (Root.default) { | ||
Root = Root.default | ||
} | ||
|
||
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 | ||
|
||
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() | ||
} | ||
}) | ||
} | ||
|
||
ReactDOM.render( | ||
<HotContainer> | ||
<NextRoot /> | ||
</HotContainer>, | ||
<HotContainer><Root /></HotContainer>, | ||
rootElement, | ||
() => { | ||
apiRunner(`onInitialClientRender`) | ||
} | ||
() => apiRunner(`onInitialClientRender`) | ||
) | ||
|
||
if (module.hot) { | ||
|
||
module.hot.accept(`./root`, () => { | ||
|
||
let NextRoot = require(`./root`) | ||
|
||
if (NextRoot.default) { | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is the Github diff display being weird or is there really spaces between all these lines? If so, those need removed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Apologies, some of my local formatting sneaking in, I'll strip them out. |
||
NextRoot = NextRoot.default | ||
} | ||
|
||
ReactDOM.render( | ||
<HotContainer><NextRoot /></HotContainer>, | ||
rootElement, | ||
() => apiRunner(`onInitialClientRender`) | ||
) | ||
}) | ||
} | ||
}) | ||
} | ||
.catch((error) => { throw error }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is because es6/commonjs modules work differently.