Skip to content

Commit f81b31a

Browse files
committed
Resolve conflicts.
2 parents 6cacc2e + f9286f7 commit f81b31a

File tree

22 files changed

+1240
-922
lines changed

22 files changed

+1240
-922
lines changed

.babelrc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@
99
"transform-runtime"
1010
],
1111
"env": {
12-
"test-build": {
13-
"plugins": [
14-
"istanbul"
15-
]
16-
},
1712
"test": {
1813
"presets": [
1914
"es2015",

examples/using-preact/next.config.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,7 @@ module.exports = {
1313

1414
// Disable uglify. This has been fixed in https://github.com/developit/preact-compat/issues/155.
1515
// Can be removed once there is a new preact-compat release.
16-
config.plugins = config.plugins.filter((plugin) => {
17-
if (plugin.constructor.name === 'UglifyJsPlugin') {
18-
return false
19-
} else {
20-
return true
21-
}
22-
})
16+
config.plugins = config.plugins.filter((plugin) => (plugin.constructor.name !== 'UglifyJsPlugin'))
2317

2418
return config
2519
}

examples/with-apollo/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ In this simple example, we integrate Apollo seamlessly with Next by wrapping our
3131

3232
On initial page load, while on the server and inside `getInitialProps`, we invoke the Apollo method, [`getDataFromTree`](http://dev.apollodata.com/react/server-side-rendering.html#getDataFromTree). This method returns a promise; at the point in which the promise resolves, our Apollo Client store is completely initialized.
3333

34-
This example relies on [graph.cool](graph.cool) for its GraphQL backend.
34+
This example relies on [graph.cool](https://www.graph.cool) for its GraphQL backend.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
# Shallow Routing Example
3+
4+
## How to use
5+
6+
Download the example [or clone the repo](https://github.com/zeit/next.js):
7+
8+
```bash
9+
curl https://codeload.github.com/zeit/next.js/tar.gz/master | tar -xz --strip=2 next.js-master/examples/hello-world
10+
cd hello-world
11+
```
12+
13+
Install it and run:
14+
15+
```bash
16+
npm install
17+
npm run dev
18+
```
19+
20+
Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download))
21+
22+
```bash
23+
now
24+
```
25+
26+
## The idea behind the example
27+
28+
With shallow routing, we could change the URL without actually running the `getInitialProps` every time you change the URL.
29+
30+
We do this passing the `shallow: true` option to `Router.push` or `Router.replace`.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "with-shallow-routing",
3+
"version": "1.0.0",
4+
"scripts": {
5+
"dev": "next",
6+
"build": "next build",
7+
"start": "next start"
8+
},
9+
"dependencies": {
10+
"next": "next@beta",
11+
"react": "^15.4.2",
12+
"react-dom": "^15.4.2"
13+
},
14+
"author": "",
15+
"license": "ISC"
16+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default () => (
2+
<div>About us</div>
3+
)
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import React from 'react'
2+
import Link from 'next/link'
3+
import Router from 'next/router'
4+
import { format } from 'url'
5+
6+
let counter = 1
7+
8+
export default class Index extends React.Component {
9+
static getInitialProps ({ res }) {
10+
if (res) {
11+
return { initialPropsCounter: 1 }
12+
}
13+
14+
counter++
15+
return {
16+
initialPropsCounter: counter
17+
}
18+
}
19+
20+
reload () {
21+
const { pathname, query } = Router
22+
Router.push(format({ pathname, query }))
23+
}
24+
25+
incrementStateCounter () {
26+
const { url } = this.props
27+
const currentCounter = url.query.counter ? parseInt(url.query.counter) : 0
28+
const href = `/?counter=${currentCounter + 1}`
29+
Router.push(href, href, { shallow: true })
30+
}
31+
32+
render () {
33+
const { initialPropsCounter, url } = this.props
34+
35+
return (
36+
<div>
37+
<h2>This is the Home Page</h2>
38+
<Link href='/about'><a>About</a></Link>
39+
<button onClick={() => this.reload()}>Reload</button>
40+
<button onClick={() => this.incrementStateCounter()}>Change State Counter</button>
41+
<p>"getInitialProps" ran for "{initialPropsCounter}" times.</p>
42+
<p>Counter: "{url.query.counter || 0}".</p>
43+
</div>
44+
)
45+
}
46+
}

lib/app.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ export default class App extends Component {
1818

1919
render () {
2020
const { Component, props, hash, err, router } = this.props
21-
const containerProps = { Component, props, hash, router }
21+
const url = createUrl(router)
22+
const containerProps = { Component, props, hash, router, url }
2223

2324
return <div>
2425
<Container {...containerProps} />
@@ -52,8 +53,7 @@ class Container extends Component {
5253
}
5354

5455
render () {
55-
const { Component, props, router } = this.props
56-
const url = createUrl(router)
56+
const { Component, props, url } = this.props
5757

5858
// includes AppContainer which bypasses shouldComponentUpdate method
5959
// https://github.com/gaearon/react-hot-loader/issues/442
@@ -67,18 +67,27 @@ function createUrl (router) {
6767
return {
6868
query: router.query,
6969
pathname: router.pathname,
70-
back: () => router.back(),
71-
push: (url, as) => router.push(url, as),
70+
back: () => {
71+
warn(`Warning: 'url.back()' is deprecated. Use "window.history.back()"`)
72+
router.back()
73+
},
74+
push: (url, as) => {
75+
warn(`Warning: 'url.push()' is deprecated. Use "next/router" APIs.`)
76+
return router.push(url, as)
77+
},
7278
pushTo: (href, as) => {
73-
warn(`Warning: 'url.pushTo()' is deprecated. Please use 'url.push()' instead.`)
79+
warn(`Warning: 'url.pushTo()' is deprecated. Use "next/router" APIs.`)
7480
const pushRoute = as ? href : null
7581
const pushUrl = as || href
7682

7783
return router.push(pushRoute, pushUrl)
7884
},
79-
replace: (url, as) => router.replace(url, as),
85+
replace: (url, as) => {
86+
warn(`Warning: 'url.replace()' is deprecated. Use "next/router" APIs.`)
87+
return router.replace(url, as)
88+
},
8089
replaceTo: (href, as) => {
81-
warn(`Warning: 'url.replaceTo()' is deprecated. Please use 'url.replace()' instead.`)
90+
warn(`Warning: 'url.replaceTo()' is deprecated. Use "next/router" APIs.`)
8291
const replaceRoute = as ? href : null
8392
const replaceUrl = as || href
8493

lib/router/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* global window, location */
1+
/* global window */
22
import _Router from './router'
33

44
const SingletonRouter = {
@@ -81,6 +81,7 @@ export function _notifyBuildIdMismatch (nextRoute) {
8181
if (SingletonRouter.onAppUpdated) {
8282
SingletonRouter.onAppUpdated(nextRoute)
8383
} else {
84-
location.href = nextRoute
84+
console.warn(`An app update detected. Loading the SSR version of "${nextRoute}"`)
85+
window.location.href = nextRoute
8586
}
8687
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy