-
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 27 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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
--- | ||
title: Browser Support | ||
--- | ||
|
||
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. 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" | ||
] | ||
} | ||
``` |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,4 +41,4 @@ export const pageQuery = graphql` | |
} | ||
} | ||
` | ||
*/ | ||
*/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,4 +48,4 @@ export const pageQuery = graphql` | |
} | ||
} | ||
} | ||
` | ||
` |
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`) | ||
} | ||
) | ||
}) | ||
} | ||
}) |
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.
You'll also need to update the
doc-links.yaml
file with the new link.