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 27 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
35 changes: 35 additions & 0 deletions docs/docs/browser-support.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll also need to update the doc-links.yaml file with the new link.

title: Browser Support
---

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add/replace the text at the start saying "Gatsby supports the same browsers as the stable version of React.js which is currently IE9+ as well as the most recent versions of other popular browsers. Gatsby requires support for the Promise API which is not supported in older browsers. Because of this, Gatsby…"

Gatsby supports [the same browsers as the current stable version of React.js](https://facebook.github.io/react/docs/react-dom.html#browser-support) which is currently IE9+ as well as the most recent versions of other popular browsers.

## Polyfills

Gatsby uses the ES6 Promise API. As some older browsers don't support this, Gatsby includes by default a Promise polyfill. If you would like to provide your own promise implementation, you can set `polyfill` to `false` in your `gatsby-config.js`:

```
module.exports = {
polyfill: false,
// ...
}
```

## Specify what browsers your project supports using "Browserslist"

You may customize your list of supported browser versions by declaring a [`"browserslist"`](https://github.com/ai/browserslist) key within your `package.json`. Changing these values will modify your JavaScript (via [`babel-preset-env`](https://github.com/babel/babel-preset-env#targetsbrowsers)) and your CSS (via [`autoprefixer`](https://github.com/postcss/autoprefixer)) output.

This article is a good introduction to the growing community of tools around Browserslist — https://css-tricks.com/browserlist-good-idea/

By default, Gatsby emulates the following config:

```javascript
// package.json
{
"browserslist": [
"> 1%",
"IE >= 9",
"last 2 versions"
]
}
```
20 changes: 0 additions & 20 deletions docs/docs/browserslist.md

This file was deleted.

1 change: 0 additions & 1 deletion examples/using-javascript-transforms/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ exports.createPages = ({ graphql, boundActionCreators }) => {
const { createPage } = boundActionCreators

return new Promise((resolve, reject) => {

const pages = []
const markdownTemplate = path.resolve(`src/templates/markdown.js`)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class SiteLinks extends React.Component {
<div className="blog-social">
<ul>
<li>
<a href={'mailto:' + siteMetadata.siteEmailUrl}>
<a href={`mailto:` + siteMetadata.siteEmailUrl}>
<i className="fa fa-envelope-o" /> {siteMetadata.siteEmailPretty}
</a>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import SiteNav from "../SiteNav"
import SiteLinks from "../SiteLinks"

class SiteSidebar extends React.Component {
render() {
const isHome = this.props.location.pathname === ('/');
const siteMetadata = this.props.siteMetadata;
// TODO, deal with image more nice like
render() {
const isHome = this.props.location.pathname === `/`
const siteMetadata = this.props.siteMetadata
// TODO, deal with image more nice like

let header = (
<div className="">
Expand Down
5 changes: 3 additions & 2 deletions examples/using-javascript-transforms/src/layouts/blog-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class BlogPostTemplate extends React.Component {
</div>
</div>
)
/*
/*
if (frontmatter.updated === null) {
var published = (
<div className="date-published">
Expand Down Expand Up @@ -76,7 +76,8 @@ class BlogPostTemplate extends React.Component {
*/
let published = <div className="date-published" />

return (<div>
return (
<div>
{home}
<div className="container">
{this.props.children()}
Expand Down
37 changes: 18 additions & 19 deletions examples/using-javascript-transforms/src/layouts/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import * as PropTypes from 'prop-types';
import Helmet from 'react-helmet';
import '../static/css/base.scss';
import React from "react"
import * as PropTypes from "prop-types"
import Helmet from "react-helmet"
import "../static/css/base.scss"

import InsetPage from "./inset-page"
import BlogPost from "./blog-post"
Expand All @@ -12,20 +12,20 @@ class MasterLayout extends React.Component {
let location = this.props.location.pathname
let jimmyPage // you jimmy a lock until it opens, so same thing here ;)

// let dataSource = this.props.pageResources.json.data
// let nodeType = dataSource.jsFrontmatter || dataSource.markdownRemark
// let frontmatter = nodeType.data || nodeType.frontmatter
let passdown = {
// frontmatter: frontmatter,
location: this.props.location,
siteMetadata: siteMetadata,
children: this.props.children
}
if (location === `/` || location === `/contact`) {
jimmyPage = <InsetPage {...passdown} />
} else {
jimmyPage = <BlogPost {...passdown} />
}
// let dataSource = this.props.pageResources.json.data
// let nodeType = dataSource.jsFrontmatter || dataSource.markdownRemark
// let frontmatter = nodeType.data || nodeType.frontmatter
let passdown = {
// frontmatter: frontmatter,
location: this.props.location,
siteMetadata: siteMetadata,
children: this.props.children,
}
if (location === `/` || location === `/contact`) {
jimmyPage = <InsetPage {...passdown} />
} else {
jimmyPage = <BlogPost {...passdown} />
}

return (
<div className="MasterLayout">
Expand All @@ -44,7 +44,6 @@ class MasterLayout extends React.Component {

export default MasterLayout


export const pageQuery = graphql`
query LayoutBySlug {
allSite {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import moment from "moment"

class SiteIndex extends React.Component {
render() {

const pageLinks = []
let iteratorKey = 0
let pageRaw = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ export const pageQuery = graphql`
}
}
`
*/
*/
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ export const pageQuery = graphql`
}
}
}
`
`
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"babel-preset-stage-0": "^6.24.1",
"babel-register": "^6.24.1",
"babel-runtime": "^6.23.0",
"core-js": "^2.5.0",
"create-react-class": "^15.6.0",
"cross-env": "^5.0.5",
"eslint": "^4.2.0",
Expand Down
13 changes: 11 additions & 2 deletions packages/gatsby/cache-dir/api-runner-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
// require('/path/to/plugin2/gatsby-browser.js'),
// ]

module.exports = (api, args, defaultReturn) => {
// Run each plugin in series.
export function apiRunner(api, args, defaultReturn) {
let results = plugins.map(plugin => {
if (plugin.plugin[api]) {
const result = plugin.plugin[api](args, plugin.options)
Expand All @@ -25,3 +24,13 @@ module.exports = (api, args, defaultReturn) => {
return []
}
}

export function apiRunnerAsync(api, args, defaultReturn) {
return plugins.reduce(
(previous, next) =>
next.plugin[api]
? previous.then(() => next.plugin[api](args, next.options))
: previous,
Promise.resolve()
)
}
97 changes: 49 additions & 48 deletions packages/gatsby/cache-dir/app.js
Original file line number Diff line number Diff line change
@@ -1,69 +1,70 @@
const apiRunner = require(`./api-runner-browser`)

if (__POLYFILL__) {
require("core-js/modules/es6.promise")
}
import { apiRunner, apiRunnerAsync } from "./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()
apiRunnerAsync(`onClientEntry`).then(() => {
// 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()
}
})
}
/**
* 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`)
const rootElement = document.getElementById(`___gatsby`)

let Root = require(`./root`)
if (Root.default) {
Root = Root.default
}
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
}
domReady(() =>
ReactDOM.render(
<HotContainer>
<NextRoot />
<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`)
}
)
})
}
})
Loading