Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/canary' into add/ssg-loading-s…
Browse files Browse the repository at this point in the history
…tate
  • Loading branch information
ijjk committed Feb 5, 2020
2 parents 9a8e710 + 924f8ae commit 0e0d4f9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 22 deletions.
9 changes: 3 additions & 6 deletions examples/with-apollo/lib/apollo.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@ let globalApolloClient = null
* Creates and provides the apolloContext
* to a next.js PageTree. Use it by wrapping
* your PageComponent via HOC pattern.
* @param {Function|Class} PageComponent
* @param {Object} [config]
* @param {Boolean} [config.ssr=true]
*/
export function withApollo(PageComponent, { ssr = true } = {}) {
export const withApollo = ({ ssr = true } = {}) => PageComponent => {
const WithApollo = ({ apolloClient, apolloState, ...pageProps }) => {
const client = apolloClient || initApolloClient(apolloState)
return (
Expand Down Expand Up @@ -104,7 +101,7 @@ export function withApollo(PageComponent, { ssr = true } = {}) {
* Creates or reuses apollo client in the browser.
* @param {Object} initialState
*/
function initApolloClient(initialState) {
const initApolloClient = initialState => {
// Make sure to create a new client for every server-side request so that data
// isn't shared between connections (which would be bad)
if (typeof window === 'undefined') {
Expand All @@ -123,7 +120,7 @@ function initApolloClient(initialState) {
* Creates and configures the ApolloClient
* @param {Object} [initialState={}]
*/
function createApolloClient(initialState = {}) {
const createApolloClient = (initialState = {}) => {
// Check out https://github.com/zeit/next.js/pull/4611 if you want to use the AWSAppSyncClient
return new ApolloClient({
ssrMode: typeof window === 'undefined', // Disables forceFetch on the server (so queries are only run once)
Expand Down
6 changes: 2 additions & 4 deletions examples/with-apollo/pages/client-only.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,5 @@ const ClientOnlyPage = props => (
</App>
)

export default withApollo(ClientOnlyPage, {
// Disable apollo ssr fetching in favour of automatic static optimization
ssr: false,
})
// Disable apollo ssr fetching in favour of automatic static optimization
export default withApollo({ ssr: false })(ClientOnlyPage)
2 changes: 1 addition & 1 deletion examples/with-apollo/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ const IndexPage = props => (
</App>
)

export default withApollo(IndexPage)
export default withApollo()(IndexPage)
19 changes: 8 additions & 11 deletions examples/with-zones/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,15 @@ cd with-zones

## Notes

In this example, we have two apps: 'home' and 'blog'. We'll start both apps with [Now](https://zeit.co/now):

```bash
now dev
```

Then, you can visit <http://localhost:3000> and develop for both apps as a single app.

You can also start the apps separately, for example:
In this example, we have two apps: 'home' and 'blog'. You can start each app separately, for example:

```bash
cd blog
yarn dev
```

Then, you can visit <http://localhost:3000> and develop your app.

## Special Notes

- All pages should be unique across zones. For example, the 'home' app should not have a `pages/blog/index.js` page.
Expand All @@ -55,8 +49,11 @@ yarn dev

## Production Deployment

We only need to run `now`, the same `now.json` used for development will be used for the deployment:
We only need to run `now <app>`, to deploy the app:

```bash
now
now blog
now home
```

> The rewrite destination in your `now.json` file in the `home` app must be adjusted to point to your deployment.

0 comments on commit 0e0d4f9

Please sign in to comment.