Skip to content
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

Merged
merged 29 commits into from
Aug 18, 2017
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
7ef3fe6
Here's what I'm thinking...
atrauzzi Aug 6, 2017
a907304
Didn't realize this ran the root element plugin!
atrauzzi Aug 6, 2017
080c9ef
Merge branch 'master' into topics/async-browser-plugins
atrauzzi Aug 6, 2017
fdc5309
Perform similar bootstrap for production apps.
atrauzzi Aug 6, 2017
0e9235a
Merge branch 'topics/async-browser-plugins' of github.com:atrauzzi/ga…
atrauzzi Aug 6, 2017
7a1dfc8
Remove spaces.
atrauzzi Aug 7, 2017
139ef3a
Introduce a new async API runner for browsers.
atrauzzi Aug 7, 2017
e9261c0
Add support for configurable auto polyfilling.
atrauzzi Aug 7, 2017
8618a81
Some documentation.
atrauzzi Aug 8, 2017
e4a85ae
Update docs.
atrauzzi Aug 8, 2017
69e57fd
Should be on payload.
atrauzzi Aug 8, 2017
3b775f5
Merge remote-tracking branch 'upstream/master' into topics/async-brow…
atrauzzi Aug 8, 2017
1ffb082
Merge remote-tracking branch 'upstream/master' into topics/async-brow…
atrauzzi Aug 8, 2017
99e91f6
Amend the check.
atrauzzi Aug 9, 2017
640258e
Fix expected state for config tests.
atrauzzi Aug 9, 2017
e738266
Add polyfill variable to every configuration.
atrauzzi Aug 10, 2017
8e74607
Merge branch 'master' into topics/async-browser-plugins
KyleAMathews Aug 10, 2017
5f08f9c
Keeping up with master.
atrauzzi Aug 13, 2017
9cc6beb
Updated to use async again.
atrauzzi Aug 13, 2017
ae60de4
Merge branch 'topics/async-browser-plugins' of github.com:atrauzzi/ga…
atrauzzi Aug 13, 2017
46327e4
Merge branch 'master' into topics/async-browser-plugins
KyleAMathews Aug 14, 2017
810be19
Merge again.
atrauzzi Aug 15, 2017
a78b35e
Merge branch 'topics/async-browser-plugins' of github.com:atrauzzi/ga…
atrauzzi Aug 15, 2017
eaffa6b
Merge branch 'master' into topics/async-browser-plugins
sebastienfi Aug 16, 2017
4988319
Merge branch 'master' into topics/async-browser-plugins
sebastienfi Aug 17, 2017
81917e6
Merge branch 'master' into topics/async-browser-plugins
atrauzzi Aug 17, 2017
6ccb27b
Run format and edit docs page
KyleAMathews Aug 18, 2017
61d11a5
Merge branch 'master' into topics/async-browser-plugins
KyleAMathews Aug 18, 2017
42e3bb3
fix
KyleAMathews Aug 18, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,5 @@ node_modules/
.vscode/
yarn.lock
package-lock.json

__tests__
1 change: 0 additions & 1 deletion packages/gatsby/src/cache-dir/api-runner-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
// ]

module.exports = (api, args, defaultReturn) => {
// Run each plugin in series.
let results = plugins.map(plugin => {
if (plugin.plugin[api]) {
const result = plugin.plugin[api](args, plugin.options)
Expand Down
113 changes: 59 additions & 54 deletions packages/gatsby/src/cache-dir/app.js
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?
Copy link
Contributor

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.

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) {

Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 })
Loading